Skip to content

Commit 5bb738a

Browse files
Add WS image metrics to workspace instances (#20426)
* Add WS image metrics to workspace instances * Update tests * fix ws-manager-api field description * Prefer existing DB values for metrics * Copy proto comments over to protocol type
1 parent c4d3eb3 commit 5bb738a

File tree

25 files changed

+2240
-589
lines changed

25 files changed

+2240
-589
lines changed

components/gitpod-db/src/typeorm/entity/db-workspace-instance.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
WorkspaceInstanceConfiguration,
1414
ImageBuildInfo,
1515
WorkspaceInstanceRepoStatus,
16+
WorkspaceInstanceMetrics,
1617
} from "@gitpod/gitpod-protocol";
1718
import { TypeORM } from "../typeorm";
1819
import { Transformer } from "../transformer";
@@ -84,7 +85,7 @@ export class DBWorkspaceInstance implements WorkspaceInstance {
8485
gitStatus?: WorkspaceInstanceRepoStatus;
8586

8687
/**
87-
* This field is a databse-only copy of status.phase for the sole purpose of creating indexes on it.
88+
* This field is a database-only copy of status.phase for the sole purpose of creating indexes on it.
8889
* Is replicated inside workspace-db-impl.ts/storeInstance.
8990
*/
9091
@Column({
@@ -117,4 +118,10 @@ export class DBWorkspaceInstance implements WorkspaceInstance {
117118
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED,
118119
})
119120
usageAttributionId?: string;
121+
122+
@Column({
123+
type: "simple-json",
124+
nullable: true,
125+
})
126+
metrics?: WorkspaceInstanceMetrics;
120127
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2024 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { columnExists } from "./helper/helper";
9+
10+
const table = "d_b_workspace_instance";
11+
const newColumn = "metrics";
12+
13+
export class AddWorkspaceInstanceMetrics1733397172273 implements MigrationInterface {
14+
public async up(queryRunner: QueryRunner): Promise<void> {
15+
if (!(await columnExists(queryRunner, table, newColumn))) {
16+
await queryRunner.query(`ALTER TABLE ${table} ADD COLUMN ${newColumn} JSON NULL`);
17+
}
18+
}
19+
20+
public async down(queryRunner: QueryRunner): Promise<void> {
21+
if (await columnExists(queryRunner, table, newColumn)) {
22+
await queryRunner.query(`ALTER TABLE ${table} DROP COLUMN ${newColumn}`);
23+
}
24+
}
25+
}

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

+24-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export interface WorkspaceInstance {
7575
// WorkspaceInstanceStatus describes the current state of a workspace instance
7676
export interface WorkspaceInstanceStatus {
7777
// version is the current version of the workspace instance status
78-
// Note: consider this value opague. The only guarantee given is that it imposes
78+
// Note: consider this value opaque. The only guarantee given is that it imposes
7979
// a partial order on status updates, i.e. a.version > b.version -> a newer than b.
8080
version?: number;
8181

@@ -105,6 +105,9 @@ export interface WorkspaceInstanceStatus {
105105

106106
// ownerToken is the token one needs to access the workspace. Its presence is checked by ws-proxy.
107107
ownerToken?: string;
108+
109+
// metrics contains metrics about the workspace instance
110+
metrics?: WorkspaceInstanceMetrics;
108111
}
109112

110113
// WorkspaceInstancePhase describes a high-level state of a workspace instance
@@ -122,11 +125,11 @@ export type WorkspaceInstancePhase =
122125
| "building"
123126

124127
// Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
125-
// some space within the cluster. If for example the cluster needs to scale up to accomodate the
128+
// some space within the cluster. If for example the cluster needs to scale up to accommodate the
126129
// workspace, the workspace will be in Pending state until that happened.
127130
| "pending"
128131

129-
// Creating means the workspace is currently being created. Thati includes downloading the images required
132+
// Creating means the workspace is currently being created. That includes downloading the images required
130133
// to run the workspace over the network. The time spent in this phase varies widely and depends on the current
131134
// network speed, image size and cache states.
132135
| "creating"
@@ -193,7 +196,7 @@ export interface WorkspaceInstancePort {
193196
// The outward-facing port number
194197
port: number;
195198

196-
// The visiblity of this port. Optional for backwards compatibility.
199+
// The visibility of this port. Optional for backwards compatibility.
197200
visibility?: PortVisibility;
198201

199202
// Public, outward-facing URL where the port can be accessed on.
@@ -280,7 +283,7 @@ export interface IdeSetup {
280283
// WorkspaceInstanceConfiguration contains all per-instance configuration
281284
export interface WorkspaceInstanceConfiguration {
282285
// theiaVersion is the version of Theia this workspace instance uses
283-
// @deprected: replaced with the ideImage field
286+
// @deprecated: replaced with the ideImage field
284287
theiaVersion?: string;
285288

286289
// feature flags are the lowercase feature-flag names as passed to ws-manager
@@ -324,3 +327,19 @@ export interface ImageBuildLogInfo {
324327
url: string;
325328
headers: { [key: string]: string };
326329
}
330+
331+
/**
332+
* Holds metrics about the workspace instance
333+
*/
334+
export interface WorkspaceInstanceMetrics {
335+
image?: Partial<{
336+
/**
337+
* the total size of the image in bytes (includes Gitpod-specific layers like IDE)
338+
*/
339+
totalSize: number;
340+
/**
341+
* the size of the workspace image in bytes
342+
*/
343+
workspaceImageSize: number;
344+
}>;
345+
}

components/public-api/gitpod/v1/workspace.proto

+10
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,14 @@ message WorkspaceSnapshot {
884884
}
885885

886886
message WorkspaceSession {
887+
message Metrics {
888+
// workspace_image_size is the size of the workspace image in bytes
889+
int64 workspace_image_size = 1;
890+
891+
// total_image_size is the total size of the image in bytes (includes Gitpod-specific layers like IDE)
892+
int64 total_image_size = 2;
893+
}
894+
887895
string id = 1;
888896

889897
Workspace workspace = 2;
@@ -893,4 +901,6 @@ message WorkspaceSession {
893901
google.protobuf.Timestamp started_time = 5;
894902
google.protobuf.Timestamp stopping_time = 6;
895903
google.protobuf.Timestamp stopped_time = 7;
904+
905+
Metrics metrics = 8;
896906
}

0 commit comments

Comments
 (0)