From befb7b4a56c09fef98191a3ae667ade7a72a9a8b Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Wed, 6 Apr 2022 13:59:35 +0000 Subject: [PATCH] [db] Type Prebuild.statusVersion as string due to bigint db represenation --- .../src/typeorm/entity/db-prebuilt-workspace.ts | 3 ++- components/gitpod-db/src/workspace-db.spec.db.ts | 8 ++++---- components/gitpod-protocol/src/protocol.ts | 10 +++++++++- .../server/ee/src/workspace/workspace-factory.ts | 2 +- components/ws-manager-bridge/ee/src/bridge.ts | 9 +++++---- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts index 22f3c5c6bfc795..77d3c10a3bcf98 100644 --- a/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts +++ b/components/gitpod-db/src/typeorm/entity/db-prebuilt-workspace.ts @@ -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; } diff --git a/components/gitpod-db/src/workspace-db.spec.db.ts b/components/gitpod-db/src/workspace-db.spec.db.ts index 5cb2dec8d02e05..c87f5f6f506119 100644 --- a/components/gitpod-db/src/workspace-db.spec.db.ts +++ b/components/gitpod-db/src/workspace-db.spec.db.ts @@ -247,7 +247,7 @@ class WorkspaceDBSpec { cloneURL: "", commit: "", state: "available", - statusVersion: 0, + statusVersion: "0", }); if (usageDaysAgo !== undefined) { const now = new Date(); @@ -510,7 +510,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "queued", - statusVersion: 0, + statusVersion: "0", }), // now and aborted this.storePrebuiltWorkspace({ @@ -520,7 +520,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "aborted", - statusVersion: 0, + statusVersion: "0", }), // completed over a minute ago this.storePrebuiltWorkspace({ @@ -530,7 +530,7 @@ class WorkspaceDBSpec { cloneURL: cloneURL, commit: "", state: "available", - statusVersion: 0, + statusVersion: "0", }), ]); diff --git a/components/gitpod-protocol/src/protocol.ts b/components/gitpod-protocol/src/protocol.ts index f8c29c862818e2..1eb1c49842fbfc 100644 --- a/components/gitpod-protocol/src/protocol.ts +++ b/components/gitpod-protocol/src/protocol.ts @@ -638,7 +638,7 @@ export interface PrebuiltWorkspace { buildWorkspaceId: string; creationTime: string; state: PrebuiltWorkspaceState; - statusVersion: number; + statusVersion: string; error?: string; snapshot?: string; } @@ -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 { diff --git a/components/server/ee/src/workspace/workspace-factory.ts b/components/server/ee/src/workspace/workspace-factory.ts index fb5acc2af0bc80..e5ea1a44204550 100644 --- a/components/server/ee/src/workspace/workspace-factory.ts +++ b/components/server/ee/src/workspace/workspace-factory.ts @@ -174,7 +174,7 @@ export class WorkspaceFactoryEE extends WorkspaceFactory { creationTime: new Date().toISOString(), projectId: ws.projectId, branch, - statusVersion: 0, + statusVersion: "0", }); log.debug( diff --git a/components/ws-manager-bridge/ee/src/bridge.ts b/components/ws-manager-bridge/ee/src/bridge.ts index b2576ef3ca5174..c3c1aad2c1ddb3 100644 --- a/components/ws-manager-bridge/ee/src/bridge.ts +++ b/components/ws-manager-bridge/ee/src/bridge.ts @@ -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() @@ -62,9 +62,10 @@ 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(); @@ -72,7 +73,7 @@ export class WorkspaceManagerBridgeEE extends WorkspaceManagerBridge { 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.