@gitpod/gitpod-protocol 0.1.5-pavel-git-status-fix.5 → 0.1.5-pavel-fixlog.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/lib/accounting-protocol.d.ts +1 -0
  2. package/lib/accounting-protocol.d.ts.map +1 -1
  3. package/lib/accounting-protocol.js +4 -0
  4. package/lib/accounting-protocol.js.map +1 -1
  5. package/lib/admin-protocol.d.ts +1 -1
  6. package/lib/admin-protocol.d.ts.map +1 -1
  7. package/lib/billing-mode.d.ts +36 -0
  8. package/lib/billing-mode.d.ts.map +1 -0
  9. package/lib/billing-mode.js +45 -0
  10. package/lib/billing-mode.js.map +1 -0
  11. package/lib/experiments/configcat-server.d.ts +2 -0
  12. package/lib/experiments/configcat-server.d.ts.map +1 -1
  13. package/lib/experiments/configcat-server.js +2 -1
  14. package/lib/experiments/configcat-server.js.map +1 -1
  15. package/lib/gitpod-service.d.ts +16 -3
  16. package/lib/gitpod-service.d.ts.map +1 -1
  17. package/lib/gitpod-service.js +1 -1
  18. package/lib/gitpod-service.js.map +1 -1
  19. package/lib/index.d.ts +1 -0
  20. package/lib/index.d.ts.map +1 -1
  21. package/lib/index.js +1 -0
  22. package/lib/index.js.map +1 -1
  23. package/lib/messaging/client-call-metrics.d.ts +1 -17
  24. package/lib/messaging/client-call-metrics.d.ts.map +1 -1
  25. package/lib/messaging/client-call-metrics.js +1 -2
  26. package/lib/messaging/client-call-metrics.js.map +1 -1
  27. package/lib/messaging/error.d.ts +3 -1
  28. package/lib/messaging/error.d.ts.map +1 -1
  29. package/lib/messaging/error.js +7 -3
  30. package/lib/messaging/error.js.map +1 -1
  31. package/lib/protocol.d.ts +9 -2
  32. package/lib/protocol.d.ts.map +1 -1
  33. package/lib/protocol.js +1 -1
  34. package/lib/protocol.js.map +1 -1
  35. package/lib/team-subscription-protocol.d.ts +1 -0
  36. package/lib/team-subscription-protocol.d.ts.map +1 -1
  37. package/lib/team-subscription-protocol.js +4 -0
  38. package/lib/team-subscription-protocol.js.map +1 -1
  39. package/lib/teams-projects-protocol.d.ts +12 -0
  40. package/lib/teams-projects-protocol.d.ts.map +1 -1
  41. package/lib/teams-projects-protocol.js.map +1 -1
  42. package/lib/usage.d.ts +11 -2
  43. package/lib/usage.d.ts.map +1 -1
  44. package/lib/usage.js +6 -107
  45. package/lib/usage.js.map +1 -1
  46. package/lib/util/gitpod-host-url.d.ts +3 -0
  47. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  48. package/lib/util/gitpod-host-url.js +18 -0
  49. package/lib/util/gitpod-host-url.js.map +1 -1
  50. package/lib/util/grpc.d.ts +19 -0
  51. package/lib/util/grpc.d.ts.map +1 -1
  52. package/lib/util/grpc.js +73 -1
  53. package/lib/util/grpc.js.map +1 -1
  54. package/lib/webhook-event.d.ts +44 -0
  55. package/lib/webhook-event.d.ts.map +1 -0
  56. package/lib/webhook-event.js +8 -0
  57. package/lib/webhook-event.js.map +1 -0
  58. package/lib/workspace-class.d.ts +14 -0
  59. package/lib/workspace-class.d.ts.map +1 -0
  60. package/lib/workspace-class.js +8 -0
  61. package/lib/workspace-class.js.map +1 -0
  62. package/lib/workspace-cluster.d.ts +1 -8
  63. package/lib/workspace-cluster.d.ts.map +1 -1
  64. package/lib/workspace-cluster.js.map +1 -1
  65. package/lib/wsready.d.ts +3 -3
  66. package/lib/wsready.d.ts.map +1 -1
  67. package/lib/wsready.js +0 -2
  68. package/lib/wsready.js.map +1 -1
  69. package/package.json +5 -2
  70. package/pkg-yarn.lock +3 -2
  71. package/provenance-bundle.jsonl +1 -1
  72. package/src/accounting-protocol.ts +3 -0
  73. package/src/admin-protocol.ts +1 -1
  74. package/src/billing-mode.ts +66 -0
  75. package/src/experiments/configcat-server.ts +3 -0
  76. package/src/gitpod-service.ts +21 -3
  77. package/src/index.ts +1 -0
  78. package/src/messaging/client-call-metrics.ts +1 -20
  79. package/src/messaging/error.ts +10 -4
  80. package/src/protocol.ts +12 -3
  81. package/src/team-subscription-protocol.ts +3 -0
  82. package/src/teams-projects-protocol.ts +13 -0
  83. package/src/usage.ts +13 -109
  84. package/src/util/gitpod-host-url.ts +21 -0
  85. package/src/util/grpc.ts +89 -0
  86. package/src/webhook-event.ts +55 -0
  87. package/src/workspace-class.ts +14 -0
  88. package/src/workspace-cluster.ts +0 -4
  89. package/src/wsready.ts +5 -4
package/src/protocol.ts CHANGED
@@ -45,6 +45,9 @@ export interface User {
45
45
  markedDeleted?: boolean;
46
46
 
47
47
  additionalData?: AdditionalUserData;
48
+
49
+ // Identifies an explicit team or user ID to which all the user's workspace usage should be attributed to (e.g. for billing purposes)
50
+ usageAttributionId?: string;
48
51
  }
49
52
 
50
53
  export namespace User {
@@ -199,8 +202,6 @@ export interface AdditionalUserData {
199
202
  knownGitHubOrgs?: string[];
200
203
  // Git clone URL pointing to the user's dotfile repo
201
204
  dotfileRepo?: string;
202
- // Identifies an explicit team or user ID to which all the user's workspace usage should be attributed to (e.g. for billing purposes)
203
- usageAttributionId?: string;
204
205
  // preferred workspace classes
205
206
  workspaceClasses?: WorkspaceClasses;
206
207
  // additional user profile data
@@ -270,9 +271,9 @@ export interface UserFeatureSettings {
270
271
  */
271
272
  export const WorkspaceFeatureFlags = {
272
273
  full_workspace_backup: undefined,
273
- fixed_resources: undefined,
274
274
  persistent_volume_claim: undefined,
275
275
  protected_secrets: undefined,
276
+ workspace_class_limiting: undefined,
276
277
  };
277
278
  export type NamedWorkspaceFeatureFlag = keyof typeof WorkspaceFeatureFlags;
278
279
 
@@ -1481,3 +1482,11 @@ export interface Terms {
1481
1482
  readonly content: string;
1482
1483
  readonly formElements?: object;
1483
1484
  }
1485
+
1486
+ export interface CostCenter {
1487
+ readonly id: string;
1488
+ /**
1489
+ * Unit: credits
1490
+ */
1491
+ spendingLimit: number;
1492
+ }
@@ -55,6 +55,9 @@ export namespace TeamSubscription2 {
55
55
  export const isActive = (ts2: TeamSubscription2, date: string): boolean => {
56
56
  return ts2.startDate <= date && (ts2.endDate === undefined || date < ts2.endDate);
57
57
  };
58
+ export function isCancelled(s: TeamSubscription2, date: string): boolean {
59
+ return (!!s.cancellationDate && s.cancellationDate < date) || (!!s.endDate && s.endDate < date); // This edge case is meant to handle bad data: If for whatever reason cancellationDate has not been set: treat endDate as such
60
+ }
58
61
  }
59
62
 
60
63
  /**
@@ -7,6 +7,7 @@
7
7
  import { PrebuiltWorkspaceState } from "./protocol";
8
8
  import { v4 as uuidv4 } from "uuid";
9
9
  import { DeepPartial } from "./util/deep-partial";
10
+ import { WebhookEvent } from "./webhook-event";
10
11
 
11
12
  export interface ProjectConfig {
12
13
  ".gitpod.yml": string;
@@ -152,3 +153,15 @@ export interface TeamMembershipInvite {
152
153
  /** This is a flag that triggers the HARD DELETION of this entity */
153
154
  deleted?: boolean;
154
155
  }
156
+
157
+ export interface PrebuildEvent {
158
+ id: string;
159
+ creationTime: string;
160
+ status: WebhookEvent.Status | WebhookEvent.PrebuildStatus;
161
+ message?: string;
162
+ prebuildId?: string;
163
+ projectId?: string;
164
+ cloneUrl?: string;
165
+ branch?: string;
166
+ commit?: string;
167
+ }
package/src/usage.ts CHANGED
@@ -20,14 +20,13 @@ export interface BillableSession {
20
20
 
21
21
  workspaceType: BillableWorkspaceType;
22
22
 
23
- // "standard" or "XL"
24
23
  workspaceClass: string;
25
24
 
26
25
  // When the workspace started
27
26
  startTime: string;
28
27
 
29
- // When the workspace ended
30
- endTime: string;
28
+ // When the workspace ended. Not set when the workspace is still running.
29
+ endTime?: string;
31
30
 
32
31
  // The credits used for this session
33
32
  credits: number;
@@ -36,111 +35,16 @@ export interface BillableSession {
36
35
  projectId?: string;
37
36
  }
38
37
 
38
+ export interface BillableSessionRequest {
39
+ attributionId: string;
40
+ startedTimeOrder: SortOrder;
41
+ from?: number;
42
+ to?: number;
43
+ }
44
+
39
45
  export type BillableWorkspaceType = WorkspaceType;
40
46
 
41
- export const billableSessionDummyData: BillableSession[] = [
42
- {
43
- attributionId: "some-attribution-id",
44
- userId: "prebuild",
45
- teamId: "prebuild",
46
- instanceId: "some-instance-id",
47
- workspaceId: "some-workspace-id",
48
- workspaceType: "prebuild",
49
- workspaceClass: "XL",
50
- startTime: new Date(Date.now() + -3 * 24 * 3600 * 1000).toISOString(), // 3 days ago
51
- endTime: new Date().toISOString(),
52
- credits: 320,
53
- projectId: "project-123",
54
- },
55
- {
56
- attributionId: "some-attribution-id2",
57
- userId: "some-user",
58
- teamId: "some-team",
59
- instanceId: "some-instance-id2",
60
- workspaceId: "some-workspace-id2",
61
- workspaceType: "regular",
62
- workspaceClass: "standard",
63
- startTime: new Date(Date.now() + -5 * 24 * 3600 * 1000).toISOString(),
64
- endTime: new Date().toISOString(),
65
- credits: 130,
66
- projectId: "project-123",
67
- },
68
- {
69
- attributionId: "some-attribution-id3",
70
- userId: "some-other-user",
71
- teamId: "some-other-team",
72
- instanceId: "some-instance-id3",
73
- workspaceId: "some-workspace-id3",
74
- workspaceType: "regular",
75
- workspaceClass: "XL",
76
- startTime: new Date(Date.now() + -5 * 24 * 3600 * 1000).toISOString(),
77
- endTime: new Date(Date.now() + -4 * 24 * 3600 * 1000).toISOString(),
78
- credits: 150,
79
- projectId: "project-134",
80
- },
81
- {
82
- attributionId: "some-attribution-id4",
83
- userId: "some-other-user2",
84
- teamId: "some-other-team2",
85
- instanceId: "some-instance-id4",
86
- workspaceId: "some-workspace-id4",
87
- workspaceType: "regular",
88
- workspaceClass: "standard",
89
- startTime: new Date(Date.now() + -10 * 24 * 3600 * 1000).toISOString(),
90
- endTime: new Date(Date.now() + -9 * 24 * 3600 * 1000).toISOString(),
91
- credits: 330,
92
- projectId: "project-137",
93
- },
94
- {
95
- attributionId: "some-attribution-id5",
96
- userId: "some-other-user3",
97
- teamId: "some-other-team3",
98
- instanceId: "some-instance-id5",
99
- workspaceId: "some-workspace-id5",
100
- workspaceType: "regular",
101
- workspaceClass: "XL",
102
- startTime: new Date(Date.now() + -2 * 24 * 3600 * 1000).toISOString(),
103
- endTime: new Date().toISOString(),
104
- credits: 222,
105
- projectId: "project-138",
106
- },
107
- {
108
- attributionId: "some-attribution-id6",
109
- userId: "some-other-user4",
110
- teamId: "some-other-team4",
111
- instanceId: "some-instance-id6",
112
- workspaceId: "some-workspace-id3",
113
- workspaceType: "regular",
114
- workspaceClass: "XL",
115
- startTime: new Date(Date.now() + -7 * 24 * 3600 * 1000).toISOString(),
116
- endTime: new Date(Date.now() + -6 * 24 * 3600 * 1000).toISOString(),
117
- credits: 300,
118
- projectId: "project-134",
119
- },
120
- {
121
- attributionId: "some-attribution-id8",
122
- userId: "some-other-user5",
123
- teamId: "some-other-team5",
124
- instanceId: "some-instance-id8",
125
- workspaceId: "some-workspace-id3",
126
- workspaceType: "regular",
127
- workspaceClass: "standard",
128
- startTime: new Date(Date.now() + -1 * 24 * 3600 * 1000).toISOString(),
129
- endTime: new Date().toISOString(),
130
- credits: 100,
131
- projectId: "project-567",
132
- },
133
- {
134
- attributionId: "some-attribution-id7",
135
- userId: "prebuild",
136
- teamId: "some-other-team7",
137
- instanceId: "some-instance-id7",
138
- workspaceId: "some-workspace-id7",
139
- workspaceType: "prebuild",
140
- workspaceClass: "XL",
141
- startTime: new Date(Date.now() + -1 * 24 * 3600 * 1000).toISOString(),
142
- endTime: new Date().toISOString(),
143
- credits: 200,
144
- projectId: "project-345",
145
- },
146
- ];
47
+ export enum SortOrder {
48
+ Descending = 0,
49
+ Ascending = 1,
50
+ }
@@ -85,6 +85,10 @@ export class GitpodHostUrl {
85
85
  return this.with((url) => ({ protocol: url.protocol === "https:" ? "wss:" : "ws:" }));
86
86
  }
87
87
 
88
+ asWorkspacePage(): GitpodHostUrl {
89
+ return this.with((url) => ({ pathname: "/workspaces" }));
90
+ }
91
+
88
92
  asDashboard(): GitpodHostUrl {
89
93
  return this.with((url) => ({ pathname: "/" }));
90
94
  }
@@ -171,4 +175,21 @@ export class GitpodHostUrl {
171
175
  asApiLogout(): GitpodHostUrl {
172
176
  return this.withApi((url) => ({ pathname: "/logout/" }));
173
177
  }
178
+
179
+ asIDEProxy(): GitpodHostUrl {
180
+ const hostSegments = this.url.host.split(".");
181
+ if (hostSegments[0] === "ide") {
182
+ return this;
183
+ }
184
+ return this.with((url) => ({ host: "ide." + url.host }));
185
+ }
186
+
187
+ asIDEMetrics(): GitpodHostUrl {
188
+ let newUrl: GitpodHostUrl = this;
189
+ const hostSegments = this.url.host.split(".");
190
+ if (hostSegments[0] !== "ide") {
191
+ newUrl = newUrl.asIDEProxy();
192
+ }
193
+ return newUrl.with((url) => ({ pathname: "/metrics-api" }));
194
+ }
174
195
  }
package/src/util/grpc.ts CHANGED
@@ -4,6 +4,9 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
+ import * as grpc from "@grpc/grpc-js";
8
+ import { Status } from "@grpc/grpc-js/build/src/constants";
9
+
7
10
  export const defaultGRPCOptions = {
8
11
  "grpc.keepalive_timeout_ms": 10000,
9
12
  "grpc.keepalive_time_ms": 60000,
@@ -13,3 +16,89 @@ export const defaultGRPCOptions = {
13
16
  "grpc.max_reconnect_backoff_ms": 5000,
14
17
  "grpc.max_receive_message_length": 1024 * 1024 * 16,
15
18
  };
19
+
20
+ export type GrpcMethodType = "unary" | "client_stream" | "server_stream" | "bidi_stream";
21
+
22
+ export interface IGrpcCallMetricsLabels {
23
+ service: string;
24
+ method: string;
25
+ type: GrpcMethodType;
26
+ }
27
+
28
+ export interface IGrpcCallMetricsLabelsWithCode extends IGrpcCallMetricsLabels {
29
+ code: string;
30
+ }
31
+
32
+ export const IClientCallMetrics = Symbol("IClientCallMetrics");
33
+
34
+ export interface IClientCallMetrics {
35
+ started(labels: IGrpcCallMetricsLabels): void;
36
+ sent(labels: IGrpcCallMetricsLabels): void;
37
+ received(labels: IGrpcCallMetricsLabels): void;
38
+ handled(labels: IGrpcCallMetricsLabelsWithCode): void;
39
+ }
40
+
41
+ export function getGrpcMethodType(requestStream: boolean, responseStream: boolean): GrpcMethodType {
42
+ if (requestStream) {
43
+ if (responseStream) {
44
+ return "bidi_stream";
45
+ } else {
46
+ return "client_stream";
47
+ }
48
+ } else {
49
+ if (responseStream) {
50
+ return "server_stream";
51
+ } else {
52
+ return "unary";
53
+ }
54
+ }
55
+ }
56
+
57
+ export function createClientCallMetricsInterceptor(metrics: IClientCallMetrics): grpc.Interceptor {
58
+ return (options, nextCall): grpc.InterceptingCall => {
59
+ const methodDef = options.method_definition;
60
+ const method = methodDef.path.substring(methodDef.path.lastIndexOf("/") + 1);
61
+ const service = methodDef.path.substring(1, methodDef.path.length - method.length - 1);
62
+ const labels = {
63
+ service,
64
+ method,
65
+ type: getGrpcMethodType(options.method_definition.requestStream, options.method_definition.responseStream),
66
+ };
67
+ const requester = new grpc.RequesterBuilder()
68
+ .withStart((metadata, listener, next) => {
69
+ const newListener = new grpc.ListenerBuilder()
70
+ .withOnReceiveStatus((status, next) => {
71
+ try {
72
+ metrics.handled({
73
+ ...labels,
74
+ code: Status[status.code],
75
+ });
76
+ } finally {
77
+ next(status);
78
+ }
79
+ })
80
+ .withOnReceiveMessage((message, next) => {
81
+ try {
82
+ metrics.received(labels);
83
+ } finally {
84
+ next(message);
85
+ }
86
+ })
87
+ .build();
88
+ try {
89
+ metrics.started(labels);
90
+ } finally {
91
+ next(metadata, newListener);
92
+ }
93
+ })
94
+ .withSendMessage((message, next) => {
95
+ try {
96
+ metrics.sent(labels);
97
+ } finally {
98
+ next(message);
99
+ }
100
+ })
101
+ .build();
102
+ return new grpc.InterceptingCall(nextCall(options), requester);
103
+ };
104
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copyright (c) 2022 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
+ export interface WebhookEvent {
8
+ id: string;
9
+ creationTime: string;
10
+ type: "push" | string;
11
+
12
+ /**
13
+ * Typically the webhook installer is referenced here.
14
+ */
15
+ authorizedUserId?: string;
16
+
17
+ /**
18
+ * webhook event's payload
19
+ */
20
+ rawEvent: string;
21
+
22
+ /**
23
+ * The general status of the received webhook event.
24
+ */
25
+ status: WebhookEvent.Status;
26
+
27
+ /**
28
+ * Optional message to help understand errors with handling events.
29
+ */
30
+ message?: string;
31
+
32
+ /**
33
+ * If the webhook event is considered to trigger a prebuild, the `prebuildStatus`
34
+ * contains a more specific status.
35
+ */
36
+ prebuildStatus?: WebhookEvent.PrebuildStatus;
37
+
38
+ /**
39
+ * If `prebuildStatus` is `prebuild_triggered` this points to a prebuild.
40
+ */
41
+ prebuildId?: string;
42
+
43
+ projectId?: string;
44
+
45
+ cloneUrl?: string;
46
+
47
+ branch?: string;
48
+
49
+ commit?: string;
50
+ }
51
+
52
+ export namespace WebhookEvent {
53
+ export type Status = "received" | "dismissed_unauthorized" | "ignored" | "processed";
54
+ export type PrebuildStatus = "ignored_unconfigured" | "prebuild_trigger_failed" | "prebuild_triggered";
55
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) 2022 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
+ export interface SupportedWorkspaceClass {
8
+ id: string;
9
+ category: string;
10
+ displayName: string;
11
+ description: string;
12
+ powerups: number;
13
+ isDefault: boolean;
14
+ }
@@ -56,13 +56,9 @@ export type WorkspaceManagerConnectionInfo = Pick<WorkspaceCluster, "name" | "ur
56
56
  export type AdmissionConstraint =
57
57
  | AdmissionConstraintFeaturePreview
58
58
  | AdmissionConstraintHasPermission
59
- | AdmissionConstraintHasUserLevel
60
- | AdmissionConstraintHasMoreResources
61
59
  | AdmissionConstraintHasClass;
62
60
  export type AdmissionConstraintFeaturePreview = { type: "has-feature-preview" };
63
61
  export type AdmissionConstraintHasPermission = { type: "has-permission"; permission: PermissionName };
64
- export type AdmissionConstraintHasUserLevel = { type: "has-user-level"; level: string };
65
- export type AdmissionConstraintHasMoreResources = { type: "has-more-resources" };
66
62
  export type AdmissionConstraintHasClass = { type: "has-class"; id: string; displayName: string };
67
63
 
68
64
  export namespace AdmissionConstraint {
package/src/wsready.ts CHANGED
@@ -4,14 +4,15 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
- // generated using github.com/32leaves/bel on 2022-05-18 18:19:49.011672619 +0000 UTC m=+0.006607361
7
+ // generated using github.com/32leaves/bel on 2022-07-21 07:41:48.081573085 +0000 UTC m=+0.009109470
8
8
  // DO NOT MODIFY
9
9
 
10
+ export interface WorkspaceReadyMessage {
11
+ source: WorkspaceInitSource;
12
+ }
13
+
10
14
  export enum WorkspaceInitSource {
11
15
  WorkspaceInitFromBackup = "from-backup",
12
16
  WorkspaceInitFromPrebuild = "from-prebuild",
13
17
  WorkspaceInitFromOther = "from-other",
14
18
  }
15
- export interface WorkspaceReadyMessage {
16
- source: WorkspaceInitSource;
17
- }