Skip to content

Commit 48aff21

Browse files
csweichelroboquat
authored andcommitted
[ws-manager-bridge] Use WS update status version
1 parent 5bb6e2a commit 48aff21

File tree

8 files changed

+366
-271
lines changed

8 files changed

+366
-271
lines changed

components/ee/payment-endpoint/src/accounting/account-service.spec.db.ts

Lines changed: 335 additions & 271 deletions
Large diffs are not rendered by default.

components/gitpod-db/src/user-db.spec.db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ namespace TestData {
218218
deployedTime: undefined,
219219
stoppedTime: undefined,
220220
status: {
221+
version: 1,
221222
phase: "preparing",
222223
conditions: {},
223224
},

components/gitpod-db/src/workspace-db.spec.db.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class WorkspaceDBSpec {
5858
stoppingTime: undefined,
5959
stoppedTime: undefined,
6060
status: {
61+
version: 1,
6162
phase: "preparing",
6263
conditions: {},
6364
},
@@ -81,6 +82,7 @@ class WorkspaceDBSpec {
8182
stoppingTime: undefined,
8283
stoppedTime: undefined,
8384
status: {
85+
version: 1,
8486
phase: "running",
8587
conditions: {},
8688
},
@@ -119,6 +121,7 @@ class WorkspaceDBSpec {
119121
stoppingTime: undefined,
120122
stoppedTime: undefined,
121123
status: {
124+
version: 1,
122125
phase: "preparing",
123126
conditions: {},
124127
},
@@ -157,6 +160,7 @@ class WorkspaceDBSpec {
157160
stoppingTime: undefined,
158161
stoppedTime: undefined,
159162
status: {
163+
version: 1,
160164
phase: "preparing",
161165
conditions: {},
162166
},

components/gitpod-protocol/src/workspace-instance.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export interface WorkspaceInstance {
7272

7373
// WorkspaceInstanceStatus describes the current state of a workspace instance
7474
export interface WorkspaceInstanceStatus {
75+
// version is the current version of the workspace instance status
76+
// Note: consider this value opague. The only guarantee given is that it imposes
77+
// a partial order on status updates, i.e. a.version > b.version -> a newer than b.
78+
version?: number;
79+
7580
// phase describes a high-level state of the workspace instance
7681
phase: WorkspaceInstancePhase;
7782

components/server/src/auth/resource-access.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ class TestResourceAccess {
585585
creationTime: new Date(2000, 1, 2).toISOString(),
586586
region: "local",
587587
status: {
588+
version: 1,
588589
conditions: {},
589590
phase: "running",
590591
},

components/server/src/workspace/workspace-starter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ export class WorkspaceStarter {
780780
region: this.config.installationShortname, // Shortname set to bridge can cleanup workspaces stuck preparing
781781
workspaceImage: "", // Initially empty, filled during starting process
782782
status: {
783+
version: 0,
783784
conditions: {},
784785
phase: "preparing",
785786
},

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export class WorkspaceManagerBridge implements Disposable {
227227
const span = TraceContext.startSpan("handleStatusUpdate", ctx);
228228
span.setTag("status", JSON.stringify(filterStatus(status)));
229229
span.setTag("writeToDB", writeToDB);
230+
span.setTag("statusVersion", status.statusVersion);
230231
try {
231232
// Beware of the ID mapping here: What's a workspace to the ws-manager is a workspace instance to the rest of the system.
232233
// The workspace ID of ws-manager is the workspace instance ID in the database.
@@ -252,6 +253,14 @@ export class WorkspaceManagerBridge implements Disposable {
252253
return;
253254
}
254255

256+
const currentStatusVersion = instance.status.version || 0;
257+
if (currentStatusVersion > 0 && currentStatusVersion >= status.statusVersion) {
258+
// We've gotten an event which is older than one we've already processed. We shouldn't process the stale one.
259+
span.setTag("statusUpdate.staleEvent", true);
260+
this.prometheusExporter.recordStaleStatusUpdate();
261+
log.debug(ctx, "Stale status update received, skipping.");
262+
}
263+
255264
if (!!status.spec.exposedPortsList) {
256265
instance.status.exposedPorts = status.spec.exposedPortsList.map((p) => {
257266
return <WorkspaceInstancePort>{
@@ -269,6 +278,7 @@ export class WorkspaceManagerBridge implements Disposable {
269278
}
270279

271280
instance.ideUrl = status.spec.url!;
281+
instance.status.version = status.statusVersion;
272282
instance.status.timeout = status.spec.timeout;
273283
if (!!instance.status.conditions.failed && !status.conditions.failed) {
274284
// We already have a "failed" condition, and received an empty one: This is a bug, "failed" conditions are terminal per definition.

components/ws-manager-bridge/src/prometheus-metrics-exporter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class PrometheusMetricsExporter {
1717
protected readonly clusterScore: prom.Gauge<string>;
1818
protected readonly clusterCordoned: prom.Gauge<string>;
1919
protected readonly statusUpdatesTotal: prom.Counter<string>;
20+
protected readonly staleStatusUpdatesTotal: prom.Counter<string>;
2021
protected readonly stalePrebuildEventsTotal: prom.Counter<string>;
2122
protected readonly prebuildsCompletedTotal: prom.Counter<string>;
2223

@@ -53,6 +54,10 @@ export class PrometheusMetricsExporter {
5354
help: "Total workspace status updates received",
5455
labelNames: ["workspace_cluster", "known_instance"],
5556
});
57+
this.staleStatusUpdatesTotal = new prom.Counter({
58+
name: "gitpod_ws_manager_bridge_stale_status_updates_total",
59+
help: "Total count of stale status updates received by workspace manager bridge",
60+
});
5661
this.stalePrebuildEventsTotal = new prom.Counter({
5762
name: "gitpod_ws_manager_bridge_stale_prebuild_events_total",
5863
help: "Total count of stale prebuild events received by workspace manager bridge",
@@ -129,6 +134,10 @@ export class PrometheusMetricsExporter {
129134
this.statusUpdatesTotal.labels(installation, knownInstance ? "true" : "false").inc();
130135
}
131136

137+
recordStaleStatusUpdate(): void {
138+
this.staleStatusUpdatesTotal.inc();
139+
}
140+
132141
recordStalePrebuildEvent(): void {
133142
this.stalePrebuildEventsTotal.inc();
134143
}

0 commit comments

Comments
 (0)