Skip to content

[db] Add statusVersion to prebuilds to track status version #9114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace {
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED,
})
error?: string;

// statusVersion defines the last observed stateVersion from a WorkspaceStatus. See ws-manager-api/core.proto.
// statusVersion must only be set by controller/observer.
@Column({
default: 0,
})
statusVersion: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { MigrationInterface, QueryRunner } from "typeorm";
import { columnExists } from "./helper/helper";

export class PrebuildStatusVersionColumn1649107789640 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
if (!(await columnExists(queryRunner, TABLE_NAME, COLUMN_NAME))) {
await queryRunner.query(
`ALTER TABLE ${TABLE_NAME} ADD COLUMN \`${COLUMN_NAME}\` BIGINT(20) NOT NULL DEFAULT '0'`,
);
}
}

public async down(queryRunner: QueryRunner): Promise<void> {}
}
4 changes: 4 additions & 0 deletions components/gitpod-db/src/workspace-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class WorkspaceDBSpec {
cloneURL: "",
commit: "",
state: "available",
statusVersion: 0,
});
if (usageDaysAgo !== undefined) {
const now = new Date();
Expand Down Expand Up @@ -509,6 +510,7 @@ class WorkspaceDBSpec {
cloneURL: cloneURL,
commit: "",
state: "queued",
statusVersion: 0,
}),
// now and aborted
this.storePrebuiltWorkspace({
Expand All @@ -518,6 +520,7 @@ class WorkspaceDBSpec {
cloneURL: cloneURL,
commit: "",
state: "aborted",
statusVersion: 0,
}),
// completed over a minute ago
this.storePrebuiltWorkspace({
Expand All @@ -527,6 +530,7 @@ class WorkspaceDBSpec {
cloneURL: cloneURL,
commit: "",
state: "available",
statusVersion: 0,
}),
]);

Expand Down
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ export interface PrebuiltWorkspace {
buildWorkspaceId: string;
creationTime: string;
state: PrebuiltWorkspaceState;
statusVersion: number;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely happy that the statusVersion needs to be exposed in the protocol and sent to clients. Is there a way (without significantly changing the system) to have this data only available to internal components and continue not having it in clients?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue not having it in clients?

You could :

  1. introduce a sub-shape of that we use in protocol, and a more expanded shape we expose in GitpodService
  2. and hand-remove this field when sending it to clients (we do this with some sensitive field of WorkspaceInstance in GitpodServerImpl)
  3. but I'm not sure it warrant's the effort, now and for this single field. Let's hope make it better with the new API 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's what I was thinking as well. Unless there is a strong objection, I'll leave it as is for now.

error?: string;
snapshot?: string;
}
Expand Down