@gitpod/gitpod-protocol 0.1.5-pd-gen47-patch-test.0 → 0.1.5-pd-ide-metrics.33

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 (126) hide show
  1. package/data/gitpod-schema.json +16 -0
  2. package/lib/admin-protocol.d.ts +4 -0
  3. package/lib/admin-protocol.d.ts.map +1 -1
  4. package/lib/admin-protocol.js.map +1 -1
  5. package/lib/attribution.d.ts +20 -0
  6. package/lib/attribution.d.ts.map +1 -0
  7. package/lib/attribution.js +40 -0
  8. package/lib/attribution.js.map +1 -0
  9. package/lib/blocked-repositories-protocol.d.ts +13 -0
  10. package/lib/blocked-repositories-protocol.d.ts.map +1 -0
  11. package/lib/blocked-repositories-protocol.js +8 -0
  12. package/lib/blocked-repositories-protocol.js.map +1 -0
  13. package/lib/context-url.js +1 -1
  14. package/lib/context-url.js.map +1 -1
  15. package/lib/experiments/always-default.d.ts +8 -0
  16. package/lib/experiments/always-default.d.ts.map +1 -0
  17. package/lib/experiments/always-default.js +20 -0
  18. package/lib/experiments/always-default.js.map +1 -0
  19. package/lib/experiments/configcat-server.d.ts +8 -0
  20. package/lib/experiments/configcat-server.d.ts.map +1 -0
  21. package/lib/experiments/configcat-server.js +35 -0
  22. package/lib/experiments/configcat-server.js.map +1 -0
  23. package/lib/experiments/configcat.d.ts +22 -0
  24. package/lib/experiments/configcat.d.ts.map +1 -0
  25. package/lib/experiments/configcat.js +53 -0
  26. package/lib/experiments/configcat.js.map +1 -0
  27. package/lib/experiments/types.d.ts +23 -0
  28. package/lib/experiments/types.d.ts.map +1 -0
  29. package/lib/experiments/types.js +10 -0
  30. package/lib/experiments/types.js.map +1 -0
  31. package/lib/gitpod-service.d.ts +23 -2
  32. package/lib/gitpod-service.d.ts.map +1 -1
  33. package/lib/gitpod-service.js +1 -1
  34. package/lib/gitpod-service.js.map +1 -1
  35. package/lib/index.d.ts +1 -0
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +1 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/installation-admin-protocol.d.ts +3 -0
  40. package/lib/installation-admin-protocol.d.ts.map +1 -1
  41. package/lib/installation-admin-protocol.js +1 -0
  42. package/lib/installation-admin-protocol.js.map +1 -1
  43. package/lib/messaging/client-call-metrics.d.ts +1 -17
  44. package/lib/messaging/client-call-metrics.d.ts.map +1 -1
  45. package/lib/messaging/client-call-metrics.js +1 -2
  46. package/lib/messaging/client-call-metrics.js.map +1 -1
  47. package/lib/messaging/error.d.ts +1 -0
  48. package/lib/messaging/error.d.ts.map +1 -1
  49. package/lib/messaging/error.js +2 -0
  50. package/lib/messaging/error.js.map +1 -1
  51. package/lib/protocol.d.ts +34 -1
  52. package/lib/protocol.d.ts.map +1 -1
  53. package/lib/protocol.js +42 -2
  54. package/lib/protocol.js.map +1 -1
  55. package/lib/teams-projects-protocol.d.ts +14 -0
  56. package/lib/teams-projects-protocol.d.ts.map +1 -1
  57. package/lib/teams-projects-protocol.js.map +1 -1
  58. package/lib/usage.d.ts +31 -0
  59. package/lib/usage.d.ts.map +1 -0
  60. package/lib/usage.js +14 -0
  61. package/lib/usage.js.map +1 -0
  62. package/lib/util/debug-app.d.ts +25 -0
  63. package/lib/util/debug-app.d.ts.map +1 -0
  64. package/lib/util/debug-app.js +100 -0
  65. package/lib/util/debug-app.js.map +1 -0
  66. package/lib/util/gitpod-host-url.d.ts +1 -0
  67. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  68. package/lib/util/gitpod-host-url.js +3 -0
  69. package/lib/util/gitpod-host-url.js.map +1 -1
  70. package/lib/util/grpc.d.ts +19 -0
  71. package/lib/util/grpc.d.ts.map +1 -1
  72. package/lib/util/grpc.js +73 -1
  73. package/lib/util/grpc.js.map +1 -1
  74. package/lib/util/logging.d.ts.map +1 -1
  75. package/lib/util/logging.js +8 -1
  76. package/lib/util/logging.js.map +1 -1
  77. package/lib/util/timeutil.d.ts +1 -0
  78. package/lib/util/timeutil.d.ts.map +1 -1
  79. package/lib/util/timeutil.js +7 -1
  80. package/lib/util/timeutil.js.map +1 -1
  81. package/lib/webhook-event.d.ts +44 -0
  82. package/lib/webhook-event.d.ts.map +1 -0
  83. package/lib/webhook-event.js +8 -0
  84. package/lib/webhook-event.js.map +1 -0
  85. package/lib/workspace-class.d.ts +14 -0
  86. package/lib/workspace-class.d.ts.map +1 -0
  87. package/lib/workspace-class.js +8 -0
  88. package/lib/workspace-class.js.map +1 -0
  89. package/lib/workspace-cluster.d.ts +5 -7
  90. package/lib/workspace-cluster.d.ts.map +1 -1
  91. package/lib/workspace-cluster.js.map +1 -1
  92. package/lib/workspace-instance.d.ts +11 -0
  93. package/lib/workspace-instance.d.ts.map +1 -1
  94. package/lib/wsready.d.ts +3 -3
  95. package/lib/wsready.d.ts.map +1 -1
  96. package/lib/wsready.js +0 -2
  97. package/lib/wsready.js.map +1 -1
  98. package/package.json +12 -6
  99. package/pkg-yarn.lock +8 -5
  100. package/provenance-bundle.jsonl +1 -1
  101. package/src/admin-protocol.ts +7 -0
  102. package/src/attribution.ts +48 -0
  103. package/src/blocked-repositories-protocol.ts +13 -0
  104. package/src/context-url.ts +1 -1
  105. package/src/experiments/always-default.ts +24 -0
  106. package/src/experiments/configcat-server.ts +38 -0
  107. package/src/experiments/configcat.ts +58 -0
  108. package/src/experiments/types.ts +35 -0
  109. package/src/gitpod-service.ts +29 -1
  110. package/src/index.ts +1 -0
  111. package/src/installation-admin-protocol.ts +3 -0
  112. package/src/messaging/client-call-metrics.ts +1 -20
  113. package/src/messaging/error.ts +3 -0
  114. package/src/protocol.ts +85 -4
  115. package/src/teams-projects-protocol.ts +15 -0
  116. package/src/usage.ts +50 -0
  117. package/src/util/debug-app.ts +81 -0
  118. package/src/util/gitpod-host-url.ts +4 -0
  119. package/src/util/grpc.ts +89 -0
  120. package/src/util/logging.ts +11 -2
  121. package/src/util/timeutil.ts +6 -0
  122. package/src/webhook-event.ts +55 -0
  123. package/src/workspace-class.ts +14 -0
  124. package/src/workspace-cluster.ts +2 -4
  125. package/src/workspace-instance.ts +17 -0
  126. package/src/wsready.ts +5 -4
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Copyright (c) 2021 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 * as http from "http";
8
+ import * as express from "express";
9
+ import { injectable, postConstruct } from "inversify";
10
+ import { log, LogrusLogLevel } from "./logging";
11
+
12
+ export interface SetLogLevelRequest {
13
+ level: LogrusLogLevel;
14
+ }
15
+ export namespace SetLogLevelRequest {
16
+ export function is(o: any): o is SetLogLevelRequest {
17
+ return typeof o === "object" && "level" in o;
18
+ }
19
+ }
20
+
21
+ @injectable()
22
+ export class DebugApp {
23
+ protected _app: express.Application;
24
+ protected httpServer: http.Server | undefined = undefined;
25
+
26
+ @postConstruct()
27
+ public ctor() {
28
+ this._app = this.create();
29
+ }
30
+
31
+ create(): express.Application {
32
+ const app = express();
33
+
34
+ app.use(express.json());
35
+ app.use(express.urlencoded({ extended: true }));
36
+
37
+ app.post("/debug/logging", (req, res) => {
38
+ try {
39
+ const levelRequest = req.body;
40
+ if (!SetLogLevelRequest.is(levelRequest)) {
41
+ res.status(400).end("not a SetLogLevelRequest");
42
+ return;
43
+ }
44
+
45
+ const newLogLevel = levelRequest.level;
46
+ log.setLogLevel(newLogLevel);
47
+ log.info("set log level", { newLogLevel });
48
+ res.status(200).end(JSON.stringify(levelRequest));
49
+ } catch (err) {
50
+ res.status(500).end(err);
51
+ }
52
+ });
53
+ return app;
54
+ }
55
+
56
+ public start(port: number = 6060) {
57
+ this.httpServer = this._app.listen(port, "localhost", () => {
58
+ log.info(`debug server listening on port: ${port}`);
59
+ });
60
+ }
61
+
62
+ public async stop() {
63
+ const server = this.httpServer;
64
+ if (!server) {
65
+ return;
66
+ }
67
+ return new Promise<void>((resolve) =>
68
+ server.close((err: any) => {
69
+ if (err) {
70
+ log.warn(`error while closing http server`, { err });
71
+ }
72
+ this.httpServer = undefined;
73
+ resolve();
74
+ }),
75
+ );
76
+ }
77
+
78
+ public get app(): express.Application {
79
+ return this._app;
80
+ }
81
+ }
@@ -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
  }
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
+ }
@@ -6,6 +6,7 @@
6
6
 
7
7
  const inspect: (object: any) => string = require("util").inspect; // undefined in frontend
8
8
 
9
+ let plainLogging: boolean = false; // set to true during development to get non JSON output
9
10
  let jsonLogging: boolean = false;
10
11
  let component: string | undefined;
11
12
  let version: string | undefined;
@@ -309,7 +310,7 @@ function makeLogItem(
309
310
  }
310
311
 
311
312
  const payload: any = payloadArgs.length == 0 ? undefined : payloadArgs.length == 1 ? payloadArgs[0] : payloadArgs;
312
- const logItem: any = {
313
+ const logItem = {
313
314
  // undefined fields get eliminated in JSON.stringify()
314
315
  ...reportedErrorEvent,
315
316
  component,
@@ -321,11 +322,19 @@ function makeLogItem(
321
322
  payload,
322
323
  loggedViaConsole: calledViaConsole ? true : undefined,
323
324
  };
325
+ if (plainLogging) {
326
+ return `[${logItem.severity}] [${logItem.component}] ${logItem.message}
327
+ ${JSON.stringify(payload || "", undefined, " ")}
328
+ ${error || ""}
329
+ `.trim();
330
+ }
324
331
  let result: string = stringifyLogItem(logItem);
325
332
 
326
333
  if (result.length > maxAllowedLogItemLength && payload !== undefined) {
327
334
  delete logItem.payload;
328
- logItem.payloadStub = `Payload stripped as log item was longer than ${maxAllowedLogItemLength} characters`;
335
+ (<any>(
336
+ logItem
337
+ )).payloadStub = `Payload stripped as log item was longer than ${maxAllowedLogItemLength} characters`;
329
338
 
330
339
  result = stringifyLogItem(logItem);
331
340
 
@@ -47,6 +47,12 @@ export const orderAsc = (d1: string, d2: string): number => liftDate(d1, d2, (d1
47
47
  export const liftDate1 = <T>(d1: string, f: (d1: Date) => T): T => f(new Date(d1));
48
48
  export const liftDate = <T>(d1: string, d2: string, f: (d1: Date, d2: Date) => T): T => f(new Date(d1), new Date(d2));
49
49
 
50
+ export function hoursBefore(date: string, hours: number): string {
51
+ const result = new Date(date);
52
+ result.setHours(result.getHours() - hours);
53
+ return result.toISOString();
54
+ }
55
+
50
56
  export function hoursLater(date: string, hours: number): string {
51
57
  const result = new Date(date);
52
58
  result.setHours(result.getHours() + hours);
@@ -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,12 +56,10 @@ export type WorkspaceManagerConnectionInfo = Pick<WorkspaceCluster, "name" | "ur
56
56
  export type AdmissionConstraint =
57
57
  | AdmissionConstraintFeaturePreview
58
58
  | AdmissionConstraintHasPermission
59
- | AdmissionConstraintHasUserLevel
60
- | AdmissionConstraintHasMoreResources;
59
+ | AdmissionConstraintHasClass;
61
60
  export type AdmissionConstraintFeaturePreview = { type: "has-feature-preview" };
62
61
  export type AdmissionConstraintHasPermission = { type: "has-permission"; permission: PermissionName };
63
- export type AdmissionConstraintHasUserLevel = { type: "has-user-level"; level: string };
64
- export type AdmissionConstraintHasMoreResources = { type: "has-more-resources" };
62
+ export type AdmissionConstraintHasClass = { type: "has-class"; id: string; displayName: string };
65
63
 
66
64
  export namespace AdmissionConstraint {
67
65
  export function is(o: any): o is AdmissionConstraint {
@@ -56,10 +56,27 @@ export interface WorkspaceInstance {
56
56
  * Contains information about the image build, if there was any
57
57
  */
58
58
  imageBuildInfo?: ImageBuildInfo;
59
+
60
+ /**
61
+ * workspace class, also known as workspace size, determines the type of
62
+ * resources that are provided to the workspace.
63
+ */
64
+ workspaceClass?: string;
65
+
66
+ /**
67
+ * Identifies the team or user to which this instance's runtime should be attributed to
68
+ * (e.g. for usage analytics or billing purposes).
69
+ */
70
+ usageAttributionId?: string;
59
71
  }
60
72
 
61
73
  // WorkspaceInstanceStatus describes the current state of a workspace instance
62
74
  export interface WorkspaceInstanceStatus {
75
+ // version is the current version of the workspace instance status
76
+ // Note: consider this value opague. The only guarantee given is that it imposes
77
+ // a partial order on status updates, i.e. a.version > b.version -> a newer than b.
78
+ version?: number;
79
+
63
80
  // phase describes a high-level state of the workspace instance
64
81
  phase: WorkspaceInstancePhase;
65
82
 
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
- }