@webex/internal-plugin-metrics 3.0.0-beta.4 → 3.0.0-beta.41
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/README.md +1 -3
- package/dist/batcher.js +3 -22
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic-events-batcher.js +2 -12
- package/dist/call-diagnostic-events-batcher.js.map +1 -1
- package/dist/client-metrics-batcher.js +1 -7
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +21 -5
- package/dist/config.js.map +1 -1
- package/dist/index.js +13 -10
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +22 -54
- package/dist/metrics.js.map +1 -1
- package/package.json +8 -8
- package/src/batcher.js +33 -26
- package/src/call-diagnostic-events-batcher.js +5 -5
- package/src/client-metrics-batcher.js +3 -4
- package/src/config.js +25 -5
- package/src/index.js +2 -2
- package/src/metrics.js +31 -39
- package/test/unit/spec/batcher.js +26 -15
- package/test/unit/spec/call-diagnostic-events-batcher.js +39 -24
- package/test/unit/spec/client-metrics-batcher.js +26 -15
- package/test/unit/spec/metrics.js +22 -21
|
@@ -27,8 +27,8 @@ describe('plugin-metrics', () => {
|
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
webex = new MockWebex({
|
|
29
29
|
children: {
|
|
30
|
-
metrics: Metrics
|
|
31
|
-
}
|
|
30
|
+
metrics: Metrics,
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
webex.config.metrics = config.metrics;
|
|
@@ -37,7 +37,7 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
options
|
|
40
|
+
options,
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
sinon.spy(webex, 'request');
|
|
@@ -58,14 +58,15 @@ describe('plugin-metrics', () => {
|
|
|
58
58
|
it('clears the queue', () => {
|
|
59
59
|
clock.uninstall();
|
|
60
60
|
|
|
61
|
-
return webex.internal.metrics.callDiagnosticEventsBatcher
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
return webex.internal.metrics.callDiagnosticEventsBatcher
|
|
62
|
+
.request({
|
|
63
|
+
type: 'diagnostic-event',
|
|
64
|
+
eventPayload: {
|
|
65
|
+
originTime: {
|
|
66
|
+
triggered: 'mock triggered timestamp',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
})
|
|
69
70
|
.then(() => {
|
|
70
71
|
assert.calledOnce(webex.request);
|
|
71
72
|
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
|
|
@@ -85,21 +86,23 @@ describe('plugin-metrics', () => {
|
|
|
85
86
|
|
|
86
87
|
sinon.stub(webex, 'request').callsFake((options) => {
|
|
87
88
|
options.headers = {
|
|
88
|
-
trackingid: count
|
|
89
|
+
trackingid: count,
|
|
89
90
|
};
|
|
90
91
|
|
|
91
92
|
count += 1;
|
|
92
93
|
if (count < 9) {
|
|
93
|
-
return Promise.reject(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
return Promise.reject(
|
|
95
|
+
new WebexHttpError.NetworkOrCORSError({
|
|
96
|
+
statusCode: 0,
|
|
97
|
+
options,
|
|
98
|
+
})
|
|
99
|
+
);
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
return Promise.resolve({
|
|
100
103
|
statusCode: 204,
|
|
101
104
|
body: undefined,
|
|
102
|
-
options
|
|
105
|
+
options,
|
|
103
106
|
});
|
|
104
107
|
});
|
|
105
108
|
|
|
@@ -107,13 +110,15 @@ describe('plugin-metrics', () => {
|
|
|
107
110
|
type: 'diagnostic-event',
|
|
108
111
|
eventPayload: {
|
|
109
112
|
originTime: {
|
|
110
|
-
triggered: 'mock triggered timestamp'
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
+
triggered: 'mock triggered timestamp',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
113
116
|
});
|
|
114
117
|
|
|
115
118
|
return promiseTick(50)
|
|
116
|
-
.then(() =>
|
|
119
|
+
.then(() =>
|
|
120
|
+
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 1)
|
|
121
|
+
)
|
|
117
122
|
.then(() => clock.tick(config.metrics.batcherWait))
|
|
118
123
|
.then(() => assert.calledOnce(webex.request))
|
|
119
124
|
|
|
@@ -166,11 +171,21 @@ describe('plugin-metrics', () => {
|
|
|
166
171
|
.then(() => assert.callCount(webex.request, 9))
|
|
167
172
|
|
|
168
173
|
.then(() => promiseTick(50))
|
|
169
|
-
.then(() =>
|
|
174
|
+
.then(() =>
|
|
175
|
+
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0)
|
|
176
|
+
)
|
|
170
177
|
.then(() => promise)
|
|
171
178
|
.then(() => {
|
|
172
|
-
assert.lengthOf(
|
|
173
|
-
|
|
179
|
+
assert.lengthOf(
|
|
180
|
+
webex.request.args[1][0].body.metrics,
|
|
181
|
+
1,
|
|
182
|
+
'Reenqueuing the metric once did not increase the number of metrics to be submitted'
|
|
183
|
+
);
|
|
184
|
+
assert.lengthOf(
|
|
185
|
+
webex.request.args[2][0].body.metrics,
|
|
186
|
+
1,
|
|
187
|
+
'Reenqueuing the metric twice did not increase the number of metrics to be submitted'
|
|
188
|
+
);
|
|
174
189
|
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
|
|
175
190
|
});
|
|
176
191
|
});
|
|
@@ -27,8 +27,8 @@ describe('plugin-metrics', () => {
|
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
webex = new MockWebex({
|
|
29
29
|
children: {
|
|
30
|
-
metrics: Metrics
|
|
31
|
-
}
|
|
30
|
+
metrics: Metrics,
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
webex.config.metrics = config.metrics;
|
|
@@ -37,7 +37,7 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
options
|
|
40
|
+
options,
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
sinon.spy(webex, 'request');
|
|
@@ -58,9 +58,10 @@ describe('plugin-metrics', () => {
|
|
|
58
58
|
it('clears the queue', () => {
|
|
59
59
|
clock.uninstall();
|
|
60
60
|
|
|
61
|
-
return webex.internal.metrics.clientMetricsBatcher
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
return webex.internal.metrics.clientMetricsBatcher
|
|
62
|
+
.request({
|
|
63
|
+
key: 'testMetric',
|
|
64
|
+
})
|
|
64
65
|
.then(() => {
|
|
65
66
|
assert.calledOnce(webex.request);
|
|
66
67
|
assert.lengthOf(webex.internal.metrics.clientMetricsBatcher.queue, 0);
|
|
@@ -80,26 +81,28 @@ describe('plugin-metrics', () => {
|
|
|
80
81
|
|
|
81
82
|
sinon.stub(webex, 'request').callsFake((options) => {
|
|
82
83
|
options.headers = {
|
|
83
|
-
trackingid: count
|
|
84
|
+
trackingid: count,
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
count += 1;
|
|
87
88
|
if (count < 9) {
|
|
88
|
-
return Promise.reject(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
return Promise.reject(
|
|
90
|
+
new WebexHttpError.NetworkOrCORSError({
|
|
91
|
+
statusCode: 0,
|
|
92
|
+
options,
|
|
93
|
+
})
|
|
94
|
+
);
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
return Promise.resolve({
|
|
95
98
|
statusCode: 204,
|
|
96
99
|
body: undefined,
|
|
97
|
-
options
|
|
100
|
+
options,
|
|
98
101
|
});
|
|
99
102
|
});
|
|
100
103
|
|
|
101
104
|
const promise = webex.internal.metrics.clientMetricsBatcher.request({
|
|
102
|
-
key: 'testMetric'
|
|
105
|
+
key: 'testMetric',
|
|
103
106
|
});
|
|
104
107
|
|
|
105
108
|
return promiseTick(50)
|
|
@@ -159,8 +162,16 @@ describe('plugin-metrics', () => {
|
|
|
159
162
|
.then(() => assert.lengthOf(webex.internal.metrics.clientMetricsBatcher.queue, 0))
|
|
160
163
|
.then(() => promise)
|
|
161
164
|
.then(() => {
|
|
162
|
-
assert.lengthOf(
|
|
163
|
-
|
|
165
|
+
assert.lengthOf(
|
|
166
|
+
webex.request.args[1][0].body.metrics,
|
|
167
|
+
1,
|
|
168
|
+
'Reenqueuing the metric once did not increase the number of metrics to be submitted'
|
|
169
|
+
);
|
|
170
|
+
assert.lengthOf(
|
|
171
|
+
webex.request.args[2][0].body.metrics,
|
|
172
|
+
1,
|
|
173
|
+
'Reenqueuing the metric twice did not increase the number of metrics to be submitted'
|
|
174
|
+
);
|
|
164
175
|
assert.lengthOf(webex.internal.metrics.clientMetricsBatcher.queue, 0);
|
|
165
176
|
});
|
|
166
177
|
});
|
|
@@ -29,35 +29,35 @@ describe('plugin-metrics', () => {
|
|
|
29
29
|
const eventName = 'test_event';
|
|
30
30
|
const mockPayload = {
|
|
31
31
|
fields: {
|
|
32
|
-
testField: 123
|
|
32
|
+
testField: 123,
|
|
33
33
|
},
|
|
34
34
|
tags: {
|
|
35
|
-
testTag: 'tag value'
|
|
35
|
+
testTag: 'tag value',
|
|
36
36
|
},
|
|
37
37
|
metricName: eventName,
|
|
38
38
|
test: 'this field should not be included in final payload',
|
|
39
39
|
type: 'behavioral',
|
|
40
|
-
eventPayload: {value: 'splunk business metric payload'}
|
|
40
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
41
41
|
};
|
|
42
42
|
const transformedProps = {
|
|
43
43
|
fields: {
|
|
44
|
-
testField: 123
|
|
44
|
+
testField: 123,
|
|
45
45
|
},
|
|
46
46
|
tags: {
|
|
47
|
-
testTag: 'tag value'
|
|
47
|
+
testTag: 'tag value',
|
|
48
48
|
},
|
|
49
49
|
metricName: eventName,
|
|
50
50
|
type: 'behavioral',
|
|
51
|
-
timestamp: Date.now()
|
|
51
|
+
timestamp: Date.now(),
|
|
52
52
|
};
|
|
53
53
|
const preLoginId = '1b90cf5e-27a6-41aa-a208-1f6eb6b9e6b6';
|
|
54
54
|
const preLoginProps = {
|
|
55
|
-
metrics: [transformedProps]
|
|
55
|
+
metrics: [transformedProps],
|
|
56
56
|
};
|
|
57
57
|
const mockCallDiagnosticEvent = {
|
|
58
58
|
originTime: {
|
|
59
|
-
triggered: 'mock triggered timestamp'
|
|
60
|
-
}
|
|
59
|
+
triggered: 'mock triggered timestamp',
|
|
60
|
+
},
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
beforeEach(() => {
|
|
@@ -71,8 +71,8 @@ describe('plugin-metrics', () => {
|
|
|
71
71
|
beforeEach(() => {
|
|
72
72
|
webex = new MockWebex({
|
|
73
73
|
children: {
|
|
74
|
-
metrics: Metrics
|
|
75
|
-
}
|
|
74
|
+
metrics: Metrics,
|
|
75
|
+
},
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
webex.config.metrics = config.metrics;
|
|
@@ -82,7 +82,7 @@ describe('plugin-metrics', () => {
|
|
|
82
82
|
return Promise.resolve({
|
|
83
83
|
statusCode: 204,
|
|
84
84
|
body: undefined,
|
|
85
|
-
options
|
|
85
|
+
options,
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
|
|
@@ -94,8 +94,7 @@ describe('plugin-metrics', () => {
|
|
|
94
94
|
...webex.config,
|
|
95
95
|
appName: 'appName',
|
|
96
96
|
appPlatform: 'appPlatform',
|
|
97
|
-
appVersion: 'appVersion'
|
|
98
|
-
|
|
97
|
+
appVersion: 'appVersion',
|
|
99
98
|
};
|
|
100
99
|
webex.config.metrics.type = ['operational'];
|
|
101
100
|
webex.config.metrics.appType = 'sdk';
|
|
@@ -167,15 +166,18 @@ describe('plugin-metrics', () => {
|
|
|
167
166
|
});
|
|
168
167
|
describe('after login', () => {
|
|
169
168
|
it('submits a metric to clientmetrics', () => {
|
|
170
|
-
webex.credentials.supertoken = new Token(
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
webex.credentials.supertoken = new Token(
|
|
170
|
+
{
|
|
171
|
+
access_token: 'a_b_orgid',
|
|
172
|
+
},
|
|
173
|
+
{parent: webex}
|
|
174
|
+
);
|
|
173
175
|
|
|
174
176
|
const testPayload = {
|
|
175
177
|
tags: {success: true},
|
|
176
178
|
fields: {perceivedDurationInMillis: 314},
|
|
177
179
|
context: {},
|
|
178
|
-
eventPayload: {value: 'splunk business metric payload'}
|
|
180
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
179
181
|
};
|
|
180
182
|
const date = clock.now;
|
|
181
183
|
|
|
@@ -213,7 +215,6 @@ describe('plugin-metrics', () => {
|
|
|
213
215
|
assert.property(metric.context, 'locale');
|
|
214
216
|
assert.property(metric.context, 'os');
|
|
215
217
|
|
|
216
|
-
|
|
217
218
|
assert.equal(metric.timestamp, date);
|
|
218
219
|
assert.equal(metric.metricName, 'test');
|
|
219
220
|
assert.equal(metric.tags.success, true);
|
|
@@ -294,8 +295,8 @@ describe('plugin-metrics', () => {
|
|
|
294
295
|
const promise = metrics.submitCallDiagnosticEvents({
|
|
295
296
|
...mockCallDiagnosticEvent,
|
|
296
297
|
origin: {
|
|
297
|
-
buildType: 'prod'
|
|
298
|
-
}
|
|
298
|
+
buildType: 'prod',
|
|
299
|
+
},
|
|
299
300
|
});
|
|
300
301
|
|
|
301
302
|
return promiseTick(50)
|