Skip to content

Commit

Permalink
[db] Type Prebuild.statusVersion as string due to bigint db represena…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
easyCZ committed Apr 6, 2022
1 parent 5816e45 commit befb7b4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace {
// statusVersion must only be set by controller/observer.
@Column({
default: 0,
type: "bigint",
})
statusVersion: number;
statusVersion: string;
}
8 changes: 4 additions & 4 deletions components/gitpod-db/src/workspace-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class WorkspaceDBSpec {
cloneURL: "",
commit: "",
state: "available",
statusVersion: 0,
statusVersion: "0",
});
if (usageDaysAgo !== undefined) {
const now = new Date();
Expand Down Expand Up @@ -510,7 +510,7 @@ class WorkspaceDBSpec {
cloneURL: cloneURL,
commit: "",
state: "queued",
statusVersion: 0,
statusVersion: "0",
}),
// now and aborted
this.storePrebuiltWorkspace({
Expand All @@ -520,7 +520,7 @@ class WorkspaceDBSpec {
cloneURL: cloneURL,
commit: "",
state: "aborted",
statusVersion: 0,
statusVersion: "0",
}),
// completed over a minute ago
this.storePrebuiltWorkspace({
Expand All @@ -530,7 +530,7 @@ class WorkspaceDBSpec {
cloneURL: cloneURL,
commit: "",
state: "available",
statusVersion: 0,
statusVersion: "0",
}),
]);

Expand Down
10 changes: 9 additions & 1 deletion components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export interface PrebuiltWorkspace {
buildWorkspaceId: string;
creationTime: string;
state: PrebuiltWorkspaceState;
statusVersion: number;
statusVersion: string;
error?: string;
snapshot?: string;
}
Expand All @@ -655,6 +655,14 @@ export namespace PrebuiltWorkspace {
export function buildDidSucceed(pws: PrebuiltWorkspace) {
return pws.state === "available" && !pws.error;
}

export function getStatusVersion(pws: PrebuiltWorkspace): number {
const n = Number(pws.statusVersion);
if (isNaN(n)) {
return 0;
}
return n;
}
}

export interface PrebuiltWorkspaceUpdatable {
Expand Down
2 changes: 1 addition & 1 deletion components/server/ee/src/workspace/workspace-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory {
creationTime: new Date().toISOString(),
projectId: ws.projectId,
branch,
statusVersion: 0,
statusVersion: "0",
});

log.debug(
Expand Down
9 changes: 5 additions & 4 deletions components/ws-manager-bridge/ee/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { injectable } from "inversify";
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
import { WorkspaceStatus, WorkspaceType, WorkspacePhase } from "@gitpod/ws-manager/lib";
import { HeadlessWorkspaceEvent, HeadlessWorkspaceEventType } from "@gitpod/gitpod-protocol/lib/headless-workspace-log";
import { WorkspaceInstance } from "@gitpod/gitpod-protocol";
import { WorkspaceInstance, PrebuiltWorkspace } from "@gitpod/gitpod-protocol";
import { log, LogContext } from "@gitpod/gitpod-protocol/lib/util/logging";

@injectable()
Expand Down Expand Up @@ -62,17 +62,18 @@ export class WorkspaceManagerBridgeEE extends WorkspaceManagerBridge {
span.setTag("updatePrebuiltWorkspace.prebuildId", prebuild.id);
span.setTag("updatePrebuiltWorkspace.workspaceInstance.statusVersion", status.statusVersion);

if (prebuild.statusVersion <= status.statusVersion) {
const prebuildStatusVersion = PrebuiltWorkspace.getStatusVersion(prebuild);
if (prebuildStatusVersion <= status.statusVersion) {
// prebuild.statusVersion = 0 is the default value in the DB, these shouldn't be counted as stale in our metrics
if (prebuild.statusVersion > 0) {
if (prebuildStatusVersion > 0) {
// We've gotten an event which is younger than one we've already processed. We shouldn't process the stale one.
span.setTag("updatePrebuiltWorkspace.staleEvent", true);
this.prometheusExporter.recordStalePrebuildEvent();
log.info(logCtx, "Stale prebuild event received, skipping.");
return;
}
}
prebuild.statusVersion = status.statusVersion;
prebuild.statusVersion = String(status.statusVersion);

if (prebuild.state === "queued") {
// We've received an update from ws-man for this workspace, hence it must be running.
Expand Down

0 comments on commit befb7b4

Please sign in to comment.