Skip to content

Commit b897e67

Browse files
committed
Generate better workspace ids
1 parent 5642433 commit b897e67

30 files changed

+1416
-128
lines changed

components/common-go/namegen/workspaceid.go

Lines changed: 481 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package namegen_test
6+
7+
import (
8+
"testing"
9+
10+
"github.com/gitpod-io/gitpod/common-go/namegen"
11+
)
12+
13+
func TestGenerateWorkspaceID(t *testing.T) {
14+
15+
for i := 0; i < 1000; i++ {
16+
name, err := namegen.GenerateWorkspaceID()
17+
if err != nil {
18+
t.Error(err)
19+
}
20+
if !namegen.WorkspaceIdPattern.MatchString(name) {
21+
t.Errorf("The workspace id \"%s\" didn't met the expectation.", name)
22+
}
23+
}
24+
}

components/ee/ws-scheduler/pkg/scaler/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/gitpod-io/gitpod/common-go/log"
14+
"github.com/gitpod-io/gitpod/common-go/namegen"
1415
"github.com/gitpod-io/gitpod/common-go/util"
1516
csapi "github.com/gitpod-io/gitpod/content-service/api"
1617
"github.com/gitpod-io/gitpod/ws-manager/api"
@@ -241,11 +242,10 @@ func (wspd *WorkspaceManagerPrescaleDriver) startGhostWorkspaces(ctx context.Con
241242
}
242243
instanceID := instanceUUID.String()
243244
ids[i] = instanceID
244-
metaUUID, err := uuid.NewRandom()
245+
metaID, err := namegen.GenerateWorkspaceID()
245246
if err != nil {
246247
return nil, err
247248
}
248-
metaID := metaUUID.String()
249249

250250
_, err = wspd.Client.StartWorkspace(ctx, &api.StartWorkspaceRequest{
251251
Type: api.WorkspaceType_GHOST,

components/gitpod-db/src/typeorm/entity/db-layout-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import { PrimaryColumn, Column, Entity } from "typeorm";
88

99
import { LayoutData } from "@gitpod/gitpod-protocol";
10-
import { TypeORM } from "../typeorm";
1110
import { Transformer } from "../transformer";
11+
import { TypeORM } from "../typeorm";
1212

1313
@Entity()
1414
export class DBLayoutData implements LayoutData {
1515

16-
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
16+
@PrimaryColumn(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
1717
workspaceId: string;
1818

1919
@Column({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class DBPrebuiltWorkspace implements PrebuiltWorkspace {
3535
})
3636
creationTime: string;
3737

38-
@Column(TypeORM.UUID_COLUMN_TYPE)
38+
@Column(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
3939
@Index('ind_buildWorkspaceId')
4040
buildWorkspaceId: string;
4141

components/gitpod-db/src/typeorm/entity/db-snapshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class DBSnapshot implements Snapshot {
2424
})
2525
creationTime: string;
2626

27-
@Column(TypeORM.UUID_COLUMN_TYPE)
27+
@Column(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
2828
@Index("ind_originalWorkspaceId")
2929
originalWorkspaceId: string;
3030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class DBWorkspaceInstance implements WorkspaceInstance {
1818
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
1919
id: string;
2020

21-
@Column(TypeORM.UUID_COLUMN_TYPE)
21+
@Column(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
2222
@Index()
2323
workspaceId: string;
2424

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Transformer } from "../transformer";
1313
@Entity()
1414
// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync
1515
export class DBWorkspace implements Workspace {
16-
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
16+
@PrimaryColumn(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
1717
id: string;
1818

1919
@Column("varchar")

components/gitpod-db/src/typeorm/typeorm.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class TypeORM {
1818
type: 'char',
1919
length: 36
2020
};
21+
static readonly WORKSPACE_ID_COLUMN_TYPE: ColumnOptions = {
22+
type: 'char',
23+
length: 36
24+
};
2125

2226
static defaultOptions(dir: string): ConnectionOptions {
2327
console.log(`Loading TypeORM entities and migrations from ${dir}`);

components/gitpod-protocol/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"devDependencies": {
1313
"@types/chai-subset": "^1.3.1",
1414
"@types/js-yaml": "^3.10.1",
15+
"@types/random-number-csprng": "^1.0.0",
1516
"@types/uuid": "^3.4.5",
1617
"@types/ws": "^5.1.2",
1718
"chai": "^4.1.2",
@@ -38,6 +39,7 @@
3839
"js-yaml": "^3.10.0",
3940
"opentracing": "^0.14.4",
4041
"prom-client": "^10.2.0",
42+
"random-number-csprng": "^1.0.2",
4143
"reconnecting-websocket": "^4.2.0",
4244
"reflect-metadata": "^0.1.10",
4345
"uuid": "^3.3.3",

0 commit comments

Comments
 (0)