@gitpod/gitpod-protocol 0.1.5-v0.6.0-beta4 → 0.1.5-vn-6525.75

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 (344) hide show
  1. package/data/gitpod-schema.json +68 -26
  2. package/lib/accounting-protocol.d.ts +155 -0
  3. package/lib/accounting-protocol.d.ts.map +1 -0
  4. package/lib/accounting-protocol.js +100 -0
  5. package/lib/accounting-protocol.js.map +1 -0
  6. package/lib/admin-protocol.d.ts +33 -4
  7. package/lib/admin-protocol.d.ts.map +1 -1
  8. package/lib/admin-protocol.js +15 -0
  9. package/lib/admin-protocol.js.map +1 -1
  10. package/lib/analytics.d.ts +44 -0
  11. package/lib/analytics.d.ts.map +1 -0
  12. package/lib/analytics.js +10 -0
  13. package/lib/analytics.js.map +1 -0
  14. package/lib/auth.d.ts +25 -0
  15. package/lib/auth.d.ts.map +1 -0
  16. package/lib/auth.js +16 -0
  17. package/lib/auth.js.map +1 -0
  18. package/lib/context-url.d.ts +31 -0
  19. package/lib/context-url.d.ts.map +1 -0
  20. package/lib/context-url.js +102 -0
  21. package/lib/context-url.js.map +1 -0
  22. package/lib/context-url.spec.d.ts +14 -0
  23. package/lib/context-url.spec.d.ts.map +1 -0
  24. package/lib/context-url.spec.js +109 -0
  25. package/lib/context-url.spec.js.map +1 -0
  26. package/lib/email-protocol.d.ts +1 -2
  27. package/lib/email-protocol.d.ts.map +1 -1
  28. package/lib/email-protocol.js +4 -4
  29. package/lib/email-protocol.js.map +1 -1
  30. package/lib/encryption/container-module.d.ts.map +1 -1
  31. package/lib/encryption/container-module.js +5 -4
  32. package/lib/encryption/container-module.js.map +1 -1
  33. package/lib/encryption/encryption-engine.d.ts.map +1 -1
  34. package/lib/encryption/encryption-engine.js +25 -26
  35. package/lib/encryption/encryption-engine.js.map +1 -1
  36. package/lib/encryption/encryption-engine.spec.d.ts.map +1 -1
  37. package/lib/encryption/encryption-engine.spec.js +29 -37
  38. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  39. package/lib/encryption/encryption-service.d.ts.map +1 -1
  40. package/lib/encryption/encryption-service.js +30 -44
  41. package/lib/encryption/encryption-service.js.map +1 -1
  42. package/lib/encryption/key-provider.d.ts.map +1 -1
  43. package/lib/encryption/key-provider.js +31 -38
  44. package/lib/encryption/key-provider.js.map +1 -1
  45. package/lib/env.d.ts +2 -3
  46. package/lib/env.d.ts.map +1 -1
  47. package/lib/env.js +24 -25
  48. package/lib/env.js.map +1 -1
  49. package/lib/gitpod-file-parser.d.ts.map +1 -1
  50. package/lib/gitpod-file-parser.js +26 -42
  51. package/lib/gitpod-file-parser.js.map +1 -1
  52. package/lib/gitpod-file-parser.spec.js +145 -142
  53. package/lib/gitpod-file-parser.spec.js.map +1 -1
  54. package/lib/gitpod-service.d.ts +172 -33
  55. package/lib/gitpod-service.d.ts.map +1 -1
  56. package/lib/gitpod-service.js +187 -267
  57. package/lib/gitpod-service.js.map +1 -1
  58. package/lib/headless-workspace-log.d.ts +9 -11
  59. package/lib/headless-workspace-log.d.ts.map +1 -1
  60. package/lib/headless-workspace-log.js +6 -8
  61. package/lib/headless-workspace-log.js.map +1 -1
  62. package/lib/ide-frontend-service.d.ts +5 -1
  63. package/lib/ide-frontend-service.d.ts.map +1 -1
  64. package/lib/ide-protocol.d.ts +105 -0
  65. package/lib/ide-protocol.d.ts.map +1 -0
  66. package/lib/{util/without.js → ide-protocol.js} +2 -2
  67. package/lib/ide-protocol.js.map +1 -0
  68. package/lib/index.d.ts +16 -10
  69. package/lib/index.d.ts.map +1 -1
  70. package/lib/index.js +7 -1
  71. package/lib/index.js.map +1 -1
  72. package/lib/installation-admin-protocol.d.ts +27 -0
  73. package/lib/installation-admin-protocol.d.ts.map +1 -0
  74. package/lib/installation-admin-protocol.js +30 -0
  75. package/lib/installation-admin-protocol.js.map +1 -0
  76. package/lib/license-protocol.d.ts.map +1 -1
  77. package/lib/license-protocol.js.map +1 -1
  78. package/lib/messaging/browser/connection.d.ts +5 -3
  79. package/lib/messaging/browser/connection.d.ts.map +1 -1
  80. package/lib/messaging/browser/connection.js +184 -34
  81. package/lib/messaging/browser/connection.js.map +1 -1
  82. package/lib/messaging/browser/window-connection.d.ts +4 -4
  83. package/lib/messaging/browser/window-connection.d.ts.map +1 -1
  84. package/lib/messaging/browser/window-connection.js +42 -59
  85. package/lib/messaging/browser/window-connection.js.map +1 -1
  86. package/lib/messaging/client-call-metrics.d.ts +35 -0
  87. package/lib/messaging/client-call-metrics.d.ts.map +1 -0
  88. package/lib/messaging/client-call-metrics.js +83 -0
  89. package/lib/messaging/client-call-metrics.js.map +1 -0
  90. package/lib/messaging/error.d.ts +5 -1
  91. package/lib/messaging/error.d.ts.map +1 -1
  92. package/lib/messaging/error.js +10 -2
  93. package/lib/messaging/error.js.map +1 -1
  94. package/lib/messaging/handler.d.ts +10 -0
  95. package/lib/messaging/handler.d.ts.map +1 -1
  96. package/lib/messaging/handler.js +1 -1
  97. package/lib/messaging/node/connection.d.ts +1 -17
  98. package/lib/messaging/node/connection.d.ts.map +1 -1
  99. package/lib/messaging/node/connection.js +24 -60
  100. package/lib/messaging/node/connection.js.map +1 -1
  101. package/lib/messaging/proxy-factory.d.ts +3 -1
  102. package/lib/messaging/proxy-factory.d.ts.map +1 -1
  103. package/lib/messaging/proxy-factory.js +75 -162
  104. package/lib/messaging/proxy-factory.js.map +1 -1
  105. package/lib/oss-allowlist.d.ts +14 -0
  106. package/lib/oss-allowlist.d.ts.map +1 -0
  107. package/lib/oss-allowlist.js +8 -0
  108. package/lib/oss-allowlist.js.map +1 -0
  109. package/lib/payment-protocol.d.ts +18 -0
  110. package/lib/payment-protocol.d.ts.map +1 -0
  111. package/lib/payment-protocol.js +13 -0
  112. package/lib/payment-protocol.js.map +1 -0
  113. package/lib/permission.d.ts +10 -5
  114. package/lib/permission.d.ts.map +1 -1
  115. package/lib/permission.js +41 -35
  116. package/lib/permission.js.map +1 -1
  117. package/lib/plans.d.ts +210 -0
  118. package/lib/plans.d.ts.map +1 -0
  119. package/lib/plans.js +605 -0
  120. package/lib/plans.js.map +1 -0
  121. package/lib/protocol.d.ts +164 -88
  122. package/lib/protocol.d.ts.map +1 -1
  123. package/lib/protocol.js +184 -199
  124. package/lib/protocol.js.map +1 -1
  125. package/lib/snapshot-url.d.ts +14 -0
  126. package/lib/snapshot-url.d.ts.map +1 -0
  127. package/lib/snapshot-url.js +26 -0
  128. package/lib/snapshot-url.js.map +1 -0
  129. package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
  130. package/lib/snapshot-url.spec.d.ts.map +1 -0
  131. package/lib/snapshot-url.spec.js +41 -0
  132. package/lib/snapshot-url.spec.js.map +1 -0
  133. package/lib/team-subscription-protocol.d.ts +75 -0
  134. package/lib/team-subscription-protocol.d.ts.map +1 -0
  135. package/lib/team-subscription-protocol.js +63 -0
  136. package/lib/team-subscription-protocol.js.map +1 -0
  137. package/lib/teams-projects-protocol.d.ts +113 -0
  138. package/lib/teams-projects-protocol.d.ts.map +1 -0
  139. package/lib/teams-projects-protocol.js +30 -0
  140. package/lib/teams-projects-protocol.js.map +1 -0
  141. package/lib/typings/globals.d.ts +2 -2
  142. package/lib/typings/globals.d.ts.map +1 -1
  143. package/lib/util/analytics.d.ts +8 -0
  144. package/lib/util/analytics.d.ts.map +1 -0
  145. package/lib/util/analytics.js +88 -0
  146. package/lib/util/analytics.js.map +1 -0
  147. package/lib/util/async-iterator.d.ts.map +1 -1
  148. package/lib/util/async-iterator.js +57 -135
  149. package/lib/util/async-iterator.js.map +1 -1
  150. package/lib/util/cancelable.js +17 -59
  151. package/lib/util/cancelable.js.map +1 -1
  152. package/lib/util/date-time.js +11 -11
  153. package/lib/util/date-time.js.map +1 -1
  154. package/lib/util/deferred.js +10 -12
  155. package/lib/util/deferred.js.map +1 -1
  156. package/lib/util/disposable.d.ts.map +1 -1
  157. package/lib/util/disposable.js +27 -40
  158. package/lib/util/disposable.js.map +1 -1
  159. package/lib/util/event.d.ts.map +1 -1
  160. package/lib/util/event.js +63 -77
  161. package/lib/util/event.js.map +1 -1
  162. package/lib/util/garbage-collected-cache.d.ts +1 -0
  163. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  164. package/lib/util/garbage-collected-cache.js +27 -47
  165. package/lib/util/garbage-collected-cache.js.map +1 -1
  166. package/lib/util/generate-workspace-id.d.ts +4 -0
  167. package/lib/util/generate-workspace-id.d.ts.map +1 -0
  168. package/lib/util/generate-workspace-id.js +487 -0
  169. package/lib/util/generate-workspace-id.js.map +1 -0
  170. package/{src/theia-plugins.ts → lib/util/generate-workspace-id.spec.d.ts} +2 -6
  171. package/lib/util/generate-workspace-id.spec.d.ts.map +1 -0
  172. package/lib/util/generate-workspace-id.spec.js +91 -0
  173. package/lib/util/generate-workspace-id.spec.js.map +1 -0
  174. package/lib/util/gitpod-cookie.d.ts +20 -0
  175. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  176. package/lib/util/gitpod-cookie.js +41 -0
  177. package/lib/util/gitpod-cookie.js.map +1 -0
  178. package/lib/util/gitpod-host-url.d.ts +2 -2
  179. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  180. package/lib/util/gitpod-host-url.js +109 -106
  181. package/lib/util/gitpod-host-url.js.map +1 -1
  182. package/lib/util/gitpod-host-url.spec.d.ts +8 -1
  183. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  184. package/lib/util/gitpod-host-url.spec.js +114 -22
  185. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  186. package/lib/util/grpc.d.ts +15 -0
  187. package/lib/util/grpc.d.ts.map +1 -0
  188. package/lib/util/grpc.js +18 -0
  189. package/lib/util/grpc.js.map +1 -0
  190. package/lib/util/jaeger-client-types.d.ts +68 -0
  191. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  192. package/lib/{theia-plugins.js → util/jaeger-client-types.js} +1 -1
  193. package/lib/util/jaeger-client-types.js.map +1 -0
  194. package/lib/util/logging.d.ts +49 -33
  195. package/lib/util/logging.d.ts.map +1 -1
  196. package/lib/util/logging.js +125 -129
  197. package/lib/util/logging.js.map +1 -1
  198. package/lib/util/make-link.js +5 -5
  199. package/lib/util/make-link.js.map +1 -1
  200. package/lib/util/parse-workspace-id.d.ts +13 -3
  201. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  202. package/lib/util/parse-workspace-id.js +37 -8
  203. package/lib/util/parse-workspace-id.js.map +1 -1
  204. package/lib/util/parse-workspace-id.spec.d.ts +8 -0
  205. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  206. package/lib/util/parse-workspace-id.spec.js +127 -47
  207. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  208. package/lib/util/queue.js +16 -55
  209. package/lib/util/queue.js.map +1 -1
  210. package/lib/util/queue.spec.js +147 -288
  211. package/lib/util/queue.spec.js.map +1 -1
  212. package/lib/util/repeat.d.ts +15 -0
  213. package/lib/util/repeat.d.ts.map +1 -0
  214. package/lib/util/repeat.js +55 -0
  215. package/lib/util/repeat.js.map +1 -0
  216. package/lib/util/semaphore.d.ts.map +1 -1
  217. package/lib/util/semaphore.js +15 -46
  218. package/lib/util/semaphore.js.map +1 -1
  219. package/lib/util/skip-if.d.ts.map +1 -1
  220. package/lib/util/skip-if.js +6 -6
  221. package/lib/util/skip-if.js.map +1 -1
  222. package/lib/util/timeutil.d.ts.map +1 -1
  223. package/lib/util/timeutil.js +28 -16
  224. package/lib/util/timeutil.js.map +1 -1
  225. package/lib/util/timeutil.spec.d.ts.map +1 -1
  226. package/lib/util/timeutil.spec.js +21 -24
  227. package/lib/util/timeutil.spec.js.map +1 -1
  228. package/lib/util/tracing.d.ts +52 -6
  229. package/lib/util/tracing.d.ts.map +1 -1
  230. package/lib/util/tracing.js +199 -64
  231. package/lib/util/tracing.js.map +1 -1
  232. package/lib/util/tracing.spec.d.ts +7 -0
  233. package/lib/util/tracing.spec.d.ts.map +1 -0
  234. package/lib/util/tracing.spec.js +121 -0
  235. package/lib/util/tracing.spec.js.map +1 -0
  236. package/lib/util/workspace-port-authentication.d.ts +7 -7
  237. package/lib/util/workspace-port-authentication.d.ts.map +1 -1
  238. package/lib/util/workspace-port-authentication.js +10 -12
  239. package/lib/util/workspace-port-authentication.js.map +1 -1
  240. package/lib/workspace-cluster.d.ts +76 -0
  241. package/lib/workspace-cluster.d.ts.map +1 -0
  242. package/lib/workspace-cluster.js +31 -0
  243. package/lib/workspace-cluster.js.map +1 -0
  244. package/lib/workspace-instance.d.ts +28 -4
  245. package/lib/workspace-instance.d.ts.map +1 -1
  246. package/lib/wsready.d.ts +1 -1
  247. package/lib/wsready.d.ts.map +1 -1
  248. package/lib/wsready.js +2 -2
  249. package/package.json +33 -17
  250. package/pkg-yarn.lock +18 -9
  251. package/provenance-bundle.jsonl +2 -0
  252. package/src/accounting-protocol.ts +231 -0
  253. package/src/admin-protocol.ts +71 -19
  254. package/src/analytics.ts +52 -0
  255. package/src/auth.ts +27 -0
  256. package/src/context-url.spec.ts +67 -0
  257. package/src/context-url.ts +109 -0
  258. package/src/email-protocol.ts +5 -7
  259. package/src/encryption/container-module.ts +2 -3
  260. package/src/encryption/encryption-engine.spec.ts +9 -8
  261. package/src/encryption/encryption-engine.ts +14 -14
  262. package/src/encryption/encryption-service.ts +4 -5
  263. package/src/encryption/key-provider.ts +16 -19
  264. package/src/env.ts +18 -18
  265. package/src/gitpod-file-parser.spec.ts +55 -61
  266. package/src/gitpod-file-parser.ts +16 -17
  267. package/src/gitpod-service.ts +327 -102
  268. package/src/headless-workspace-log.ts +12 -14
  269. package/src/ide-frontend-service.ts +6 -2
  270. package/src/ide-protocol.ts +119 -0
  271. package/src/index.ts +16 -10
  272. package/src/installation-admin-protocol.ts +42 -0
  273. package/src/license-protocol.ts +5 -6
  274. package/src/messaging/browser/connection.ts +197 -18
  275. package/src/messaging/browser/window-connection.ts +39 -29
  276. package/src/messaging/client-call-metrics.ts +96 -0
  277. package/src/messaging/error.ts +15 -5
  278. package/src/messaging/handler.ts +13 -1
  279. package/src/messaging/node/connection.ts +23 -70
  280. package/src/messaging/proxy-factory.ts +35 -34
  281. package/src/oss-allowlist.ts +15 -0
  282. package/src/payment-protocol.ts +20 -0
  283. package/src/permission.ts +42 -38
  284. package/src/plans.ts +679 -0
  285. package/src/protocol.ts +384 -279
  286. package/src/snapshot-url.spec.ts +27 -0
  287. package/src/snapshot-url.ts +27 -0
  288. package/src/team-subscription-protocol.ts +123 -0
  289. package/src/teams-projects-protocol.ts +147 -0
  290. package/src/typings/globals.ts +4 -4
  291. package/src/util/analytics.ts +109 -0
  292. package/src/util/async-iterator.ts +4 -5
  293. package/src/util/cancelable.ts +3 -3
  294. package/src/util/date-time.ts +8 -8
  295. package/src/util/deferred.ts +6 -6
  296. package/src/util/disposable.ts +3 -6
  297. package/src/util/event.ts +9 -11
  298. package/src/util/garbage-collected-cache.ts +11 -8
  299. package/src/util/generate-workspace-id.spec.ts +51 -0
  300. package/src/util/generate-workspace-id.ts +475 -0
  301. package/src/util/gitpod-cookie.ts +38 -0
  302. package/src/util/gitpod-host-url.spec.ts +63 -7
  303. package/src/util/gitpod-host-url.ts +55 -38
  304. package/src/util/grpc.ts +15 -0
  305. package/src/util/jaeger-client-types.ts +102 -0
  306. package/src/util/logging.ts +145 -71
  307. package/src/util/make-link.ts +6 -7
  308. package/src/util/parse-workspace-id.spec.ts +60 -10
  309. package/src/util/parse-workspace-id.ts +38 -8
  310. package/src/util/queue.spec.ts +28 -26
  311. package/src/util/repeat.ts +45 -0
  312. package/src/util/semaphore.ts +6 -8
  313. package/src/util/skip-if.ts +10 -7
  314. package/src/util/timeutil.spec.ts +14 -15
  315. package/src/util/timeutil.ts +19 -15
  316. package/src/util/tracing.spec.ts +88 -0
  317. package/src/util/tracing.ts +202 -31
  318. package/src/util/workspace-port-authentication.ts +10 -13
  319. package/src/workspace-cluster.ts +107 -0
  320. package/src/workspace-instance.ts +72 -30
  321. package/src/wsready.ts +3 -3
  322. package/data/builtin-theia-plugins.json +0 -372
  323. package/lib/messaging/connection-error-handler.d.ts +0 -27
  324. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  325. package/lib/messaging/connection-error-handler.js +0 -46
  326. package/lib/messaging/connection-error-handler.js.map +0 -1
  327. package/lib/theia-plugins.d.ts +0 -11
  328. package/lib/theia-plugins.d.ts.map +0 -1
  329. package/lib/theia-plugins.js.map +0 -1
  330. package/lib/util/repeater.d.ts +0 -22
  331. package/lib/util/repeater.d.ts.map +0 -1
  332. package/lib/util/repeater.js +0 -118
  333. package/lib/util/repeater.js.map +0 -1
  334. package/lib/util/safe-promise.d.ts +0 -11
  335. package/lib/util/safe-promise.d.ts.map +0 -1
  336. package/lib/util/safe-promise.js +0 -34
  337. package/lib/util/safe-promise.js.map +0 -1
  338. package/lib/util/without.d.ts +0 -7
  339. package/lib/util/without.d.ts.map +0 -1
  340. package/lib/util/without.js.map +0 -1
  341. package/src/messaging/connection-error-handler.ts +0 -62
  342. package/src/util/jaeger-client.d.ts +0 -105
  343. package/src/util/repeater.ts +0 -49
  344. package/src/util/safe-promise.ts +0 -26
@@ -0,0 +1,45 @@
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 { Disposable } from "..";
8
+ import { log } from "./logging";
9
+
10
+ /**
11
+ * This intends to be a drop-in replacement for 'setInterval' implemented with a 'setTimeout' chain
12
+ * to ensure we're not creating more timeouts than we can process.
13
+ * @param op
14
+ * @param everyMilliseconds
15
+ * @returns
16
+ */
17
+ export function repeat(op: () => Promise<void> | void, everyMilliseconds: number): Disposable {
18
+ let timer: NodeJS.Timeout | undefined = undefined;
19
+ let stopped = false;
20
+ const repeated = () => {
21
+ if (stopped) {
22
+ // in case we missed the clearTimeout i 'await'
23
+ return;
24
+ }
25
+
26
+ timer = setTimeout(async () => {
27
+ try {
28
+ await op();
29
+ } catch (err) {
30
+ // catch error here to
31
+ log.error(err);
32
+ }
33
+
34
+ repeated(); // chain ourselves - after the 'await'
35
+ }, everyMilliseconds);
36
+ };
37
+ repeated();
38
+
39
+ return Disposable.create(() => {
40
+ stopped = true;
41
+ if (timer) {
42
+ clearTimeout(timer);
43
+ }
44
+ });
45
+ }
@@ -4,20 +4,19 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
-
8
7
  export class Semaphore {
9
8
  protected queue: (() => void)[] = [];
10
9
  protected used: number;
11
10
 
12
- constructor(protected readonly capacity: number) {
13
- if(capacity < 1) {
11
+ constructor(protected readonly capacity: number) {
12
+ if (capacity < 1) {
14
13
  throw new Error("Capacity cannot be less than 1");
15
14
  }
16
15
  }
17
16
 
18
17
  public release() {
19
- if(this.used == 0) return;
20
-
18
+ if (this.used == 0) return;
19
+
21
20
  const queued = this.queue.shift();
22
21
  if (queued) {
23
22
  queued();
@@ -28,7 +27,7 @@ export class Semaphore {
28
27
 
29
28
  public async acquire(): Promise<void> {
30
29
  this.used++;
31
- if(this.used <= this.capacity) {
30
+ if (this.used <= this.capacity) {
32
31
  return Promise.resolve();
33
32
  }
34
33
 
@@ -36,5 +35,4 @@ export class Semaphore {
36
35
  this.queue.push(rs);
37
36
  });
38
37
  }
39
-
40
- }
38
+ }
@@ -4,7 +4,6 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
-
8
7
  /**
9
8
  * The subset of actually available fields and methods which are not exported but we care about
10
9
  */
@@ -18,16 +17,20 @@ interface TestSuiteContext extends Mocha.ISuiteCallbackContext {
18
17
  * @param doSkip A function which takes a TestSuite and decides if it should be skipped
19
18
  */
20
19
  export function skipIf(doSkip: (suite: TestSuiteContext) => boolean): MochaTypeScript.SuiteTrait {
21
- const trait: MochaTypeScript.SuiteTrait = function(this: Mocha.ISuiteCallbackContext, ctx: Mocha.ISuiteCallbackContext, ctor: Function): void {
22
- const suite = ctx as any as TestSuiteContext; // No idea why those fields are not exported in the types
20
+ const trait: MochaTypeScript.SuiteTrait = function (
21
+ this: Mocha.ISuiteCallbackContext,
22
+ ctx: Mocha.ISuiteCallbackContext,
23
+ ctor: Function,
24
+ ): void {
25
+ const suite = ctx as any as TestSuiteContext; // No idea why those fields are not exported in the types
23
26
  const skip = doSkip(suite);
24
- suite.beforeEach(function(this: Mocha.IHookCallbackContext) {
27
+ suite.beforeEach(function (this: Mocha.IHookCallbackContext) {
25
28
  if (skip) {
26
29
  this.skip();
27
30
  }
28
- })
31
+ });
29
32
  };
30
-
33
+
31
34
  // Mark as "trait": mimics the behavior of https://github.com/testdeck/testdeck/blob/9d2dd6a458c2c86c945f6f2999b8278b7528a7a7/index.ts#L433
32
35
  (trait as any)["__mts_isTrait"] = true;
33
36
  return trait;
@@ -45,4 +48,4 @@ export function skipIfEnvVarNotSet(name: string): MochaTypeScript.SuiteTrait {
45
48
  }
46
49
  return skip;
47
50
  });
48
- }
51
+ }
@@ -4,40 +4,39 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
- import * as chai from 'chai';
7
+ import * as chai from "chai";
8
8
  const expect = chai.expect;
9
- import { suite, test } from 'mocha-typescript';
10
- import { oneMonthLater } from './timeutil';
9
+ import { suite, test } from "mocha-typescript";
10
+ import { oneMonthLater } from "./timeutil";
11
11
 
12
12
  @suite()
13
13
  export class TimeutilSpec {
14
-
15
14
  @test
16
15
  testTimeutil() {
17
16
  // targeting a 1st, 1th of Jan => 1st of Feb
18
- this.isOneMonthLater(new Date(2000, 0, 1), 1, new Date(2000, 1, 1))
17
+ this.isOneMonthLater(new Date(2000, 0, 1), 1, new Date(2000, 1, 1));
19
18
 
20
19
  // targeting a 31th, 30th of Apr => 31st of May
21
- this.isOneMonthLater(new Date(2000, 3, 30), 31, new Date(2000, 4, 31))
20
+ this.isOneMonthLater(new Date(2000, 3, 30), 31, new Date(2000, 4, 31));
22
21
 
23
22
  // targeting a 31th, 31th of Mar => 30th of Apr
24
- this.isOneMonthLater(new Date(2000, 2, 31), 31, new Date(2000, 3, 30))
23
+ this.isOneMonthLater(new Date(2000, 2, 31), 31, new Date(2000, 3, 30));
25
24
 
26
25
  // targeting a 30th, 30th of Mar => 30th of Apr
27
- this.isOneMonthLater(new Date(2000, 2, 30), 30, new Date(2000, 3, 30))
26
+ this.isOneMonthLater(new Date(2000, 2, 30), 30, new Date(2000, 3, 30));
28
27
 
29
28
  // next year
30
- this.isOneMonthLater(new Date(2000, 11, 1), 1, new Date(2001, 0, 1))
31
- this.isOneMonthLater(new Date(2000, 11, 31), 31, new Date(2001, 0, 31))
29
+ this.isOneMonthLater(new Date(2000, 11, 1), 1, new Date(2001, 0, 1));
30
+ this.isOneMonthLater(new Date(2000, 11, 31), 31, new Date(2001, 0, 31));
32
31
 
33
32
  // Feb
34
- this.isOneMonthLater(new Date(2001, 0, 31), 31, new Date(2001, 1, 28))
33
+ this.isOneMonthLater(new Date(2001, 0, 31), 31, new Date(2001, 1, 28));
35
34
  // Feb leap year
36
- this.isOneMonthLater(new Date(2000, 0, 31), 31, new Date(2000, 1, 29))
35
+ this.isOneMonthLater(new Date(2000, 0, 31), 31, new Date(2000, 1, 29));
37
36
  }
38
37
 
39
38
  isOneMonthLater(from: Date, day: number, expectation: Date) {
40
- const later = oneMonthLater(from.toISOString(), day)
41
- expect(later, `expected ${later} to be equal ${expectation}`).to.be.equal(expectation.toISOString())
39
+ const later = oneMonthLater(from.toISOString(), day);
40
+ expect(later, `expected ${later} to be equal ${expectation}`).to.be.equal(expectation.toISOString());
42
41
  }
43
- }
42
+ }
@@ -6,12 +6,12 @@
6
6
 
7
7
  /**
8
8
  * Returns the <code>day</code>th of the next month from <code>formDate</code>.
9
- * If the next month does not have a <code>day</code>th, the last day of that
9
+ * If the next month does not have a <code>day</code>th, the last day of that
10
10
  * month is taken.
11
11
  * The time is copied from <code>fromDate</code>.
12
- *
13
- * @param fromDate
14
- * @param day
12
+ *
13
+ * @param fromDate
14
+ * @param day
15
15
  */
16
16
  export function oneMonthLater(fromDate: string, day?: number): string {
17
17
  const later = new Date(fromDate);
@@ -24,28 +24,32 @@ export function oneMonthLater(fromDate: string, day?: number): string {
24
24
  }
25
25
  return later.toISOString();
26
26
  }
27
- export const yearsLater = (fromDate: string, years: number): string => liftDate1(fromDate, (d) => {
28
- d.setUTCFullYear(d.getUTCFullYear() + years);
29
- return d.toISOString();
30
- });
27
+ export const yearsLater = (fromDate: string, years: number): string =>
28
+ liftDate1(fromDate, (d) => {
29
+ d.setUTCFullYear(d.getUTCFullYear() + years);
30
+ return d.toISOString();
31
+ });
31
32
 
32
33
  // tslint:disable-next-line:no-shadowed-variable
33
- export const addMillis = (d1: string, millis: number) => liftDate1(d1, (d1) => new Date(d1.getTime() + millis).toISOString());
34
- export const durationInHours = (d1: string, d2: string) => liftDate(d1, d2, (d1, d2) => millisecondsToHours(d1.getTime() - d2.getTime()));
34
+ export const addMillis = (d1: string, millis: number) =>
35
+ liftDate1(d1, (d1) => new Date(d1.getTime() + millis).toISOString());
36
+ export const durationInHours = (d1: string, d2: string) =>
37
+ liftDate(d1, d2, (d1, d2) => millisecondsToHours(d1.getTime() - d2.getTime()));
35
38
  export const durationInMillis = (d1: string, d2: string) => liftDate(d1, d2, (d1, d2) => d1.getTime() - d2.getTime());
36
39
  // tslint:disable-next-line:no-shadowed-variable
37
- export const isDateGreaterOrEqual = (d1: string, d2: string): boolean => liftDate(d1, d2, (d1, d2) => d1.getTime() >= d2.getTime());
40
+ export const isDateGreaterOrEqual = (d1: string, d2: string): boolean =>
41
+ liftDate(d1, d2, (d1, d2) => d1.getTime() >= d2.getTime());
38
42
  export const isDateSmallerOrEqual = (d1: string, d2: string | undefined) => !d2 || d1 <= d2;
39
43
  export const isDateSmaller = (d1: string, d2: string | undefined) => !d2 || d1 < d2;
40
- export const oldest = (d1: string, d2: string): string => d1 > d2 ? d1 : d2;
41
- export const earliest = (d1: string, d2: string): string => d1 < d2 ? d1 : d2;
44
+ export const oldest = (d1: string, d2: string): string => (d1 > d2 ? d1 : d2);
45
+ export const earliest = (d1: string, d2: string): string => (d1 < d2 ? d1 : d2);
42
46
  export const orderAsc = (d1: string, d2: string): number => liftDate(d1, d2, (d1, d2) => d1.getTime() - d2.getTime());
43
47
  export const liftDate1 = <T>(d1: string, f: (d1: Date) => T): T => f(new Date(d1));
44
48
  export const liftDate = <T>(d1: string, d2: string, f: (d1: Date, d2: Date) => T): T => f(new Date(d1), new Date(d2));
45
49
 
46
50
  export function hoursLater(date: string, hours: number): string {
47
- const result = new Date(date)
48
- result.setHours(result.getHours() + hours)
51
+ const result = new Date(date);
52
+ result.setHours(result.getHours() + hours);
49
53
  return result.toISOString();
50
54
  }
51
55
 
@@ -0,0 +1,88 @@
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 * as chai from "chai";
9
+ import { TraceContext } from "./tracing";
10
+ import { MockTracer } from "opentracing";
11
+
12
+ const expect = chai.expect;
13
+
14
+ @suite
15
+ class TestTracing {
16
+ @test public async testTracingContext_addNestedTags() {
17
+ const tracer = new MockTracer();
18
+ const span = tracer.startSpan("testTracingContext_addNestedTags");
19
+ TraceContext.addNestedTags(
20
+ { span },
21
+ {
22
+ rpc: {
23
+ system: "jsonrpc",
24
+ jsonrpc: {
25
+ version: "1.0",
26
+ method: "test",
27
+ parameters: ["abc", "def"],
28
+ },
29
+ },
30
+ },
31
+ );
32
+
33
+ const mockSpan = tracer.report().spans[0];
34
+ expect(mockSpan.tags()).to.deep.equal({
35
+ "rpc.system": "jsonrpc",
36
+ "rpc.jsonrpc.version": "1.0",
37
+ "rpc.jsonrpc.method": "test",
38
+ "rpc.jsonrpc.parameters.0": "abc",
39
+ "rpc.jsonrpc.parameters.1": "def",
40
+ });
41
+ }
42
+
43
+ @test public async testTracingContext_addNestedTags_null() {
44
+ const tracer = new MockTracer();
45
+ const span = tracer.startSpan("testTracingContext_addNestedTags_null");
46
+ TraceContext.addNestedTags(
47
+ { span },
48
+ {
49
+ someShape: {
50
+ thisIsNull: null,
51
+ thisIsUndefined: undefined,
52
+ },
53
+ },
54
+ );
55
+
56
+ const mockSpan = tracer.report().spans[0];
57
+ expect(mockSpan.tags()).to.deep.equal({
58
+ "someShape.thisIsNull": null,
59
+ "someShape.thisIsUndefined": undefined,
60
+ });
61
+ }
62
+
63
+ @test public async testTracingContext_addJsonRPCParameters() {
64
+ const tracer = new MockTracer();
65
+ const span = tracer.startSpan("testTracingContext_addJsonRPCParameters");
66
+ const ctx = { span };
67
+ TraceContext.addJsonRPCParameters(ctx, {
68
+ one: "one",
69
+ two: {
70
+ name: "two",
71
+ some: "shape",
72
+ containing: "PII",
73
+ },
74
+ three: "three",
75
+ });
76
+
77
+ const mockSpan = tracer.report().spans[0];
78
+ expect(mockSpan.tags()).to.deep.equal({
79
+ "rpc.jsonrpc.parameters.one": "one",
80
+ "rpc.jsonrpc.parameters.two.containing": "PII",
81
+ "rpc.jsonrpc.parameters.two.name": "two",
82
+ "rpc.jsonrpc.parameters.two.some": "shape",
83
+ "rpc.jsonrpc.parameters.three": "three",
84
+ "rpc.system": "jsonrpc",
85
+ });
86
+ }
87
+ }
88
+ module.exports = new TestTracing();
@@ -4,48 +4,194 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
-
8
- import * as opentracing from 'opentracing';
9
- import { TracingConfig, initTracerFromEnv, Sampler, SamplingDecision } from 'jaeger-client';
10
- import { initGlobalTracer } from 'opentracing';
11
- import { injectable } from 'inversify';
7
+ import * as opentracing from "opentracing";
8
+ import { TracingConfig, initTracerFromEnv } from "jaeger-client";
9
+ import { Sampler, SamplingDecision } from "./jaeger-client-types";
10
+ import { initGlobalTracer } from "opentracing";
11
+ import { injectable } from "inversify";
12
+ import { ResponseError } from "vscode-jsonrpc";
13
+ import { log, LogContext } from "./logging";
12
14
 
13
15
  export interface TraceContext {
14
- span?: opentracing.Span
16
+ span?: opentracing.Span;
15
17
  }
18
+ export type TraceContextWithSpan = TraceContext & {
19
+ span: opentracing.Span;
20
+ };
16
21
 
17
22
  export namespace TraceContext {
18
- export function startSpan(operation: string, ctx: TraceContext): opentracing.Span {
19
- const options: opentracing.SpanOptions = {
20
- childOf: ctx.span
23
+ export function startSpan(operation: string, parentCtx?: TraceContext): opentracing.Span {
24
+ const options: opentracing.SpanOptions = {};
25
+ if (parentCtx && parentCtx.span && !!parentCtx.span.context().toSpanId()) {
26
+ options.childOf = parentCtx.span;
21
27
  }
28
+ // TODO(gpl) references lead to a huge amount of errors in prod logs. Avoid those until we have time to figure out how to fix it.
29
+ // if (referencedSpans) {
30
+ // // note: allthough followsForm's type says it takes 'opentracing.Span | opentracing.SpanContext', it only works with SpanContext (typing mismatch)
31
+ // // note2: we need to filter out debug spans (spanId === "")
32
+ // options.references = referencedSpans.filter(s => s !== undefined)
33
+ // .filter(s => !!s!.context().toSpanId())
34
+ // .map(s => followsFrom(s!.context()));
35
+ // }
36
+
22
37
  return opentracing.globalTracer().startSpan(operation, options);
23
38
  }
24
39
 
25
- export function startAsyncSpan(operation: string, ctx: TraceContext): opentracing.Span {
26
- const options: opentracing.SpanOptions = {};
27
- if (!!ctx.span) {
28
- options.references = [opentracing.followsFrom(ctx.span.context())];
40
+ export function childContext(operation: string, parentCtx: TraceContext): TraceContextWithSpan {
41
+ const span = startSpan(operation, parentCtx);
42
+ return { span };
43
+ }
44
+
45
+ export function withSpan(operation: string, callback: (ctx: TraceContext) => void, ctx?: TraceContext): void {
46
+ // if we don't have a parent span, don't create a trace here as those <trace-without-root-spans> are not useful.
47
+ if (!ctx || !ctx.span || !ctx.span.context()) {
48
+ callback({});
49
+ return;
50
+ }
51
+
52
+ const span = TraceContext.startSpan(operation, ctx);
53
+ try {
54
+ callback({ span });
55
+ } catch (e) {
56
+ TraceContext.setError({ span }, e);
57
+ throw e;
58
+ } finally {
59
+ span.finish();
60
+ }
61
+ }
62
+
63
+ export function setError(ctx: TraceContext, err: Error) {
64
+ if (!ctx.span) {
65
+ return;
66
+ }
67
+
68
+ TraceContext.addNestedTags(ctx, {
69
+ error: {
70
+ message: err.message,
71
+ stacktrace: err.stack,
72
+ },
73
+ });
74
+ ctx.span.setTag("error", true);
75
+ }
76
+
77
+ export function setJsonRPCMetadata(ctx: TraceContext, method?: string) {
78
+ if (!ctx.span) {
79
+ return;
80
+ }
81
+
82
+ const tags: { [key: string]: any } = {
83
+ rpc: {
84
+ system: "jsonrpc",
85
+ // version,
86
+ },
87
+ };
88
+ if (method) {
89
+ tags.rpc.method = method;
90
+ }
91
+ addNestedTags(ctx, tags);
92
+ }
93
+
94
+ export function setJsonRPCError(
95
+ ctx: TraceContext,
96
+ method: string,
97
+ err: ResponseError<any>,
98
+ withStatusCode: boolean = false,
99
+ ) {
100
+ if (!ctx.span) {
101
+ return;
102
+ }
103
+ // not use setError bc this is (most likely) a working operation
104
+
105
+ setJsonRPCMetadata(ctx, method);
106
+ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md#json-rpc
107
+ addNestedTags(ctx, {
108
+ rpc: {
109
+ jsonrpc: {
110
+ error_code: err.code,
111
+ error_message: err.message,
112
+ },
113
+ },
114
+ });
115
+
116
+ // the field "status_code" is used by honeycomb to derive insights like success rate, etc. Defaults to "0".
117
+ if (withStatusCode) {
118
+ ctx.span.setTag("status_code", err.code);
29
119
  }
30
- return opentracing.globalTracer().startSpan(operation, options);
31
120
  }
32
121
 
33
- export function logError(ctx: TraceContext, err: Error) {
122
+ export function addJsonRPCParameters(ctx: TraceContext, params: { [key: string]: any }) {
34
123
  if (!ctx.span) {
35
124
  return;
36
125
  }
37
126
 
38
- ctx.span.log({
39
- "error": err.message,
40
- "stacktrace": err.stack
41
- })
42
- ctx.span.setTag("error", true)
127
+ setJsonRPCMetadata(ctx);
128
+ addNestedTags(ctx, {
129
+ rpc: {
130
+ jsonrpc: {
131
+ parameters: params,
132
+ },
133
+ },
134
+ });
135
+ }
136
+
137
+ /**
138
+ * Does what one would expect from `span.addTags`: Calls `span.addTag` for all keys in map, recursively for objects.
139
+ * Example:
140
+ * ```
141
+ * TraceContext.addNestedTags(ctx, {
142
+ * rpc: {
143
+ * system: "jsonrpc",
144
+ * jsonrpc: {
145
+ * version: "1.0",
146
+ * method: "test",
147
+ * parameters: ["abc", "def"],
148
+ * },
149
+ * },
150
+ * });
151
+ * ```
152
+ * gives
153
+ * rpc.system = "jsonrpc"
154
+ * rpc.jsonrpc.version = "1.0"
155
+ * rpc.jsonrpc.method = "test"
156
+ * rpc.jsonrpc.parameters.0 = "abc"
157
+ * rpc.jsonrpc.parameters.1 = "def"
158
+ * @param ctx
159
+ * @param keyValueMap
160
+ * @returns
161
+ */
162
+ export function addNestedTags(ctx: TraceContext, keyValueMap: { [key: string]: any }, _namespace?: string) {
163
+ if (!ctx.span) {
164
+ return;
165
+ }
166
+ const namespace = _namespace ? `${_namespace}.` : "";
167
+
168
+ try {
169
+ for (const k of Object.keys(keyValueMap)) {
170
+ const v = keyValueMap[k];
171
+ if (v instanceof Object) {
172
+ addNestedTags(ctx, v, `${namespace}${k}`);
173
+ } else {
174
+ ctx.span.setTag(`${namespace}${k}`, v);
175
+ }
176
+ }
177
+ } catch (err) {
178
+ // general resilience against odd shapes/parameters
179
+ log.error("Tracing.addNestedTags", err, { namespace });
180
+ }
181
+ }
182
+
183
+ export function setOWI(ctx: TraceContext, owi: LogContext) {
184
+ if (!ctx.span) {
185
+ return;
186
+ }
187
+ addNestedTags(ctx, {
188
+ context: owi,
189
+ });
43
190
  }
44
191
  }
45
192
 
46
193
  @injectable()
47
194
  export class TracingManager {
48
-
49
195
  public setup(serviceName: string, opts?: CustomTracerOpts) {
50
196
  initGlobalTracer(this.getTracerForService(serviceName, opts));
51
197
  }
@@ -54,13 +200,18 @@ export class TracingManager {
54
200
  const config: TracingConfig = {
55
201
  disable: false,
56
202
  reporter: {
57
- logSpans: false
203
+ logSpans: false,
58
204
  },
59
- serviceName
60
- }
205
+ serviceName,
206
+ };
61
207
  const t = initTracerFromEnv(config, {
62
- logger: console
208
+ logger: console,
209
+ tags: {
210
+ "service.build.commit": process.env.GITPOD_BUILD_GIT_COMMIT,
211
+ "service.build.version": process.env.GITPOD_BUILD_VERSION,
212
+ },
63
213
  });
214
+
64
215
  if (opts) {
65
216
  if (opts.perOpSampling) {
66
217
  (t as any)._sampler = new PerOperationSampler((t as any)._sampler, opts.perOpSampling);
@@ -68,24 +219,22 @@ export class TracingManager {
68
219
  }
69
220
  return t;
70
221
  }
71
-
72
222
  }
73
223
 
74
224
  export interface CustomTracerOpts {
75
- perOpSampling?: PerOperationSampling
225
+ perOpSampling?: PerOperationSampling;
76
226
  }
77
227
 
78
-
79
228
  // has to conform to https://github.com/jaegertracing/jaeger-client-node/blob/0042b1c0a0796bb655eb93e77ff76ab5e94c2bb6/src/_flow/sampler-thrift.js#L32
80
229
  export interface PerOperationSampling {
81
- [key: string]: boolean
230
+ [key: string]: boolean;
82
231
  }
83
232
 
84
233
  export class PerOperationSampler implements Sampler {
85
234
  constructor(protected readonly fallback: Sampler, protected readonly strategies: PerOperationSampling) {}
86
235
 
87
236
  name(): string {
88
- return 'PerOperationSampler';
237
+ return "PerOperationSampler";
89
238
  }
90
239
 
91
240
  toString(): string {
@@ -125,10 +274,32 @@ export class PerOperationSampler implements Sampler {
125
274
  return false; // TODO equal should be removed
126
275
  }
127
276
 
128
- close(callback: ()=>void): void {
277
+ close(callback: () => void): void {
129
278
  // all nested samplers are of simple types, so we do not need to Close them
130
279
  if (callback) {
131
280
  callback();
132
281
  }
133
282
  }
134
283
  }
284
+
285
+ // Augment interfaces with an leading parameter "TraceContext" on every method
286
+ type IsValidArg<T> = T extends object ? (keyof T extends never ? false : true) : true;
287
+ type AddTraceContext<T> = T extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E, f: infer F) => infer R
288
+ ? IsValidArg<F> extends true
289
+ ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E, f: F) => R
290
+ : IsValidArg<E> extends true
291
+ ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E) => R
292
+ : IsValidArg<D> extends true
293
+ ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D) => R
294
+ : IsValidArg<C> extends true
295
+ ? (ctx: TraceContextWithSpan, a: A, b: B, c: C) => R
296
+ : IsValidArg<B> extends true
297
+ ? (ctx: TraceContextWithSpan, a: A, b: B) => R
298
+ : IsValidArg<A> extends true
299
+ ? (ctx: TraceContextWithSpan, a: A) => R
300
+ : (ctx: TraceContextWithSpan) => Promise<R>
301
+ : never;
302
+
303
+ export type InterfaceWithTraceContext<T> = {
304
+ [P in keyof T]: AddTraceContext<T[P]>;
305
+ };
@@ -5,16 +5,13 @@
5
5
  */
6
6
 
7
7
  /**
8
- * These cookies are set in the Theia frontend. This pattern is relied upon in:
9
- * - proxy:
10
- * - to filter it out on port locations
11
- * - to forward it to the server for authentication
12
- * - server:
13
- * - to authenticate access to port locations
14
- */
15
- export const worspacePortAuthCookieName = function(host: string, workspaceId: string): string {
16
- return host
17
- .replace(/https?/, '')
18
- .replace(/[\W_]+/g, "_")
19
- + `_ws_${workspaceId}_port_auth_`;
20
- };
8
+ * These cookies are set in the Theia frontend. This pattern is relied upon in:
9
+ * - proxy:
10
+ * - to filter it out on port locations
11
+ * - to forward it to the server for authentication
12
+ * - server:
13
+ * - to authenticate access to port locations
14
+ */
15
+ export const worspacePortAuthCookieName = function (host: string, workspaceId: string): string {
16
+ return host.replace(/https?/, "").replace(/[\W_]+/g, "_") + `_ws_${workspaceId}_port_auth_`;
17
+ };