@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,70 +1,70 @@
|
|
|
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
|
-
import { PluginMetricTimeCount } from './metric-output/plugin-metrics-time-count';
|
|
17
|
-
import { PluginMetricTimeSum } from './metric-output/plugin-metrics-time-sum';
|
|
18
|
-
import { MetricsMap } from '../common/plugin-metrics-types';
|
|
19
|
-
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
20
|
-
|
|
21
|
-
@injectable()
|
|
22
|
-
export class PluginMetricStringGenerator {
|
|
23
|
-
|
|
24
|
-
@inject(PluginMetricTimeCount)
|
|
25
|
-
private pluginMetricsTimeCount: PluginMetricTimeCount;
|
|
26
|
-
|
|
27
|
-
@inject(PluginMetricTimeSum)
|
|
28
|
-
private pluginMetricsTimeSum: PluginMetricTimeSum;
|
|
29
|
-
|
|
30
|
-
getMetricsString(extensionIDAnalytics: MetricsMap): string {
|
|
31
|
-
|
|
32
|
-
if (Object.keys(extensionIDAnalytics).length === 0) {
|
|
33
|
-
return '';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let metricString = this.pluginMetricsTimeCount.header;
|
|
37
|
-
for (const extensionID in extensionIDAnalytics) {
|
|
38
|
-
if (!extensionIDAnalytics.hasOwnProperty(extensionID)) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const methodToAnalytic = extensionIDAnalytics[extensionID];
|
|
43
|
-
for (const method in methodToAnalytic) {
|
|
44
|
-
if (!methodToAnalytic.hasOwnProperty(method)) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const analytic = methodToAnalytic[method];
|
|
48
|
-
metricString += this.pluginMetricsTimeCount.createMetricOutput(extensionID, method, analytic);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
metricString += this.pluginMetricsTimeSum.header;
|
|
53
|
-
for (const extensionID in extensionIDAnalytics) {
|
|
54
|
-
if (!extensionIDAnalytics.hasOwnProperty(extensionID)) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const methodToAnalytic = extensionIDAnalytics[extensionID];
|
|
59
|
-
for (const method in methodToAnalytic) {
|
|
60
|
-
if (!methodToAnalytic.hasOwnProperty(method)) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const analytic = methodToAnalytic[method];
|
|
64
|
-
metricString += this.pluginMetricsTimeSum.createMetricOutput(extensionID, method, analytic);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return metricString;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
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
|
+
import { PluginMetricTimeCount } from './metric-output/plugin-metrics-time-count';
|
|
17
|
+
import { PluginMetricTimeSum } from './metric-output/plugin-metrics-time-sum';
|
|
18
|
+
import { MetricsMap } from '../common/plugin-metrics-types';
|
|
19
|
+
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
20
|
+
|
|
21
|
+
@injectable()
|
|
22
|
+
export class PluginMetricStringGenerator {
|
|
23
|
+
|
|
24
|
+
@inject(PluginMetricTimeCount)
|
|
25
|
+
private pluginMetricsTimeCount: PluginMetricTimeCount;
|
|
26
|
+
|
|
27
|
+
@inject(PluginMetricTimeSum)
|
|
28
|
+
private pluginMetricsTimeSum: PluginMetricTimeSum;
|
|
29
|
+
|
|
30
|
+
getMetricsString(extensionIDAnalytics: MetricsMap): string {
|
|
31
|
+
|
|
32
|
+
if (Object.keys(extensionIDAnalytics).length === 0) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let metricString = this.pluginMetricsTimeCount.header;
|
|
37
|
+
for (const extensionID in extensionIDAnalytics) {
|
|
38
|
+
if (!extensionIDAnalytics.hasOwnProperty(extensionID)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const methodToAnalytic = extensionIDAnalytics[extensionID];
|
|
43
|
+
for (const method in methodToAnalytic) {
|
|
44
|
+
if (!methodToAnalytic.hasOwnProperty(method)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const analytic = methodToAnalytic[method];
|
|
48
|
+
metricString += this.pluginMetricsTimeCount.createMetricOutput(extensionID, method, analytic);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
metricString += this.pluginMetricsTimeSum.header;
|
|
53
|
+
for (const extensionID in extensionIDAnalytics) {
|
|
54
|
+
if (!extensionIDAnalytics.hasOwnProperty(extensionID)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const methodToAnalytic = extensionIDAnalytics[extensionID];
|
|
59
|
+
for (const method in methodToAnalytic) {
|
|
60
|
+
if (!methodToAnalytic.hasOwnProperty(method)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const analytic = methodToAnalytic[method];
|
|
64
|
+
metricString += this.pluginMetricsTimeSum.createMetricOutput(extensionID, method, analytic);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return metricString;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,234 +1,234 @@
|
|
|
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 { AnalyticsFromRequests } from '../common/plugin-metrics-types';
|
|
18
|
-
import { PluginMetricsContributor } from './metrics-contributor';
|
|
19
|
-
import { Container, ContainerModule } from '@theia/core/shared/inversify';
|
|
20
|
-
import { PluginMetricsImpl } from './plugin-metrics-impl';
|
|
21
|
-
import { PluginMetrics } from '../common/metrics-protocol';
|
|
22
|
-
import * as assert from 'assert';
|
|
23
|
-
|
|
24
|
-
describe('Metrics contributor:', () => {
|
|
25
|
-
let testContainer: Container;
|
|
26
|
-
before(() => {
|
|
27
|
-
testContainer = new Container();
|
|
28
|
-
|
|
29
|
-
const module = new ContainerModule(bind => {
|
|
30
|
-
bind(PluginMetrics).to(PluginMetricsImpl).inTransientScope();
|
|
31
|
-
bind(PluginMetricsContributor).toSelf().inTransientScope();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
testContainer.load(module);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('reconcile:', () => {
|
|
38
|
-
it('Reconcile with one client connected', async () => {
|
|
39
|
-
// given
|
|
40
|
-
const analytics = {
|
|
41
|
-
sumOfTimeForFailure: 0,
|
|
42
|
-
sumOfTimeForSuccess: 5,
|
|
43
|
-
successfulResponses: 10,
|
|
44
|
-
totalRequests: 15
|
|
45
|
-
} as AnalyticsFromRequests;
|
|
46
|
-
const metricExtensionID = 'my_test_metric.test_metric';
|
|
47
|
-
const metricMethod = 'textDocument/testMethod';
|
|
48
|
-
|
|
49
|
-
const metricsMap = {
|
|
50
|
-
[metricExtensionID]: {
|
|
51
|
-
[metricMethod]: analytics
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
56
|
-
const pluginMetrics = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
57
|
-
pluginMetrics.setMetrics(JSON.stringify(metricsMap));
|
|
58
|
-
metricsContributor.clients.add(pluginMetrics);
|
|
59
|
-
|
|
60
|
-
// when
|
|
61
|
-
const reconciledMap = metricsContributor.reconcile();
|
|
62
|
-
|
|
63
|
-
// then
|
|
64
|
-
assert.deepStrictEqual(reconciledMap, metricsMap);
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('Reconcile same extension id and method with two clients connected', async () => {
|
|
69
|
-
// given
|
|
70
|
-
|
|
71
|
-
// first client
|
|
72
|
-
const firstClientAnalytics = {
|
|
73
|
-
sumOfTimeForFailure: 0,
|
|
74
|
-
sumOfTimeForSuccess: 5,
|
|
75
|
-
successfulResponses: 10,
|
|
76
|
-
totalRequests: 15
|
|
77
|
-
} as AnalyticsFromRequests;
|
|
78
|
-
const firstClientMetricExtensionID = 'my_test_metric.test_metric';
|
|
79
|
-
const firstClientMetricMethod = 'textDocument/testMethod';
|
|
80
|
-
const firstClientMetricsMap = {
|
|
81
|
-
[firstClientMetricExtensionID]: {
|
|
82
|
-
[firstClientMetricMethod]: firstClientAnalytics
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const secondClientAnalytics = {
|
|
87
|
-
sumOfTimeForFailure: 0,
|
|
88
|
-
sumOfTimeForSuccess: 15,
|
|
89
|
-
successfulResponses: 20,
|
|
90
|
-
totalRequests: 18
|
|
91
|
-
} as AnalyticsFromRequests;
|
|
92
|
-
const secondClientMetricsMap = {
|
|
93
|
-
[firstClientMetricExtensionID]: {
|
|
94
|
-
[firstClientMetricMethod]: secondClientAnalytics
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
98
|
-
const firstClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
99
|
-
firstClientPluginMetric.setMetrics(JSON.stringify(firstClientMetricsMap));
|
|
100
|
-
metricsContributor.clients.add(firstClientPluginMetric);
|
|
101
|
-
|
|
102
|
-
const secondClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
103
|
-
secondClientPluginMetric.setMetrics(JSON.stringify(secondClientMetricsMap));
|
|
104
|
-
metricsContributor.clients.add(secondClientPluginMetric);
|
|
105
|
-
|
|
106
|
-
// when
|
|
107
|
-
const reconciledMap = metricsContributor.reconcile();
|
|
108
|
-
|
|
109
|
-
// then
|
|
110
|
-
const expectedAnalytics = {
|
|
111
|
-
sumOfTimeForFailure: 0,
|
|
112
|
-
sumOfTimeForSuccess: 20,
|
|
113
|
-
successfulResponses: 30,
|
|
114
|
-
totalRequests: 33
|
|
115
|
-
} as AnalyticsFromRequests;
|
|
116
|
-
|
|
117
|
-
const expectedMap = {
|
|
118
|
-
[firstClientMetricExtensionID]: {
|
|
119
|
-
[firstClientMetricMethod]: expectedAnalytics
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
assert.deepStrictEqual(reconciledMap, expectedMap);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('Reconcile different extension id and method with two clients connected', async () => {
|
|
127
|
-
// given
|
|
128
|
-
|
|
129
|
-
// first client
|
|
130
|
-
const firstClientAnalytics = {
|
|
131
|
-
sumOfTimeForFailure: 0,
|
|
132
|
-
sumOfTimeForSuccess: 5,
|
|
133
|
-
successfulResponses: 10,
|
|
134
|
-
totalRequests: 15
|
|
135
|
-
} as AnalyticsFromRequests;
|
|
136
|
-
const firstClientMetricExtensionID = 'my_test_metric.test_metric';
|
|
137
|
-
const firstClientMetricMethod = 'textDocument/testMethod';
|
|
138
|
-
const firstClientMetricsMap = {
|
|
139
|
-
[firstClientMetricExtensionID]: {
|
|
140
|
-
[firstClientMetricMethod]: firstClientAnalytics
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const secondClientAnalytics = {
|
|
145
|
-
sumOfTimeForFailure: 0,
|
|
146
|
-
sumOfTimeForSuccess: 15,
|
|
147
|
-
successfulResponses: 20,
|
|
148
|
-
totalRequests: 18
|
|
149
|
-
} as AnalyticsFromRequests;
|
|
150
|
-
const secondClientMetricExtensionID = 'my_other_test_metric.test_metric';
|
|
151
|
-
const secondClientMetricsMap = {
|
|
152
|
-
[secondClientMetricExtensionID]: {
|
|
153
|
-
[firstClientMetricMethod]: secondClientAnalytics
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
157
|
-
const firstClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
158
|
-
firstClientPluginMetric.setMetrics(JSON.stringify(firstClientMetricsMap));
|
|
159
|
-
metricsContributor.clients.add(firstClientPluginMetric);
|
|
160
|
-
|
|
161
|
-
const secondClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
162
|
-
secondClientPluginMetric.setMetrics(JSON.stringify(secondClientMetricsMap));
|
|
163
|
-
metricsContributor.clients.add(secondClientPluginMetric);
|
|
164
|
-
|
|
165
|
-
// when
|
|
166
|
-
const reconciledMap = metricsContributor.reconcile();
|
|
167
|
-
|
|
168
|
-
// then
|
|
169
|
-
const expectedMap = {
|
|
170
|
-
[firstClientMetricExtensionID]: {
|
|
171
|
-
[firstClientMetricMethod]: firstClientAnalytics
|
|
172
|
-
},
|
|
173
|
-
[secondClientMetricExtensionID]: {
|
|
174
|
-
[firstClientMetricMethod]: secondClientAnalytics
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
assert.deepStrictEqual(reconciledMap, expectedMap);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('Reconcile same extension id and different method with two clients connected', async () => {
|
|
182
|
-
// given
|
|
183
|
-
|
|
184
|
-
// first client
|
|
185
|
-
const firstClientAnalytics = {
|
|
186
|
-
sumOfTimeForFailure: 0,
|
|
187
|
-
sumOfTimeForSuccess: 5,
|
|
188
|
-
successfulResponses: 10,
|
|
189
|
-
totalRequests: 15
|
|
190
|
-
} as AnalyticsFromRequests;
|
|
191
|
-
const firstClientMetricExtensionID = 'my_test_metric.test_metric';
|
|
192
|
-
const firstClientMetricMethod = 'textDocument/testMethod';
|
|
193
|
-
const firstClientMetricsMap = {
|
|
194
|
-
[firstClientMetricExtensionID]: {
|
|
195
|
-
[firstClientMetricMethod]: firstClientAnalytics
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
const secondClientAnalytics = {
|
|
199
|
-
sumOfTimeForFailure: 0,
|
|
200
|
-
sumOfTimeForSuccess: 15,
|
|
201
|
-
successfulResponses: 20,
|
|
202
|
-
totalRequests: 18
|
|
203
|
-
} as AnalyticsFromRequests;
|
|
204
|
-
const secondClientMetricMethod = 'textDocument/myOthertestMethod';
|
|
205
|
-
const secondClientMetricsMap = {
|
|
206
|
-
[firstClientMetricExtensionID]: {
|
|
207
|
-
[secondClientMetricMethod]: secondClientAnalytics
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
211
|
-
const firstClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
212
|
-
firstClientPluginMetric.setMetrics(JSON.stringify(firstClientMetricsMap));
|
|
213
|
-
metricsContributor.clients.add(firstClientPluginMetric);
|
|
214
|
-
|
|
215
|
-
const secondClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
216
|
-
secondClientPluginMetric.setMetrics(JSON.stringify(secondClientMetricsMap));
|
|
217
|
-
metricsContributor.clients.add(secondClientPluginMetric);
|
|
218
|
-
|
|
219
|
-
// when
|
|
220
|
-
const reconciledMap = metricsContributor.reconcile();
|
|
221
|
-
|
|
222
|
-
// then
|
|
223
|
-
const expectedMap = {
|
|
224
|
-
[firstClientMetricExtensionID]: {
|
|
225
|
-
[firstClientMetricMethod]: firstClientAnalytics,
|
|
226
|
-
[secondClientMetricMethod]: secondClientAnalytics
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
assert.deepStrictEqual(reconciledMap, expectedMap);
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
});
|
|
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 { AnalyticsFromRequests } from '../common/plugin-metrics-types';
|
|
18
|
+
import { PluginMetricsContributor } from './metrics-contributor';
|
|
19
|
+
import { Container, ContainerModule } from '@theia/core/shared/inversify';
|
|
20
|
+
import { PluginMetricsImpl } from './plugin-metrics-impl';
|
|
21
|
+
import { PluginMetrics } from '../common/metrics-protocol';
|
|
22
|
+
import * as assert from 'assert';
|
|
23
|
+
|
|
24
|
+
describe('Metrics contributor:', () => {
|
|
25
|
+
let testContainer: Container;
|
|
26
|
+
before(() => {
|
|
27
|
+
testContainer = new Container();
|
|
28
|
+
|
|
29
|
+
const module = new ContainerModule(bind => {
|
|
30
|
+
bind(PluginMetrics).to(PluginMetricsImpl).inTransientScope();
|
|
31
|
+
bind(PluginMetricsContributor).toSelf().inTransientScope();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
testContainer.load(module);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('reconcile:', () => {
|
|
38
|
+
it('Reconcile with one client connected', async () => {
|
|
39
|
+
// given
|
|
40
|
+
const analytics = {
|
|
41
|
+
sumOfTimeForFailure: 0,
|
|
42
|
+
sumOfTimeForSuccess: 5,
|
|
43
|
+
successfulResponses: 10,
|
|
44
|
+
totalRequests: 15
|
|
45
|
+
} as AnalyticsFromRequests;
|
|
46
|
+
const metricExtensionID = 'my_test_metric.test_metric';
|
|
47
|
+
const metricMethod = 'textDocument/testMethod';
|
|
48
|
+
|
|
49
|
+
const metricsMap = {
|
|
50
|
+
[metricExtensionID]: {
|
|
51
|
+
[metricMethod]: analytics
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
56
|
+
const pluginMetrics = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
57
|
+
pluginMetrics.setMetrics(JSON.stringify(metricsMap));
|
|
58
|
+
metricsContributor.clients.add(pluginMetrics);
|
|
59
|
+
|
|
60
|
+
// when
|
|
61
|
+
const reconciledMap = metricsContributor.reconcile();
|
|
62
|
+
|
|
63
|
+
// then
|
|
64
|
+
assert.deepStrictEqual(reconciledMap, metricsMap);
|
|
65
|
+
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Reconcile same extension id and method with two clients connected', async () => {
|
|
69
|
+
// given
|
|
70
|
+
|
|
71
|
+
// first client
|
|
72
|
+
const firstClientAnalytics = {
|
|
73
|
+
sumOfTimeForFailure: 0,
|
|
74
|
+
sumOfTimeForSuccess: 5,
|
|
75
|
+
successfulResponses: 10,
|
|
76
|
+
totalRequests: 15
|
|
77
|
+
} as AnalyticsFromRequests;
|
|
78
|
+
const firstClientMetricExtensionID = 'my_test_metric.test_metric';
|
|
79
|
+
const firstClientMetricMethod = 'textDocument/testMethod';
|
|
80
|
+
const firstClientMetricsMap = {
|
|
81
|
+
[firstClientMetricExtensionID]: {
|
|
82
|
+
[firstClientMetricMethod]: firstClientAnalytics
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const secondClientAnalytics = {
|
|
87
|
+
sumOfTimeForFailure: 0,
|
|
88
|
+
sumOfTimeForSuccess: 15,
|
|
89
|
+
successfulResponses: 20,
|
|
90
|
+
totalRequests: 18
|
|
91
|
+
} as AnalyticsFromRequests;
|
|
92
|
+
const secondClientMetricsMap = {
|
|
93
|
+
[firstClientMetricExtensionID]: {
|
|
94
|
+
[firstClientMetricMethod]: secondClientAnalytics
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
98
|
+
const firstClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
99
|
+
firstClientPluginMetric.setMetrics(JSON.stringify(firstClientMetricsMap));
|
|
100
|
+
metricsContributor.clients.add(firstClientPluginMetric);
|
|
101
|
+
|
|
102
|
+
const secondClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
103
|
+
secondClientPluginMetric.setMetrics(JSON.stringify(secondClientMetricsMap));
|
|
104
|
+
metricsContributor.clients.add(secondClientPluginMetric);
|
|
105
|
+
|
|
106
|
+
// when
|
|
107
|
+
const reconciledMap = metricsContributor.reconcile();
|
|
108
|
+
|
|
109
|
+
// then
|
|
110
|
+
const expectedAnalytics = {
|
|
111
|
+
sumOfTimeForFailure: 0,
|
|
112
|
+
sumOfTimeForSuccess: 20,
|
|
113
|
+
successfulResponses: 30,
|
|
114
|
+
totalRequests: 33
|
|
115
|
+
} as AnalyticsFromRequests;
|
|
116
|
+
|
|
117
|
+
const expectedMap = {
|
|
118
|
+
[firstClientMetricExtensionID]: {
|
|
119
|
+
[firstClientMetricMethod]: expectedAnalytics
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
assert.deepStrictEqual(reconciledMap, expectedMap);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('Reconcile different extension id and method with two clients connected', async () => {
|
|
127
|
+
// given
|
|
128
|
+
|
|
129
|
+
// first client
|
|
130
|
+
const firstClientAnalytics = {
|
|
131
|
+
sumOfTimeForFailure: 0,
|
|
132
|
+
sumOfTimeForSuccess: 5,
|
|
133
|
+
successfulResponses: 10,
|
|
134
|
+
totalRequests: 15
|
|
135
|
+
} as AnalyticsFromRequests;
|
|
136
|
+
const firstClientMetricExtensionID = 'my_test_metric.test_metric';
|
|
137
|
+
const firstClientMetricMethod = 'textDocument/testMethod';
|
|
138
|
+
const firstClientMetricsMap = {
|
|
139
|
+
[firstClientMetricExtensionID]: {
|
|
140
|
+
[firstClientMetricMethod]: firstClientAnalytics
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const secondClientAnalytics = {
|
|
145
|
+
sumOfTimeForFailure: 0,
|
|
146
|
+
sumOfTimeForSuccess: 15,
|
|
147
|
+
successfulResponses: 20,
|
|
148
|
+
totalRequests: 18
|
|
149
|
+
} as AnalyticsFromRequests;
|
|
150
|
+
const secondClientMetricExtensionID = 'my_other_test_metric.test_metric';
|
|
151
|
+
const secondClientMetricsMap = {
|
|
152
|
+
[secondClientMetricExtensionID]: {
|
|
153
|
+
[firstClientMetricMethod]: secondClientAnalytics
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
157
|
+
const firstClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
158
|
+
firstClientPluginMetric.setMetrics(JSON.stringify(firstClientMetricsMap));
|
|
159
|
+
metricsContributor.clients.add(firstClientPluginMetric);
|
|
160
|
+
|
|
161
|
+
const secondClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
162
|
+
secondClientPluginMetric.setMetrics(JSON.stringify(secondClientMetricsMap));
|
|
163
|
+
metricsContributor.clients.add(secondClientPluginMetric);
|
|
164
|
+
|
|
165
|
+
// when
|
|
166
|
+
const reconciledMap = metricsContributor.reconcile();
|
|
167
|
+
|
|
168
|
+
// then
|
|
169
|
+
const expectedMap = {
|
|
170
|
+
[firstClientMetricExtensionID]: {
|
|
171
|
+
[firstClientMetricMethod]: firstClientAnalytics
|
|
172
|
+
},
|
|
173
|
+
[secondClientMetricExtensionID]: {
|
|
174
|
+
[firstClientMetricMethod]: secondClientAnalytics
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
assert.deepStrictEqual(reconciledMap, expectedMap);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('Reconcile same extension id and different method with two clients connected', async () => {
|
|
182
|
+
// given
|
|
183
|
+
|
|
184
|
+
// first client
|
|
185
|
+
const firstClientAnalytics = {
|
|
186
|
+
sumOfTimeForFailure: 0,
|
|
187
|
+
sumOfTimeForSuccess: 5,
|
|
188
|
+
successfulResponses: 10,
|
|
189
|
+
totalRequests: 15
|
|
190
|
+
} as AnalyticsFromRequests;
|
|
191
|
+
const firstClientMetricExtensionID = 'my_test_metric.test_metric';
|
|
192
|
+
const firstClientMetricMethod = 'textDocument/testMethod';
|
|
193
|
+
const firstClientMetricsMap = {
|
|
194
|
+
[firstClientMetricExtensionID]: {
|
|
195
|
+
[firstClientMetricMethod]: firstClientAnalytics
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const secondClientAnalytics = {
|
|
199
|
+
sumOfTimeForFailure: 0,
|
|
200
|
+
sumOfTimeForSuccess: 15,
|
|
201
|
+
successfulResponses: 20,
|
|
202
|
+
totalRequests: 18
|
|
203
|
+
} as AnalyticsFromRequests;
|
|
204
|
+
const secondClientMetricMethod = 'textDocument/myOthertestMethod';
|
|
205
|
+
const secondClientMetricsMap = {
|
|
206
|
+
[firstClientMetricExtensionID]: {
|
|
207
|
+
[secondClientMetricMethod]: secondClientAnalytics
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const metricsContributor = testContainer.get(PluginMetricsContributor);
|
|
211
|
+
const firstClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
212
|
+
firstClientPluginMetric.setMetrics(JSON.stringify(firstClientMetricsMap));
|
|
213
|
+
metricsContributor.clients.add(firstClientPluginMetric);
|
|
214
|
+
|
|
215
|
+
const secondClientPluginMetric = testContainer.get(PluginMetrics) as PluginMetrics;
|
|
216
|
+
secondClientPluginMetric.setMetrics(JSON.stringify(secondClientMetricsMap));
|
|
217
|
+
metricsContributor.clients.add(secondClientPluginMetric);
|
|
218
|
+
|
|
219
|
+
// when
|
|
220
|
+
const reconciledMap = metricsContributor.reconcile();
|
|
221
|
+
|
|
222
|
+
// then
|
|
223
|
+
const expectedMap = {
|
|
224
|
+
[firstClientMetricExtensionID]: {
|
|
225
|
+
[firstClientMetricMethod]: firstClientAnalytics,
|
|
226
|
+
[secondClientMetricMethod]: secondClientAnalytics
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
assert.deepStrictEqual(reconciledMap, expectedMap);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
});
|