@webex/internal-plugin-metrics 3.0.0-beta.38 → 3.0.0-beta.380
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/dist/batcher.js +40 -1
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +476 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +841 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +364 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +627 -0
- package/dist/call-diagnostic/config.js.map +1 -0
- package/dist/client-metrics-batcher.js +2 -1
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +23 -28
- package/dist/metrics.js.map +1 -1
- package/dist/metrics.types.js +7 -0
- package/dist/metrics.types.js.map +1 -0
- package/dist/new-metrics.js +299 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/prelogin-metrics-batcher.js +82 -0
- package/dist/prelogin-metrics-batcher.js.map +1 -0
- package/dist/types/batcher.d.ts +7 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +204 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +425 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +103 -0
- package/dist/types/call-diagnostic/config.d.ts +178 -0
- package/dist/types/client-metrics-batcher.d.ts +2 -0
- package/dist/types/config.d.ts +36 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/metrics.d.ts +3 -0
- package/dist/types/metrics.types.d.ts +105 -0
- package/dist/types/new-metrics.d.ts +131 -0
- package/dist/types/prelogin-metrics-batcher.d.ts +2 -0
- package/dist/types/utils.d.ts +6 -0
- package/dist/utils.js +27 -0
- package/dist/utils.js.map +1 -0
- package/package.json +16 -8
- package/src/batcher.js +38 -0
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +72 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +435 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +899 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +392 -0
- package/src/call-diagnostic/config.ts +685 -0
- package/src/client-metrics-batcher.js +1 -0
- package/src/config.js +1 -0
- package/src/index.ts +54 -0
- package/src/metrics.js +18 -24
- package/src/metrics.types.ts +168 -0
- package/src/new-metrics.ts +278 -0
- package/src/prelogin-metrics-batcher.ts +95 -0
- package/src/utils.ts +17 -0
- package/test/unit/spec/batcher.js +2 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +457 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +520 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2137 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +629 -0
- package/test/unit/spec/client-metrics-batcher.js +2 -0
- package/test/unit/spec/metrics.js +66 -97
- package/test/unit/spec/new-metrics.ts +234 -0
- package/test/unit/spec/prelogin-metrics-batcher.ts +250 -0
- package/test/unit/spec/utils.ts +22 -0
- package/tsconfig.json +6 -0
- package/dist/call-diagnostic-events-batcher.js +0 -60
- package/dist/call-diagnostic-events-batcher.js.map +0 -1
- package/src/call-diagnostic-events-batcher.js +0 -62
- package/src/index.js +0 -17
- package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
|
@@ -8,6 +8,9 @@ import {Token, Credentials} from '@webex/webex-core';
|
|
|
8
8
|
import FakeTimers from '@sinonjs/fake-timers';
|
|
9
9
|
import sinon from 'sinon';
|
|
10
10
|
import Metrics, {config} from '@webex/internal-plugin-metrics';
|
|
11
|
+
import {BrowserDetection} from '@webex/common';
|
|
12
|
+
|
|
13
|
+
const {getOSVersion} = BrowserDetection();
|
|
11
14
|
|
|
12
15
|
function promiseTick(count) {
|
|
13
16
|
let promise = Promise.resolve();
|
|
@@ -82,6 +85,7 @@ describe('plugin-metrics', () => {
|
|
|
82
85
|
return Promise.resolve({
|
|
83
86
|
statusCode: 204,
|
|
84
87
|
body: undefined,
|
|
88
|
+
waitForServiceTimeout: 30,
|
|
85
89
|
options,
|
|
86
90
|
});
|
|
87
91
|
};
|
|
@@ -102,7 +106,6 @@ describe('plugin-metrics', () => {
|
|
|
102
106
|
sinon.spy(webex, 'request');
|
|
103
107
|
sinon.spy(metrics, 'postPreLoginMetric');
|
|
104
108
|
sinon.spy(metrics, 'aliasUser');
|
|
105
|
-
sinon.spy(metrics, 'submitCallDiagnosticEvents');
|
|
106
109
|
});
|
|
107
110
|
|
|
108
111
|
describe('#submit()', () => {
|
|
@@ -131,6 +134,67 @@ describe('plugin-metrics', () => {
|
|
|
131
134
|
});
|
|
132
135
|
});
|
|
133
136
|
|
|
137
|
+
describe('#getClientMetricsPayload()', () => {
|
|
138
|
+
it('returns the expected payload', () => {
|
|
139
|
+
webex.credentials.supertoken = new Token(
|
|
140
|
+
{
|
|
141
|
+
access_token: 'a_b_orgid',
|
|
142
|
+
},
|
|
143
|
+
{parent: webex}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const testPayload = {
|
|
147
|
+
tags: {success: true},
|
|
148
|
+
fields: {perceivedDurationInMillis: 314},
|
|
149
|
+
context: {},
|
|
150
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
151
|
+
};
|
|
152
|
+
const date = clock.now;
|
|
153
|
+
|
|
154
|
+
const result = metrics.getClientMetricsPayload('test', testPayload);
|
|
155
|
+
|
|
156
|
+
assert.deepEqual(result, {
|
|
157
|
+
context: {
|
|
158
|
+
app: {
|
|
159
|
+
version: undefined,
|
|
160
|
+
},
|
|
161
|
+
locale: 'en-US',
|
|
162
|
+
os: {
|
|
163
|
+
name: 'other',
|
|
164
|
+
version: getOSVersion(),
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
eventPayload: {
|
|
168
|
+
value: 'splunk business metric payload',
|
|
169
|
+
},
|
|
170
|
+
fields: {
|
|
171
|
+
browser_version: '',
|
|
172
|
+
client_id: 'fake',
|
|
173
|
+
os_version: getOSVersion(),
|
|
174
|
+
perceivedDurationInMillis: 314,
|
|
175
|
+
platform: 'Web',
|
|
176
|
+
sdk_version: undefined,
|
|
177
|
+
spark_user_agent: 'webex-js-sdk appName/appVersion appPlatform',
|
|
178
|
+
},
|
|
179
|
+
metricName: 'test',
|
|
180
|
+
tags: {
|
|
181
|
+
browser: '',
|
|
182
|
+
domain: 'whatever',
|
|
183
|
+
os: 'other',
|
|
184
|
+
success: true,
|
|
185
|
+
},
|
|
186
|
+
timestamp: 0,
|
|
187
|
+
type: ['operational'],
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('throws when no event name is specified', () => {
|
|
192
|
+
assert.throws(() => {
|
|
193
|
+
metrics.getClientMetricsPayload();
|
|
194
|
+
}, 'Missing behavioral metric name. Please provide one');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
134
198
|
describe('#submitClientMetrics()', () => {
|
|
135
199
|
describe('before login', () => {
|
|
136
200
|
it('posts pre-login metric', () => {
|
|
@@ -199,17 +263,15 @@ describe('plugin-metrics', () => {
|
|
|
199
263
|
assert.property(metric, 'eventPayload');
|
|
200
264
|
|
|
201
265
|
assert.property(metric.tags, 'browser');
|
|
202
|
-
assert.property(metric.tags, 'org_id');
|
|
203
266
|
assert.property(metric.tags, 'os');
|
|
204
267
|
assert.property(metric.tags, 'domain');
|
|
205
|
-
assert.property(metric.tags, 'client_id');
|
|
206
|
-
assert.property(metric.tags, 'user_id');
|
|
207
268
|
|
|
208
269
|
assert.property(metric.fields, 'browser_version');
|
|
209
270
|
assert.property(metric.fields, 'os_version');
|
|
210
271
|
assert.property(metric.fields, 'sdk_version');
|
|
211
272
|
assert.property(metric.fields, 'platform');
|
|
212
273
|
assert.property(metric.fields, 'spark_user_agent');
|
|
274
|
+
assert.property(metric.fields, 'client_id');
|
|
213
275
|
|
|
214
276
|
assert.property(metric.context, 'app');
|
|
215
277
|
assert.property(metric.context, 'locale');
|
|
@@ -269,98 +331,5 @@ describe('plugin-metrics', () => {
|
|
|
269
331
|
assert.match(params, {alias: true});
|
|
270
332
|
}));
|
|
271
333
|
});
|
|
272
|
-
|
|
273
|
-
describe('#submitCallDiagnosticEvents()', () => {
|
|
274
|
-
it('submits a call diagnostic event', () => {
|
|
275
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
276
|
-
|
|
277
|
-
return promiseTick(50)
|
|
278
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
279
|
-
.then(() => promise)
|
|
280
|
-
.then(() => {
|
|
281
|
-
assert.calledOnce(webex.request);
|
|
282
|
-
const req = webex.request.args[0][0];
|
|
283
|
-
const metric = req.body.metrics[0];
|
|
284
|
-
|
|
285
|
-
assert.property(metric.eventPayload, 'origin');
|
|
286
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
287
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
288
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
289
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
290
|
-
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it('submits a call diagnostic event with buildType set in the payload', () => {
|
|
295
|
-
const promise = metrics.submitCallDiagnosticEvents({
|
|
296
|
-
...mockCallDiagnosticEvent,
|
|
297
|
-
origin: {
|
|
298
|
-
buildType: 'prod',
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
return promiseTick(50)
|
|
303
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
304
|
-
.then(() => promise)
|
|
305
|
-
.then(() => {
|
|
306
|
-
assert.calledOnce(webex.request);
|
|
307
|
-
const req = webex.request.args[0][0];
|
|
308
|
-
const metric = req.body.metrics[0];
|
|
309
|
-
|
|
310
|
-
assert.property(metric.eventPayload, 'origin');
|
|
311
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
312
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
313
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
314
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
315
|
-
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
xit('submits a call diagnostic event with a test domain', () => {
|
|
320
|
-
global.window.location.hostname = 'test.webex.com';
|
|
321
|
-
|
|
322
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
323
|
-
|
|
324
|
-
return promiseTick(50)
|
|
325
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
326
|
-
.then(() => promise)
|
|
327
|
-
.then(() => {
|
|
328
|
-
assert.calledOnce(webex.request);
|
|
329
|
-
const req = webex.request.args[0][0];
|
|
330
|
-
const metric = req.body.metrics[0];
|
|
331
|
-
|
|
332
|
-
assert.property(metric.eventPayload, 'origin');
|
|
333
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
334
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
335
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
336
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
337
|
-
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
// Skip because it's current unable to overwrite NODE_ENV
|
|
342
|
-
// However doing `NODE_ENV=test npm run test ...` will get this test case to pass
|
|
343
|
-
xit('submits a call diagnostic event with a NODE_ENV=production', () => {
|
|
344
|
-
process.env.NODE_ENV = 'production';
|
|
345
|
-
|
|
346
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
347
|
-
|
|
348
|
-
return promiseTick(50)
|
|
349
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
350
|
-
.then(() => promise)
|
|
351
|
-
.then(() => {
|
|
352
|
-
assert.calledOnce(webex.request);
|
|
353
|
-
const req = webex.request.args[0][0];
|
|
354
|
-
const metric = req.body.metrics[0];
|
|
355
|
-
|
|
356
|
-
assert.property(metric.eventPayload, 'origin');
|
|
357
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
358
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
359
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
360
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
361
|
-
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
334
|
});
|
|
366
335
|
});
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import {assert} from '@webex/test-helper-chai';
|
|
2
|
+
import {NewMetrics} from '@webex/internal-plugin-metrics';
|
|
3
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import {Utils} from '@webex/internal-plugin-metrics';
|
|
6
|
+
|
|
7
|
+
describe('internal-plugin-metrics', () => {
|
|
8
|
+
|
|
9
|
+
describe('check submitClientEvent when webex is not ready', () => {
|
|
10
|
+
let webex;
|
|
11
|
+
//@ts-ignore
|
|
12
|
+
webex = new MockWebex({
|
|
13
|
+
children: {
|
|
14
|
+
newMetrics: NewMetrics,
|
|
15
|
+
},
|
|
16
|
+
meetings: {
|
|
17
|
+
meetingCollection: {
|
|
18
|
+
get: sinon.stub(),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
request: sinon.stub().resolves({}),
|
|
22
|
+
logger: {
|
|
23
|
+
log: sinon.stub(),
|
|
24
|
+
error: sinon.stub(),
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('checks the log', () => {
|
|
29
|
+
webex.internal.newMetrics.submitClientEvent({
|
|
30
|
+
name: 'client.alert.displayed',
|
|
31
|
+
options: {
|
|
32
|
+
meetingId: '123',
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
assert.calledWith(
|
|
36
|
+
webex.logger.log,
|
|
37
|
+
'NewMetrics: @submitClientEvent. Attempted to submit before webex.ready. Event name: client.alert.displayed'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('new-metrics', () => {
|
|
43
|
+
let webex;
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
//@ts-ignore
|
|
47
|
+
webex = new MockWebex({
|
|
48
|
+
children: {
|
|
49
|
+
newMetrics: NewMetrics,
|
|
50
|
+
},
|
|
51
|
+
meetings: {
|
|
52
|
+
meetingCollection: {
|
|
53
|
+
get: sinon.stub(),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
request: sinon.stub().resolves({}),
|
|
57
|
+
logger: {
|
|
58
|
+
log: sinon.stub(),
|
|
59
|
+
error: sinon.stub(),
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
webex.emit('ready');
|
|
64
|
+
|
|
65
|
+
webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp = sinon.stub();
|
|
66
|
+
webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps = sinon.stub();
|
|
67
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent = sinon.stub();
|
|
68
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitMQE = sinon.stub();
|
|
69
|
+
webex.internal.newMetrics.callDiagnosticMetrics.clientMetricsAliasUser = sinon.stub();
|
|
70
|
+
webex.internal.newMetrics.callDiagnosticMetrics.buildClientEventFetchRequestOptions =
|
|
71
|
+
sinon.stub();
|
|
72
|
+
webex.setTimingsAndFetch = sinon.stub();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
sinon.restore();
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('submits Client Event successfully', () => {
|
|
80
|
+
webex.internal.newMetrics.submitClientEvent({
|
|
81
|
+
name: 'client.alert.displayed',
|
|
82
|
+
options: {
|
|
83
|
+
meetingId: '123',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, {
|
|
88
|
+
key: 'client.alert.displayed',
|
|
89
|
+
options: {meetingId: '123'},
|
|
90
|
+
});
|
|
91
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent, {
|
|
92
|
+
name: 'client.alert.displayed',
|
|
93
|
+
payload: undefined,
|
|
94
|
+
options: {meetingId: '123'},
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
it('submits MQE successfully', () => {
|
|
100
|
+
webex.internal.newMetrics.submitMQE({
|
|
101
|
+
name: 'client.mediaquality.event',
|
|
102
|
+
//@ts-ignore
|
|
103
|
+
payload: {intervals: [{}]},
|
|
104
|
+
options: {
|
|
105
|
+
meetingId: '123',
|
|
106
|
+
networkType: 'wifi',
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, {
|
|
111
|
+
key: 'client.mediaquality.event',
|
|
112
|
+
});
|
|
113
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitMQE, {
|
|
114
|
+
name: 'client.mediaquality.event',
|
|
115
|
+
//@ts-ignore
|
|
116
|
+
payload: {intervals: [{}]},
|
|
117
|
+
options: {
|
|
118
|
+
meetingId: '123',
|
|
119
|
+
networkType: 'wifi',
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('submits Internal Event successfully', () => {
|
|
125
|
+
webex.internal.newMetrics.submitInternalEvent({
|
|
126
|
+
name: 'client.mediaquality.event',
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, {
|
|
130
|
+
key: 'client.mediaquality.event',
|
|
131
|
+
});
|
|
132
|
+
assert.notCalled(webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('submits Internal Event successfully for clearing the join latencies', () => {
|
|
136
|
+
webex.internal.newMetrics.submitInternalEvent({
|
|
137
|
+
name: 'internal.reset.join.latencies',
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
assert.notCalled(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp);
|
|
141
|
+
assert.calledOnce(webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('#clientMetricsAliasUser', () => {
|
|
145
|
+
it('aliases the user correctly', async () => {
|
|
146
|
+
webex.request.resolves({response: 'abc'});
|
|
147
|
+
await webex.internal.newMetrics.clientMetricsAliasUser('my-id');
|
|
148
|
+
assert.calledWith(webex.request, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
api: 'metrics',
|
|
151
|
+
resource: 'clientmetrics',
|
|
152
|
+
headers: { 'x-prelogin-userid': 'my-id' },
|
|
153
|
+
body: {},
|
|
154
|
+
qs: { alias: true },
|
|
155
|
+
});
|
|
156
|
+
assert.calledWith(
|
|
157
|
+
webex.logger.log,
|
|
158
|
+
'NewMetrics: @clientMetricsAliasUser. Request successful.'
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('handles failed request correctly', async () => {
|
|
163
|
+
webex.request.rejects(new Error("test error"));
|
|
164
|
+
sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError')
|
|
165
|
+
try {
|
|
166
|
+
await webex.internal.newMetrics.clientMetricsAliasUser({event: 'test'}, 'my-id');
|
|
167
|
+
} catch (err) {
|
|
168
|
+
assert.calledWith(
|
|
169
|
+
webex.logger.error,
|
|
170
|
+
'NewMetrics: @clientMetricsAliasUser. Request failed:',
|
|
171
|
+
`err: formattedError`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('#buildClientEventFetchRequestOptions', () => {
|
|
178
|
+
it('builds client event fetch options successfully', () => {
|
|
179
|
+
webex.internal.newMetrics.buildClientEventFetchRequestOptions({
|
|
180
|
+
name: 'client.alert.displayed',
|
|
181
|
+
options: {
|
|
182
|
+
meetingId: '123',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
assert.calledWith(
|
|
187
|
+
webex.internal.newMetrics.callDiagnosticMetrics.buildClientEventFetchRequestOptions,
|
|
188
|
+
{
|
|
189
|
+
name: 'client.alert.displayed',
|
|
190
|
+
payload: undefined,
|
|
191
|
+
options: {meetingId: '123'},
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('#setMetricTimingsAndFetch', () => {
|
|
198
|
+
beforeEach(() => {
|
|
199
|
+
global.fetch = sinon.stub();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('calls fetch with the expected options', () => {
|
|
203
|
+
const now = new Date();
|
|
204
|
+
sinon.useFakeTimers(now.getTime());
|
|
205
|
+
|
|
206
|
+
webex.internal.newMetrics.setMetricTimingsAndFetch({
|
|
207
|
+
json: true,
|
|
208
|
+
body: JSON.stringify({metrics: [{eventPayload: {}}]}),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const expected = {
|
|
212
|
+
json: true,
|
|
213
|
+
body: JSON.stringify({
|
|
214
|
+
metrics: [
|
|
215
|
+
{
|
|
216
|
+
eventPayload: {
|
|
217
|
+
originTime: {
|
|
218
|
+
triggered: now.toISOString(),
|
|
219
|
+
sent: now.toISOString(),
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
}),
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
sinon.assert.calledOnce(webex.setTimingsAndFetch);
|
|
228
|
+
sinon.assert.calledWith(webex.setTimingsAndFetch, expected);
|
|
229
|
+
|
|
230
|
+
sinon.restore();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import {config, Utils} from '@webex/internal-plugin-metrics';
|
|
7
|
+
import {CallDiagnosticUtils} from '@webex/internal-plugin-metrics';
|
|
8
|
+
import MockWebex from '@webex/test-helper-mock-webex';
|
|
9
|
+
import sinon from 'sinon';
|
|
10
|
+
import FakeTimers from '@sinonjs/fake-timers';
|
|
11
|
+
import {NewMetrics} from '@webex/internal-plugin-metrics';
|
|
12
|
+
import {uniqueId} from 'lodash';
|
|
13
|
+
|
|
14
|
+
const flushPromises = () => new Promise(setImmediate);
|
|
15
|
+
|
|
16
|
+
describe('internal-plugin-metrics', () => {
|
|
17
|
+
describe('PreLoginMetricsBatcher', () => {
|
|
18
|
+
let webex;
|
|
19
|
+
let clock;
|
|
20
|
+
let now;
|
|
21
|
+
|
|
22
|
+
const preLoginId = 'my_prelogin_id';
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
now = new Date();
|
|
26
|
+
clock = FakeTimers.install({now});
|
|
27
|
+
|
|
28
|
+
//@ts-ignore
|
|
29
|
+
webex = new MockWebex({
|
|
30
|
+
children: {
|
|
31
|
+
newMetrics: NewMetrics,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
webex.request = (options) =>
|
|
36
|
+
Promise.resolve({body: {items: []}, waitForServiceTimeout: 15, options});
|
|
37
|
+
|
|
38
|
+
sinon.spy(webex, 'request');
|
|
39
|
+
webex.emit('ready');
|
|
40
|
+
webex.config.metrics = config.metrics;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
sinon.restore();
|
|
45
|
+
clock.uninstall();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('#request()', () => {
|
|
49
|
+
it('when the request completes successfully, clears the queue', async () => {
|
|
50
|
+
const promise =
|
|
51
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
|
|
52
|
+
//@ts-ignore
|
|
53
|
+
{event: {name: 'client.interstitial-window.launched'}},
|
|
54
|
+
preLoginId
|
|
55
|
+
);
|
|
56
|
+
await flushPromises();
|
|
57
|
+
clock.tick(config.metrics.batcherWait);
|
|
58
|
+
|
|
59
|
+
await promise;
|
|
60
|
+
|
|
61
|
+
const webexRequestArgs = webex.request.args[0][0];
|
|
62
|
+
|
|
63
|
+
const dateAfterBatcherWait = new Date(now.getTime() + config.metrics.batcherWait);
|
|
64
|
+
//@ts-ignore
|
|
65
|
+
assert.calledOnce(webex.request);
|
|
66
|
+
|
|
67
|
+
// matching because the request includes a symbol key: value pair and sinon cannot handle to compare it..
|
|
68
|
+
assert.match(webexRequestArgs, {
|
|
69
|
+
body: {
|
|
70
|
+
metrics: [
|
|
71
|
+
{
|
|
72
|
+
eventPayload: {
|
|
73
|
+
event: {
|
|
74
|
+
joinTimes: {
|
|
75
|
+
meetingInfoReqResp: undefined,
|
|
76
|
+
clickToInterstitial: undefined,
|
|
77
|
+
},
|
|
78
|
+
name: 'client.interstitial-window.launched',
|
|
79
|
+
},
|
|
80
|
+
origin: {
|
|
81
|
+
buildType: 'test',
|
|
82
|
+
networkType: 'unknown',
|
|
83
|
+
},
|
|
84
|
+
originTime: {
|
|
85
|
+
sent: dateAfterBatcherWait.toISOString(),
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
type: ['diagnostic-event'],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
headers: {
|
|
93
|
+
authorization: false,
|
|
94
|
+
'x-prelogin-userid': preLoginId,
|
|
95
|
+
},
|
|
96
|
+
method: 'POST',
|
|
97
|
+
resource: 'clientmetrics-prelogin',
|
|
98
|
+
service: 'metrics',
|
|
99
|
+
waitForServiceTimeout: 30,
|
|
100
|
+
});
|
|
101
|
+
assert.lengthOf(
|
|
102
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.queue,
|
|
103
|
+
0
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('when the request fails, does not clear the queue', async () => {
|
|
108
|
+
webex.request = sinon.stub().rejects(new Error('my_error'));
|
|
109
|
+
|
|
110
|
+
webex.logger.error = sinon.stub();
|
|
111
|
+
webex.logger.log = sinon.stub();
|
|
112
|
+
sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError');
|
|
113
|
+
|
|
114
|
+
const promise =
|
|
115
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
|
|
116
|
+
{
|
|
117
|
+
event: 'my.event',
|
|
118
|
+
},
|
|
119
|
+
preLoginId
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
await flushPromises();
|
|
123
|
+
clock.tick(config.metrics.batcherWait);
|
|
124
|
+
|
|
125
|
+
let error;
|
|
126
|
+
|
|
127
|
+
// catch the expected error and store it
|
|
128
|
+
try {
|
|
129
|
+
await promise;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
error = err;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// This is horrific, but stubbing lodash is proving difficult
|
|
135
|
+
const expectedBatchId = parseInt(uniqueId()) - 1;
|
|
136
|
+
|
|
137
|
+
assert.equal(error.message, 'my_error');
|
|
138
|
+
assert.calledOnceWithExactly(
|
|
139
|
+
webex.logger.error,
|
|
140
|
+
'Pre Login Metrics -->',
|
|
141
|
+
`PreLoginMetricsBatcher: @submitHttpRequest#prelogin-ca-batch-${expectedBatchId}. Request failed:`,
|
|
142
|
+
`error: formattedError`
|
|
143
|
+
);
|
|
144
|
+
assert.lengthOf(
|
|
145
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.queue,
|
|
146
|
+
0
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('fails if preLoinId is not set', async () => {
|
|
151
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId = undefined;
|
|
152
|
+
|
|
153
|
+
const promise =
|
|
154
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
|
|
155
|
+
{
|
|
156
|
+
event: 'my.event',
|
|
157
|
+
},
|
|
158
|
+
undefined
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
await flushPromises();
|
|
162
|
+
clock.tick(config.metrics.batcherWait);
|
|
163
|
+
|
|
164
|
+
let error;
|
|
165
|
+
|
|
166
|
+
// catch the expected error and store it
|
|
167
|
+
try {
|
|
168
|
+
await promise;
|
|
169
|
+
} catch (err) {
|
|
170
|
+
error = err;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
assert.equal(error.message, 'PreLoginId is not set.');
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('prepareItem', () => {
|
|
178
|
+
it('calls prepareDiagnosticMetricItem correctly', async () => {
|
|
179
|
+
// avoid setting .sent timestamp
|
|
180
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.prepareRequest = (q) =>
|
|
181
|
+
Promise.resolve(q);
|
|
182
|
+
|
|
183
|
+
const prepareItemSpy = sinon.spy(
|
|
184
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher,
|
|
185
|
+
'prepareItem'
|
|
186
|
+
);
|
|
187
|
+
const prepareDiagnosticMetricItemSpy = sinon.spy(
|
|
188
|
+
CallDiagnosticUtils,
|
|
189
|
+
'prepareDiagnosticMetricItem'
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const promise =
|
|
193
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
|
|
194
|
+
{
|
|
195
|
+
event: 'my.event',
|
|
196
|
+
},
|
|
197
|
+
preLoginId
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
await flushPromises();
|
|
201
|
+
|
|
202
|
+
clock.tick(config.metrics.batcherWait);
|
|
203
|
+
|
|
204
|
+
await promise;
|
|
205
|
+
|
|
206
|
+
const calls = prepareItemSpy.getCalls()[0];
|
|
207
|
+
|
|
208
|
+
// item also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
|
|
209
|
+
assert.deepEqual(calls.args[0].eventPayload, {
|
|
210
|
+
event: 'my.event',
|
|
211
|
+
origin: {buildType: 'test', networkType: 'unknown'},
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
assert.deepEqual(calls.args[0].type, ['diagnostic-event']);
|
|
215
|
+
|
|
216
|
+
const prepareDiagnosticMetricItemCalls = prepareDiagnosticMetricItemSpy.getCalls();
|
|
217
|
+
|
|
218
|
+
// second argument (item) also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
|
|
219
|
+
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[0], webex);
|
|
220
|
+
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].eventPayload, {
|
|
221
|
+
event: 'my.event',
|
|
222
|
+
origin: {
|
|
223
|
+
buildType: 'test',
|
|
224
|
+
networkType: 'unknown',
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].type, ['diagnostic-event']);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
describe('savePreLoginId', () => {
|
|
232
|
+
it('saves the preLoginId', () => {
|
|
233
|
+
const preLoginId = 'my_prelogin_id';
|
|
234
|
+
|
|
235
|
+
assert.isUndefined(
|
|
236
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.savePreLoginId(
|
|
240
|
+
preLoginId
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
assert.equal(
|
|
244
|
+
webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId,
|
|
245
|
+
preLoginId
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|