@gitpod/gitpod-protocol 0.1.5-me-test04251.0 → 0.1.5-me-fixheader.1

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 (319) hide show
  1. package/data/gitpod-schema.json +73 -115
  2. package/lib/accounting-protocol.d.ts +9 -1
  3. package/lib/accounting-protocol.d.ts.map +1 -1
  4. package/lib/accounting-protocol.js +13 -2
  5. package/lib/accounting-protocol.js.map +1 -1
  6. package/lib/admin-protocol.d.ts +8 -1
  7. package/lib/admin-protocol.d.ts.map +1 -1
  8. package/lib/admin-protocol.js +1 -1
  9. package/lib/admin-protocol.js.map +1 -1
  10. package/lib/analytics.d.ts +1 -1
  11. package/lib/analytics.js +1 -1
  12. package/lib/attribution.d.ts +23 -0
  13. package/lib/attribution.d.ts.map +1 -0
  14. package/lib/attribution.js +50 -0
  15. package/lib/attribution.js.map +1 -0
  16. package/lib/auth.d.ts +1 -1
  17. package/lib/auth.js +1 -1
  18. package/lib/billing-mode.d.ts +41 -0
  19. package/lib/billing-mode.d.ts.map +1 -0
  20. package/lib/billing-mode.js +44 -0
  21. package/lib/billing-mode.js.map +1 -0
  22. package/lib/blocked-repositories-protocol.d.ts +13 -0
  23. package/lib/blocked-repositories-protocol.d.ts.map +1 -0
  24. package/lib/blocked-repositories-protocol.js +8 -0
  25. package/lib/blocked-repositories-protocol.js.map +1 -0
  26. package/lib/context-url.d.ts +1 -1
  27. package/lib/context-url.js +2 -2
  28. package/lib/context-url.js.map +1 -1
  29. package/lib/context-url.spec.d.ts +1 -1
  30. package/lib/context-url.spec.js +1 -1
  31. package/lib/encryption/container-module.d.ts +1 -1
  32. package/lib/encryption/container-module.js +1 -1
  33. package/lib/encryption/encryption-engine.d.ts +1 -1
  34. package/lib/encryption/encryption-engine.d.ts.map +1 -1
  35. package/lib/encryption/encryption-engine.js +4 -4
  36. package/lib/encryption/encryption-engine.js.map +1 -1
  37. package/lib/encryption/encryption-engine.spec.d.ts +1 -1
  38. package/lib/encryption/encryption-engine.spec.js +2 -2
  39. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  40. package/lib/encryption/encryption-service.d.ts +1 -1
  41. package/lib/encryption/encryption-service.js +1 -1
  42. package/lib/encryption/key-provider.d.ts +1 -1
  43. package/lib/encryption/key-provider.js +2 -2
  44. package/lib/encryption/key-provider.js.map +1 -1
  45. package/lib/env.d.ts +1 -1
  46. package/lib/env.js +1 -1
  47. package/lib/experiments/always-default.d.ts +8 -0
  48. package/lib/experiments/always-default.d.ts.map +1 -0
  49. package/lib/experiments/always-default.js +20 -0
  50. package/lib/experiments/always-default.js.map +1 -0
  51. package/lib/experiments/configcat-server.d.ts +10 -0
  52. package/lib/experiments/configcat-server.d.ts.map +1 -0
  53. package/lib/experiments/configcat-server.js +36 -0
  54. package/lib/experiments/configcat-server.js.map +1 -0
  55. package/lib/experiments/configcat.d.ts +21 -0
  56. package/lib/experiments/configcat.d.ts.map +1 -0
  57. package/lib/experiments/configcat.js +51 -0
  58. package/lib/experiments/configcat.js.map +1 -0
  59. package/lib/experiments/types.d.ts +22 -0
  60. package/lib/experiments/types.d.ts.map +1 -0
  61. package/lib/experiments/types.js +10 -0
  62. package/lib/experiments/types.js.map +1 -0
  63. package/lib/gitpod-file-parser.d.ts +1 -1
  64. package/lib/gitpod-file-parser.js +1 -1
  65. package/lib/gitpod-file-parser.spec.d.ts +1 -1
  66. package/lib/gitpod-file-parser.spec.js +1 -1
  67. package/lib/gitpod-service.d.ts +40 -22
  68. package/lib/gitpod-service.d.ts.map +1 -1
  69. package/lib/gitpod-service.js +22 -9
  70. package/lib/gitpod-service.js.map +1 -1
  71. package/lib/headless-workspace-log.d.ts +1 -1
  72. package/lib/headless-workspace-log.js +1 -1
  73. package/lib/ide-frontend-service.d.ts +1 -1
  74. package/lib/ide-frontend-service.js +1 -1
  75. package/lib/ide-protocol.d.ts +9 -1
  76. package/lib/ide-protocol.d.ts.map +1 -1
  77. package/lib/ide-protocol.js +1 -1
  78. package/lib/index.d.ts +2 -2
  79. package/lib/index.d.ts.map +1 -1
  80. package/lib/index.js +2 -2
  81. package/lib/index.js.map +1 -1
  82. package/lib/installation-admin-protocol.d.ts +4 -1
  83. package/lib/installation-admin-protocol.d.ts.map +1 -1
  84. package/lib/installation-admin-protocol.js +2 -1
  85. package/lib/installation-admin-protocol.js.map +1 -1
  86. package/lib/license-protocol.d.ts +8 -1
  87. package/lib/license-protocol.d.ts.map +1 -1
  88. package/lib/license-protocol.js +1 -1
  89. package/lib/license-protocol.js.map +1 -1
  90. package/lib/messaging/browser/window-connection.d.ts +1 -1
  91. package/lib/messaging/browser/window-connection.js +1 -1
  92. package/lib/messaging/client-call-metrics.d.ts +2 -18
  93. package/lib/messaging/client-call-metrics.d.ts.map +1 -1
  94. package/lib/messaging/client-call-metrics.js +2 -3
  95. package/lib/messaging/client-call-metrics.js.map +1 -1
  96. package/lib/messaging/error.d.ts +7 -2
  97. package/lib/messaging/error.d.ts.map +1 -1
  98. package/lib/messaging/error.js +14 -4
  99. package/lib/messaging/error.js.map +1 -1
  100. package/lib/oss-allowlist.d.ts +1 -1
  101. package/lib/oss-allowlist.js +1 -1
  102. package/lib/payment-protocol.d.ts +1 -1
  103. package/lib/payment-protocol.js +1 -1
  104. package/lib/permission.d.ts +1 -1
  105. package/lib/permission.js +1 -1
  106. package/lib/plans.d.ts +2 -1
  107. package/lib/plans.d.ts.map +1 -1
  108. package/lib/plans.js +7 -3
  109. package/lib/plans.js.map +1 -1
  110. package/lib/protocol.d.ts +112 -21
  111. package/lib/protocol.d.ts.map +1 -1
  112. package/lib/protocol.js +175 -12
  113. package/lib/protocol.js.map +1 -1
  114. package/lib/protocol.spec.d.ts +7 -0
  115. package/lib/protocol.spec.d.ts.map +1 -0
  116. package/lib/protocol.spec.js +127 -0
  117. package/lib/protocol.spec.js.map +1 -0
  118. package/lib/snapshot-url.d.ts +1 -1
  119. package/lib/snapshot-url.js +1 -1
  120. package/lib/snapshot-url.spec.d.ts +1 -1
  121. package/lib/snapshot-url.spec.js +1 -1
  122. package/lib/team-subscription-protocol.d.ts +18 -1
  123. package/lib/team-subscription-protocol.d.ts.map +1 -1
  124. package/lib/team-subscription-protocol.js +17 -2
  125. package/lib/team-subscription-protocol.js.map +1 -1
  126. package/lib/teams-projects-protocol.d.ts +15 -2
  127. package/lib/teams-projects-protocol.d.ts.map +1 -1
  128. package/lib/teams-projects-protocol.js +1 -1
  129. package/lib/teams-projects-protocol.js.map +1 -1
  130. package/lib/typings/globals.d.ts +1 -1
  131. package/lib/typings/globals.js +1 -1
  132. package/lib/usage.d.ts +61 -0
  133. package/lib/usage.d.ts.map +1 -0
  134. package/lib/usage.js +14 -0
  135. package/lib/usage.js.map +1 -0
  136. package/lib/util/analytics.d.ts +1 -1
  137. package/lib/util/analytics.js +1 -1
  138. package/lib/util/async-iterator.d.ts +1 -1
  139. package/lib/util/async-iterator.js +1 -1
  140. package/lib/util/cancelable.d.ts +1 -1
  141. package/lib/util/cancelable.js +1 -1
  142. package/lib/util/date-time.d.ts +1 -1
  143. package/lib/util/date-time.js +1 -1
  144. package/lib/util/debug-app.d.ts +25 -0
  145. package/lib/util/debug-app.d.ts.map +1 -0
  146. package/lib/util/debug-app.js +100 -0
  147. package/lib/util/debug-app.js.map +1 -0
  148. package/lib/util/deep-partial.d.ts +1 -1
  149. package/lib/util/deep-partial.js +1 -1
  150. package/lib/util/deferred.d.ts +1 -1
  151. package/lib/util/deferred.js +1 -1
  152. package/lib/util/garbage-collected-cache.d.ts +1 -1
  153. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  154. package/lib/util/garbage-collected-cache.js +6 -1
  155. package/lib/util/garbage-collected-cache.js.map +1 -1
  156. package/lib/util/generate-workspace-id.d.ts +1 -1
  157. package/lib/util/generate-workspace-id.js +1 -1
  158. package/lib/util/generate-workspace-id.spec.d.ts +1 -1
  159. package/lib/util/generate-workspace-id.spec.js +1 -1
  160. package/lib/util/gitpod-cookie.d.ts +1 -1
  161. package/lib/util/gitpod-cookie.js +1 -1
  162. package/lib/util/gitpod-host-url.d.ts +4 -1
  163. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  164. package/lib/util/gitpod-host-url.js +19 -1
  165. package/lib/util/gitpod-host-url.js.map +1 -1
  166. package/lib/util/gitpod-host-url.spec.d.ts +1 -1
  167. package/lib/util/gitpod-host-url.spec.js +1 -1
  168. package/lib/util/grpc.d.ts +20 -1
  169. package/lib/util/grpc.d.ts.map +1 -1
  170. package/lib/util/grpc.js +74 -2
  171. package/lib/util/grpc.js.map +1 -1
  172. package/lib/util/jaeger-client-types.d.ts +1 -1
  173. package/lib/util/jaeger-client-types.js +1 -1
  174. package/lib/util/logging.d.ts +1 -1
  175. package/lib/util/logging.d.ts.map +1 -1
  176. package/lib/util/logging.js +9 -2
  177. package/lib/util/logging.js.map +1 -1
  178. package/lib/util/logging.spec.d.ts +7 -0
  179. package/lib/util/logging.spec.d.ts.map +1 -0
  180. package/lib/util/logging.spec.js +52 -0
  181. package/lib/util/logging.spec.js.map +1 -0
  182. package/lib/util/make-link.d.ts +1 -1
  183. package/lib/util/make-link.js +1 -1
  184. package/lib/util/nice-grpc.d.ts +9 -0
  185. package/lib/util/nice-grpc.d.ts.map +1 -0
  186. package/lib/util/nice-grpc.js +119 -0
  187. package/lib/util/nice-grpc.js.map +1 -0
  188. package/lib/util/parse-workspace-id.d.ts +1 -1
  189. package/lib/util/parse-workspace-id.js +1 -1
  190. package/lib/util/parse-workspace-id.spec.d.ts +1 -1
  191. package/lib/util/parse-workspace-id.spec.js +1 -1
  192. package/lib/util/queue.d.ts +1 -1
  193. package/lib/util/queue.js +1 -1
  194. package/lib/util/queue.spec.d.ts +1 -1
  195. package/lib/util/queue.spec.js +1 -1
  196. package/lib/util/repeat.d.ts +1 -1
  197. package/lib/util/repeat.js +1 -1
  198. package/lib/util/semaphore.d.ts +1 -1
  199. package/lib/util/semaphore.js +1 -1
  200. package/lib/util/skip-if.d.ts +1 -1
  201. package/lib/util/skip-if.js +1 -1
  202. package/lib/util/timeutil.d.ts +3 -1
  203. package/lib/util/timeutil.d.ts.map +1 -1
  204. package/lib/util/timeutil.js +14 -2
  205. package/lib/util/timeutil.js.map +1 -1
  206. package/lib/util/timeutil.spec.d.ts +3 -1
  207. package/lib/util/timeutil.spec.d.ts.map +1 -1
  208. package/lib/util/timeutil.spec.js +35 -1
  209. package/lib/util/timeutil.spec.js.map +1 -1
  210. package/lib/util/tracing.d.ts +1 -1
  211. package/lib/util/tracing.js +1 -1
  212. package/lib/util/tracing.spec.d.ts +1 -1
  213. package/lib/util/tracing.spec.js +1 -1
  214. package/lib/util/workspace-port-authentication.d.ts +1 -1
  215. package/lib/util/workspace-port-authentication.js +1 -1
  216. package/lib/webhook-event.d.ts +44 -0
  217. package/lib/webhook-event.d.ts.map +1 -0
  218. package/lib/webhook-event.js +8 -0
  219. package/lib/webhook-event.js.map +1 -0
  220. package/lib/workspace-class.d.ts +14 -0
  221. package/lib/workspace-class.d.ts.map +1 -0
  222. package/lib/workspace-class.js +8 -0
  223. package/lib/workspace-class.js.map +1 -0
  224. package/lib/workspace-cluster.d.ts +7 -8
  225. package/lib/workspace-cluster.d.ts.map +1 -1
  226. package/lib/workspace-cluster.js +1 -1
  227. package/lib/workspace-cluster.js.map +1 -1
  228. package/lib/workspace-instance.d.ts +14 -2
  229. package/lib/workspace-instance.d.ts.map +1 -1
  230. package/lib/workspace-instance.js +1 -1
  231. package/lib/wsready.d.ts +1 -1
  232. package/lib/wsready.js +2 -2
  233. package/package.json +14 -6
  234. package/pkg-yarn.lock +10 -5
  235. package/provenance-bundle.jsonl +1 -1
  236. package/src/accounting-protocol.ts +14 -1
  237. package/src/admin-protocol.ts +11 -1
  238. package/src/analytics.ts +1 -1
  239. package/src/attribution.ts +59 -0
  240. package/src/auth.ts +1 -1
  241. package/src/billing-mode.ts +77 -0
  242. package/src/blocked-repositories-protocol.ts +13 -0
  243. package/src/context-url.spec.ts +1 -1
  244. package/src/context-url.ts +2 -2
  245. package/src/encryption/container-module.ts +1 -1
  246. package/src/encryption/encryption-engine.spec.ts +2 -2
  247. package/src/encryption/encryption-engine.ts +8 -4
  248. package/src/encryption/encryption-service.ts +1 -1
  249. package/src/encryption/key-provider.ts +2 -2
  250. package/src/env.ts +1 -1
  251. package/src/experiments/always-default.ts +24 -0
  252. package/src/experiments/configcat-server.ts +41 -0
  253. package/src/experiments/configcat.ts +56 -0
  254. package/src/experiments/types.ts +34 -0
  255. package/src/gitpod-file-parser.spec.ts +1 -1
  256. package/src/gitpod-file-parser.ts +1 -1
  257. package/src/gitpod-service.ts +76 -30
  258. package/src/headless-workspace-log.ts +1 -1
  259. package/src/ide-frontend-service.ts +1 -1
  260. package/src/ide-protocol.ts +11 -1
  261. package/src/index.ts +2 -2
  262. package/src/installation-admin-protocol.ts +4 -1
  263. package/src/license-protocol.ts +8 -1
  264. package/src/messaging/browser/window-connection.ts +1 -1
  265. package/src/messaging/client-call-metrics.ts +2 -21
  266. package/src/messaging/error.ts +20 -5
  267. package/src/oss-allowlist.ts +1 -1
  268. package/src/payment-protocol.ts +1 -1
  269. package/src/permission.ts +1 -1
  270. package/src/plans.ts +7 -3
  271. package/src/protocol.spec.ts +97 -0
  272. package/src/protocol.ts +270 -27
  273. package/src/snapshot-url.spec.ts +1 -1
  274. package/src/snapshot-url.ts +1 -1
  275. package/src/team-subscription-protocol.ts +28 -1
  276. package/src/teams-projects-protocol.ts +16 -2
  277. package/src/typings/globals.ts +1 -1
  278. package/src/usage.ts +71 -0
  279. package/src/util/analytics.ts +1 -1
  280. package/src/util/async-iterator.ts +1 -1
  281. package/src/util/cancelable.ts +1 -1
  282. package/src/util/date-time.ts +1 -1
  283. package/src/util/debug-app.ts +81 -0
  284. package/src/util/deep-partial.ts +1 -1
  285. package/src/util/deferred.ts +1 -1
  286. package/src/util/garbage-collected-cache.ts +6 -1
  287. package/src/util/generate-workspace-id.spec.ts +1 -1
  288. package/src/util/generate-workspace-id.ts +1 -1
  289. package/src/util/gitpod-cookie.ts +1 -1
  290. package/src/util/gitpod-host-url.spec.ts +1 -1
  291. package/src/util/gitpod-host-url.ts +22 -1
  292. package/src/util/grpc.ts +90 -1
  293. package/src/util/jaeger-client-types.ts +1 -1
  294. package/src/util/logging.spec.ts +23 -0
  295. package/src/util/logging.ts +12 -3
  296. package/src/util/make-link.ts +1 -1
  297. package/src/util/nice-grpc.ts +93 -0
  298. package/src/util/parse-workspace-id.spec.ts +1 -1
  299. package/src/util/parse-workspace-id.ts +1 -1
  300. package/src/util/queue.spec.ts +1 -1
  301. package/src/util/queue.ts +1 -1
  302. package/src/util/repeat.ts +1 -1
  303. package/src/util/semaphore.ts +1 -1
  304. package/src/util/skip-if.ts +1 -1
  305. package/src/util/timeutil.spec.ts +29 -2
  306. package/src/util/timeutil.ts +13 -1
  307. package/src/util/tracing.spec.ts +1 -1
  308. package/src/util/tracing.ts +1 -1
  309. package/src/util/workspace-port-authentication.ts +1 -1
  310. package/src/webhook-event.ts +55 -0
  311. package/src/workspace-class.ts +14 -0
  312. package/src/workspace-cluster.ts +7 -5
  313. package/src/workspace-instance.ts +26 -2
  314. package/src/wsready.ts +2 -2
  315. package/lib/email-protocol.d.ts +0 -49
  316. package/lib/email-protocol.d.ts.map +0 -1
  317. package/lib/email-protocol.js +0 -28
  318. package/lib/email-protocol.js.map +0 -1
  319. package/src/email-protocol.ts +0 -65
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  // Use asyncIterators with es2015
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { Disposable } from "./disposable";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  export function formatDate(date?: string) {
@@ -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
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  export class Deferred<T> {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { repeat } from "./repeat";
@@ -37,6 +37,11 @@ export class GarbageCollectedCache<T> {
37
37
  if (!entry) {
38
38
  return undefined;
39
39
  }
40
+ // Still valid?
41
+ if (entry.expiryDate < Date.now()) {
42
+ this.store.delete(entry.key);
43
+ return undefined;
44
+ }
40
45
  return entry.value;
41
46
  }
42
47
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { suite, test } from "mocha-typescript";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import randomNumber = require("random-number-csprng");
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
  import * as cookie from "cookie";
7
7
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import * as chai from "chai";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  const URL = require("url").URL || window.URL;
@@ -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
@@ -1,9 +1,12 @@
1
1
  /**
2
2
  * Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
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
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { opentracing } from "jaeger-client";
@@ -0,0 +1,23 @@
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 { suite, test } from "mocha-typescript";
8
+ import { log } from "./logging";
9
+
10
+ @suite
11
+ class TestLogging {
12
+ @test public async testLogInfo_output() {
13
+ const testObj = {
14
+ null: null,
15
+ undefined: undefined,
16
+ empty: "",
17
+ foo: "bar",
18
+ number: 0,
19
+ };
20
+ log.info("info logging test", testObj);
21
+ }
22
+ }
23
+ module.exports = new TestLogging();
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
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
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  function isOpenNewTab(event: MouseEvent): boolean {
@@ -0,0 +1,93 @@
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
+ import { isAbortError } from "abort-controller-x";
8
+ import {
9
+ CallOptions,
10
+ ClientError,
11
+ ClientMiddleware,
12
+ ClientMiddlewareCall,
13
+ Status,
14
+ MethodDescriptor,
15
+ } from "nice-grpc-common";
16
+ import { GrpcMethodType, IClientCallMetrics } from "./grpc";
17
+
18
+ function getLabels(method: MethodDescriptor) {
19
+ const callType = method.requestStream
20
+ ? method.responseStream
21
+ ? "bidi_stream"
22
+ : "client_stream"
23
+ : method.responseStream
24
+ ? "server_stream"
25
+ : "unary";
26
+ const { path } = method;
27
+ const [serviceName, methodName] = path.split("/").slice(1);
28
+
29
+ return {
30
+ type: callType as GrpcMethodType,
31
+ service: serviceName,
32
+ method: methodName,
33
+ };
34
+ }
35
+
36
+ async function* incrementStreamMessagesCounter<T>(iterable: AsyncIterable<T>, callback: () => void): AsyncIterable<T> {
37
+ for await (const item of iterable) {
38
+ callback();
39
+ yield item;
40
+ }
41
+ }
42
+
43
+ export function prometheusClientMiddleware(metrics: IClientCallMetrics): ClientMiddleware {
44
+ return async function* prometheusClientMiddlewareGenerator<Request, Response>(
45
+ call: ClientMiddlewareCall<Request, Response>,
46
+ options: CallOptions,
47
+ ): AsyncGenerator<Response, Response | void, undefined> {
48
+ const labels = getLabels(call.method);
49
+
50
+ metrics.started(labels);
51
+
52
+ let settled = false;
53
+ let status: Status = Status.OK;
54
+
55
+ try {
56
+ let request;
57
+
58
+ if (!call.requestStream) {
59
+ request = call.request;
60
+ } else {
61
+ request = incrementStreamMessagesCounter(call.request, metrics.sent.bind(metrics, labels));
62
+ }
63
+
64
+ if (!call.responseStream) {
65
+ const response = yield* call.next(request, options);
66
+ settled = true;
67
+ return response;
68
+ } else {
69
+ yield* incrementStreamMessagesCounter(
70
+ call.next(request, options),
71
+ metrics.received.bind(metrics, labels),
72
+ );
73
+ settled = true;
74
+ return;
75
+ }
76
+ } catch (err) {
77
+ settled = true;
78
+ if (err instanceof ClientError) {
79
+ status = err.code;
80
+ } else if (isAbortError(err)) {
81
+ status = Status.CANCELLED;
82
+ } else {
83
+ status = Status.UNKNOWN;
84
+ }
85
+ throw err;
86
+ } finally {
87
+ if (!settled) {
88
+ status = Status.CANCELLED;
89
+ }
90
+ metrics.handled({ ...labels, code: Status[status] });
91
+ }
92
+ };
93
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import * as chai from "chai";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  const REGEX_WORKSPACE_ID = /[0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}/;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { suite, test, slow, timeout } from "mocha-typescript";
package/src/util/queue.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { Deferred } from "./deferred";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import { Disposable } from "..";
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  export class Semaphore {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  /**
@@ -1,16 +1,22 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  import * as chai from "chai";
8
8
  const expect = chai.expect;
9
9
  import { suite, test } from "mocha-typescript";
10
- import { oneMonthLater } from "./timeutil";
10
+ import { daysBefore, hoursBefore, oneMonthLater } from "./timeutil";
11
11
 
12
12
  @suite()
13
13
  export class TimeutilSpec {
14
+ @test
15
+ testDaysBefore() {
16
+ const now = new Date().toISOString();
17
+ expect(daysBefore(now, 2)).to.be.eq(hoursBefore(now, 48));
18
+ }
19
+
14
20
  @test
15
21
  testTimeutil() {
16
22
  // targeting a 1st, 1th of Jan => 1st of Feb
@@ -39,4 +45,25 @@ export class TimeutilSpec {
39
45
  const later = oneMonthLater(from.toISOString(), day);
40
46
  expect(later, `expected ${later} to be equal ${expectation}`).to.be.equal(expectation.toISOString());
41
47
  }
48
+
49
+ @test
50
+ testDaysBefore2() {
51
+ const tests: { date: Date; daysEarlier: number; expectation: string }[] = [
52
+ {
53
+ date: new Date("2021-07-13T00:00:00.000Z"),
54
+ daysEarlier: 365,
55
+ expectation: "2020-07-13T00:00:00.000Z",
56
+ },
57
+ {
58
+ date: new Date("2019-02-01T00:00:00.000Z"),
59
+ daysEarlier: 365,
60
+ expectation: "2018-02-01T00:00:00.000Z",
61
+ },
62
+ ];
63
+
64
+ for (const t of tests) {
65
+ const actual = daysBefore(t.date.toISOString(), t.daysEarlier);
66
+ expect(actual).to.equal(t.expectation, `expected ${actual} to be equal ${t.expectation}`);
67
+ }
68
+ }
42
69
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
4
- * See License-AGPL.txt in the project root for license information.
4
+ * See License.AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
7
  /**
@@ -47,6 +47,18 @@ 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 daysBefore(date: string, days: number): string {
51
+ const result = new Date(date);
52
+ result.setDate(result.getDate() - days);
53
+ return result.toISOString();
54
+ }
55
+
56
+ export function hoursBefore(date: string, hours: number): string {
57
+ const result = new Date(date);
58
+ result.setHours(result.getHours() - hours);
59
+ return result.toISOString();
60
+ }
61
+
50
62
  export function hoursLater(date: string, hours: number): string {
51
63
  const result = new Date(date);
52
64
  result.setHours(result.getHours() + hours);