@theia/plugin-metrics 1.34.2 → 1.34.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/LICENSE +641 -641
- package/README.md +63 -63
- package/lib/browser/plugin-metrics-creator.d.ts +67 -67
- package/lib/browser/plugin-metrics-creator.js +185 -185
- package/lib/browser/plugin-metrics-frontend-module.d.ts +3 -3
- package/lib/browser/plugin-metrics-frontend-module.js +36 -36
- package/lib/browser/plugin-metrics-languages-main.d.ts +58 -58
- package/lib/browser/plugin-metrics-languages-main.js +211 -211
- package/lib/browser/plugin-metrics-output-registry.d.ts +7 -7
- package/lib/browser/plugin-metrics-output-registry.js +48 -48
- package/lib/browser/plugin-metrics-resolver.d.ts +17 -17
- package/lib/browser/plugin-metrics-resolver.js +69 -69
- package/lib/common/metrics-protocol.d.ts +10 -10
- package/lib/common/metrics-protocol.js +24 -24
- package/lib/common/plugin-metrics-types.d.ts +27 -27
- package/lib/common/plugin-metrics-types.js +56 -56
- package/lib/node/metric-output/plugin-metrics-time-count.d.ts +5 -5
- package/lib/node/metric-output/plugin-metrics-time-count.js +43 -43
- package/lib/node/metric-output/plugin-metrics-time-sum.d.ts +5 -5
- package/lib/node/metric-output/plugin-metrics-time-sum.js +41 -41
- package/lib/node/metric-string-generator.d.ts +6 -6
- package/lib/node/metric-string-generator.js +78 -78
- package/lib/node/metrics-contributor.d.ts +6 -6
- package/lib/node/metrics-contributor.js +76 -76
- package/lib/node/metrics-contributor.spec.d.ts +1 -1
- package/lib/node/metrics-contributor.spec.js +203 -203
- package/lib/node/plugin-metrics-backend-module.d.ts +3 -3
- package/lib/node/plugin-metrics-backend-module.js +47 -47
- package/lib/node/plugin-metrics-impl.d.ts +10 -10
- package/lib/node/plugin-metrics-impl.js +45 -45
- package/lib/node/plugin-metrics.d.ts +10 -10
- package/lib/node/plugin-metrics.js +54 -54
- package/package.json +7 -7
- package/src/browser/plugin-metrics-creator.ts +189 -189
- package/src/browser/plugin-metrics-frontend-module.ts +38 -38
- package/src/browser/plugin-metrics-languages-main.ts +325 -325
- package/src/browser/plugin-metrics-output-registry.ts +37 -37
- package/src/browser/plugin-metrics-resolver.ts +57 -57
- package/src/common/metrics-protocol.ts +27 -27
- package/src/common/plugin-metrics-types.ts +80 -80
- package/src/node/metric-output/plugin-metrics-time-count.ts +36 -36
- package/src/node/metric-output/plugin-metrics-time-sum.ts +35 -35
- package/src/node/metric-string-generator.ts +70 -70
- package/src/node/metrics-contributor.spec.ts +234 -234
- package/src/node/metrics-contributor.ts +70 -70
- package/src/node/plugin-metrics-backend-module.ts +49 -49
- package/src/node/plugin-metrics-impl.ts +38 -38
- package/src/node/plugin-metrics.ts +44 -44
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MetricsContribution } from '@theia/metrics/lib/node/metrics-contribution';
|
|
2
|
-
import { PluginMetricsContributor } from './metrics-contributor';
|
|
3
|
-
import { PluginMetricStringGenerator } from './metric-string-generator';
|
|
4
|
-
export declare class PluginMetricsContribution implements MetricsContribution {
|
|
5
|
-
protected readonly metricsContributor: PluginMetricsContributor;
|
|
6
|
-
protected readonly stringGenerator: PluginMetricStringGenerator;
|
|
7
|
-
private metrics;
|
|
8
|
-
getMetrics(): string;
|
|
9
|
-
startCollecting(): void;
|
|
10
|
-
}
|
|
1
|
+
import { MetricsContribution } from '@theia/metrics/lib/node/metrics-contribution';
|
|
2
|
+
import { PluginMetricsContributor } from './metrics-contributor';
|
|
3
|
+
import { PluginMetricStringGenerator } from './metric-string-generator';
|
|
4
|
+
export declare class PluginMetricsContribution implements MetricsContribution {
|
|
5
|
+
protected readonly metricsContributor: PluginMetricsContributor;
|
|
6
|
+
protected readonly stringGenerator: PluginMetricStringGenerator;
|
|
7
|
+
private metrics;
|
|
8
|
+
getMetrics(): string;
|
|
9
|
+
startCollecting(): void;
|
|
10
|
+
}
|
|
11
11
|
//# sourceMappingURL=plugin-metrics.d.ts.map
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.PluginMetricsContribution = void 0;
|
|
28
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
-
const metrics_protocol_1 = require("../common/metrics-protocol");
|
|
30
|
-
const metrics_contributor_1 = require("./metrics-contributor");
|
|
31
|
-
const metric_string_generator_1 = require("./metric-string-generator");
|
|
32
|
-
let PluginMetricsContribution = class PluginMetricsContribution {
|
|
33
|
-
getMetrics() {
|
|
34
|
-
return this.metrics;
|
|
35
|
-
}
|
|
36
|
-
startCollecting() {
|
|
37
|
-
setInterval(() => {
|
|
38
|
-
const reconciledMetrics = this.metricsContributor.reconcile();
|
|
39
|
-
this.metrics = this.stringGenerator.getMetricsString(reconciledMetrics);
|
|
40
|
-
}, metrics_protocol_1.METRICS_TIMEOUT);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
__decorate([
|
|
44
|
-
(0, inversify_1.inject)(metrics_contributor_1.PluginMetricsContributor),
|
|
45
|
-
__metadata("design:type", metrics_contributor_1.PluginMetricsContributor)
|
|
46
|
-
], PluginMetricsContribution.prototype, "metricsContributor", void 0);
|
|
47
|
-
__decorate([
|
|
48
|
-
(0, inversify_1.inject)(metric_string_generator_1.PluginMetricStringGenerator),
|
|
49
|
-
__metadata("design:type", metric_string_generator_1.PluginMetricStringGenerator)
|
|
50
|
-
], PluginMetricsContribution.prototype, "stringGenerator", void 0);
|
|
51
|
-
PluginMetricsContribution = __decorate([
|
|
52
|
-
(0, inversify_1.injectable)()
|
|
53
|
-
], PluginMetricsContribution);
|
|
54
|
-
exports.PluginMetricsContribution = PluginMetricsContribution;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.PluginMetricsContribution = void 0;
|
|
28
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
29
|
+
const metrics_protocol_1 = require("../common/metrics-protocol");
|
|
30
|
+
const metrics_contributor_1 = require("./metrics-contributor");
|
|
31
|
+
const metric_string_generator_1 = require("./metric-string-generator");
|
|
32
|
+
let PluginMetricsContribution = class PluginMetricsContribution {
|
|
33
|
+
getMetrics() {
|
|
34
|
+
return this.metrics;
|
|
35
|
+
}
|
|
36
|
+
startCollecting() {
|
|
37
|
+
setInterval(() => {
|
|
38
|
+
const reconciledMetrics = this.metricsContributor.reconcile();
|
|
39
|
+
this.metrics = this.stringGenerator.getMetricsString(reconciledMetrics);
|
|
40
|
+
}, metrics_protocol_1.METRICS_TIMEOUT);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, inversify_1.inject)(metrics_contributor_1.PluginMetricsContributor),
|
|
45
|
+
__metadata("design:type", metrics_contributor_1.PluginMetricsContributor)
|
|
46
|
+
], PluginMetricsContribution.prototype, "metricsContributor", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, inversify_1.inject)(metric_string_generator_1.PluginMetricStringGenerator),
|
|
49
|
+
__metadata("design:type", metric_string_generator_1.PluginMetricStringGenerator)
|
|
50
|
+
], PluginMetricsContribution.prototype, "stringGenerator", void 0);
|
|
51
|
+
PluginMetricsContribution = __decorate([
|
|
52
|
+
(0, inversify_1.injectable)()
|
|
53
|
+
], PluginMetricsContribution);
|
|
54
|
+
exports.PluginMetricsContribution = PluginMetricsContribution;
|
|
55
55
|
//# sourceMappingURL=plugin-metrics.js.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/plugin-metrics",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.3",
|
|
4
4
|
"description": "Theia - Plugin Metrics",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/core": "1.34.
|
|
7
|
-
"@theia/metrics": "1.34.
|
|
6
|
+
"@theia/core": "1.34.3",
|
|
7
|
+
"@theia/metrics": "1.34.3",
|
|
8
8
|
"@theia/monaco-editor-core": "1.72.3",
|
|
9
|
-
"@theia/plugin": "1.34.
|
|
10
|
-
"@theia/plugin-ext": "1.34.
|
|
9
|
+
"@theia/plugin": "1.34.3",
|
|
10
|
+
"@theia/plugin-ext": "1.34.3"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"watch": "theiaext watch"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@theia/ext-scripts": "1.34.
|
|
46
|
+
"@theia/ext-scripts": "1.34.3"
|
|
47
47
|
},
|
|
48
48
|
"nyc": {
|
|
49
49
|
"extends": "../../configs/nyc.json"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "a6cf9fe96b1624d6e27a11dce2ebdeae820478e5"
|
|
52
52
|
}
|
|
@@ -1,189 +1,189 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
-
import { PluginMetrics, METRICS_TIMEOUT } from '../common/metrics-protocol';
|
|
19
|
-
import { AnalyticsFromRequests, DataFromRequest, createRequestData, createDefaultAnalytics, MetricsMap } from '../common/plugin-metrics-types';
|
|
20
|
-
|
|
21
|
-
@injectable()
|
|
22
|
-
export class PluginMetricsCreator {
|
|
23
|
-
|
|
24
|
-
@inject(PluginMetrics)
|
|
25
|
-
private pluginMetrics: PluginMetrics;
|
|
26
|
-
|
|
27
|
-
private _extensionIDAnalytics: MetricsMap;
|
|
28
|
-
|
|
29
|
-
private NODE_BASED_REGEX = /Request(.*?)failed/;
|
|
30
|
-
|
|
31
|
-
constructor() {
|
|
32
|
-
this.setPluginMetrics();
|
|
33
|
-
this._extensionIDAnalytics = {};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Create an error metric for requestData.pluginID by attempting to extract the erroring
|
|
38
|
-
* language server method from the requestData.errorContentsOrMethod. If it cannot extract the
|
|
39
|
-
* error language server method from requestData.errorContentsOrMethod then it will not
|
|
40
|
-
* create a metric.
|
|
41
|
-
*
|
|
42
|
-
* @param pluginID The id of the plugin
|
|
43
|
-
* @param errorContents The contents that the language server error has produced
|
|
44
|
-
*/
|
|
45
|
-
async createErrorMetric(requestData: DataFromRequest): Promise<void> {
|
|
46
|
-
if (!requestData.pluginID) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const method = this.extractMethodFromValue(requestData.errorContentsOrMethod);
|
|
51
|
-
|
|
52
|
-
// only log the metric if we can find the method that it occurred in
|
|
53
|
-
if (method) {
|
|
54
|
-
const createdMetric = createRequestData(requestData.pluginID, method, requestData.timeTaken);
|
|
55
|
-
this.createMetric(createdMetric, false);
|
|
56
|
-
|
|
57
|
-
this.decreaseExtensionRequests(requestData.pluginID, method);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Decreases the total requests and the successful responses for pluginID with method by 1.
|
|
63
|
-
*
|
|
64
|
-
* This is needed because an error and a successful language server request aren't currently
|
|
65
|
-
* associated together because of https://github.com/microsoft/vscode-languageserver-node/issues/517.
|
|
66
|
-
* That means that every language server request that resolves counts as a successful language server request.
|
|
67
|
-
* Therefore, we need to decrease the extension requests for pluginID when we know there is an error.
|
|
68
|
-
* Otherwise, for every language server request that errors we would count it as both a success and a failure.
|
|
69
|
-
*
|
|
70
|
-
* @param pluginID The id of the plugin that should have the decreased requests
|
|
71
|
-
*/
|
|
72
|
-
private decreaseExtensionRequests(pluginID: string, method: string): void {
|
|
73
|
-
const thisExtension = this._extensionIDAnalytics[pluginID];
|
|
74
|
-
if (thisExtension) {
|
|
75
|
-
const currentAnalytics = thisExtension[method];
|
|
76
|
-
if (currentAnalytics) {
|
|
77
|
-
currentAnalytics.totalRequests -= 1;
|
|
78
|
-
currentAnalytics.successfulResponses -= 1;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Update the internal metrics structure for pluginID with method when a request is made
|
|
85
|
-
*
|
|
86
|
-
* @param requestData The data from the request that was made
|
|
87
|
-
* @param isRequestSuccessful If the language server request was successful or not
|
|
88
|
-
*/
|
|
89
|
-
async createMetric(requestData: DataFromRequest, isRequestSuccessful: boolean): Promise<void> {
|
|
90
|
-
if (!requestData.pluginID) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// When we are in this function we know its a method so we can make it clearer
|
|
95
|
-
const method = requestData.errorContentsOrMethod;
|
|
96
|
-
const defaultAnalytic = createDefaultAnalytics(requestData.timeTaken, isRequestSuccessful);
|
|
97
|
-
|
|
98
|
-
this.createExtensionIDAnalyticIfNotFound(requestData, defaultAnalytic);
|
|
99
|
-
this.createExtensionIDMethodIfNotFound(requestData, defaultAnalytic);
|
|
100
|
-
|
|
101
|
-
const thisExtension = this._extensionIDAnalytics[requestData.pluginID];
|
|
102
|
-
if (thisExtension) {
|
|
103
|
-
const currentAnalytic = thisExtension[method];
|
|
104
|
-
if (currentAnalytic) {
|
|
105
|
-
currentAnalytic.totalRequests += 1;
|
|
106
|
-
if (isRequestSuccessful) {
|
|
107
|
-
currentAnalytic.successfulResponses += 1;
|
|
108
|
-
}
|
|
109
|
-
if (isRequestSuccessful) {
|
|
110
|
-
currentAnalytic.sumOfTimeForSuccess = currentAnalytic.sumOfTimeForSuccess + requestData.timeTaken;
|
|
111
|
-
} else {
|
|
112
|
-
currentAnalytic.sumOfTimeForFailure = currentAnalytic.sumOfTimeForFailure + requestData.timeTaken;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Create an entry in _extensionIDAnalytics with createdAnalytic if there does not exist one
|
|
120
|
-
*
|
|
121
|
-
* @param requestData data that we will turn into metrics
|
|
122
|
-
* @param createdAnalytic the analytic being created
|
|
123
|
-
*/
|
|
124
|
-
private createExtensionIDAnalyticIfNotFound(requestData: DataFromRequest, createdAnalytic: AnalyticsFromRequests): void {
|
|
125
|
-
const method = requestData.errorContentsOrMethod; // We know its a metric if this is being called
|
|
126
|
-
|
|
127
|
-
if (!this._extensionIDAnalytics[requestData.pluginID]) {
|
|
128
|
-
this._extensionIDAnalytics[requestData.pluginID] = {
|
|
129
|
-
[method]: createdAnalytic
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Create an entry in _extensionIDAnalytics for requestData.pluginID with requestData.errorContentsOrMethod as the method
|
|
136
|
-
* if there does not exist one
|
|
137
|
-
*
|
|
138
|
-
* @param requestData data that we will turn into metrics
|
|
139
|
-
* @param createdAnalytic the analytic being created
|
|
140
|
-
*/
|
|
141
|
-
private createExtensionIDMethodIfNotFound(requestData: DataFromRequest, createdAnalytic: AnalyticsFromRequests): void {
|
|
142
|
-
const method = requestData.errorContentsOrMethod; // We know its a metric if this is being called
|
|
143
|
-
|
|
144
|
-
if (this._extensionIDAnalytics[requestData.pluginID]) {
|
|
145
|
-
const methodToAnalyticMap = this._extensionIDAnalytics[requestData.pluginID];
|
|
146
|
-
if (!methodToAnalyticMap[method]) {
|
|
147
|
-
methodToAnalyticMap[method] = createdAnalytic;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* setPluginMetrics is a constant running function that sets
|
|
154
|
-
* pluginMetrics every {$METRICS_TIMEOUT} seconds so that it doesn't
|
|
155
|
-
* update /metrics on every request
|
|
156
|
-
*/
|
|
157
|
-
private setPluginMetrics(): void {
|
|
158
|
-
const self = this;
|
|
159
|
-
setInterval(() => {
|
|
160
|
-
if (Object.keys(self._extensionIDAnalytics).length !== 0) {
|
|
161
|
-
self.pluginMetrics.setMetrics(JSON.stringify(self._extensionIDAnalytics));
|
|
162
|
-
}
|
|
163
|
-
}, METRICS_TIMEOUT);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// Map of plugin extension id to method to analytic
|
|
167
|
-
get extensionIDAnalytics(): MetricsMap {
|
|
168
|
-
return this._extensionIDAnalytics;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Attempts to extract the method name from the current errorContents using the
|
|
173
|
-
* vscode-languageclient matching regex.
|
|
174
|
-
*
|
|
175
|
-
* If it cannot find a match in the errorContents it returns undefined
|
|
176
|
-
*
|
|
177
|
-
* @param errorContents The contents of the current error or undefined
|
|
178
|
-
*/
|
|
179
|
-
private extractMethodFromValue(errorContents: string | undefined): string | undefined {
|
|
180
|
-
if (!errorContents) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
const matches = errorContents.match(this.NODE_BASED_REGEX);
|
|
184
|
-
if (matches) {
|
|
185
|
-
return matches[1].trim();
|
|
186
|
-
}
|
|
187
|
-
return undefined;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2019 Red Hat, Inc. and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
18
|
+
import { PluginMetrics, METRICS_TIMEOUT } from '../common/metrics-protocol';
|
|
19
|
+
import { AnalyticsFromRequests, DataFromRequest, createRequestData, createDefaultAnalytics, MetricsMap } from '../common/plugin-metrics-types';
|
|
20
|
+
|
|
21
|
+
@injectable()
|
|
22
|
+
export class PluginMetricsCreator {
|
|
23
|
+
|
|
24
|
+
@inject(PluginMetrics)
|
|
25
|
+
private pluginMetrics: PluginMetrics;
|
|
26
|
+
|
|
27
|
+
private _extensionIDAnalytics: MetricsMap;
|
|
28
|
+
|
|
29
|
+
private NODE_BASED_REGEX = /Request(.*?)failed/;
|
|
30
|
+
|
|
31
|
+
constructor() {
|
|
32
|
+
this.setPluginMetrics();
|
|
33
|
+
this._extensionIDAnalytics = {};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create an error metric for requestData.pluginID by attempting to extract the erroring
|
|
38
|
+
* language server method from the requestData.errorContentsOrMethod. If it cannot extract the
|
|
39
|
+
* error language server method from requestData.errorContentsOrMethod then it will not
|
|
40
|
+
* create a metric.
|
|
41
|
+
*
|
|
42
|
+
* @param pluginID The id of the plugin
|
|
43
|
+
* @param errorContents The contents that the language server error has produced
|
|
44
|
+
*/
|
|
45
|
+
async createErrorMetric(requestData: DataFromRequest): Promise<void> {
|
|
46
|
+
if (!requestData.pluginID) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const method = this.extractMethodFromValue(requestData.errorContentsOrMethod);
|
|
51
|
+
|
|
52
|
+
// only log the metric if we can find the method that it occurred in
|
|
53
|
+
if (method) {
|
|
54
|
+
const createdMetric = createRequestData(requestData.pluginID, method, requestData.timeTaken);
|
|
55
|
+
this.createMetric(createdMetric, false);
|
|
56
|
+
|
|
57
|
+
this.decreaseExtensionRequests(requestData.pluginID, method);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Decreases the total requests and the successful responses for pluginID with method by 1.
|
|
63
|
+
*
|
|
64
|
+
* This is needed because an error and a successful language server request aren't currently
|
|
65
|
+
* associated together because of https://github.com/microsoft/vscode-languageserver-node/issues/517.
|
|
66
|
+
* That means that every language server request that resolves counts as a successful language server request.
|
|
67
|
+
* Therefore, we need to decrease the extension requests for pluginID when we know there is an error.
|
|
68
|
+
* Otherwise, for every language server request that errors we would count it as both a success and a failure.
|
|
69
|
+
*
|
|
70
|
+
* @param pluginID The id of the plugin that should have the decreased requests
|
|
71
|
+
*/
|
|
72
|
+
private decreaseExtensionRequests(pluginID: string, method: string): void {
|
|
73
|
+
const thisExtension = this._extensionIDAnalytics[pluginID];
|
|
74
|
+
if (thisExtension) {
|
|
75
|
+
const currentAnalytics = thisExtension[method];
|
|
76
|
+
if (currentAnalytics) {
|
|
77
|
+
currentAnalytics.totalRequests -= 1;
|
|
78
|
+
currentAnalytics.successfulResponses -= 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Update the internal metrics structure for pluginID with method when a request is made
|
|
85
|
+
*
|
|
86
|
+
* @param requestData The data from the request that was made
|
|
87
|
+
* @param isRequestSuccessful If the language server request was successful or not
|
|
88
|
+
*/
|
|
89
|
+
async createMetric(requestData: DataFromRequest, isRequestSuccessful: boolean): Promise<void> {
|
|
90
|
+
if (!requestData.pluginID) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// When we are in this function we know its a method so we can make it clearer
|
|
95
|
+
const method = requestData.errorContentsOrMethod;
|
|
96
|
+
const defaultAnalytic = createDefaultAnalytics(requestData.timeTaken, isRequestSuccessful);
|
|
97
|
+
|
|
98
|
+
this.createExtensionIDAnalyticIfNotFound(requestData, defaultAnalytic);
|
|
99
|
+
this.createExtensionIDMethodIfNotFound(requestData, defaultAnalytic);
|
|
100
|
+
|
|
101
|
+
const thisExtension = this._extensionIDAnalytics[requestData.pluginID];
|
|
102
|
+
if (thisExtension) {
|
|
103
|
+
const currentAnalytic = thisExtension[method];
|
|
104
|
+
if (currentAnalytic) {
|
|
105
|
+
currentAnalytic.totalRequests += 1;
|
|
106
|
+
if (isRequestSuccessful) {
|
|
107
|
+
currentAnalytic.successfulResponses += 1;
|
|
108
|
+
}
|
|
109
|
+
if (isRequestSuccessful) {
|
|
110
|
+
currentAnalytic.sumOfTimeForSuccess = currentAnalytic.sumOfTimeForSuccess + requestData.timeTaken;
|
|
111
|
+
} else {
|
|
112
|
+
currentAnalytic.sumOfTimeForFailure = currentAnalytic.sumOfTimeForFailure + requestData.timeTaken;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Create an entry in _extensionIDAnalytics with createdAnalytic if there does not exist one
|
|
120
|
+
*
|
|
121
|
+
* @param requestData data that we will turn into metrics
|
|
122
|
+
* @param createdAnalytic the analytic being created
|
|
123
|
+
*/
|
|
124
|
+
private createExtensionIDAnalyticIfNotFound(requestData: DataFromRequest, createdAnalytic: AnalyticsFromRequests): void {
|
|
125
|
+
const method = requestData.errorContentsOrMethod; // We know its a metric if this is being called
|
|
126
|
+
|
|
127
|
+
if (!this._extensionIDAnalytics[requestData.pluginID]) {
|
|
128
|
+
this._extensionIDAnalytics[requestData.pluginID] = {
|
|
129
|
+
[method]: createdAnalytic
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Create an entry in _extensionIDAnalytics for requestData.pluginID with requestData.errorContentsOrMethod as the method
|
|
136
|
+
* if there does not exist one
|
|
137
|
+
*
|
|
138
|
+
* @param requestData data that we will turn into metrics
|
|
139
|
+
* @param createdAnalytic the analytic being created
|
|
140
|
+
*/
|
|
141
|
+
private createExtensionIDMethodIfNotFound(requestData: DataFromRequest, createdAnalytic: AnalyticsFromRequests): void {
|
|
142
|
+
const method = requestData.errorContentsOrMethod; // We know its a metric if this is being called
|
|
143
|
+
|
|
144
|
+
if (this._extensionIDAnalytics[requestData.pluginID]) {
|
|
145
|
+
const methodToAnalyticMap = this._extensionIDAnalytics[requestData.pluginID];
|
|
146
|
+
if (!methodToAnalyticMap[method]) {
|
|
147
|
+
methodToAnalyticMap[method] = createdAnalytic;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* setPluginMetrics is a constant running function that sets
|
|
154
|
+
* pluginMetrics every {$METRICS_TIMEOUT} seconds so that it doesn't
|
|
155
|
+
* update /metrics on every request
|
|
156
|
+
*/
|
|
157
|
+
private setPluginMetrics(): void {
|
|
158
|
+
const self = this;
|
|
159
|
+
setInterval(() => {
|
|
160
|
+
if (Object.keys(self._extensionIDAnalytics).length !== 0) {
|
|
161
|
+
self.pluginMetrics.setMetrics(JSON.stringify(self._extensionIDAnalytics));
|
|
162
|
+
}
|
|
163
|
+
}, METRICS_TIMEOUT);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Map of plugin extension id to method to analytic
|
|
167
|
+
get extensionIDAnalytics(): MetricsMap {
|
|
168
|
+
return this._extensionIDAnalytics;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Attempts to extract the method name from the current errorContents using the
|
|
173
|
+
* vscode-languageclient matching regex.
|
|
174
|
+
*
|
|
175
|
+
* If it cannot find a match in the errorContents it returns undefined
|
|
176
|
+
*
|
|
177
|
+
* @param errorContents The contents of the current error or undefined
|
|
178
|
+
*/
|
|
179
|
+
private extractMethodFromValue(errorContents: string | undefined): string | undefined {
|
|
180
|
+
if (!errorContents) {
|
|
181
|
+
return undefined;
|
|
182
|
+
}
|
|
183
|
+
const matches = errorContents.match(this.NODE_BASED_REGEX);
|
|
184
|
+
if (matches) {
|
|
185
|
+
return matches[1].trim();
|
|
186
|
+
}
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2019 Red Hat and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
-
import { LanguagesMainPluginMetrics } from './plugin-metrics-languages-main';
|
|
19
|
-
import { PluginMetrics, metricsJsonRpcPath } from '../common/metrics-protocol';
|
|
20
|
-
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
|
|
21
|
-
import { PluginMetricsCreator } from './plugin-metrics-creator';
|
|
22
|
-
import { PluginMetricsResolver } from './plugin-metrics-resolver';
|
|
23
|
-
import { PluginMetricsOutputChannelRegistry } from './plugin-metrics-output-registry';
|
|
24
|
-
import { LanguagesMainImpl } from '@theia/plugin-ext/lib/main/browser/languages-main';
|
|
25
|
-
import { OutputChannelRegistryMainImpl } from '@theia/plugin-ext/lib/main/browser/output-channel-registry-main';
|
|
26
|
-
|
|
27
|
-
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
28
|
-
bind(PluginMetricsResolver).toSelf().inSingletonScope();
|
|
29
|
-
bind(PluginMetricsCreator).toSelf().inSingletonScope();
|
|
30
|
-
|
|
31
|
-
rebind(LanguagesMainImpl).to(LanguagesMainPluginMetrics).inTransientScope();
|
|
32
|
-
rebind(OutputChannelRegistryMainImpl).to(PluginMetricsOutputChannelRegistry).inTransientScope();
|
|
33
|
-
|
|
34
|
-
bind(PluginMetrics).toDynamicValue(ctx => {
|
|
35
|
-
const connection = ctx.container.get(WebSocketConnectionProvider);
|
|
36
|
-
return connection.createProxy<PluginMetrics>(metricsJsonRpcPath);
|
|
37
|
-
}).inSingletonScope();
|
|
38
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2019 Red Hat and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { LanguagesMainPluginMetrics } from './plugin-metrics-languages-main';
|
|
19
|
+
import { PluginMetrics, metricsJsonRpcPath } from '../common/metrics-protocol';
|
|
20
|
+
import { WebSocketConnectionProvider } from '@theia/core/lib/browser/messaging/ws-connection-provider';
|
|
21
|
+
import { PluginMetricsCreator } from './plugin-metrics-creator';
|
|
22
|
+
import { PluginMetricsResolver } from './plugin-metrics-resolver';
|
|
23
|
+
import { PluginMetricsOutputChannelRegistry } from './plugin-metrics-output-registry';
|
|
24
|
+
import { LanguagesMainImpl } from '@theia/plugin-ext/lib/main/browser/languages-main';
|
|
25
|
+
import { OutputChannelRegistryMainImpl } from '@theia/plugin-ext/lib/main/browser/output-channel-registry-main';
|
|
26
|
+
|
|
27
|
+
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
28
|
+
bind(PluginMetricsResolver).toSelf().inSingletonScope();
|
|
29
|
+
bind(PluginMetricsCreator).toSelf().inSingletonScope();
|
|
30
|
+
|
|
31
|
+
rebind(LanguagesMainImpl).to(LanguagesMainPluginMetrics).inTransientScope();
|
|
32
|
+
rebind(OutputChannelRegistryMainImpl).to(PluginMetricsOutputChannelRegistry).inTransientScope();
|
|
33
|
+
|
|
34
|
+
bind(PluginMetrics).toDynamicValue(ctx => {
|
|
35
|
+
const connection = ctx.container.get(WebSocketConnectionProvider);
|
|
36
|
+
return connection.createProxy<PluginMetrics>(metricsJsonRpcPath);
|
|
37
|
+
}).inSingletonScope();
|
|
38
|
+
});
|