Skip to content

Commit c54c7ca

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

File tree

15 files changed

+67
-50
lines changed

15 files changed

+67
-50
lines changed

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

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,12 @@ 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.maxInstanceDuration,
460+
);
456461

457462
disconnectStarted = Number.MAX_SAFE_INTEGER; // Reset disconnect period
458463
} catch (err) {
@@ -489,6 +494,7 @@ export class WorkspaceManagerBridge implements Disposable {
489494
parentCtx: TraceContext,
490495
runningInstances: RunningWorkspaceInfo[],
491496
clientProvider: ClientProvider,
497+
maxInstanceDuration: number,
492498
) {
493499
const installation = this.config.installation;
494500

@@ -508,36 +514,33 @@ export class WorkspaceManagerBridge implements Disposable {
508514
for (const [instanceId, ri] of runningInstancesIdx.entries()) {
509515
const instance = ri.latestInstance;
510516
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-
});
517+
518+
// When ws-manager is not aware of the following instances outside of the timeout duration,
519+
// they should be marked as stopped.
520+
// pending states timeout is 1 hour after creationTime.
521+
// stopping states timeout is 1 hour after stoppingTime.
522+
if (
523+
(phase === "pending" &&
524+
durationLongerThanSeconds(Date.parse(instance.creationTime), maxInstanceDuration)) ||
525+
(phase === "stopping" &&
526+
instance.stoppingTime &&
527+
durationLongerThanSeconds(Date.parse(instance.stoppingTime), maxInstanceDuration))
528+
) {
529+
log.info(
530+
{ instanceId, workspaceId: instance.workspaceId },
531+
"Database says the instance is running, but ws-man does not know about it. Marking as stopped in database.",
532+
{ installation },
533+
{ phase },
534+
);
535+
await this.markWorkspaceInstanceAsStopped(ctx, ri, new Date());
533536
continue;
534537
}
535538

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());
539+
log.debug({ instanceId }, "Skipping instance", {
540+
phase: phase,
541+
creationTime: instance.creationTime,
542+
region: instance.region,
543+
});
541544
}
542545

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface Configuration {
3131
preparingPhaseSeconds: number;
3232
buildingPhaseSeconds: number;
3333
unknownPhaseSeconds: number;
34+
maxInstanceDuration: number;
3435
};
3536

3637
// 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: 3 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: 3 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: 3 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: 3 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: 3 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: 3 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: 3 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: 3 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: 3 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: 3 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: 3 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
2828
PreparingPhaseSeconds: 3600,
2929
BuildingPhaseSeconds: 3600,
3030
UnknownPhaseSeconds: 600,
31+
MaxInstanceDuration: 3600,
3132
},
3233
EmulatePreparingIntervalSeconds: 10,
3334
StaticBridges: WSManagerList(ctx),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Timeouts struct {
2626
PreparingPhaseSeconds int32 `json:"preparingPhaseSeconds"`
2727
BuildingPhaseSeconds int32 `json:"buildingPhaseSeconds"`
2828
UnknownPhaseSeconds int32 `json:"unknownPhaseSeconds"`
29+
MaxInstanceDuration int32 `json:"maxInstanceDuration"`
2930
}
3031

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

0 commit comments

Comments
 (0)