@gitpod/gitpod-protocol 0.1.5-wth-test.41 → 0.1.5-wth-test.80

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 (140) hide show
  1. package/data/gitpod-schema.json +18 -3
  2. package/lib/admin-protocol.d.ts +12 -1
  3. package/lib/admin-protocol.d.ts.map +1 -1
  4. package/lib/admin-protocol.js.map +1 -1
  5. package/lib/analytics.d.ts +4 -5
  6. package/lib/analytics.d.ts.map +1 -1
  7. package/lib/context-url.d.ts +18 -5
  8. package/lib/context-url.d.ts.map +1 -1
  9. package/lib/context-url.js +58 -5
  10. package/lib/context-url.js.map +1 -1
  11. package/lib/context-url.spec.d.ts +2 -0
  12. package/lib/context-url.spec.d.ts.map +1 -1
  13. package/lib/context-url.spec.js +25 -4
  14. package/lib/context-url.spec.js.map +1 -1
  15. package/lib/gitpod-service.d.ts +33 -6
  16. package/lib/gitpod-service.d.ts.map +1 -1
  17. package/lib/gitpod-service.js +4 -2
  18. package/lib/gitpod-service.js.map +1 -1
  19. package/lib/ide-protocol.d.ts +105 -0
  20. package/lib/ide-protocol.d.ts.map +1 -0
  21. package/lib/ide-protocol.js +8 -0
  22. package/lib/ide-protocol.js.map +1 -0
  23. package/lib/index.d.ts +2 -0
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +2 -0
  26. package/lib/index.js.map +1 -1
  27. package/lib/installation-admin-protocol.d.ts +27 -0
  28. package/lib/installation-admin-protocol.d.ts.map +1 -0
  29. package/lib/installation-admin-protocol.js +30 -0
  30. package/lib/installation-admin-protocol.js.map +1 -0
  31. package/lib/messaging/error.d.ts +1 -0
  32. package/lib/messaging/error.d.ts.map +1 -1
  33. package/lib/messaging/error.js +2 -0
  34. package/lib/messaging/error.js.map +1 -1
  35. package/lib/messaging/node/connection.d.ts +1 -17
  36. package/lib/messaging/node/connection.d.ts.map +1 -1
  37. package/lib/messaging/node/connection.js +21 -57
  38. package/lib/messaging/node/connection.js.map +1 -1
  39. package/lib/oss-allowlist.d.ts +14 -0
  40. package/lib/oss-allowlist.d.ts.map +1 -0
  41. package/lib/oss-allowlist.js +8 -0
  42. package/lib/oss-allowlist.js.map +1 -0
  43. package/lib/permission.d.ts +7 -1
  44. package/lib/permission.d.ts.map +1 -1
  45. package/lib/permission.js +24 -4
  46. package/lib/permission.js.map +1 -1
  47. package/lib/protocol.d.ts +28 -40
  48. package/lib/protocol.d.ts.map +1 -1
  49. package/lib/protocol.js +16 -4
  50. package/lib/protocol.js.map +1 -1
  51. package/lib/teams-projects-protocol.d.ts +10 -0
  52. package/lib/teams-projects-protocol.d.ts.map +1 -1
  53. package/lib/teams-projects-protocol.js +7 -0
  54. package/lib/teams-projects-protocol.js.map +1 -1
  55. package/lib/util/analytics.js +12 -3
  56. package/lib/util/analytics.js.map +1 -1
  57. package/lib/util/garbage-collected-cache.d.ts +1 -0
  58. package/lib/util/garbage-collected-cache.d.ts.map +1 -1
  59. package/lib/util/garbage-collected-cache.js +5 -1
  60. package/lib/util/garbage-collected-cache.js.map +1 -1
  61. package/lib/util/generate-workspace-id.d.ts +1 -1
  62. package/lib/util/generate-workspace-id.d.ts.map +1 -1
  63. package/lib/util/generate-workspace-id.js +19 -2
  64. package/lib/util/generate-workspace-id.js.map +1 -1
  65. package/lib/util/generate-workspace-id.spec.js +24 -0
  66. package/lib/util/generate-workspace-id.spec.js.map +1 -1
  67. package/lib/util/gitpod-host-url.d.ts +0 -1
  68. package/lib/util/gitpod-host-url.d.ts.map +1 -1
  69. package/lib/util/gitpod-host-url.js +3 -6
  70. package/lib/util/gitpod-host-url.js.map +1 -1
  71. package/lib/util/jaeger-client-types.d.ts +68 -0
  72. package/lib/util/jaeger-client-types.d.ts.map +1 -0
  73. package/lib/util/jaeger-client-types.js +8 -0
  74. package/lib/util/jaeger-client-types.js.map +1 -0
  75. package/lib/util/parse-workspace-id.js +1 -1
  76. package/lib/util/parse-workspace-id.js.map +1 -1
  77. package/lib/util/repeat.d.ts +15 -0
  78. package/lib/util/repeat.d.ts.map +1 -0
  79. package/lib/util/repeat.js +55 -0
  80. package/lib/util/repeat.js.map +1 -0
  81. package/lib/util/tracing.d.ts +51 -5
  82. package/lib/util/tracing.d.ts.map +1 -1
  83. package/lib/util/tracing.js +156 -17
  84. package/lib/util/tracing.js.map +1 -1
  85. package/lib/util/tracing.spec.d.ts +7 -0
  86. package/lib/util/tracing.spec.d.ts.map +1 -0
  87. package/lib/util/tracing.spec.js +121 -0
  88. package/lib/util/tracing.spec.js.map +1 -0
  89. package/lib/workspace-cluster.d.ts +9 -7
  90. package/lib/workspace-cluster.d.ts.map +1 -1
  91. package/lib/workspace-cluster.js +18 -1
  92. package/lib/workspace-cluster.js.map +1 -1
  93. package/lib/workspace-instance.d.ts +19 -0
  94. package/lib/workspace-instance.d.ts.map +1 -1
  95. package/package.json +5 -3
  96. package/pkg-yarn.lock +2 -2
  97. package/provenance-bundle.jsonl +2 -0
  98. package/src/admin-protocol.ts +19 -5
  99. package/src/analytics.ts +4 -6
  100. package/src/context-url.spec.ts +18 -4
  101. package/src/context-url.ts +62 -6
  102. package/src/gitpod-service.ts +41 -10
  103. package/src/ide-frontend-service.ts +1 -1
  104. package/src/ide-protocol.ts +119 -0
  105. package/src/index.ts +2 -0
  106. package/src/installation-admin-protocol.ts +42 -0
  107. package/src/messaging/error.ts +3 -0
  108. package/src/messaging/node/connection.ts +21 -68
  109. package/src/oss-allowlist.ts +15 -0
  110. package/src/permission.ts +22 -3
  111. package/src/protocol.ts +45 -44
  112. package/src/teams-projects-protocol.ts +16 -1
  113. package/src/util/analytics.ts +21 -3
  114. package/src/util/garbage-collected-cache.ts +7 -1
  115. package/src/util/generate-workspace-id.spec.ts +17 -0
  116. package/src/util/generate-workspace-id.ts +20 -2
  117. package/src/util/gitpod-host-url.ts +4 -8
  118. package/src/util/jaeger-client-types.ts +102 -0
  119. package/src/util/parse-workspace-id.ts +1 -1
  120. package/src/util/repeat.ts +45 -0
  121. package/src/util/tracing.spec.ts +83 -0
  122. package/src/util/tracing.ts +183 -17
  123. package/src/workspace-cluster.ts +17 -9
  124. package/src/workspace-instance.ts +20 -0
  125. package/lib/messaging/connection-error-handler.d.ts +0 -27
  126. package/lib/messaging/connection-error-handler.d.ts.map +0 -1
  127. package/lib/messaging/connection-error-handler.js +0 -34
  128. package/lib/messaging/connection-error-handler.js.map +0 -1
  129. package/lib/util/repeater.d.ts +0 -22
  130. package/lib/util/repeater.d.ts.map +0 -1
  131. package/lib/util/repeater.js +0 -65
  132. package/lib/util/repeater.js.map +0 -1
  133. package/lib/util/safe-promise.d.ts +0 -11
  134. package/lib/util/safe-promise.d.ts.map +0 -1
  135. package/lib/util/safe-promise.js +0 -31
  136. package/lib/util/safe-promise.js.map +0 -1
  137. package/src/messaging/connection-error-handler.ts +0 -62
  138. package/src/util/jaeger-client.d.ts +0 -105
  139. package/src/util/repeater.ts +0 -49
  140. 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
+ };
@@ -35,9 +35,6 @@ export interface WorkspaceCluster {
35
35
 
36
36
  // An optional set of constraints that limit who can start workspaces on the cluster
37
37
  admissionConstraints?: AdmissionConstraint[];
38
-
39
- // An optional set of admission preferences that guide cluster selection
40
- admissionPreferences?: AdmissionPreference[];
41
38
  }
42
39
 
43
40
  export type WorkspaceClusterState = "available" | "cordoned" | "draining";
@@ -55,14 +52,25 @@ export namespace TLSConfig {
55
52
  export type WorkspaceClusterWoTLS = Omit<WorkspaceCluster, "tls">;
56
53
  export type WorkspaceManagerConnectionInfo = Pick<WorkspaceCluster, "name" | "url" | "tls">;
57
54
 
58
- export type AdmissionConstraint = AdmissionConstraintFeaturePreview | AdmissionConstraintHasRole | AdmissionConstraintHasUserLevel;
55
+ export type AdmissionConstraint = AdmissionConstraintFeaturePreview | AdmissionConstraintHasPermission | AdmissionConstraintHasUserLevel | AdmissionConstraintHasMoreResources;
59
56
  export type AdmissionConstraintFeaturePreview = { type: "has-feature-preview" };
60
- export type AdmissionConstraintHasRole = { type: "has-permission", permission: PermissionName };
57
+ export type AdmissionConstraintHasPermission = { type: "has-permission", permission: PermissionName };
61
58
  export type AdmissionConstraintHasUserLevel = { type: "has-user-level", level: string };
62
-
63
- export type AdmissionPreference = AdmissionPreferenceUserLevel;
64
- export type AdmissionPreferenceUserLevel = { type: 'user-level', level: string };
65
-
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
+ }
66
74
 
67
75
  export const WorkspaceClusterDB = Symbol("WorkspaceClusterDB");
68
76
  export interface WorkspaceClusterDB {
@@ -51,6 +51,11 @@ export interface WorkspaceInstance {
51
51
 
52
52
  // instance is hard-deleted on the database and about to be collected by db-sync
53
53
  readonly deleted?: boolean;
54
+
55
+ /**
56
+ * Contains information about the image build, if there was any
57
+ */
58
+ imageBuildInfo?: ImageBuildInfo;
54
59
  }
55
60
 
56
61
  // WorkspaceInstanceStatus describes the current state of a workspace instance
@@ -213,3 +218,18 @@ export interface WorkspaceInstanceConfiguration {
213
218
  // supervisorImage is the ref of the supervisor image this instance uses.
214
219
  supervisorImage?: string;
215
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 },
235
+ }
@@ -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,34 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ConnectionErrorHandler = void 0;
10
- const logging_1 = require("../util/logging");
11
- class ConnectionErrorHandler {
12
- constructor(options) {
13
- this.restarts = [];
14
- this.options = Object.assign({ maxErrors: 3, maxRestarts: 5, restartInterval: 3 }, options);
15
- }
16
- shouldStop(error, message, count) {
17
- return !count || count > this.options.maxErrors;
18
- }
19
- shouldRestart() {
20
- this.restarts.push(Date.now());
21
- if (this.restarts.length <= this.options.maxRestarts) {
22
- return true;
23
- }
24
- const diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
25
- if (diff <= this.options.restartInterval * 60 * 1000) {
26
- logging_1.log.error(`Server ${this.options.serverName} crashed ${this.options.maxRestarts} times in the last ${this.options.restartInterval} minutes. Will not restart`);
27
- return false;
28
- }
29
- this.restarts.shift();
30
- return true;
31
- }
32
- }
33
- exports.ConnectionErrorHandler = ConnectionErrorHandler;
34
- //# 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,6CAAsC;AAsBtC,MAAa,sBAAsB;IAG/B,YAAY,OAAsC;QAa/B,aAAQ,GAAa,EAAE,CAAC;QAZvC,IAAI,CAAC,OAAO,mBACR,SAAS,EAAE,CAAC,EACZ,WAAW,EAAE,CAAC,EACd,eAAe,EAAE,CAAC,IACf,OAAO,CACb,CAAC;IACN,CAAC;IAED,UAAU,CAAC,KAAY,EAAE,OAAiB,EAAE,KAAc;QACtD,OAAO,CAAC,KAAK,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IACpD,CAAC;IAGD,aAAa;QACT,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,MAAM,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,UAAU,IAAI,CAAC,OAAO,CAAC,UAAU,YAAY,IAAI,CAAC,OAAO,CAAC,WAAW,sBAAsB,IAAI,CAAC,OAAO,CAAC,eAAe,4BAA4B,CAAC,CAAC;YAC/J,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;CAEJ;AA/BD,wDA+BC"}
@@ -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"}
@@ -1,65 +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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Repeater = void 0;
18
- const deferred_1 = require("./deferred");
19
- const logging_1 = require("./logging");
20
- /**
21
- * Repeats a given function until it is stopped
22
- */
23
- class Repeater {
24
- constructor(fn, timeout) {
25
- this.fn = fn;
26
- this.timeout = timeout;
27
- }
28
- start() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- this.run();
31
- });
32
- }
33
- run() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- this.shouldRun = true;
36
- this.finished = new deferred_1.Deferred();
37
- while (this.shouldRun) {
38
- try {
39
- yield this.fn();
40
- }
41
- catch (err) {
42
- logging_1.log.error(err);
43
- }
44
- yield this.sleep(this.timeout);
45
- }
46
- this.finished.resolve();
47
- });
48
- }
49
- sleep(timeout) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- return new Promise(resolve => this.timer = setTimeout(resolve, timeout));
52
- });
53
- }
54
- stop() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- this.shouldRun = false;
57
- if (this.timer) {
58
- clearTimeout(this.timer);
59
- }
60
- return this.finished.promise;
61
- });
62
- }
63
- }
64
- exports.Repeater = Repeater;
65
- //# sourceMappingURL=repeater.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repeater.js","sourceRoot":"","sources":["../../src/util/repeater.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,yCAAsC;AACtC,uCAAgC;AAEhC;;GAEG;AACH,MAAa,QAAQ;IAKjB,YAA+B,EAA8B,EAAqB,OAAe;QAAlE,OAAE,GAAF,EAAE,CAA4B;QAAqB,YAAO,GAAP,OAAO,CAAQ;IAAI,CAAC;IAEhG,KAAK;;YACP,IAAI,CAAC,GAAG,EAAE,CAAC;QACf,CAAC;KAAA;IAEK,GAAG;;YACL,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAQ,EAAQ,CAAC;YACrC,OAAO,IAAI,CAAC,SAAS,EAAE;gBACnB,IAAI;oBACA,MAAM,IAAI,CAAC,EAAE,EAAE,CAAC;iBACnB;gBAAC,OAAO,GAAG,EAAE;oBACV,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBAClB;gBACD,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAClC;YACD,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC5B,CAAC;KAAA;IAEe,KAAK,CAAC,OAAe;;YACjC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QAC7E,CAAC;KAAA;IAEK,IAAI;;YACN,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;YACvB,IAAI,IAAI,CAAC,KAAK,EAAE;gBACZ,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC5B;YACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACjC,CAAC;KAAA;CACJ;AApCD,4BAoCC"}
@@ -1,11 +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 { LogContext } from './logging';
7
- export declare class SafePromise {
8
- static catchAndLog<T>(p: Promise<T>, logCtx?: LogContext): Promise<T>;
9
- static catch<T>(p: Promise<T>, handler: (err: any) => void): Promise<T>;
10
- }
11
- //# sourceMappingURL=safe-promise.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"safe-promise.d.ts","sourceRoot":"","sources":["../../src/util/safe-promise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAO,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,qBAAa,WAAW;WACN,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,UAAU;WASjD,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC;CAMjF"}
@@ -1,31 +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.SafePromise = void 0;
9
- const logging_1 = require("./logging");
10
- class SafePromise {
11
- static catchAndLog(p, logCtx) {
12
- return SafePromise.catch(p, (err) => {
13
- if (logCtx) {
14
- logging_1.log.error(logCtx, err);
15
- }
16
- else {
17
- logging_1.log.error(err);
18
- }
19
- });
20
- }
21
- ;
22
- static catch(p, handler) {
23
- return p.catch((err) => {
24
- handler(err);
25
- return {}; // Nobody will ever see this value as the Promise already failed. It's just there to please the compiler
26
- });
27
- }
28
- ;
29
- }
30
- exports.SafePromise = SafePromise;
31
- //# sourceMappingURL=safe-promise.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"safe-promise.js","sourceRoot":"","sources":["../../src/util/safe-promise.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,uCAA4C;AAE5C,MAAa,WAAW;IACb,MAAM,CAAC,WAAW,CAAI,CAAa,EAAE,MAAmB;QAC3D,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE;YAChC,IAAI,MAAM,EAAE;gBACR,aAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;aAC1B;iBAAM;gBACH,aAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aAClB;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAAA,CAAC;IACK,MAAM,CAAC,KAAK,CAAI,CAAa,EAAE,OAA2B;QAC7D,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,OAAO,CAAC,GAAG,CAAC,CAAC;YACb,OAAO,EAAO,CAAC,CAAC,wGAAwG;QAC5H,CAAC,CAAC,CAAC;IACP,CAAC;IAAA,CAAC;CACL;AAhBD,kCAgBC"}
@@ -1,62 +0,0 @@
1
- /*
2
- * Copyright (C) 2017 TypeFox and others.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- */
7
-
8
- import { Message } from "vscode-jsonrpc";
9
- import { log } from '../util/logging';
10
-
11
- export interface ResolvedConnectionErrorHandlerOptions {
12
- readonly serverName: string
13
- /**
14
- * The maximum amount of errors allowed before stopping the server.
15
- */
16
- readonly maxErrors: number
17
- /**
18
- * The maimum amount of restarts allowed in the restart interval.
19
- */
20
- readonly maxRestarts: number
21
- /**
22
- * In minutes.
23
- */
24
- readonly restartInterval: number
25
- }
26
-
27
- export type ConnectionErrorHandlerOptions = Partial<ResolvedConnectionErrorHandlerOptions> & {
28
- readonly serverName: string
29
- };
30
-
31
- export class ConnectionErrorHandler {
32
-
33
- protected readonly options: ResolvedConnectionErrorHandlerOptions;
34
- constructor(options: ConnectionErrorHandlerOptions) {
35
- this.options = {
36
- maxErrors: 3,
37
- maxRestarts: 5,
38
- restartInterval: 3,
39
- ...options
40
- };
41
- }
42
-
43
- shouldStop(error: Error, message?: Message, count?: number): boolean {
44
- return !count || count > this.options.maxErrors;
45
- }
46
-
47
- protected readonly restarts: number[] = [];
48
- shouldRestart(): boolean {
49
- this.restarts.push(Date.now());
50
- if (this.restarts.length <= this.options.maxRestarts) {
51
- return true;
52
- }
53
- const diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
54
- if (diff <= this.options.restartInterval * 60 * 1000) {
55
- log.error(`Server ${this.options.serverName} crashed ${this.options.maxRestarts} times in the last ${this.options.restartInterval} minutes. Will not restart`);
56
- return false;
57
- }
58
- this.restarts.shift();
59
- return true;
60
- }
61
-
62
- }