Skip to content

Commit 062a78c

Browse files
author
Laurie T. Malau
committed
[bridge] Mark as stopped pending and stopping
1 parent aeb4485 commit 062a78c

File tree

15 files changed

+83
-50
lines changed

15 files changed

+83
-50
lines changed

components/ws-manager-bridge/src/bridge.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,13 @@ export class WorkspaceManagerBridge implements Disposable {
452452

453453
// Control running workspace instances against ws-manager
454454
try {
455-
await this.controlNonStoppedWSManagerManagedInstances(ctx, nonStoppedInstances, clientProvider);
455+
await this.controlNonStoppedWSManagerManagedInstances(
456+
ctx,
457+
nonStoppedInstances,
458+
clientProvider,
459+
this.config.timeouts.pendingPhaseSeconds,
460+
this.config.timeouts.stoppingPhaseSeconds,
461+
);
456462

457463
disconnectStarted = Number.MAX_SAFE_INTEGER; // Reset disconnect period
458464
} catch (err) {
@@ -489,6 +495,8 @@ export class WorkspaceManagerBridge implements Disposable {
489495
parentCtx: TraceContext,
490496
runningInstances: RunningWorkspaceInfo[],
491497
clientProvider: ClientProvider,
498+
pendingPhaseSeconds: number,
499+
stoppingPhaseSeconds: number,
492500
) {
493501
const installation = this.config.installation;
494502

@@ -508,36 +516,33 @@ export class WorkspaceManagerBridge implements Disposable {
508516
for (const [instanceId, ri] of runningInstancesIdx.entries()) {
509517
const instance = ri.latestInstance;
510518
const phase = instance.status.phase;
511-
if (phase !== "running") {
512-
// This below if block is to validate the planned fix
513-
if (
514-
phase === "pending" ||
515-
phase === "creating" ||
516-
phase === "initializing" ||
517-
(phase === "stopping" &&
518-
instance.stoppingTime &&
519-
durationLongerThanSeconds(Date.parse(instance.stoppingTime), 10))
520-
) {
521-
log.info(
522-
{ instanceId, workspaceId: instance.workspaceId },
523-
"Logging to validate #12902. Should mark as stopped in database.",
524-
{ installation },
525-
{ phase },
526-
);
527-
}
528-
log.debug({ instanceId }, "Skipping instance", {
529-
phase: instance.status.phase,
530-
creationTime: instance.creationTime,
531-
region: instance.region,
532-
});
519+
520+
// When ws-manager is not aware of the following instances outside of the timeout duration,
521+
// they should be marked as stopped.
522+
// pending states timeout is 1 hour after creationTime.
523+
// stopping states timeout is 1 hour after stoppingTime.
524+
if (
525+
phase === "running" ||
526+
(phase === "pending" &&
527+
durationLongerThanSeconds(Date.parse(instance.creationTime), pendingPhaseSeconds)) ||
528+
(phase === "stopping" &&
529+
instance.stoppingTime &&
530+
durationLongerThanSeconds(Date.parse(instance.stoppingTime), stoppingPhaseSeconds))
531+
) {
532+
log.info(
533+
{ instanceId, workspaceId: instance.workspaceId },
534+
"Database says the instance is present, but ws-man does not know about it. Marking as stopped in database.",
535+
{ installation, phase },
536+
);
537+
await this.markWorkspaceInstanceAsStopped(ctx, ri, new Date());
533538
continue;
534539
}
535540

536-
log.info(
537-
"Database says the instance is running, but wsman does not know about it. Marking as stopped in database.",
538-
{ instanceId, workspaceId: instance.workspaceId, installation, phase },
539-
);
540-
await this.markWorkspaceInstanceAsStopped(ctx, ri, new Date());
541+
log.debug({ instanceId }, "Skipping instance", {
542+
phase: phase,
543+
creationTime: instance.creationTime,
544+
region: instance.region,
545+
});
541546
}
542547

543548
log.debug("Done controlling running instances.", { installation });

components/ws-manager-bridge/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface Configuration {
3131
preparingPhaseSeconds: number;
3232
buildingPhaseSeconds: number;
3333
unknownPhaseSeconds: number;
34+
pendingPhaseSeconds: number;
35+
stoppingPhaseSeconds: number;
3436
};
3537

3638
// emulatePreparingIntervalSeconds configures how often we check for Workspaces in phase "preparing" for clusters we do not govern

install/installer/cmd/testdata/render/aws-setup/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/azure-setup/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/customization/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/external-registry/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/gcp-setup/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/http-proxy/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/insecure-s3-setup/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/minimal/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/statefulset-customization/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/use-pod-security-policies/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/cmd/testdata/render/workspace-requests-limits/output.golden

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install/installer/pkg/components/ws-manager-bridge/configmap.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
2828
PreparingPhaseSeconds: 3600,
2929
BuildingPhaseSeconds: 3600,
3030
UnknownPhaseSeconds: 600,
31+
PendingPhaseSeconds: 3600,
32+
StoppingPhaseSeconds: 3600,
3133
},
3234
EmulatePreparingIntervalSeconds: 10,
3335
StaticBridges: WSManagerList(ctx),

install/installer/pkg/components/ws-manager-bridge/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Timeouts struct {
2626
PreparingPhaseSeconds int32 `json:"preparingPhaseSeconds"`
2727
BuildingPhaseSeconds int32 `json:"buildingPhaseSeconds"`
2828
UnknownPhaseSeconds int32 `json:"unknownPhaseSeconds"`
29+
PendingPhaseSeconds int32 `json:"pendingPhaseSeconds"`
30+
StoppingPhaseSeconds int32 `json:"stoppingPhaseSeconds"`
2931
}
3032

3133
// WorkspaceCluster from components/gitpod-protocol/src/workspace-cluster.ts

0 commit comments

Comments
 (0)