@gitpod/gitpod-protocol 0.1.5-me-ingress.14 → 0.1.5-me-image.3
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.
- package/data/gitpod-schema.json +12 -0
- package/lib/admin-protocol.d.ts +10 -0
- package/lib/admin-protocol.d.ts.map +1 -1
- package/lib/admin-protocol.js.map +1 -1
- package/lib/analytics.d.ts +4 -5
- package/lib/analytics.d.ts.map +1 -1
- package/lib/context-url.d.ts +18 -5
- package/lib/context-url.d.ts.map +1 -1
- package/lib/context-url.js +58 -5
- package/lib/context-url.js.map +1 -1
- package/lib/context-url.spec.d.ts +2 -0
- package/lib/context-url.spec.d.ts.map +1 -1
- package/lib/context-url.spec.js +25 -4
- package/lib/context-url.spec.js.map +1 -1
- package/lib/gitpod-service.d.ts +23 -2
- package/lib/gitpod-service.d.ts.map +1 -1
- package/lib/gitpod-service.js +4 -2
- package/lib/gitpod-service.js.map +1 -1
- package/lib/ide-protocol.d.ts +24 -0
- package/lib/ide-protocol.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/installation-admin-protocol.d.ts +27 -0
- package/lib/installation-admin-protocol.d.ts.map +1 -0
- package/lib/installation-admin-protocol.js +30 -0
- package/lib/installation-admin-protocol.js.map +1 -0
- package/lib/messaging/error.d.ts +1 -0
- package/lib/messaging/error.d.ts.map +1 -1
- package/lib/messaging/error.js +2 -0
- package/lib/messaging/error.js.map +1 -1
- package/lib/messaging/node/connection.d.ts +1 -7
- package/lib/messaging/node/connection.d.ts.map +1 -1
- package/lib/messaging/node/connection.js +20 -18
- package/lib/messaging/node/connection.js.map +1 -1
- package/lib/permission.d.ts +7 -1
- package/lib/permission.d.ts.map +1 -1
- package/lib/permission.js +24 -4
- package/lib/permission.js.map +1 -1
- package/lib/protocol.d.ts +22 -39
- package/lib/protocol.d.ts.map +1 -1
- package/lib/protocol.js +16 -4
- package/lib/protocol.js.map +1 -1
- package/lib/teams-projects-protocol.d.ts +3 -0
- package/lib/teams-projects-protocol.d.ts.map +1 -1
- package/lib/teams-projects-protocol.js +7 -0
- package/lib/teams-projects-protocol.js.map +1 -1
- package/lib/util/generate-workspace-id.d.ts.map +1 -1
- package/lib/util/generate-workspace-id.js +1 -0
- package/lib/util/generate-workspace-id.js.map +1 -1
- package/lib/util/generate-workspace-id.spec.js +1 -0
- package/lib/util/generate-workspace-id.spec.js.map +1 -1
- package/lib/util/gitpod-host-url.d.ts +0 -1
- package/lib/util/gitpod-host-url.d.ts.map +1 -1
- package/lib/util/gitpod-host-url.js +0 -3
- package/lib/util/gitpod-host-url.js.map +1 -1
- package/lib/util/tracing.d.ts +2 -1
- package/lib/util/tracing.d.ts.map +1 -1
- package/lib/util/tracing.js +29 -6
- package/lib/util/tracing.js.map +1 -1
- package/lib/workspace-cluster.d.ts +9 -7
- package/lib/workspace-cluster.d.ts.map +1 -1
- package/lib/workspace-cluster.js +18 -1
- package/lib/workspace-cluster.js.map +1 -1
- package/lib/workspace-instance.d.ts +19 -0
- package/lib/workspace-instance.d.ts.map +1 -1
- package/package.json +2 -2
- package/pkg-yarn.lock +2 -2
- package/provenance-bundle.jsonl +1 -1
- package/src/admin-protocol.ts +17 -4
- package/src/analytics.ts +4 -6
- package/src/context-url.spec.ts +18 -4
- package/src/context-url.ts +62 -6
- package/src/gitpod-service.ts +33 -6
- package/src/ide-frontend-service.ts +1 -1
- package/src/ide-protocol.ts +27 -0
- package/src/index.ts +1 -0
- package/src/installation-admin-protocol.ts +42 -0
- package/src/messaging/error.ts +3 -0
- package/src/messaging/node/connection.ts +20 -23
- package/src/permission.ts +22 -3
- package/src/protocol.ts +37 -43
- package/src/teams-projects-protocol.ts +7 -1
- package/src/util/generate-workspace-id.spec.ts +1 -0
- package/src/util/generate-workspace-id.ts +1 -0
- package/src/util/gitpod-host-url.ts +1 -5
- package/src/util/tracing.ts +29 -7
- package/src/workspace-cluster.ts +17 -9
- package/src/workspace-instance.ts +20 -0
- package/lib/messaging/connection-error-handler.d.ts +0 -27
- package/lib/messaging/connection-error-handler.d.ts.map +0 -1
- package/lib/messaging/connection-error-handler.js +0 -34
- package/lib/messaging/connection-error-handler.js.map +0 -1
- package/lib/util/safe-promise.d.ts +0 -11
- package/lib/util/safe-promise.d.ts.map +0 -1
- package/lib/util/safe-promise.js +0 -31
- package/lib/util/safe-promise.js.map +0 -1
- package/src/messaging/connection-error-handler.ts +0 -62
- package/src/util/safe-promise.ts +0 -26
package/src/util/tracing.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import * as opentracing from 'opentracing';
|
|
9
9
|
import { TracingConfig, initTracerFromEnv } from 'jaeger-client';
|
|
10
10
|
import { Sampler, SamplingDecision } from './jaeger-client-types';
|
|
11
|
-
import {
|
|
11
|
+
import { initGlobalTracer } from 'opentracing';
|
|
12
12
|
import { injectable } from 'inversify';
|
|
13
13
|
import { ResponseError } from 'vscode-jsonrpc';
|
|
14
14
|
import { log, LogContext } from './logging';
|
|
@@ -22,15 +22,19 @@ export type TraceContextWithSpan = TraceContext & {
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
export namespace TraceContext {
|
|
25
|
-
export function startSpan(operation: string, parentCtx?: TraceContext
|
|
25
|
+
export function startSpan(operation: string, parentCtx?: TraceContext): opentracing.Span {
|
|
26
26
|
const options: opentracing.SpanOptions = {};
|
|
27
|
-
if (parentCtx) {
|
|
27
|
+
if (parentCtx && parentCtx.span && !!parentCtx.span.context().toSpanId()) {
|
|
28
28
|
options.childOf = parentCtx.span;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
// }
|
|
34
38
|
|
|
35
39
|
return opentracing.globalTracer().startSpan(operation, options);
|
|
36
40
|
}
|
|
@@ -40,6 +44,24 @@ export namespace TraceContext {
|
|
|
40
44
|
return { span };
|
|
41
45
|
}
|
|
42
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();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
43
65
|
export function setError(ctx: TraceContext, err: Error) {
|
|
44
66
|
if (!ctx.span) {
|
|
45
67
|
return;
|
package/src/workspace-cluster.ts
CHANGED
|
@@ -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 |
|
|
55
|
+
export type AdmissionConstraint = AdmissionConstraintFeaturePreview | AdmissionConstraintHasPermission | AdmissionConstraintHasUserLevel | AdmissionConstraintHasMoreResources;
|
|
59
56
|
export type AdmissionConstraintFeaturePreview = { type: "has-feature-preview" };
|
|
60
|
-
export type
|
|
57
|
+
export type AdmissionConstraintHasPermission = { type: "has-permission", permission: PermissionName };
|
|
61
58
|
export type AdmissionConstraintHasUserLevel = { type: "has-user-level", level: string };
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
export
|
|
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,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"}
|
package/lib/util/safe-promise.js
DELETED
|
@@ -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
|
-
}
|
package/src/util/safe-promise.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
|
|
3
|
-
* Licensed under the GNU Affero General Public License (AGPL).
|
|
4
|
-
* See License-AGPL.txt in the project root for license information.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { log, LogContext } from './logging';
|
|
9
|
-
|
|
10
|
-
export class SafePromise {
|
|
11
|
-
public static catchAndLog<T>(p: Promise<T>, logCtx?: LogContext) {
|
|
12
|
-
return SafePromise.catch(p, (err) => {
|
|
13
|
-
if (logCtx) {
|
|
14
|
-
log.error(logCtx, err);
|
|
15
|
-
} else {
|
|
16
|
-
log.error(err);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
public static catch<T>(p: Promise<T>, handler: (err: any) => void): Promise<T> {
|
|
21
|
-
return p.catch((err) => {
|
|
22
|
-
handler(err);
|
|
23
|
-
return {} as T; // Nobody will ever see this value as the Promise already failed. It's just there to please the compiler
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
}
|