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..7981f65f76451d 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,8 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace { // statusVersion must only be set by controller/observer. @Column({ default: 0, + type: "bigint", + transformer: Transformer.MAP_BIGINT_TO_NUMBER, }) statusVersion: number; } diff --git a/components/gitpod-db/src/typeorm/transformer.ts b/components/gitpod-db/src/typeorm/transformer.ts index 552f62bddcd161..6219d1501879ff 100644 --- a/components/gitpod-db/src/typeorm/transformer.ts +++ b/components/gitpod-db/src/typeorm/transformer.ts @@ -63,6 +63,32 @@ export namespace Transformer { export const compose = (upper: ValueTransformer, lower: ValueTransformer) => { return new CompositeValueTransformer(upper, lower); }; + + export const MAP_BIGINT_TO_NUMBER: ValueTransformer = { + to(value: any): any { + // we expect to receive a number, as that's what our type system gives us. + const isNumber = typeof value === "number"; + if (!isNumber) { + return "0"; + } + + return value.toString(); + }, + from(value: any): any { + // the underlying representation of a BIGINT is a string + const isString = typeof value === "string" || value instanceof String; + if (!isString) { + return 0; + } + + const num = Number(value); + if (isNaN(num)) { + return 0; + } + + return num; + }, + }; } export class CompositeValueTransformer implements ValueTransformer { diff --git a/components/ws-manager-bridge/ee/src/bridge.ts b/components/ws-manager-bridge/ee/src/bridge.ts index b2576ef3ca5174..ee03aabf298182 100644 --- a/components/ws-manager-bridge/ee/src/bridge.ts +++ b/components/ws-manager-bridge/ee/src/bridge.ts @@ -51,6 +51,8 @@ export class WorkspaceManagerBridgeEE extends WorkspaceManagerBridge { const workspaceId = status.metadata!.metaId!; const logCtx: LogContext = { instanceId, workspaceId, userId }; + log.info("Handling prebuild workspace update.", status); + const span = TraceContext.startSpan("updatePrebuiltWorkspace", ctx); try { const prebuild = await this.workspaceDB.trace({ span }).findPrebuildByWorkspaceID(status.metadata!.metaId!); @@ -61,15 +63,12 @@ export class WorkspaceManagerBridgeEE extends WorkspaceManagerBridge { } span.setTag("updatePrebuiltWorkspace.prebuildId", prebuild.id); span.setTag("updatePrebuiltWorkspace.workspaceInstance.statusVersion", status.statusVersion); + log.info("Found prebuild record in database.", prebuild); if (prebuild.statusVersion <= 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) { - // 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;