@gitpod/gitpod-protocol 0.1.5-v0.6.0-beta2 → 0.1.5-vn-integrate-gitpod-yml-tasks-into-jetbrainsa.5

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 (299) hide show
  1. package/data/builtin-theia-plugins.json +9 -9
  2. package/data/gitpod-schema.json +25 -24
  3. package/lib/accounting-protocol.d.ts +155 -0
  4. package/lib/accounting-protocol.d.ts.map +1 -0
  5. package/lib/accounting-protocol.js +109 -0
  6. package/lib/accounting-protocol.js.map +1 -0
  7. package/lib/admin-protocol.d.ts +31 -4
  8. package/lib/admin-protocol.d.ts.map +1 -1
  9. package/lib/admin-protocol.js +15 -0
  10. package/lib/admin-protocol.js.map +1 -1
  11. package/lib/analytics.d.ts +45 -0
  12. package/lib/analytics.d.ts.map +1 -0
  13. package/lib/analytics.js +10 -0
  14. package/lib/analytics.js.map +1 -0
  15. package/lib/auth.d.ts +25 -0
  16. package/lib/auth.d.ts.map +1 -0
  17. package/lib/auth.js +16 -0
  18. package/lib/auth.js.map +1 -0
  19. package/lib/context-url.d.ts +31 -0
  20. package/lib/context-url.d.ts.map +1 -0
  21. package/lib/context-url.js +102 -0
  22. package/lib/context-url.js.map +1 -0
  23. package/lib/context-url.spec.d.ts +14 -0
  24. package/lib/context-url.spec.d.ts.map +1 -0
  25. package/lib/context-url.spec.js +94 -0
  26. package/lib/context-url.spec.js.map +1 -0
  27. package/lib/email-protocol.d.ts +1 -2
  28. package/lib/email-protocol.d.ts.map +1 -1
  29. package/lib/email-protocol.js +4 -4
  30. package/lib/email-protocol.js.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.js +19 -20
  34. package/lib/encryption/encryption-engine.js.map +1 -1
  35. package/lib/encryption/encryption-engine.spec.js +29 -36
  36. package/lib/encryption/encryption-engine.spec.js.map +1 -1
  37. package/lib/encryption/encryption-service.js +29 -43
  38. package/lib/encryption/encryption-service.js.map +1 -1
  39. package/lib/encryption/key-provider.js +25 -30
  40. package/lib/encryption/key-provider.js.map +1 -1
  41. package/lib/env.d.ts +1 -2
  42. package/lib/env.d.ts.map +1 -1
  43. package/lib/env.js +20 -21
  44. package/lib/env.js.map +1 -1
  45. package/lib/gitpod-file-parser.js +25 -41
  46. package/lib/gitpod-file-parser.js.map +1 -1
  47. package/lib/gitpod-file-parser.spec.js +116 -116
  48. package/lib/gitpod-file-parser.spec.js.map +1 -1
  49. package/lib/gitpod-service.d.ts +162 -20
  50. package/lib/gitpod-service.d.ts.map +1 -1
  51. package/lib/gitpod-service.js +170 -256
  52. package/lib/gitpod-service.js.map +1 -1
  53. package/lib/headless-workspace-log.d.ts +8 -11
  54. package/lib/headless-workspace-log.d.ts.map +1 -1
  55. package/lib/headless-workspace-log.js +4 -7
  56. package/lib/headless-workspace-log.js.map +1 -1
  57. package/lib/ide-frontend-service.d.ts +4 -0
  58. package/lib/ide-frontend-service.d.ts.map +1 -1
  59. package/lib/ide-protocol.d.ts +105 -0
  60. package/lib/ide-protocol.d.ts.map +1 -0
  61. package/lib/ide-protocol.js +8 -0
  62. package/lib/ide-protocol.js.map +1 -0
  63. package/lib/index.d.ts +6 -0
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js +7 -1
  66. package/lib/index.js.map +1 -1
  67. package/lib/installation-admin-protocol.d.ts +27 -0
  68. package/lib/installation-admin-protocol.d.ts.map +1 -0
  69. package/lib/installation-admin-protocol.js +30 -0
  70. package/lib/installation-admin-protocol.js.map +1 -0
  71. package/lib/messaging/browser/connection.d.ts +5 -3
  72. package/lib/messaging/browser/connection.d.ts.map +1 -1
  73. package/lib/messaging/browser/connection.js +183 -33
  74. package/lib/messaging/browser/connection.js.map +1 -1
  75. package/lib/messaging/browser/window-connection.js +35 -55
  76. package/lib/messaging/browser/window-connection.js.map +1 -1
  77. package/lib/messaging/client-call-metrics.d.ts +35 -0
  78. package/lib/messaging/client-call-metrics.d.ts.map +1 -0
  79. package/lib/messaging/client-call-metrics.js +83 -0
  80. package/lib/messaging/client-call-metrics.js.map +1 -0
  81. package/lib/messaging/error.d.ts +5 -1
  82. package/lib/messaging/error.d.ts.map +1 -1
  83. package/lib/messaging/error.js +10 -2
  84. package/lib/messaging/error.js.map +1 -1
  85. package/lib/messaging/handler.d.ts +10 -0
  86. package/lib/messaging/handler.d.ts.map +1 -1
  87. package/lib/messaging/node/connection.d.ts +1 -17
  88. package/lib/messaging/node/connection.d.ts.map +1 -1
  89. package/lib/messaging/node/connection.js +23 -59
  90. package/lib/messaging/node/connection.js.map +1 -1
  91. package/lib/messaging/proxy-factory.d.ts +2 -0
  92. package/lib/messaging/proxy-factory.d.ts.map +1 -1
  93. package/lib/messaging/proxy-factory.js +74 -159
  94. package/lib/messaging/proxy-factory.js.map +1 -1
  95. package/lib/oss-allowlist.d.ts +14 -0
  96. package/lib/oss-allowlist.d.ts.map +1 -0
  97. package/lib/oss-allowlist.js +8 -0
  98. package/lib/oss-allowlist.js.map +1 -0
  99. package/lib/payment-protocol.d.ts +18 -0
  100. package/lib/payment-protocol.d.ts.map +1 -0
  101. package/lib/payment-protocol.js +13 -0
  102. package/lib/payment-protocol.js.map +1 -0
  103. package/lib/permission.d.ts +8 -3
  104. package/lib/permission.d.ts.map +1 -1
  105. package/lib/permission.js +36 -19
  106. package/lib/permission.js.map +1 -1
  107. package/lib/plans.d.ts +210 -0
  108. package/lib/plans.d.ts.map +1 -0
  109. package/lib/plans.js +570 -0
  110. package/lib/plans.js.map +1 -0
  111. package/lib/protocol.d.ts +118 -58
  112. package/lib/protocol.d.ts.map +1 -1
  113. package/lib/protocol.js +116 -130
  114. package/lib/protocol.js.map +1 -1
  115. package/lib/snapshot-url.d.ts +14 -0
  116. package/lib/snapshot-url.d.ts.map +1 -0
  117. package/lib/snapshot-url.js +26 -0
  118. package/lib/snapshot-url.js.map +1 -0
  119. package/{src/util/without.ts → lib/snapshot-url.spec.d.ts} +2 -3
  120. package/lib/snapshot-url.spec.d.ts.map +1 -0
  121. package/lib/snapshot-url.spec.js +41 -0
  122. package/lib/snapshot-url.spec.js.map +1 -0
  123. package/lib/team-subscription-protocol.d.ts +73 -0
  124. package/lib/team-subscription-protocol.d.ts.map +1 -0
  125. package/lib/team-subscription-protocol.js +63 -0
  126. package/lib/team-subscription-protocol.js.map +1 -0
  127. package/lib/teams-projects-protocol.d.ts +113 -0
  128. package/lib/teams-projects-protocol.d.ts.map +1 -0
  129. package/lib/teams-projects-protocol.js +30 -0
  130. package/lib/teams-projects-protocol.js.map +1 -0
  131. package/lib/util/analytics.d.ts +8 -0
  132. package/lib/util/analytics.d.ts.map +1 -0
  133. package/lib/util/analytics.js +79 -0
  134. package/lib/util/analytics.js.map +1 -0
  135. package/lib/util/async-iterator.js +55 -133
  136. package/lib/util/async-iterator.js.map +1 -1
  137. package/lib/util/cancelable.js +17 -59
  138. package/lib/util/cancelable.js.map +1 -1
  139. package/lib/util/date-time.js +8 -8
  140. package/lib/util/date-time.js.map +1 -1
  141. package/lib/util/deferred.js +10 -12
  142. package/lib/util/deferred.js.map +1 -1
  143. package/lib/util/disposable.js +26 -39
  144. package/lib/util/disposable.js.map +1 -1
  145. package/lib/util/event.js +58 -74
  146. package/lib/util/event.js.map +1 -1
  147. package/lib/util/garbage-collected-cache.d.ts +1 -0
  148. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  149. package/lib/util/garbage-collected-cache.js +26 -46
  150. package/lib/util/garbage-collected-cache.js.map +1 -1
  151. package/lib/util/generate-workspace-id.d.ts +4 -0
  152. package/lib/util/generate-workspace-id.d.ts.map +1 -0
  153. package/lib/util/generate-workspace-id.js +487 -0
  154. package/lib/util/generate-workspace-id.js.map +1 -0
  155. package/lib/util/{without.d.ts → generate-workspace-id.spec.d.ts} +2 -2
  156. package/lib/util/generate-workspace-id.spec.d.ts.map +1 -0
  157. package/lib/util/generate-workspace-id.spec.js +87 -0
  158. package/lib/util/generate-workspace-id.spec.js.map +1 -0
  159. package/lib/util/gitpod-cookie.d.ts +20 -0
  160. package/lib/util/gitpod-cookie.d.ts.map +1 -0
  161. package/lib/util/gitpod-cookie.js +44 -0
  162. package/lib/util/gitpod-cookie.js.map +1 -0
  163. package/lib/util/gitpod-host-url.d.ts +2 -2
  164. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  165. package/lib/util/gitpod-host-url.js +96 -95
  166. package/lib/util/gitpod-host-url.js.map +1 -1
  167. package/lib/util/gitpod-host-url.spec.d.ts +8 -1
  168. package/lib/util/gitpod-host-url.spec.d.ts.map +1 -1
  169. package/lib/util/gitpod-host-url.spec.js +104 -22
  170. package/lib/util/gitpod-host-url.spec.js.map +1 -1
  171. package/lib/util/grpc.d.ts +15 -0
  172. package/lib/util/grpc.d.ts.map +1 -0
  173. package/lib/util/grpc.js +18 -0
  174. package/lib/util/grpc.js.map +1 -0
  175. package/lib/util/jaeger-client-types.d.ts +68 -0
  176. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  177. package/lib/util/{without.js → jaeger-client-types.js} +1 -1
  178. package/lib/util/jaeger-client-types.js.map +1 -0
  179. package/lib/util/logging.d.ts +49 -33
  180. package/lib/util/logging.d.ts.map +1 -1
  181. package/lib/util/logging.js +107 -110
  182. package/lib/util/logging.js.map +1 -1
  183. package/lib/util/make-link.js +2 -2
  184. package/lib/util/make-link.js.map +1 -1
  185. package/lib/util/parse-workspace-id.d.ts +13 -3
  186. package/lib/util/parse-workspace-id.d.ts.map +1 -1
  187. package/lib/util/parse-workspace-id.js +38 -8
  188. package/lib/util/parse-workspace-id.js.map +1 -1
  189. package/lib/util/parse-workspace-id.spec.d.ts +8 -0
  190. package/lib/util/parse-workspace-id.spec.d.ts.map +1 -1
  191. package/lib/util/parse-workspace-id.spec.js +127 -47
  192. package/lib/util/parse-workspace-id.spec.js.map +1 -1
  193. package/lib/util/queue.js +16 -55
  194. package/lib/util/queue.js.map +1 -1
  195. package/lib/util/queue.spec.js +144 -288
  196. package/lib/util/queue.spec.js.map +1 -1
  197. package/lib/util/repeat.d.ts +15 -0
  198. package/lib/util/repeat.d.ts.map +1 -0
  199. package/lib/util/repeat.js +55 -0
  200. package/lib/util/repeat.js.map +1 -0
  201. package/lib/util/semaphore.js +15 -46
  202. package/lib/util/semaphore.js.map +1 -1
  203. package/lib/util/skip-if.js +6 -6
  204. package/lib/util/skip-if.js.map +1 -1
  205. package/lib/util/timeutil.js +28 -16
  206. package/lib/util/timeutil.js.map +1 -1
  207. package/lib/util/timeutil.spec.js +21 -24
  208. package/lib/util/timeutil.spec.js.map +1 -1
  209. package/lib/util/tracing.d.ts +51 -5
  210. package/lib/util/tracing.d.ts.map +1 -1
  211. package/lib/util/tracing.js +197 -62
  212. package/lib/util/tracing.js.map +1 -1
  213. package/lib/util/tracing.spec.d.ts +7 -0
  214. package/lib/util/tracing.spec.d.ts.map +1 -0
  215. package/lib/util/tracing.spec.js +121 -0
  216. package/lib/util/tracing.spec.js.map +1 -0
  217. package/lib/util/workspace-port-authentication.js +3 -2
  218. package/lib/util/workspace-port-authentication.js.map +1 -1
  219. package/lib/workspace-cluster.d.ts +76 -0
  220. package/lib/workspace-cluster.d.ts.map +1 -0
  221. package/lib/workspace-cluster.js +33 -0
  222. package/lib/workspace-cluster.js.map +1 -0
  223. package/lib/workspace-instance.d.ts +26 -2
  224. package/lib/workspace-instance.d.ts.map +1 -1
  225. package/lib/wsready.d.ts +1 -1
  226. package/lib/wsready.js +2 -2
  227. package/package.json +33 -17
  228. package/pkg-yarn.lock +18 -9
  229. package/provenance-bundle.jsonl +2 -0
  230. package/src/accounting-protocol.ts +229 -0
  231. package/src/admin-protocol.ts +53 -5
  232. package/src/analytics.ts +54 -0
  233. package/src/auth.ts +27 -0
  234. package/src/context-url.spec.ts +53 -0
  235. package/src/context-url.ts +107 -0
  236. package/src/email-protocol.ts +2 -3
  237. package/src/env.ts +10 -10
  238. package/src/gitpod-service.ts +237 -38
  239. package/src/headless-workspace-log.ts +7 -11
  240. package/src/ide-frontend-service.ts +5 -1
  241. package/src/ide-protocol.ts +119 -0
  242. package/src/index.ts +7 -1
  243. package/src/installation-admin-protocol.ts +42 -0
  244. package/src/messaging/browser/connection.ts +195 -14
  245. package/src/messaging/client-call-metrics.ts +97 -0
  246. package/src/messaging/error.ts +14 -2
  247. package/src/messaging/handler.ts +12 -0
  248. package/src/messaging/node/connection.ts +21 -68
  249. package/src/messaging/proxy-factory.ts +14 -6
  250. package/src/oss-allowlist.ts +15 -0
  251. package/src/payment-protocol.ts +20 -0
  252. package/src/permission.ts +24 -9
  253. package/src/plans.ts +632 -0
  254. package/src/protocol.ts +192 -87
  255. package/src/snapshot-url.spec.ts +25 -0
  256. package/src/snapshot-url.ts +27 -0
  257. package/src/team-subscription-protocol.ts +113 -0
  258. package/src/teams-projects-protocol.ts +147 -0
  259. package/src/util/analytics.ts +87 -0
  260. package/src/util/deferred.ts +1 -1
  261. package/src/util/garbage-collected-cache.ts +9 -3
  262. package/src/util/generate-workspace-id.spec.ts +48 -0
  263. package/src/util/generate-workspace-id.ts +475 -0
  264. package/src/util/gitpod-cookie.ts +39 -0
  265. package/src/util/gitpod-host-url.spec.ts +30 -1
  266. package/src/util/gitpod-host-url.ts +27 -13
  267. package/src/util/grpc.ts +15 -0
  268. package/src/util/jaeger-client-types.ts +102 -0
  269. package/src/util/logging.ts +102 -38
  270. package/src/util/parse-workspace-id.spec.ts +45 -4
  271. package/src/util/parse-workspace-id.ts +38 -7
  272. package/src/util/queue.spec.ts +1 -1
  273. package/src/util/repeat.ts +45 -0
  274. package/src/util/semaphore.ts +2 -2
  275. package/src/util/skip-if.ts +1 -1
  276. package/src/util/timeutil.ts +4 -4
  277. package/src/util/tracing.spec.ts +83 -0
  278. package/src/util/tracing.ts +183 -17
  279. package/src/workspace-cluster.ts +104 -0
  280. package/src/workspace-instance.ts +51 -13
  281. package/src/wsready.ts +2 -2
  282. package/lib/messaging/connection-error-handler.d.ts +0 -27
  283. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  284. package/lib/messaging/connection-error-handler.js +0 -46
  285. package/lib/messaging/connection-error-handler.js.map +0 -1
  286. package/lib/util/repeater.d.ts +0 -22
  287. package/lib/util/repeater.d.ts.map +0 -1
  288. package/lib/util/repeater.js +0 -118
  289. package/lib/util/repeater.js.map +0 -1
  290. package/lib/util/safe-promise.d.ts +0 -11
  291. package/lib/util/safe-promise.d.ts.map +0 -1
  292. package/lib/util/safe-promise.js +0 -34
  293. package/lib/util/safe-promise.js.map +0 -1
  294. package/lib/util/without.d.ts.map +0 -1
  295. package/lib/util/without.js.map +0 -1
  296. package/src/messaging/connection-error-handler.ts +0 -62
  297. package/src/util/jaeger-client.d.ts +0 -105
  298. package/src/util/repeater.ts +0 -49
  299. package/src/util/safe-promise.ts +0 -26
@@ -6,40 +6,184 @@
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
+ const options: opentracing.SpanOptions = {};
27
+ if (parentCtx && parentCtx.span && !!parentCtx.span.context().toSpanId()) {
28
+ options.childOf = parentCtx.span;
21
29
  }
30
+ // 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.
31
+ // if (referencedSpans) {
32
+ // // note: allthough followsForm's type says it takes 'opentracing.Span | opentracing.SpanContext', it only works with SpanContext (typing mismatch)
33
+ // // note2: we need to filter out debug spans (spanId === "")
34
+ // options.references = referencedSpans.filter(s => s !== undefined)
35
+ // .filter(s => !!s!.context().toSpanId())
36
+ // .map(s => followsFrom(s!.context()));
37
+ // }
38
+
22
39
  return opentracing.globalTracer().startSpan(operation, options);
23
40
  }
24
41
 
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())];
42
+ export function childContext(operation: string, parentCtx: TraceContext): TraceContextWithSpan {
43
+ const span = startSpan(operation, parentCtx);
44
+ return { span };
45
+ }
46
+
47
+ export function withSpan(operation: string, callback: (ctx: TraceContext) => void, ctx?: TraceContext): void {
48
+ // if we don't have a parent span, don't create a trace here as those <trace-without-root-spans> are not useful.
49
+ if (!ctx || !ctx.span || !ctx.span.context()) {
50
+ callback({});
51
+ return;
52
+ }
53
+
54
+ const span = TraceContext.startSpan(operation, ctx);
55
+ try {
56
+ callback({span});
57
+ } catch (e) {
58
+ TraceContext.setError({span}, e);
59
+ throw e;
60
+ } finally {
61
+ span.finish();
29
62
  }
30
- return opentracing.globalTracer().startSpan(operation, options);
31
63
  }
32
64
 
33
- export function logError(ctx: TraceContext, err: Error) {
65
+ export function setError(ctx: TraceContext, err: Error) {
34
66
  if (!ctx.span) {
35
67
  return;
36
68
  }
37
69
 
38
- ctx.span.log({
39
- "error": err.message,
40
- "stacktrace": err.stack
41
- })
42
- ctx.span.setTag("error", true)
70
+ TraceContext.addNestedTags(ctx, {
71
+ error: {
72
+ message: err.message,
73
+ stacktrace: err.stack,
74
+ },
75
+ });
76
+ ctx.span.setTag("error", true);
77
+ }
78
+
79
+ export function setJsonRPCMetadata(ctx: TraceContext, method?: string) {
80
+ if (!ctx.span) {
81
+ return;
82
+ }
83
+
84
+ const tags: { [key: string]: any } = {
85
+ rpc: {
86
+ system: "jsonrpc",
87
+ // version,
88
+ },
89
+ };
90
+ if (method) {
91
+ tags.rpc.method = method;
92
+ }
93
+ addNestedTags(ctx, tags);
94
+ }
95
+
96
+ export function setJsonRPCError(ctx: TraceContext, method: string, err: ResponseError<any>, withStatusCode: boolean = false) {
97
+ if (!ctx.span) {
98
+ return;
99
+ }
100
+ // not use setError bc this is (most likely) a working operation
101
+
102
+ setJsonRPCMetadata(ctx, method);
103
+ // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md#json-rpc
104
+ addNestedTags(ctx, {
105
+ rpc: {
106
+ jsonrpc: {
107
+ error_code: err.code,
108
+ error_message: err.message,
109
+ },
110
+ },
111
+ });
112
+
113
+ // the field "status_code" is used by honeycomb to derive insights like success rate, etc. Defaults to "0".
114
+ if (withStatusCode) {
115
+ ctx.span.setTag("status_code", err.code);
116
+ }
117
+ }
118
+
119
+ export function addJsonRPCParameters(ctx: TraceContext, params: { [key: string]: any }) {
120
+ if (!ctx.span) {
121
+ return;
122
+ }
123
+
124
+ setJsonRPCMetadata(ctx);
125
+ addNestedTags(ctx, {
126
+ rpc: {
127
+ jsonrpc: {
128
+ parameters: params,
129
+ },
130
+ },
131
+ });
132
+ }
133
+
134
+ /**
135
+ * Does what one would expect from `span.addTags`: Calls `span.addTag` for all keys in map, recursively for objects.
136
+ * Example:
137
+ * ```
138
+ * TraceContext.addNestedTags(ctx, {
139
+ * rpc: {
140
+ * system: "jsonrpc",
141
+ * jsonrpc: {
142
+ * version: "1.0",
143
+ * method: "test",
144
+ * parameters: ["abc", "def"],
145
+ * },
146
+ * },
147
+ * });
148
+ * ```
149
+ * gives
150
+ * rpc.system = "jsonrpc"
151
+ * rpc.jsonrpc.version = "1.0"
152
+ * rpc.jsonrpc.method = "test"
153
+ * rpc.jsonrpc.parameters.0 = "abc"
154
+ * rpc.jsonrpc.parameters.1 = "def"
155
+ * @param ctx
156
+ * @param keyValueMap
157
+ * @returns
158
+ */
159
+ export function addNestedTags(ctx: TraceContext, keyValueMap: { [key: string]: any }, _namespace?: string) {
160
+ if (!ctx.span) {
161
+ return;
162
+ }
163
+ const namespace = _namespace ? `${_namespace}.` : '';
164
+
165
+ try {
166
+ for (const k of Object.keys(keyValueMap)) {
167
+ const v = keyValueMap[k];
168
+ if (v instanceof Object) {
169
+ addNestedTags(ctx, v, `${namespace}${k}`);
170
+ } else {
171
+ ctx.span.setTag(`${namespace}${k}`, v);
172
+ }
173
+ }
174
+ } catch (err) {
175
+ // general resilience against odd shapes/parameters
176
+ log.error("Tracing.addNestedTags", err, { namespace });
177
+ }
178
+ }
179
+
180
+ export function setOWI(ctx: TraceContext, owi: LogContext) {
181
+ if (!ctx.span) {
182
+ return;
183
+ }
184
+ addNestedTags(ctx, {
185
+ context: owi,
186
+ });
43
187
  }
44
188
  }
45
189
 
@@ -56,11 +200,16 @@ export class TracingManager {
56
200
  reporter: {
57
201
  logSpans: false
58
202
  },
59
- serviceName
203
+ serviceName,
60
204
  }
61
205
  const t = initTracerFromEnv(config, {
62
- logger: console
206
+ logger: console,
207
+ tags: {
208
+ 'service.build.commit': process.env.GITPOD_BUILD_GIT_COMMIT,
209
+ 'service.build.version': process.env.GITPOD_BUILD_VERSION,
210
+ }
63
211
  });
212
+
64
213
  if (opts) {
65
214
  if (opts.perOpSampling) {
66
215
  (t as any)._sampler = new PerOperationSampler((t as any)._sampler, opts.perOpSampling);
@@ -132,3 +281,20 @@ export class PerOperationSampler implements Sampler {
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> =
288
+ T extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E, f: infer F) => infer R ? (
289
+ IsValidArg<F> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E, f: F) => R :
290
+ IsValidArg<E> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D, e: E) => R :
291
+ IsValidArg<D> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C, d: D) => R :
292
+ IsValidArg<C> extends true ? (ctx: TraceContextWithSpan, a: A, b: B, c: C) => R :
293
+ IsValidArg<B> extends true ? (ctx: TraceContextWithSpan, a: A, b: B) => R :
294
+ IsValidArg<A> extends true ? (ctx: TraceContextWithSpan, a: A) => R :
295
+ (ctx: TraceContextWithSpan) => Promise<R>
296
+ ) : never;
297
+
298
+ export type InterfaceWithTraceContext<T> = {
299
+ [P in keyof T]: AddTraceContext<T[P]>
300
+ };
@@ -0,0 +1,104 @@
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
+ import * as fs from 'fs';
8
+ import { filePathTelepresenceAware } from './env';
9
+ import { DeepPartial } from "./util/deep-partial";
10
+ import { PermissionName } from './permission';
11
+
12
+ export interface WorkspaceCluster {
13
+ // Name of the workspace cluster.
14
+ // This is the string set in each
15
+ // Must be identical to the installationShortname of the cluster it represents!
16
+ name: string;
17
+
18
+ // URL of the cluster's ws-manager API
19
+ url: string;
20
+
21
+ // TLS contains the keys and certificates necessary to use mTLS between server and clients
22
+ tls?: TLSConfig;
23
+
24
+ // Current state of the cluster
25
+ state: WorkspaceClusterState;
26
+
27
+ // Maximum value score can reach for this cluster
28
+ maxScore: number;
29
+
30
+ // Score used for cluster selection when starting workspace instances
31
+ score: number;
32
+
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
+
40
+ export type WorkspaceClusterState = "available" | "cordoned" | "draining";
41
+ export interface TLSConfig {
42
+ // the CA shared between client and server (base64 encoded)
43
+ ca: string;
44
+ // the private key (base64 encoded)
45
+ key: string;
46
+ // the certificate signed with the shared CA (base64 encoded)
47
+ crt: string;
48
+ }
49
+ export namespace TLSConfig {
50
+ export const loadFromBase64File = (path: string): string => fs.readFileSync(filePathTelepresenceAware(path)).toString("base64");
51
+ }
52
+ export type WorkspaceClusterWoTLS = Omit<WorkspaceCluster, "tls">;
53
+ export type WorkspaceManagerConnectionInfo = Pick<WorkspaceCluster, "name" | "url" | "tls">;
54
+
55
+ export type AdmissionConstraint = AdmissionConstraintFeaturePreview | AdmissionConstraintHasPermission | AdmissionConstraintHasUserLevel | AdmissionConstraintHasMoreResources;
56
+ export type AdmissionConstraintFeaturePreview = { type: "has-feature-preview" };
57
+ export type AdmissionConstraintHasPermission = { type: "has-permission", permission: PermissionName };
58
+ export type AdmissionConstraintHasUserLevel = { type: "has-user-level", level: string };
59
+ export type AdmissionConstraintHasMoreResources = { type: "has-more-resources" };
60
+
61
+ export namespace AdmissionConstraint {
62
+ export function is(o: any): o is AdmissionConstraint {
63
+ return !!o
64
+ && 'type' in o;
65
+ }
66
+ export function isHasPermissionConstraint(o: any): o is AdmissionConstraintHasPermission {
67
+ return is(o)
68
+ && o.type === "has-permission";
69
+ }
70
+ export function hasPermission(ac: AdmissionConstraint, permission: PermissionName): boolean {
71
+ return isHasPermissionConstraint(ac) && ac.permission === permission;
72
+ }
73
+ }
74
+
75
+ export const WorkspaceClusterDB = Symbol("WorkspaceClusterDB");
76
+ export interface WorkspaceClusterDB {
77
+ /**
78
+ * Stores the given WorkspaceCluster to the cluster-local DB in a consistent manner.
79
+ * If there already is an entry with the same name it's merged and updated with the given state.
80
+ * @param cluster
81
+ */
82
+ save(cluster: WorkspaceCluster): Promise<void>;
83
+
84
+ /**
85
+ * Deletes the cluster identified by this name, if any.
86
+ * @param name
87
+ */
88
+ deleteByName(name: string): Promise<void>;
89
+
90
+ /**
91
+ * Finds a WorkspaceCluster with the given name. If there is none, `undefined` is returned.
92
+ * @param name
93
+ */
94
+ findByName(name: string): Promise<WorkspaceCluster | undefined>;
95
+
96
+ /**
97
+ * Lists all WorkspaceClusterWoTls for which the given predicate is true (does not return TLS for size/speed concerns)
98
+ * @param predicate
99
+ */
100
+ findFiltered(predicate: DeepPartial<WorkspaceClusterFilter>): Promise<WorkspaceClusterWoTLS[]>;
101
+ }
102
+ export interface WorkspaceClusterFilter extends Pick<WorkspaceCluster, "state" | "govern" | "url"> {
103
+ minScore: number;
104
+ }
@@ -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
@@ -45,6 +51,11 @@ export interface WorkspaceInstance {
45
51
 
46
52
  // instance is hard-deleted on the database and about to be collected by db-sync
47
53
  readonly deleted?: boolean;
54
+
55
+ /**
56
+ * Contains information about the image build, if there was any
57
+ */
58
+ imageBuildInfo?: ImageBuildInfo;
48
59
  }
49
60
 
50
61
  // WorkspaceInstanceStatus describes the current state of a workspace instance
@@ -70,6 +81,12 @@ export interface WorkspaceInstanceStatus {
70
81
  // nodeName is the name of the node the instance was scheduled onto
71
82
  nodeName?: string;
72
83
 
84
+ // podName is the name of the pod of this instance
85
+ podName?: string;
86
+
87
+ // nodeIp is the IP of the node the workspace is running on
88
+ nodeIp?: string;
89
+
73
90
  // ownerToken is the token one needs to access the workspace. Its presence is checked by ws-proxy.
74
91
  ownerToken?: string;
75
92
  }
@@ -77,7 +94,7 @@ export interface WorkspaceInstanceStatus {
77
94
  // WorkspaceInstancePhase describes a high-level state of a workspace instance
78
95
  export type WorkspaceInstancePhase =
79
96
  // unknown indicates an issue within the system in that it cannot determine the actual phase of
80
- // a workspace. This phase is usually accompanied by an error.
97
+ // a workspace. This phase is usually accompanied by an error.
81
98
  "unknown" |
82
99
 
83
100
  // Preparing means that we haven't actually started the workspace instance just yet, but rather
@@ -85,21 +102,21 @@ export type WorkspaceInstancePhase =
85
102
  "preparing" |
86
103
 
87
104
  // Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
88
- // some space within the cluster. If for example the cluster needs to scale up to accomodate the
89
- // workspace, the workspace will be in Pending state until that happened.
105
+ // some space within the cluster. If for example the cluster needs to scale up to accomodate the
106
+ // workspace, the workspace will be in Pending state until that happened.
90
107
  "pending" |
91
108
 
92
109
  // Creating means the workspace is currently being created. Thati includes downloading the images required
93
- // to run the workspace over the network. The time spent in this phase varies widely and depends on the current
94
- // network speed, image size and cache states.
110
+ // to run the workspace over the network. The time spent in this phase varies widely and depends on the current
111
+ // network speed, image size and cache states.
95
112
  "creating" |
96
113
 
97
114
  // Initializing is the phase in which the workspace is executing the appropriate workspace initializer (e.g. Git
98
- // clone or backup download). After this phase one can expect the workspace to either be Running or Failed.
115
+ // clone or backup download). After this phase one can expect the workspace to either be Running or Failed.
99
116
  "initializing" |
100
117
 
101
118
  // Running means the workspace is able to actively perform work, either by serving a user through Theia,
102
- // or as a headless workspace.
119
+ // or as a headless workspace.
103
120
  "running" |
104
121
 
105
122
  // Interrupted is an exceptional state where the container should be running but is temporarily unavailable.
@@ -122,9 +139,6 @@ export interface WorkspaceInstanceConditions {
122
139
  // PullingImages marks if the workspace is currently pulling its images. This condition can only be set during PhaseCreating
123
140
  pullingImages?: boolean
124
141
 
125
- // ServiceExists denotes if the workspace theia-/ports- services exist. This condition will be true if either of the two services exist.
126
- serviceExists?: boolean
127
-
128
142
  // deployed marks that a workspace instance was sent/deployed at a workspace manager
129
143
  deployed?: boolean;
130
144
 
@@ -133,6 +147,12 @@ export interface WorkspaceInstanceConditions {
133
147
 
134
148
  // ISO8601 timestamp when the first user activity was registered in the frontend. Only set if the workspace is running.
135
149
  firstUserActivity?: string;
150
+
151
+ // headless_task_failed indicates that a headless workspace task failed
152
+ headlessTaskFailed?: string;
153
+
154
+ // stopped_by_request is true if the workspace was stopped using a StopWorkspace call
155
+ stoppedByRequest?: boolean;
136
156
  }
137
157
 
138
158
  // AdmissionLevel describes who can access a workspace instance and its ports.
@@ -146,9 +166,6 @@ export interface WorkspaceInstancePort {
146
166
  // The outward-facing port number
147
167
  port: number;
148
168
 
149
- // An optional inward-facing port number. If not present we'll use port.
150
- targetPort?: number;
151
-
152
169
  // The visiblity of this port. Optional for backwards compatibility.
153
170
  visibility?: PortVisibility;
154
171
 
@@ -194,4 +211,25 @@ export interface WorkspaceInstanceConfiguration {
194
211
 
195
212
  // ideImage is the ref of the IDE image this instance uses.
196
213
  ideImage: string;
214
+
215
+ // desktopIdeImage is the ref of the desktop IDE image this instance uses.
216
+ desktopIdeImage?: string
217
+
218
+ // supervisorImage is the ref of the supervisor image this instance uses.
219
+ supervisorImage?: string;
220
+ }
221
+
222
+ /**
223
+ * Holds information about the image build (if there was one) for this WorkspaceInstance
224
+ */
225
+ export interface ImageBuildInfo {
226
+ log?: ImageBuildLogInfo,
227
+ }
228
+
229
+ /**
230
+ * Holds information about how to access logs for this an image build
231
+ */
232
+ export interface ImageBuildLogInfo {
233
+ url: string,
234
+ headers: { [key: string]: string },
197
235
  }
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,27 +0,0 @@
1
- import { Message } from "vscode-jsonrpc";
2
- export interface ResolvedConnectionErrorHandlerOptions {
3
- readonly serverName: string;
4
- /**
5
- * The maximum amount of errors allowed before stopping the server.
6
- */
7
- readonly maxErrors: number;
8
- /**
9
- * The maimum amount of restarts allowed in the restart interval.
10
- */
11
- readonly maxRestarts: number;
12
- /**
13
- * In minutes.
14
- */
15
- readonly restartInterval: number;
16
- }
17
- export declare type ConnectionErrorHandlerOptions = Partial<ResolvedConnectionErrorHandlerOptions> & {
18
- readonly serverName: string;
19
- };
20
- export declare class ConnectionErrorHandler {
21
- protected readonly options: ResolvedConnectionErrorHandlerOptions;
22
- constructor(options: ConnectionErrorHandlerOptions);
23
- shouldStop(error: Error, message?: Message, count?: number): boolean;
24
- protected readonly restarts: number[];
25
- shouldRestart(): boolean;
26
- }
27
- //# sourceMappingURL=connection-error-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-error-handler.d.ts","sourceRoot":"","sources":["../../src/messaging/connection-error-handler.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,MAAM,WAAW,qCAAqC;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B;;OAEG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;CACnC;AAED,oBAAY,6BAA6B,GAAG,OAAO,CAAC,qCAAqC,CAAC,GAAG;IACzF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC9B,CAAC;AAEF,qBAAa,sBAAsB;IAE/B,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,qCAAqC,CAAC;gBACtD,OAAO,EAAE,6BAA6B;IASlD,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO;IAIpE,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAM;IAC3C,aAAa,IAAI,OAAO;CAc3B"}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (C) 2017 TypeFox and others.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7
- */
8
- var __assign = (this && this.__assign) || function () {
9
- __assign = Object.assign || function(t) {
10
- for (var s, i = 1, n = arguments.length; i < n; i++) {
11
- s = arguments[i];
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13
- t[p] = s[p];
14
- }
15
- return t;
16
- };
17
- return __assign.apply(this, arguments);
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ConnectionErrorHandler = void 0;
21
- var logging_1 = require("../util/logging");
22
- var ConnectionErrorHandler = /** @class */ (function () {
23
- function ConnectionErrorHandler(options) {
24
- this.restarts = [];
25
- this.options = __assign({ maxErrors: 3, maxRestarts: 5, restartInterval: 3 }, options);
26
- }
27
- ConnectionErrorHandler.prototype.shouldStop = function (error, message, count) {
28
- return !count || count > this.options.maxErrors;
29
- };
30
- ConnectionErrorHandler.prototype.shouldRestart = function () {
31
- this.restarts.push(Date.now());
32
- if (this.restarts.length <= this.options.maxRestarts) {
33
- return true;
34
- }
35
- var diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
36
- if (diff <= this.options.restartInterval * 60 * 1000) {
37
- logging_1.log.error("Server " + this.options.serverName + " crashed " + this.options.maxRestarts + " times in the last " + this.options.restartInterval + " minutes. Will not restart");
38
- return false;
39
- }
40
- this.restarts.shift();
41
- return true;
42
- };
43
- return ConnectionErrorHandler;
44
- }());
45
- exports.ConnectionErrorHandler = ConnectionErrorHandler;
46
- //# sourceMappingURL=connection-error-handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection-error-handler.js","sourceRoot":"","sources":["../../src/messaging/connection-error-handler.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;AAGH,2CAAsC;AAsBtC;IAGI,gCAAY,OAAsC;QAa/B,aAAQ,GAAa,EAAE,CAAC;QAZvC,IAAI,CAAC,OAAO,cACR,SAAS,EAAE,CAAC,EACZ,WAAW,EAAE,CAAC,EACd,eAAe,EAAE,CAAC,IACf,OAAO,CACb,CAAC;IACN,CAAC;IAED,2CAAU,GAAV,UAAW,KAAY,EAAE,OAAiB,EAAE,KAAc;QACtD,OAAO,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IACpD,CAAC;IAGD,8CAAa,GAAb;QACI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/B,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE;YAClD,OAAO,IAAI,CAAC;SACf;QACD,IAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACxE,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,GAAG,EAAE,GAAG,IAAI,EAAE;YAClD,aAAG,CAAC,KAAK,CAAC,YAAU,IAAI,CAAC,OAAO,CAAC,UAAU,iBAAY,IAAI,CAAC,OAAO,CAAC,WAAW,2BAAsB,IAAI,CAAC,OAAO,CAAC,eAAe,+BAA4B,CAAC,CAAC;YAC/J,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEL,6BAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,wDAAsB"}
@@ -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"}