@gitpod/gitpod-protocol 0.1.5-v0.6.0-beta4 → 0.1.5-vn-implement-jetbrains-terminals.0

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 +21 -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 +5 -3
  104. package/lib/permission.d.ts.map +1 -1
  105. package/lib/permission.js +18 -17
  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 +120 -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 +71 -0
  220. package/lib/workspace-cluster.d.ts.map +1 -0
  221. package/lib/workspace-cluster.js +16 -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 +35 -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 +7 -6
  253. package/src/plans.ts +632 -0
  254. package/src/protocol.ts +194 -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 +91 -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
@@ -0,0 +1,102 @@
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 { opentracing } from "jaeger-client";
8
+
9
+ // Type definitions for jaeger-client which are not exported by @types/jaeger-client
10
+ // Project: https://github.com/uber/jaeger-client-node
11
+ // Definitions by: Julian Steger <https://github.com/julianste>
12
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
13
+
14
+ export interface TracingConfig {
15
+ serviceName?: string;
16
+ disable?: boolean;
17
+ sampler?: SamplerConfig;
18
+ reporter?: ReporterConfig;
19
+ }
20
+
21
+ export interface TracingOptions {
22
+ reporter?: Reporter;
23
+ metrics?: MetricsFactory;
24
+ logger?: Logger;
25
+ tags?: any;
26
+ }
27
+
28
+ export interface ReporterConfig {
29
+ logSpans?: boolean;
30
+ agentHost?: string;
31
+ agentPort?: number;
32
+ flushIntervalMs?: number;
33
+ }
34
+
35
+ export interface SamplerConfig {
36
+ type: string;
37
+ param: number;
38
+ host?: string;
39
+ port?: number;
40
+ refreshIntervalMs?: number;
41
+ }
42
+
43
+ export interface Logger {
44
+ info(msg: string): void;
45
+ error(msg: string): void;
46
+ }
47
+
48
+ export interface Reporter {
49
+ report(span: opentracing.Span): void;
50
+ close(callback?: () => void): void;
51
+ setProcess(serviceName: string, tags: any): void;
52
+ }
53
+
54
+ export interface MetricsFactory {
55
+ createCounter(name: string, tags: any): Counter;
56
+ createTimer(name: string, tags: any): Timer;
57
+ createGauge(name: string, tags: any): Gauge;
58
+ }
59
+
60
+ // Counter tracks the number of times an event has occurred
61
+ export interface Counter {
62
+ // Adds the given value to the counter.
63
+ increment(delta: number): void;
64
+ }
65
+
66
+ // Timer tracks how long an operation took and also computes percentiles.
67
+ export interface Timer {
68
+ // Records the time passed in.
69
+ record(value: number): void;
70
+ }
71
+
72
+ // Gauge returns instantaneous measurements of something as an int64 value
73
+ export interface Gauge {
74
+ // Update the gauge to the value passed in.
75
+ update(value: number): void;
76
+ }
77
+
78
+ // export function initTracer(
79
+ // tracingConfig: TracingConfig,
80
+ // tracingOptions: TracingOptions,
81
+ // ): opentracing.Tracer;
82
+
83
+ // export function initTracerFromEnv(
84
+ // tracingConfig: TracingConfig,
85
+ // tracingOptions: TracingOptions,
86
+ // ): opentracing.Tracer;
87
+
88
+ export interface SamplingDecision {
89
+ sample: boolean;
90
+ retryable: boolean;
91
+ tags: any;
92
+ }
93
+
94
+ // added by TypeFox
95
+ export interface Sampler {
96
+ name(): string
97
+ isSampled(operation: string, tags: any): boolean;
98
+ onCreateSpan(span: opentracing.Span): SamplingDecision;
99
+ onSetOperationName(span: opentracing.Span, operationName: string): SamplingDecision;
100
+ onSetTag(span: opentracing.Span, key: string, value: any): SamplingDecision;
101
+ close(callback: () => void): void
102
+ }
@@ -30,66 +30,66 @@ export interface LogPayload {
30
30
  };
31
31
 
32
32
  export namespace log {
33
- export function error(context: LogContext, message: string, error: Error, payload: LogPayload): void;
34
- export function error(context: LogContext, message: string, error: Error): void;
33
+ export function error(context: LogContext, message: string, error: any, payload: LogPayload): void;
34
+ export function error(context: LogContext, message: string, error: any): void;
35
35
  export function error(context: LogContext, message: string, payload: LogPayload): void;
36
36
  export function error(context: LogContext, message: string): void;
37
- export function error(context: LogContext, error: Error, payload: LogPayload): void;
38
- export function error(context: LogContext, error: Error): void;
39
- export function error(message: string, error: Error, payload: LogPayload): void;
40
- export function error(message: string, error: Error): void;
37
+ export function error(context: LogContext, error: any, payload: LogPayload): void;
38
+ export function error(context: LogContext, error: any): void;
39
+ export function error(message: string, error: any, payload: LogPayload): void;
40
+ export function error(message: string, error: any): void;
41
41
  export function error(message: string, payload: LogPayload): void;
42
42
  export function error(message: string): void;
43
- export function error(error: Error, payload: LogPayload): void;
44
- export function error(error: Error): void;
43
+ export function error(error: any, payload: LogPayload): void;
44
+ export function error(error: any): void;
45
45
  export function error(...args: any[]): void {
46
46
  errorLog(false, args);
47
47
  }
48
48
 
49
- export function warn(context: LogContext, message: string, error: Error, payload: LogPayload): void;
50
- export function warn(context: LogContext, message: string, error: Error): void;
49
+ export function warn(context: LogContext, message: string, error: any, payload: LogPayload): void;
50
+ export function warn(context: LogContext, message: string, error: any): void;
51
51
  export function warn(context: LogContext, message: string, payload: LogPayload): void;
52
52
  export function warn(context: LogContext, message: string): void;
53
- export function warn(context: LogContext, error: Error, payload: LogPayload): void;
54
- export function warn(context: LogContext, error: Error): void;
55
- export function warn(message: string, error: Error, payload: LogPayload): void;
56
- export function warn(message: string, error: Error): void;
53
+ export function warn(context: LogContext, error: any, payload: LogPayload): void;
54
+ export function warn(context: LogContext, error: any): void;
55
+ export function warn(message: string, error: any, payload: LogPayload): void;
56
+ export function warn(message: string, error: any): void;
57
57
  export function warn(message: string, payload: LogPayload): void;
58
58
  export function warn(message: string): void;
59
- export function warn(error: Error, payload: LogPayload): void;
60
- export function warn(error: Error): void;
59
+ export function warn(error: any, payload: LogPayload): void;
60
+ export function warn(error: any): void;
61
61
  export function warn(...args: any[]): void {
62
62
  warnLog(false, args);
63
63
  }
64
64
 
65
- export function info(context: LogContext, message: string, error: Error, payload: LogPayload): void;
66
- export function info(context: LogContext, message: string, error: Error): void;
65
+ export function info(context: LogContext, message: string, error: any, payload: LogPayload): void;
66
+ export function info(context: LogContext, message: string, error: any): void;
67
67
  export function info(context: LogContext, message: string, payload: LogPayload): void;
68
68
  export function info(context: LogContext, message: string): void;
69
- export function info(context: LogContext, error: Error, payload: LogPayload): void;
70
- export function info(context: LogContext, error: Error): void;
71
- export function info(message: string, error: Error, payload: LogPayload): void;
72
- export function info(message: string, error: Error): void;
69
+ export function info(context: LogContext, error: any, payload: LogPayload): void;
70
+ export function info(context: LogContext, error: any): void;
71
+ export function info(message: string, error: any, payload: LogPayload): void;
72
+ export function info(message: string, error: any): void;
73
73
  export function info(message: string, payload: LogPayload): void;
74
74
  export function info(message: string): void;
75
- export function info(error: Error, payload: LogPayload): void;
76
- export function info(error: Error): void;
75
+ export function info(error: any, payload: LogPayload): void;
76
+ export function info(error: any): void;
77
77
  export function info(...args: any[]): void {
78
78
  infoLog(false, args);
79
79
  }
80
80
 
81
- export function debug(context: LogContext, message: string, error: Error, payload: LogPayload): void;
82
- export function debug(context: LogContext, message: string, error: Error): void;
81
+ export function debug(context: LogContext, message: string, error: any, payload: LogPayload): void;
82
+ export function debug(context: LogContext, message: string, error: any): void;
83
83
  export function debug(context: LogContext, message: string, payload: LogPayload): void;
84
84
  export function debug(context: LogContext, message: string): void;
85
- export function debug(context: LogContext, error: Error, payload: LogPayload): void;
86
- export function debug(context: LogContext, error: Error): void;
87
- export function debug(message: string, error: Error, payload: LogPayload): void;
88
- export function debug(message: string, error: Error): void;
85
+ export function debug(context: LogContext, error: any, payload: LogPayload): void;
86
+ export function debug(context: LogContext, error: any): void;
87
+ export function debug(message: string, error: any, payload: LogPayload): void;
88
+ export function debug(message: string, error: any): void;
89
89
  export function debug(message: string, payload: LogPayload): void;
90
90
  export function debug(message: string): void;
91
- export function debug(error: Error, payload: LogPayload): void;
92
- export function debug(error: Error): void;
91
+ export function debug(error: any, payload: LogPayload): void;
92
+ export function debug(error: any): void;
93
93
  export function debug(...args: any[]): void {
94
94
  debugLog(false, args);
95
95
  }
@@ -97,10 +97,14 @@ export namespace log {
97
97
  /**
98
98
  * Do not use in frontend.
99
99
  */
100
- export function enableJSONLogging(componentArg: string, versionArg: string | undefined): void {
100
+ export function enableJSONLogging(componentArg: string, versionArg: string | undefined, logLevel?: LogrusLogLevel): void {
101
101
  component = componentArg;
102
102
  version = versionArg;
103
103
 
104
+ setLogLevel(logLevel);
105
+ }
106
+
107
+ export function setLogLevel(logLevel: LogrusLogLevel | undefined) {
104
108
  jsonLogging = true;
105
109
 
106
110
  console.error = function (...args: any[]): void {
@@ -115,8 +119,20 @@ export namespace log {
115
119
  console.debug = function (...args: any[]): void {
116
120
  debugLog(true, args);
117
121
  }
122
+
118
123
  console.log = console.info;
119
124
  // FIXME wrap also other console methods (e.g. trace())
125
+
126
+ // set/unset log functions based on loglevel so we only have to evaluate once, not every call
127
+ const noop = () => {};
128
+ const setLog = (logFunc: DoLogFunction, funcLevel: LogrusLogLevel): DoLogFunction => {
129
+ return LogrusLogLevel.isGreatherOrEqual(funcLevel, logLevel) ? logFunc : noop;
130
+ };
131
+
132
+ errorLog = setLog(doErrorLog, "error");
133
+ warnLog = setLog(doWarnLog, "warning");
134
+ infoLog = setLog(doInfoLog, "info");
135
+ debugLog = setLog(doDebugLog, "debug");
120
136
  }
121
137
 
122
138
  export function resetToDefaultLogging(): void {
@@ -128,24 +144,73 @@ export namespace log {
128
144
  console.info = infoConsoleLog;
129
145
  console.debug = debugConsoleLog;
130
146
  }
147
+
148
+ export function setVersion(versionArg: string) {
149
+ version = versionArg;
150
+ }
131
151
  }
132
152
 
133
- function errorLog(calledViaConsole: boolean, args: any[]): void {
153
+ type DoLogFunction = (calledViaConsole: boolean, args: any[]) => void;
154
+
155
+ let errorLog = doErrorLog;
156
+ function doErrorLog(calledViaConsole: boolean, args: any[]): void {
134
157
  doLog(calledViaConsole, errorConsoleLog, 'ERROR', args);
135
158
  }
136
159
 
137
- function warnLog(calledViaConsole: boolean, args: any[]): void {
160
+ let warnLog = doWarnLog;
161
+ function doWarnLog(calledViaConsole: boolean, args: any[]): void {
138
162
  doLog(calledViaConsole, warnConsoleLog, 'WARNING', args);
139
163
  }
140
164
 
141
- function infoLog(calledViaConsole: boolean, args: any[]): void {
165
+ let infoLog = doInfoLog;
166
+ function doInfoLog(calledViaConsole: boolean, args: any[]): void {
142
167
  doLog(calledViaConsole, infoConsoleLog, 'INFO', args);
143
168
  }
144
169
 
145
- function debugLog(calledViaConsole: boolean, args: any[]): void {
170
+ let debugLog = doDebugLog;
171
+ function doDebugLog(calledViaConsole: boolean, args: any[]): void {
146
172
  doLog(calledViaConsole, debugConsoleLog, 'DEBUG', args);
147
173
  }
148
174
 
175
+ // Ref: https://github.com/sirupsen/logrus#level-logging
176
+ export type LogrusLogLevel = keyof (typeof LogrusLogLevels);
177
+ export const LogrusLogLevels = {
178
+ trace: true,
179
+ debug: true,
180
+ info: true,
181
+ warning: true,
182
+ error: true,
183
+ fatal: true,
184
+ panic: true,
185
+ }
186
+ export namespace LogrusLogLevel {
187
+ export function isGreatherOrEqual(lvl: LogrusLogLevel | undefined, ref: LogrusLogLevel | undefined): boolean {
188
+ if (lvl === undefined) {
189
+ return false;
190
+ }
191
+ if (ref === undefined) {
192
+ return true;
193
+ }
194
+ return getLevelArity(lvl) >= getLevelArity(ref);
195
+ }
196
+ function getLevelArity(lvl: LogrusLogLevel): number {
197
+ return Object.keys(LogrusLogLevels)
198
+ .findIndex((l) => l === lvl);
199
+ }
200
+ export function getFromEnv(): LogrusLogLevel | undefined {
201
+ const lvlStr = process.env.LOG_LEVEL;
202
+ if (!lvlStr) {
203
+ return undefined;
204
+ }
205
+ const lvl = lvlStr as LogrusLogLevel;
206
+ const exists = LogrusLogLevels[lvl]
207
+ if (!exists) {
208
+ return undefined;
209
+ }
210
+ return lvl;
211
+ }
212
+ }
213
+
149
214
  // Source: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
150
215
  type GoogleLogSeverity = 'EMERGENCY' | 'ALERT' | 'CRITICAL' | 'ERROR' | 'WARNING' | 'INFO' | 'DEBUG';
151
216
  namespace GoogleLogSeverity {
@@ -243,7 +308,6 @@ function makeLogItem(severity: GoogleLogSeverity, context: LogContext | undefine
243
308
  severity,
244
309
  time: new Date().toISOString(),
245
310
  environment: process.env.KUBE_STAGE,
246
- region: process.env.GITPOD_REGION,
247
311
  context,
248
312
  message,
249
313
  error,
@@ -6,30 +6,71 @@
6
6
 
7
7
  import * as chai from 'chai';
8
8
  import { suite, test } from 'mocha-typescript';
9
- import { parseWorkspaceIdFromHostname } from './parse-workspace-id';
9
+ import { matchesInstanceIdOrLegacyWorkspaceIdExactly, matchesNewWorkspaceIdExactly, parseWorkspaceIdFromHostname } from './parse-workspace-id';
10
10
  const expect = chai.expect;
11
11
 
12
12
  @suite
13
13
  export class ParseWorkspaceIdTest {
14
14
 
15
15
  @test public parseWorkspaceIdFromHostname_fromWorkspaceLocation() {
16
+ const actual = parseWorkspaceIdFromHostname("moccasin-ferret-155799b3.ws-eu01.gitpod.io");
17
+ expect(actual).to.equal("moccasin-ferret-155799b3");
18
+ }
19
+
20
+ @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocation() {
21
+ const actual = parseWorkspaceIdFromHostname("3000-moccasin-ferret-155799b3.ws-eu01.gitpod.io");
22
+ expect(actual).to.equal("moccasin-ferret-155799b3");
23
+ }
24
+
25
+ @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
26
+ const actual = parseWorkspaceIdFromHostname("webview-3000-moccasin-ferret-155799b3.ws-eu01.gitpod.io");
27
+ expect(actual).to.equal("moccasin-ferret-155799b3");
28
+ }
29
+
30
+ @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
31
+ const actual = parseWorkspaceIdFromHostname("webview-3000-moccasin-ferret-155799b3.ws-eu01.some.subdomain.somehost.com");
32
+ expect(actual).to.equal("moccasin-ferret-155799b3");
33
+ }
34
+
35
+ // legacy mode
36
+ @test public parseLegacyWorkspaceIdFromHostname_fromWorkspaceLocation() {
16
37
  const actual = parseWorkspaceIdFromHostname("b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
17
38
  expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
18
39
  }
19
40
 
20
- @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocation() {
41
+ @test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocation() {
21
42
  const actual = parseWorkspaceIdFromHostname("3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
22
43
  expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
23
44
  }
24
45
 
25
- @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
46
+ @test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
26
47
  const actual = parseWorkspaceIdFromHostname("webview-3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
27
48
  expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
28
49
  }
29
50
 
30
- @test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
51
+ @test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
31
52
  const actual = parseWorkspaceIdFromHostname("webview-3000-ca81a50f-09d7-465c-acd9-264a747d5351.ws-eu01.some.subdomain.somehost.com");
32
53
  expect(actual).to.equal("ca81a50f-09d7-465c-acd9-264a747d5351");
33
54
  }
55
+
56
+ // match - instance ID
57
+ @test public matchesInstanceIdOrLegacyWorkspaceIdExactly_positive() {
58
+ const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81ea-04859263b656");
59
+ expect(actual).to.be.true;
60
+ }
61
+ @test public matchesInstanceIdOrLegacyWorkspaceIdExactly_negative() {
62
+ const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81a-04859263b656");
63
+ expect(actual).to.be.false;
64
+ }
65
+
66
+ // match - new workspace ID
67
+ @test public matchesWorkspaceIdExactly_new_positive() {
68
+ const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-155799b3");
69
+ expect(actual).to.be.true;
70
+ }
71
+ @test public matchesWorkspaceIdExactly_new_negative() {
72
+ const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
73
+ expect(actual).to.be.false;
74
+ }
34
75
  }
35
76
  module.exports = new ParseWorkspaceIdTest()
@@ -4,21 +4,52 @@
4
4
  * See License-AGPL.txt in the project root for license information.
5
5
  */
6
6
 
7
+ const REGEX_WORKSPACE_ID = /[0-9a-z]{2,16}-[0-9a-z]{2,16}-[0-9a-z]{8,11}/;
8
+ const REGEX_WORKSPACE_ID_EXACT = new RegExp(`^${REGEX_WORKSPACE_ID.source}$`);
9
+ // We need to parse the workspace id precisely here to get the case '<some-str>-<port>-<wsid>.ws.' right
10
+ const REGEX_WORKSPACE_ID_FROM_HOSTNAME = new RegExp(`(${REGEX_WORKSPACE_ID.source})\.ws`);
11
+
12
+ const REGEX_WORKSPACE_ID_LEGACY = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
13
+ const REGEX_WORKSPACE_ID_LEGACY_EXACT = new RegExp(`^${REGEX_WORKSPACE_ID_LEGACY.source}$`);
14
+ const REGEX_WORKSPACE_ID_LEGACY_FROM_HOSTNAME = new RegExp(`(${REGEX_WORKSPACE_ID_LEGACY.source})\.ws`);
7
15
 
8
16
  /**
9
17
  * Hostname may be of the form:
10
- * - b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io
11
- * - 1234-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io
12
- * - webview-1234-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io (or any other string replacing webview)
18
+ * - moccasin-ferret-155799b3.ws-eu01.gitpod.io
19
+ * - 1234-moccasin-ferret-155799b3.ws-eu01.gitpod.io
20
+ * - webview-1234-moccasin-ferret-155799b3.ws-eu01.gitpod.io (or any other string replacing webview)
13
21
  * @param hostname The hostname the request is headed to
14
22
  */
15
23
  export const parseWorkspaceIdFromHostname = function(hostname: string) {
16
- // We need to parse the workspace id precisely here to get the case '<some-str>-<port>-<wsid>.ws.' right
17
- const wsIdExpression = /([a-z][0-9a-z]+\-([0-9a-z]+\-){3}[0-9a-z]+)\.ws/g;
18
- const match = wsIdExpression.exec(hostname);
24
+ const match = REGEX_WORKSPACE_ID_FROM_HOSTNAME.exec(hostname);
19
25
  if (match && match.length >= 2) {
20
26
  return match[1];
21
27
  } else {
28
+ const legacyMatch = REGEX_WORKSPACE_ID_LEGACY_FROM_HOSTNAME.exec(hostname);
29
+ if (legacyMatch && legacyMatch.length >= 2) {
30
+ return legacyMatch[1];
31
+ }
22
32
  return undefined;
23
33
  }
24
- }
34
+ };
35
+
36
+ /** Equalls UUIDv4 (and REGEX_WORKSPACE_ID_LEGACY!) */
37
+ const REGEX_INSTANCE_ID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;
38
+ const REGEX_INSTANCE_ID_EXACT = new RegExp(`^${REGEX_INSTANCE_ID.source}$`);
39
+
40
+ /**
41
+ * @param maybeId
42
+ * @returns
43
+ */
44
+ export const matchesInstanceIdOrLegacyWorkspaceIdExactly = function(maybeId: string): boolean {
45
+ return REGEX_INSTANCE_ID_EXACT.test(maybeId)
46
+ || REGEX_WORKSPACE_ID_LEGACY_EXACT.test(maybeId);
47
+ };
48
+
49
+ /**
50
+ * @param maybeWorkspaceId
51
+ * @returns
52
+ */
53
+ export const matchesNewWorkspaceIdExactly = function(maybeWorkspaceId: string): boolean {
54
+ return REGEX_WORKSPACE_ID_EXACT.test(maybeWorkspaceId);
55
+ };
@@ -32,7 +32,7 @@ const expect = chai.expect
32
32
  return new Promise((resolve) => {
33
33
  setTimeout(() => {
34
34
  this.seq.push(seqNr);
35
- resolve();
35
+ resolve(undefined);
36
36
  }, sleep);
37
37
  });
38
38
  else
@@ -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
+ }
@@ -9,7 +9,7 @@ export class Semaphore {
9
9
  protected queue: (() => void)[] = [];
10
10
  protected used: number;
11
11
 
12
- constructor(protected readonly capacity: number) {
12
+ constructor(protected readonly capacity: number) {
13
13
  if(capacity < 1) {
14
14
  throw new Error("Capacity cannot be less than 1");
15
15
  }
@@ -17,7 +17,7 @@ export class Semaphore {
17
17
 
18
18
  public release() {
19
19
  if(this.used == 0) return;
20
-
20
+
21
21
  const queued = this.queue.shift();
22
22
  if (queued) {
23
23
  queued();
@@ -27,7 +27,7 @@ export function skipIf(doSkip: (suite: TestSuiteContext) => boolean): MochaTypeS
27
27
  }
28
28
  })
29
29
  };
30
-
30
+
31
31
  // Mark as "trait": mimics the behavior of https://github.com/testdeck/testdeck/blob/9d2dd6a458c2c86c945f6f2999b8278b7528a7a7/index.ts#L433
32
32
  (trait as any)["__mts_isTrait"] = true;
33
33
  return trait;
@@ -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);
@@ -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()