@gitpod/gitpod-protocol 0.1.5-pluggable-workspace-cluster.9 → 0.1.5-port-description-3059-fork.2

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 (273) hide show
  1. package/data/gitpod-schema.json +13 -24
  2. package/lib/accounting-protocol.d.ts +3 -6
  3. package/lib/accounting-protocol.d.ts.map +1 -1
  4. package/lib/accounting-protocol.js +10 -16
  5. package/lib/accounting-protocol.js.map +1 -1
  6. package/lib/admin-protocol.d.ts +15 -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 +45 -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/context-url.d.ts +18 -0
  15. package/lib/context-url.d.ts.map +1 -0
  16. package/lib/context-url.js +49 -0
  17. package/lib/context-url.js.map +1 -0
  18. package/lib/{util/context-url.spec.d.ts → context-url.spec.d.ts} +2 -0
  19. package/lib/context-url.spec.d.ts.map +1 -0
  20. package/lib/context-url.spec.js +73 -0
  21. package/lib/context-url.spec.js.map +1 -0
  22. package/lib/email-protocol.d.ts +1 -2
  23. package/lib/email-protocol.d.ts.map +1 -1
  24. package/lib/email-protocol.js +4 -4
  25. package/lib/email-protocol.js.map +1 -1
  26. package/lib/encryption/container-module.js +4 -4
  27. package/lib/encryption/container-module.js.map +1 -1
  28. package/lib/encryption/encryption-engine.js +19 -20
  29. package/lib/encryption/encryption-engine.js.map +1 -1
  30. package/lib/encryption/encryption-engine.spec.js +29 -36
  31. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  32. package/lib/encryption/encryption-service.js +29 -43
  33. package/lib/encryption/encryption-service.js.map +1 -1
  34. package/lib/encryption/key-provider.js +25 -30
  35. package/lib/encryption/key-provider.js.map +1 -1
  36. package/lib/env.d.ts +1 -2
  37. package/lib/env.d.ts.map +1 -1
  38. package/lib/env.js +20 -21
  39. package/lib/env.js.map +1 -1
  40. package/lib/gitpod-file-parser.js +25 -41
  41. package/lib/gitpod-file-parser.js.map +1 -1
  42. package/lib/gitpod-file-parser.spec.js +116 -116
  43. package/lib/gitpod-file-parser.spec.js.map +1 -1
  44. package/lib/gitpod-service.d.ts +96 -19
  45. package/lib/gitpod-service.d.ts.map +1 -1
  46. package/lib/gitpod-service.js +155 -278
  47. package/lib/gitpod-service.js.map +1 -1
  48. package/lib/headless-workspace-log.d.ts +8 -11
  49. package/lib/headless-workspace-log.d.ts.map +1 -1
  50. package/lib/headless-workspace-log.js +4 -7
  51. package/lib/headless-workspace-log.js.map +1 -1
  52. package/lib/ide-protocol.d.ts +81 -0
  53. package/lib/ide-protocol.d.ts.map +1 -0
  54. package/lib/ide-protocol.js +8 -0
  55. package/lib/ide-protocol.js.map +1 -0
  56. package/lib/index.d.ts +4 -0
  57. package/lib/index.d.ts.map +1 -1
  58. package/lib/index.js +4 -0
  59. package/lib/index.js.map +1 -1
  60. package/lib/messaging/browser/connection.d.ts +4 -6
  61. package/lib/messaging/browser/connection.d.ts.map +1 -1
  62. package/lib/messaging/browser/connection.js +175 -44
  63. package/lib/messaging/browser/connection.js.map +1 -1
  64. package/lib/messaging/browser/window-connection.js +35 -55
  65. package/lib/messaging/browser/window-connection.js.map +1 -1
  66. package/lib/messaging/client-call-metrics.d.ts +35 -0
  67. package/lib/messaging/client-call-metrics.d.ts.map +1 -0
  68. package/lib/messaging/client-call-metrics.js +83 -0
  69. package/lib/messaging/client-call-metrics.js.map +1 -0
  70. package/lib/messaging/connection-error-handler.js +11 -23
  71. package/lib/messaging/connection-error-handler.js.map +1 -1
  72. package/lib/messaging/error.d.ts +2 -1
  73. package/lib/messaging/error.d.ts.map +1 -1
  74. package/lib/messaging/error.js +4 -2
  75. package/lib/messaging/error.js.map +1 -1
  76. package/lib/messaging/handler.d.ts +10 -0
  77. package/lib/messaging/handler.d.ts.map +1 -1
  78. package/lib/messaging/node/connection.d.ts +0 -10
  79. package/lib/messaging/node/connection.d.ts.map +1 -1
  80. package/lib/messaging/node/connection.js +12 -50
  81. package/lib/messaging/node/connection.js.map +1 -1
  82. package/lib/messaging/proxy-factory.d.ts +2 -0
  83. package/lib/messaging/proxy-factory.d.ts.map +1 -1
  84. package/lib/messaging/proxy-factory.js +74 -159
  85. package/lib/messaging/proxy-factory.js.map +1 -1
  86. package/lib/permission.d.ts +2 -1
  87. package/lib/permission.d.ts.map +1 -1
  88. package/lib/permission.js +14 -13
  89. package/lib/permission.js.map +1 -1
  90. package/lib/plans.d.ts +210 -0
  91. package/lib/plans.d.ts.map +1 -0
  92. package/lib/plans.js +570 -0
  93. package/lib/plans.js.map +1 -0
  94. package/lib/protocol.d.ts +66 -13
  95. package/lib/protocol.d.ts.map +1 -1
  96. package/lib/protocol.js +68 -115
  97. package/lib/protocol.js.map +1 -1
  98. package/lib/snapshot-url.d.ts +14 -0
  99. package/lib/snapshot-url.d.ts.map +1 -0
  100. package/lib/snapshot-url.js +26 -0
  101. package/lib/snapshot-url.js.map +1 -0
  102. package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
  103. package/lib/snapshot-url.spec.d.ts.map +1 -0
  104. package/lib/snapshot-url.spec.js +41 -0
  105. package/lib/snapshot-url.spec.js.map +1 -0
  106. package/lib/team-subscription-protocol.d.ts +4 -4
  107. package/lib/team-subscription-protocol.d.ts.map +1 -1
  108. package/lib/team-subscription-protocol.js +15 -12
  109. package/lib/team-subscription-protocol.js.map +1 -1
  110. package/lib/teams-projects-protocol.d.ts +103 -0
  111. package/lib/teams-projects-protocol.d.ts.map +1 -0
  112. package/lib/teams-projects-protocol.js +23 -0
  113. package/lib/teams-projects-protocol.js.map +1 -0
  114. package/lib/util/analytics.d.ts +8 -0
  115. package/lib/util/analytics.d.ts.map +1 -0
  116. package/lib/util/analytics.js +79 -0
  117. package/lib/util/analytics.js.map +1 -0
  118. package/lib/util/async-iterator.js +55 -133
  119. package/lib/util/async-iterator.js.map +1 -1
  120. package/lib/util/cancelable.js +17 -59
  121. package/lib/util/cancelable.js.map +1 -1
  122. package/lib/util/date-time.js +8 -8
  123. package/lib/util/date-time.js.map +1 -1
  124. package/lib/util/deferred.js +10 -12
  125. package/lib/util/deferred.js.map +1 -1
  126. package/lib/util/disposable.js +26 -39
  127. package/lib/util/disposable.js.map +1 -1
  128. package/lib/util/event.js +58 -74
  129. package/lib/util/event.js.map +1 -1
  130. package/lib/util/garbage-collected-cache.d.ts +1 -0
  131. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  132. package/lib/util/garbage-collected-cache.js +26 -46
  133. package/lib/util/garbage-collected-cache.js.map +1 -1
  134. package/lib/util/generate-workspace-id.d.ts.map +1 -1
  135. package/lib/util/generate-workspace-id.js +13 -67
  136. package/lib/util/generate-workspace-id.js.map +1 -1
  137. package/lib/util/generate-workspace-id.spec.js +34 -79
  138. package/lib/util/generate-workspace-id.spec.js.map +1 -1
  139. package/lib/util/gitpod-cookie.d.ts +20 -0
  140. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  141. package/lib/util/gitpod-cookie.js +44 -0
  142. package/lib/util/gitpod-cookie.js.map +1 -0
  143. package/lib/util/gitpod-host-url.d.ts +1 -1
  144. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  145. package/lib/util/gitpod-host-url.js +98 -98
  146. package/lib/util/gitpod-host-url.js.map +1 -1
  147. package/lib/util/gitpod-host-url.spec.d.ts +6 -0
  148. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  149. package/lib/util/gitpod-host-url.spec.js +102 -30
  150. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  151. package/lib/util/grpc.d.ts +15 -0
  152. package/lib/util/grpc.d.ts.map +1 -0
  153. package/lib/util/grpc.js +18 -0
  154. package/lib/util/grpc.js.map +1 -0
  155. package/lib/util/jaeger-client-types.d.ts +68 -0
  156. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  157. package/lib/util/{without.js → jaeger-client-types.js} +1 -1
  158. package/lib/util/jaeger-client-types.js.map +1 -0
  159. package/lib/util/logging.d.ts +49 -33
  160. package/lib/util/logging.d.ts.map +1 -1
  161. package/lib/util/logging.js +107 -110
  162. package/lib/util/logging.js.map +1 -1
  163. package/lib/util/make-link.js +2 -2
  164. package/lib/util/make-link.js.map +1 -1
  165. package/lib/util/parse-workspace-id.d.ts +10 -0
  166. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  167. package/lib/util/parse-workspace-id.js +31 -7
  168. package/lib/util/parse-workspace-id.js.map +1 -1
  169. package/lib/util/parse-workspace-id.spec.d.ts +4 -0
  170. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  171. package/lib/util/parse-workspace-id.spec.js +123 -84
  172. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  173. package/lib/util/queue.js +16 -55
  174. package/lib/util/queue.js.map +1 -1
  175. package/lib/util/queue.spec.js +144 -288
  176. package/lib/util/queue.spec.js.map +1 -1
  177. package/lib/util/repeat.d.ts +15 -0
  178. package/lib/util/repeat.d.ts.map +1 -0
  179. package/lib/util/repeat.js +55 -0
  180. package/lib/util/repeat.js.map +1 -0
  181. package/lib/util/safe-promise.js +9 -12
  182. package/lib/util/safe-promise.js.map +1 -1
  183. package/lib/util/semaphore.js +15 -46
  184. package/lib/util/semaphore.js.map +1 -1
  185. package/lib/util/skip-if.js +6 -6
  186. package/lib/util/skip-if.js.map +1 -1
  187. package/lib/util/timeutil.js +16 -16
  188. package/lib/util/timeutil.js.map +1 -1
  189. package/lib/util/timeutil.spec.js +21 -24
  190. package/lib/util/timeutil.spec.js.map +1 -1
  191. package/lib/util/tracing.d.ts +50 -5
  192. package/lib/util/tracing.d.ts.map +1 -1
  193. package/lib/util/tracing.js +169 -63
  194. package/lib/util/tracing.js.map +1 -1
  195. package/lib/util/tracing.spec.d.ts +7 -0
  196. package/lib/util/tracing.spec.d.ts.map +1 -0
  197. package/lib/util/tracing.spec.js +121 -0
  198. package/lib/util/tracing.spec.js.map +1 -0
  199. package/lib/util/workspace-port-authentication.js +2 -2
  200. package/lib/util/workspace-port-authentication.js.map +1 -1
  201. package/lib/workspace-cluster.d.ts +26 -4
  202. package/lib/workspace-cluster.d.ts.map +1 -1
  203. package/lib/workspace-cluster.js +3 -3
  204. package/lib/workspace-cluster.js.map +1 -1
  205. package/lib/workspace-instance.d.ts +5 -2
  206. package/lib/workspace-instance.d.ts.map +1 -1
  207. package/lib/wsready.d.ts +1 -1
  208. package/lib/wsready.js +2 -2
  209. package/package.json +29 -16
  210. package/pkg-yarn.lock +17 -9
  211. package/src/accounting-protocol.ts +4 -10
  212. package/src/admin-protocol.ts +33 -5
  213. package/src/analytics.ts +54 -0
  214. package/src/context-url.spec.ts +39 -0
  215. package/src/context-url.ts +51 -0
  216. package/src/email-protocol.ts +2 -3
  217. package/src/env.ts +10 -10
  218. package/src/gitpod-service.ts +131 -35
  219. package/src/headless-workspace-log.ts +7 -11
  220. package/src/ide-protocol.ts +92 -0
  221. package/src/index.ts +5 -1
  222. package/src/messaging/browser/connection.ts +184 -23
  223. package/src/messaging/client-call-metrics.ts +97 -0
  224. package/src/messaging/error.ts +5 -2
  225. package/src/messaging/handler.ts +12 -0
  226. package/src/messaging/node/connection.ts +3 -47
  227. package/src/messaging/proxy-factory.ts +13 -5
  228. package/src/permission.ts +2 -1
  229. package/src/plans.ts +632 -0
  230. package/src/protocol.ts +89 -18
  231. package/src/snapshot-url.spec.ts +25 -0
  232. package/src/snapshot-url.ts +27 -0
  233. package/src/team-subscription-protocol.ts +7 -5
  234. package/src/teams-projects-protocol.ts +132 -0
  235. package/src/util/analytics.ts +87 -0
  236. package/src/util/garbage-collected-cache.ts +9 -3
  237. package/src/util/generate-workspace-id.spec.ts +3 -3
  238. package/src/util/generate-workspace-id.ts +2 -0
  239. package/src/util/gitpod-cookie.ts +39 -0
  240. package/src/util/gitpod-host-url.spec.ts +24 -0
  241. package/src/util/gitpod-host-url.ts +23 -10
  242. package/src/util/grpc.ts +15 -0
  243. package/src/util/jaeger-client-types.ts +102 -0
  244. package/src/util/logging.ts +102 -38
  245. package/src/util/parse-workspace-id.spec.ts +21 -1
  246. package/src/util/parse-workspace-id.ts +32 -6
  247. package/src/util/repeat.ts +45 -0
  248. package/src/util/semaphore.ts +2 -2
  249. package/src/util/skip-if.ts +1 -1
  250. package/src/util/timeutil.ts +4 -4
  251. package/src/util/tracing.spec.ts +83 -0
  252. package/src/util/tracing.ts +153 -17
  253. package/src/workspace-cluster.ts +28 -10
  254. package/src/workspace-instance.ts +25 -13
  255. package/src/wsready.ts +2 -2
  256. package/lib/util/context-url.d.ts +0 -13
  257. package/lib/util/context-url.d.ts.map +0 -1
  258. package/lib/util/context-url.js +0 -26
  259. package/lib/util/context-url.js.map +0 -1
  260. package/lib/util/context-url.spec.d.ts.map +0 -1
  261. package/lib/util/context-url.spec.js +0 -52
  262. package/lib/util/context-url.spec.js.map +0 -1
  263. package/lib/util/repeater.d.ts +0 -22
  264. package/lib/util/repeater.d.ts.map +0 -1
  265. package/lib/util/repeater.js +0 -118
  266. package/lib/util/repeater.js.map +0 -1
  267. package/lib/util/without.d.ts +0 -7
  268. package/lib/util/without.d.ts.map +0 -1
  269. package/lib/util/without.js.map +0 -1
  270. package/src/util/context-url.spec.ts +0 -25
  271. package/src/util/context-url.ts +0 -23
  272. package/src/util/jaeger-client.d.ts +0 -105
  273. package/src/util/repeater.ts +0 -49
@@ -0,0 +1,83 @@
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 class TestTracing {
15
+
16
+ @test public async testTracingContext_addNestedTags() {
17
+ const tracer = new MockTracer();
18
+ const span = tracer.startSpan('testTracingContext_addNestedTags');
19
+ TraceContext.addNestedTags({ span }, {
20
+ rpc: {
21
+ system: "jsonrpc",
22
+ jsonrpc: {
23
+ version: "1.0",
24
+ method: "test",
25
+ parameters: ["abc", "def"],
26
+ },
27
+ },
28
+ });
29
+
30
+ const mockSpan = tracer.report().spans[0];
31
+ expect(mockSpan.tags()).to.deep.equal({
32
+ "rpc.system": "jsonrpc",
33
+ "rpc.jsonrpc.version": "1.0",
34
+ "rpc.jsonrpc.method": "test",
35
+ "rpc.jsonrpc.parameters.0": "abc",
36
+ "rpc.jsonrpc.parameters.1": "def",
37
+ });
38
+ }
39
+
40
+ @test public async testTracingContext_addNestedTags_null() {
41
+ const tracer = new MockTracer();
42
+ const span = tracer.startSpan('testTracingContext_addNestedTags_null');
43
+ TraceContext.addNestedTags({ span }, {
44
+ someShape: {
45
+ thisIsNull: null,
46
+ thisIsUndefined: undefined,
47
+ },
48
+ });
49
+
50
+ const mockSpan = tracer.report().spans[0];
51
+ expect(mockSpan.tags()).to.deep.equal({
52
+ "someShape.thisIsNull": null,
53
+ "someShape.thisIsUndefined": undefined,
54
+ });
55
+ }
56
+
57
+ @test public async testTracingContext_addJsonRPCParameters() {
58
+ const tracer = new MockTracer();
59
+ const span = tracer.startSpan('testTracingContext_addJsonRPCParameters');
60
+ const ctx = { span };
61
+ TraceContext.addJsonRPCParameters(ctx, {
62
+ one: "one",
63
+ two: {
64
+ name: "two",
65
+ some: "shape",
66
+ containing: "PII",
67
+ },
68
+ three: "three",
69
+ });
70
+
71
+ const mockSpan = tracer.report().spans[0];
72
+ expect(mockSpan.tags()).to.deep.equal({
73
+ "rpc.jsonrpc.parameters.one": "one",
74
+ "rpc.jsonrpc.parameters.two.containing": "PII",
75
+ "rpc.jsonrpc.parameters.two.name": "two",
76
+ "rpc.jsonrpc.parameters.two.some": "shape",
77
+ "rpc.jsonrpc.parameters.three": "three",
78
+ "rpc.system": "jsonrpc",
79
+ });
80
+ }
81
+
82
+ }
83
+ module.exports = new TestTracing()
@@ -6,40 +6,154 @@
6
6
 
7
7
 
8
8
  import * as opentracing from 'opentracing';
9
- import { TracingConfig, initTracerFromEnv, Sampler, SamplingDecision } from 'jaeger-client';
9
+ import { TracingConfig, initTracerFromEnv } from 'jaeger-client';
10
+ import { Sampler, SamplingDecision } from './jaeger-client-types';
10
11
  import { initGlobalTracer } from 'opentracing';
11
12
  import { injectable } from 'inversify';
13
+ import { ResponseError } from 'vscode-jsonrpc';
14
+ import { log, LogContext } from './logging';
12
15
 
13
16
  export interface TraceContext {
14
17
  span?: opentracing.Span
15
18
  }
19
+ export type TraceContextWithSpan = TraceContext & {
20
+ span: opentracing.Span
21
+ }
22
+
16
23
 
17
24
  export namespace TraceContext {
18
- export function startSpan(operation: string, ctx: TraceContext): opentracing.Span {
19
- const options: opentracing.SpanOptions = {
20
- childOf: ctx.span
25
+ export function startSpan(operation: string, parentCtx?: TraceContext): opentracing.Span {
26
+ let options: opentracing.SpanOptions | undefined = undefined;
27
+ if (parentCtx) {
28
+ options = {
29
+ childOf: parentCtx.span
30
+ };
21
31
  }
22
32
  return opentracing.globalTracer().startSpan(operation, options);
23
33
  }
24
34
 
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())];
35
+ export function childContext(operation: string, parentCtx: TraceContext): TraceContextWithSpan {
36
+ const span = startSpan(operation, parentCtx);
37
+ return { span };
38
+ }
39
+
40
+ export function setError(ctx: TraceContext, err: Error) {
41
+ if (!ctx.span) {
42
+ return;
29
43
  }
30
- return opentracing.globalTracer().startSpan(operation, options);
44
+
45
+ TraceContext.addNestedTags(ctx, {
46
+ error: {
47
+ message: err.message,
48
+ stacktrace: err.stack,
49
+ },
50
+ });
51
+ ctx.span.setTag("error", true);
52
+ }
53
+
54
+ export function setJsonRPCMetadata(ctx: TraceContext, method?: string) {
55
+ if (!ctx.span) {
56
+ return;
57
+ }
58
+
59
+ const tags: { [key: string]: any } = {
60
+ rpc: {
61
+ system: "jsonrpc",
62
+ // version,
63
+ },
64
+ };
65
+ if (method) {
66
+ tags.rpc.method = method;
67
+ }
68
+ addNestedTags(ctx, tags);
69
+ }
70
+
71
+ export function setJsonRPCError(ctx: TraceContext, method: string, err: ResponseError<any>) {
72
+ if (!ctx.span) {
73
+ return;
74
+ }
75
+ // not use setError bc this is (most likely) a working operation
76
+
77
+ setJsonRPCMetadata(ctx);
78
+ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md#json-rpc
79
+ addNestedTags(ctx, {
80
+ rpc: {
81
+ jsonrpc: {
82
+ error_code: err.code,
83
+ error_message: err.message,
84
+ },
85
+ },
86
+ });
31
87
  }
32
88
 
33
- export function logError(ctx: TraceContext, err: Error) {
89
+ export function addJsonRPCParameters(ctx: TraceContext, params: { [key: string]: any }) {
34
90
  if (!ctx.span) {
35
91
  return;
36
92
  }
37
93
 
38
- ctx.span.log({
39
- "error": err.message,
40
- "stacktrace": err.stack
41
- })
42
- ctx.span.setTag("error", true)
94
+ setJsonRPCMetadata(ctx);
95
+ addNestedTags(ctx, {
96
+ rpc: {
97
+ jsonrpc: {
98
+ parameters: params,
99
+ },
100
+ },
101
+ });
102
+ }
103
+
104
+ /**
105
+ * Does what one would expect from `span.addTags`: Calls `span.addTag` for all keys in map, recursively for objects.
106
+ * Example:
107
+ * ```
108
+ * TraceContext.addNestedTags(ctx, {
109
+ * rpc: {
110
+ * system: "jsonrpc",
111
+ * jsonrpc: {
112
+ * version: "1.0",
113
+ * method: "test",
114
+ * parameters: ["abc", "def"],
115
+ * },
116
+ * },
117
+ * });
118
+ * ```
119
+ * gives
120
+ * rpc.system = "jsonrpc"
121
+ * rpc.jsonrpc.version = "1.0"
122
+ * rpc.jsonrpc.method = "test"
123
+ * rpc.jsonrpc.parameters.0 = "abc"
124
+ * rpc.jsonrpc.parameters.1 = "def"
125
+ * @param ctx
126
+ * @param keyValueMap
127
+ * @returns
128
+ */
129
+ export function addNestedTags(ctx: TraceContext, keyValueMap: { [key: string]: any }, _namespace?: string) {
130
+ if (!ctx.span) {
131
+ return;
132
+ }
133
+ const namespace = _namespace ? `${_namespace}.` : '';
134
+
135
+ try {
136
+ for (const k of Object.keys(keyValueMap)) {
137
+ const v = keyValueMap[k];
138
+ if (v instanceof Object) {
139
+ addNestedTags(ctx, v, `${namespace}${k}`);
140
+ } else {
141
+ ctx.span.setTag(`${namespace}${k}`, v);
142
+ }
143
+ }
144
+ } catch (err) {
145
+ // general resilience against odd shapes/parameters
146
+ log.error("Tracing.addNestedTags", err, { namespace });
147
+ }
148
+ }
149
+
150
+ export function setOWI(ctx: TraceContext, owi: LogContext) {
151
+ if (!ctx.span) {
152
+ return;
153
+ }
154
+ addNestedTags(ctx, {
155
+ context: owi,
156
+ });
43
157
  }
44
158
  }
45
159
 
@@ -56,11 +170,16 @@ export class TracingManager {
56
170
  reporter: {
57
171
  logSpans: false
58
172
  },
59
- serviceName
173
+ serviceName,
60
174
  }
61
175
  const t = initTracerFromEnv(config, {
62
- logger: console
176
+ logger: console,
177
+ tags: {
178
+ 'service.build.commit': process.env.GITPOD_BUILD_GIT_COMMIT,
179
+ 'service.build.version': process.env.GITPOD_BUILD_VERSION,
180
+ }
63
181
  });
182
+
64
183
  if (opts) {
65
184
  if (opts.perOpSampling) {
66
185
  (t as any)._sampler = new PerOperationSampler((t as any)._sampler, opts.perOpSampling);
@@ -132,3 +251,20 @@ export class PerOperationSampler implements Sampler {
132
251
  }
133
252
  }
134
253
  }
254
+
255
+ // Augment interfaces with an leading parameter "TraceContext" on every method
256
+ type IsValidArg<T> = T extends object ? keyof T extends never ? false : true : true;
257
+ type AddTraceContext<T> =
258
+ T extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E, f: infer F) => infer R ? (
259
+ IsValidArg<F> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E, f: F) => R :
260
+ IsValidArg<E> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E) => R :
261
+ IsValidArg<D> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D) => R :
262
+ IsValidArg<C> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C) => R :
263
+ IsValidArg<B> extends true ? (ctx: TraceContextWithSpan, a: A, b: B) => R :
264
+ IsValidArg<A> extends true ? (ctx: TraceContextWithSpan, a: A) => R :
265
+ (ctx: TraceContextWithSpan) => Promise<R>
266
+ ) : never;
267
+
268
+ export type InterfaceWithTraceContext<T> = {
269
+ [P in keyof T]: AddTraceContext<T[P]>
270
+ };
@@ -7,10 +7,11 @@
7
7
  import * as fs from 'fs';
8
8
  import { filePathTelepresenceAware } from './env';
9
9
  import { DeepPartial } from "./util/deep-partial";
10
+ import { PermissionName } from './permission';
10
11
 
11
12
  export interface WorkspaceCluster {
12
13
  // Name of the workspace cluster.
13
- // This is the string set in each
14
+ // This is the string set in each
14
15
  // Must be identical to the installationShortname of the cluster it represents!
15
16
  name: string;
16
17
 
@@ -29,9 +30,16 @@ export interface WorkspaceCluster {
29
30
  // Score used for cluster selection when starting workspace instances
30
31
  score: number;
31
32
 
32
- // If the value herein matches the short name of a fat cluster's ws-manager-bridge installation, that bridge is to control the workspace cluster.
33
- controller: string;
33
+ // True if this bridge should control this cluster
34
+ govern: boolean;
35
+
36
+ // An optional set of constraints that limit who can start workspaces on the cluster
37
+ admissionConstraints?: AdmissionConstraint[];
38
+
39
+ // An optional set of admission preferences that guide cluster selection
40
+ admissionPreferences?: AdmissionPreference[];
34
41
  }
42
+
35
43
  export type WorkspaceClusterState = "available" | "cordoned" | "draining";
36
44
  export interface TLSConfig {
37
45
  // the CA shared between client and server (base64 encoded)
@@ -44,6 +52,16 @@ export interface TLSConfig {
44
52
  export namespace TLSConfig {
45
53
  export const loadFromBase64File = (path: string): string => fs.readFileSync(filePathTelepresenceAware(path)).toString("base64");
46
54
  }
55
+ export type WorkspaceClusterWoTLS = Omit<WorkspaceCluster, "tls">;
56
+ export type WorkspaceManagerConnectionInfo = Pick<WorkspaceCluster, "name" | "url" | "tls">;
57
+
58
+ export type AdmissionConstraint = AdmissionConstraintFeaturePreview | AdmissionConstraintHasRole | AdmissionConstraintHasUserLevel;
59
+ export type AdmissionConstraintFeaturePreview = { type: "has-feature-preview" };
60
+ export type AdmissionConstraintHasRole = { type: "has-permission", permission: PermissionName };
61
+ export type AdmissionConstraintHasUserLevel = { type: "has-user-level", level: string };
62
+
63
+ export type AdmissionPreference = AdmissionPreferenceUserLevel;
64
+ export type AdmissionPreferenceUserLevel = { type: 'user-level', level: string };
47
65
 
48
66
 
49
67
  export const WorkspaceClusterDB = Symbol("WorkspaceClusterDB");
@@ -51,28 +69,28 @@ export interface WorkspaceClusterDB {
51
69
  /**
52
70
  * Stores the given WorkspaceCluster to the cluster-local DB in a consistent manner.
53
71
  * If there already is an entry with the same name it's merged and updated with the given state.
54
- * @param cluster
72
+ * @param cluster
55
73
  */
56
74
  save(cluster: WorkspaceCluster): Promise<void>;
57
75
 
58
76
  /**
59
77
  * Deletes the cluster identified by this name, if any.
60
- * @param name
78
+ * @param name
61
79
  */
62
80
  deleteByName(name: string): Promise<void>;
63
81
 
64
82
  /**
65
83
  * Finds a WorkspaceCluster with the given name. If there is none, `undefined` is returned.
66
- * @param name
84
+ * @param name
67
85
  */
68
86
  findByName(name: string): Promise<WorkspaceCluster | undefined>;
69
87
 
70
88
  /**
71
- * Lists all WorkspaceCluster for which the given predicate is true
72
- * @param predicate
89
+ * Lists all WorkspaceClusterWoTls for which the given predicate is true (does not return TLS for size/speed concerns)
90
+ * @param predicate
73
91
  */
74
- findFiltered(predicate: DeepPartial<WorkspaceClusterFilter>): Promise<WorkspaceCluster[]>;
92
+ findFiltered(predicate: DeepPartial<WorkspaceClusterFilter>): Promise<WorkspaceClusterWoTLS[]>;
75
93
  }
76
- export interface WorkspaceClusterFilter extends Pick<WorkspaceCluster, "state" | "controller" | "url"> {
94
+ export interface WorkspaceClusterFilter extends Pick<WorkspaceCluster, "state" | "govern" | "url"> {
77
95
  minScore: number;
78
96
  }
@@ -23,16 +23,22 @@ export interface WorkspaceInstance {
23
23
  // The time an instance has switched phase to 'Running'
24
24
  startedTime?: string;
25
25
 
26
+ // The time an instance has switched phase to 'Stopping' */
27
+ stoppingTime?: string;
28
+
26
29
  // The time an instance has switched phase to 'Stopped' */
27
30
  stoppedTime?: string;
28
31
 
29
32
  // ideUrl is the URL at which the workspace is available on the internet
33
+ // Note: this is nitially empty, filled during starting process!
30
34
  ideUrl: string;
31
35
 
32
36
  // region is the name of the workspace cluster this instance runs in
37
+ // Note: this is nitially empty, filled during starting process!
33
38
  region: string;
34
39
 
35
40
  // workspaceImage is the name of the Docker image this instance runs
41
+ // Note: this is nitially empty, filled during starting process!
36
42
  workspaceImage: string;
37
43
 
38
44
  // status is the latest status of the instance that we're aware of
@@ -83,7 +89,7 @@ export interface WorkspaceInstanceStatus {
83
89
  // WorkspaceInstancePhase describes a high-level state of a workspace instance
84
90
  export type WorkspaceInstancePhase =
85
91
  // unknown indicates an issue within the system in that it cannot determine the actual phase of
86
- // a workspace. This phase is usually accompanied by an error.
92
+ // a workspace. This phase is usually accompanied by an error.
87
93
  "unknown" |
88
94
 
89
95
  // Preparing means that we haven't actually started the workspace instance just yet, but rather
@@ -91,21 +97,21 @@ export type WorkspaceInstancePhase =
91
97
  "preparing" |
92
98
 
93
99
  // Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
94
- // some space within the cluster. If for example the cluster needs to scale up to accomodate the
95
- // workspace, the workspace will be in Pending state until that happened.
100
+ // some space within the cluster. If for example the cluster needs to scale up to accomodate the
101
+ // workspace, the workspace will be in Pending state until that happened.
96
102
  "pending" |
97
103
 
98
104
  // Creating means the workspace is currently being created. Thati includes downloading the images required
99
- // to run the workspace over the network. The time spent in this phase varies widely and depends on the current
100
- // network speed, image size and cache states.
105
+ // to run the workspace over the network. The time spent in this phase varies widely and depends on the current
106
+ // network speed, image size and cache states.
101
107
  "creating" |
102
108
 
103
109
  // Initializing is the phase in which the workspace is executing the appropriate workspace initializer (e.g. Git
104
- // clone or backup download). After this phase one can expect the workspace to either be Running or Failed.
110
+ // clone or backup download). After this phase one can expect the workspace to either be Running or Failed.
105
111
  "initializing" |
106
112
 
107
113
  // Running means the workspace is able to actively perform work, either by serving a user through Theia,
108
- // or as a headless workspace.
114
+ // or as a headless workspace.
109
115
  "running" |
110
116
 
111
117
  // Interrupted is an exceptional state where the container should be running but is temporarily unavailable.
@@ -128,9 +134,6 @@ export interface WorkspaceInstanceConditions {
128
134
  // PullingImages marks if the workspace is currently pulling its images. This condition can only be set during PhaseCreating
129
135
  pullingImages?: boolean
130
136
 
131
- // ServiceExists denotes if the workspace theia-/ports- services exist. This condition will be true if either of the two services exist.
132
- serviceExists?: boolean
133
-
134
137
  // deployed marks that a workspace instance was sent/deployed at a workspace manager
135
138
  deployed?: boolean;
136
139
 
@@ -139,6 +142,12 @@ export interface WorkspaceInstanceConditions {
139
142
 
140
143
  // ISO8601 timestamp when the first user activity was registered in the frontend. Only set if the workspace is running.
141
144
  firstUserActivity?: string;
145
+
146
+ // headless_task_failed indicates that a headless workspace task failed
147
+ headlessTaskFailed?: string;
148
+
149
+ // stopped_by_request is true if the workspace was stopped using a StopWorkspace call
150
+ stoppedByRequest?: boolean;
142
151
  }
143
152
 
144
153
  // AdmissionLevel describes who can access a workspace instance and its ports.
@@ -152,9 +161,6 @@ export interface WorkspaceInstancePort {
152
161
  // The outward-facing port number
153
162
  port: number;
154
163
 
155
- // An optional inward-facing port number. If not present we'll use port.
156
- targetPort?: number;
157
-
158
164
  // The visiblity of this port. Optional for backwards compatibility.
159
165
  visibility?: PortVisibility;
160
166
 
@@ -200,4 +206,10 @@ export interface WorkspaceInstanceConfiguration {
200
206
 
201
207
  // ideImage is the ref of the IDE image this instance uses.
202
208
  ideImage: string;
209
+
210
+ // desktopIdeImage is the ref of the desktop IDE image this instance uses.
211
+ desktopIdeImage?: string
212
+
213
+ // supervisorImage is the ref of the supervisor image this instance uses.
214
+ supervisorImage?: string;
203
215
  }
package/src/wsready.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
+ * Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3
3
  * Licensed under the GNU Affero General Public License (AGPL).
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 2020-06-11 14:47:30.351829728 +0000 UTC m=+0.002956090
7
+ // generated using github.com/32leaves/bel on 2021-11-04 12:16:53.917570766 +0000 UTC m=+0.006002884
8
8
  // DO NOT MODIFY
9
9
 
10
10
  export enum WorkspaceInitSource {
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) 2020 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
- * The field "contextUrl" might contain prefixes like:
8
- * - envvar1=value1/...
9
- * - prebuild/...
10
- * This is the analogon to the (Prefix)ContextParser structure in "server".
11
- */
12
- export declare function contextUrlToUrl(contextUrl: string | undefined): URL | undefined;
13
- //# sourceMappingURL=context-url.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-url.d.ts","sourceRoot":"","sources":["../../src/util/context-url.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,GAAG,GAAG,SAAS,CAU/E"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
4
- * Licensed under the GNU Affero General Public License (AGPL).
5
- * See License-AGPL.txt in the project root for license information.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.contextUrlToUrl = void 0;
9
- /**
10
- * The field "contextUrl" might contain prefixes like:
11
- * - envvar1=value1/...
12
- * - prebuild/...
13
- * This is the analogon to the (Prefix)ContextParser structure in "server".
14
- */
15
- function contextUrlToUrl(contextUrl) {
16
- if (contextUrl === undefined) {
17
- return undefined;
18
- }
19
- if (contextUrl.startsWith("http")) {
20
- return new URL(contextUrl);
21
- }
22
- var finding = contextUrl.search("/http");
23
- return new URL(contextUrl.substr(finding + 1));
24
- }
25
- exports.contextUrlToUrl = contextUrlToUrl;
26
- //# sourceMappingURL=context-url.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-url.js","sourceRoot":"","sources":["../../src/util/context-url.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,UAA8B;IAC5D,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACjC,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;KAC5B;IACD,IAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC;AAVD,0CAUC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-url.spec.d.ts","sourceRoot":"","sources":["../../src/util/context-url.spec.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,qBACa,cAAc;IAEV,0BAA0B;IAK1B,4BAA4B;CAI5C"}
@@ -1,52 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) 2020 Gitpod GmbH. All rights reserved.
4
- * Licensed under the GNU Affero General Public License (AGPL).
5
- * See License-AGPL.txt in the project root for license information.
6
- */
7
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11
- return c > 3 && r && Object.defineProperty(target, key, r), r;
12
- };
13
- var __metadata = (this && this.__metadata) || function (k, v) {
14
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ContextUrlTest = void 0;
18
- var chai = require("chai");
19
- var mocha_typescript_1 = require("mocha-typescript");
20
- var context_url_1 = require("./context-url");
21
- var expect = chai.expect;
22
- var ContextUrlTest = /** @class */ (function () {
23
- function ContextUrlTest() {
24
- }
25
- ContextUrlTest.prototype.parseContextUrl_withEnvVar = function () {
26
- var actual = context_url_1.contextUrlToUrl("passedin=test%20value/https://github.com/gitpod-io/gitpod-test-repo");
27
- expect(actual === null || actual === void 0 ? void 0 : actual.pathname).to.equal("/gitpod-io/gitpod-test-repo");
28
- };
29
- ContextUrlTest.prototype.parseContextUrl_withPrebuild = function () {
30
- var actual = context_url_1.contextUrlToUrl("prebuild/https://github.com/gitpod-io/gitpod-test-repo");
31
- expect(actual === null || actual === void 0 ? void 0 : actual.host).to.equal("github.com");
32
- };
33
- __decorate([
34
- mocha_typescript_1.test,
35
- __metadata("design:type", Function),
36
- __metadata("design:paramtypes", []),
37
- __metadata("design:returntype", void 0)
38
- ], ContextUrlTest.prototype, "parseContextUrl_withEnvVar", null);
39
- __decorate([
40
- mocha_typescript_1.test,
41
- __metadata("design:type", Function),
42
- __metadata("design:paramtypes", []),
43
- __metadata("design:returntype", void 0)
44
- ], ContextUrlTest.prototype, "parseContextUrl_withPrebuild", null);
45
- ContextUrlTest = __decorate([
46
- mocha_typescript_1.suite
47
- ], ContextUrlTest);
48
- return ContextUrlTest;
49
- }());
50
- exports.ContextUrlTest = ContextUrlTest;
51
- module.exports = new ContextUrlTest();
52
- //# sourceMappingURL=context-url.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context-url.spec.js","sourceRoot":"","sources":["../../src/util/context-url.spec.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,2BAA6B;AAC7B,qDAA+C;AAC/C,6CAAgD;AAChD,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AAG3B;IAAA;IAWA,CAAC;IATgB,mDAA0B,GAAjC;QACF,IAAM,MAAM,GAAG,6BAAe,CAAC,qEAAqE,CAAC,CAAC;QACtG,MAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACrE,CAAC;IAEY,qDAA4B,GAAnC;QACF,IAAM,MAAM,GAAG,6BAAe,CAAC,wDAAwD,CAAC,CAAC;QACzF,MAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IARK;QAAL,uBAAI;;;;oEAGJ;IAEK;QAAL,uBAAI;;;;sEAGJ;IAVQ,cAAc;QAD1B,wBAAK;OACO,cAAc,CAW1B;IAAD,qBAAC;CAAA,AAXD,IAWC;AAXY,wCAAc;AAY3B,MAAM,CAAC,OAAO,GAAG,IAAI,cAAc,EAAE,CAAA"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Copyright (c) 2020 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
- import { Deferred } from "./deferred";
7
- /**
8
- * Repeats a given function until it is stopped
9
- */
10
- export declare class Repeater {
11
- protected readonly fn: () => Promise<void> | void;
12
- protected readonly timeout: number;
13
- protected shouldRun: boolean;
14
- protected finished: Deferred<void>;
15
- protected timer?: any;
16
- constructor(fn: () => Promise<void> | void, timeout: number);
17
- start(): Promise<void>;
18
- run(): Promise<void>;
19
- protected sleep(timeout: number): Promise<unknown>;
20
- stop(): Promise<void>;
21
- }
22
- //# sourceMappingURL=repeater.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repeater.d.ts","sourceRoot":"","sources":["../../src/util/repeater.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC;;GAEG;AACH,qBAAa,QAAQ;IAKL,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAJjG,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAA;IAClC,SAAS,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC;gBAES,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EAAqB,OAAO,EAAE,MAAM;IAE3F,KAAK;IAIL,GAAG;cAcO,KAAK,CAAC,OAAO,EAAE,MAAM;IAI/B,IAAI;CAOb"}