@webex/internal-plugin-metrics 3.0.0-bnr.5 → 3.0.0-next.2
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/.eslintrc.js +6 -0
- package/babel.config.js +3 -0
- package/dist/batcher.js +41 -3
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +64 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +474 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +850 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +349 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +609 -0
- package/dist/call-diagnostic/config.js.map +1 -0
- package/dist/client-metrics-batcher.js +3 -3
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +6 -9
- package/dist/config.js.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +28 -22
- 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 +302 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/prelogin-metrics-batcher.js +81 -0
- package/dist/prelogin-metrics-batcher.js.map +1 -0
- package/dist/types/batcher.d.ts +5 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +204 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +427 -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/config.d.ts +18 -0
- package/dist/types/index.d.ts +15 -3
- package/dist/types/metrics.d.ts +1 -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 +26 -0
- package/dist/utils.js.map +1 -0
- package/jest.config.js +3 -0
- package/package.json +34 -10
- package/process +1 -0
- 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 +913 -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 +20 -16
- 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 +458 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +520 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2297 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +628 -0
- package/test/unit/spec/client-metrics-batcher.js +2 -0
- package/test/unit/spec/metrics.js +76 -95
- package/test/unit/spec/new-metrics.ts +233 -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/dist/internal-plugin-metrics.d.ts +0 -21
- package/dist/tsdoc-metadata.json +0 -11
- 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
- package/dist/types/{call-diagnostic-events-batcher.d.ts → call-diagnostic/call-diagnostic-metrics-batcher.d.ts} +1 -1
|
@@ -0,0 +1,458 @@
|
|
|
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
|
+
function promiseTick(count) {
|
|
17
|
+
let promise = Promise.resolve();
|
|
18
|
+
|
|
19
|
+
while (count > 1) {
|
|
20
|
+
promise = promise.then(() => promiseTick(1));
|
|
21
|
+
count -= 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return promise;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('plugin-metrics', () => {
|
|
28
|
+
describe('CallDiagnosticEventsBatcher', () => {
|
|
29
|
+
let webex;
|
|
30
|
+
let clock;
|
|
31
|
+
let now;
|
|
32
|
+
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
now = new Date();
|
|
35
|
+
clock = FakeTimers.install({now});
|
|
36
|
+
|
|
37
|
+
//@ts-ignore
|
|
38
|
+
webex = new MockWebex({
|
|
39
|
+
children: {
|
|
40
|
+
newMetrics: NewMetrics,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
webex.request = (options) =>
|
|
45
|
+
Promise.resolve({body: {items: []}, waitForServiceTimeout: 15, options});
|
|
46
|
+
sinon.spy(webex, 'request');
|
|
47
|
+
|
|
48
|
+
webex.emit('ready');
|
|
49
|
+
|
|
50
|
+
webex.config.metrics = config.metrics;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
sinon.restore();
|
|
55
|
+
clock.uninstall();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('#request()', () => {
|
|
59
|
+
describe('when the request completes successfully', () => {
|
|
60
|
+
it('clears the queue', async () => {
|
|
61
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
62
|
+
//@ts-ignore
|
|
63
|
+
{event: {name: 'client.interstitial-window.launched'}}
|
|
64
|
+
);
|
|
65
|
+
await flushPromises();
|
|
66
|
+
clock.tick(config.metrics.batcherWait);
|
|
67
|
+
|
|
68
|
+
await promise;
|
|
69
|
+
|
|
70
|
+
//@ts-ignore
|
|
71
|
+
assert.calledOnce(webex.request);
|
|
72
|
+
assert.lengthOf(
|
|
73
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
74
|
+
0
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('doesnt include any joinTimes for other events', async () => {
|
|
79
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
80
|
+
//@ts-ignore
|
|
81
|
+
{event: {name: 'client.alert.displayed'}}
|
|
82
|
+
);
|
|
83
|
+
await flushPromises();
|
|
84
|
+
clock.tick(config.metrics.batcherWait);
|
|
85
|
+
|
|
86
|
+
await promise;
|
|
87
|
+
|
|
88
|
+
//@ts-ignore
|
|
89
|
+
assert.calledOnce(webex.request);
|
|
90
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
91
|
+
name: 'client.alert.displayed',
|
|
92
|
+
});
|
|
93
|
+
assert.lengthOf(
|
|
94
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
95
|
+
0
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('appends the correct join times to the request for client.interstitial-window.launched', async () => {
|
|
100
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
101
|
+
.stub()
|
|
102
|
+
.returns(10);
|
|
103
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getClickToInterstitial = sinon
|
|
104
|
+
.stub()
|
|
105
|
+
.returns(10);
|
|
106
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
107
|
+
//@ts-ignore
|
|
108
|
+
{event: {name: 'client.interstitial-window.launched'}}
|
|
109
|
+
);
|
|
110
|
+
await flushPromises();
|
|
111
|
+
clock.tick(config.metrics.batcherWait);
|
|
112
|
+
|
|
113
|
+
await promise;
|
|
114
|
+
|
|
115
|
+
//@ts-ignore
|
|
116
|
+
assert.calledOnce(webex.request);
|
|
117
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
118
|
+
name: 'client.interstitial-window.launched',
|
|
119
|
+
joinTimes: {
|
|
120
|
+
clickToInterstitial: 10,
|
|
121
|
+
meetingInfoReqResp: 10,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
assert.lengthOf(
|
|
125
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
126
|
+
0
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('appends the correct join times to the request for client.call.initiated', async () => {
|
|
131
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
132
|
+
.stub()
|
|
133
|
+
.returns(10);
|
|
134
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
135
|
+
//@ts-ignore
|
|
136
|
+
{event: {name: 'client.call.initiated'}}
|
|
137
|
+
);
|
|
138
|
+
await flushPromises();
|
|
139
|
+
clock.tick(config.metrics.batcherWait);
|
|
140
|
+
|
|
141
|
+
await promise;
|
|
142
|
+
//@ts-ignore
|
|
143
|
+
assert.calledOnce(webex.request);
|
|
144
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
145
|
+
name: 'client.call.initiated',
|
|
146
|
+
joinTimes: {
|
|
147
|
+
meetingInfoReqResp: 10,
|
|
148
|
+
registerWDMDeviceJMT: 10,
|
|
149
|
+
showInterstitialTime: 10,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
assert.lengthOf(
|
|
153
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
154
|
+
0
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('appends the correct join times to the request for client.locus.join.response', async () => {
|
|
159
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
160
|
+
.stub()
|
|
161
|
+
.returns(10);
|
|
162
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getJoinRespSentReceived = sinon
|
|
163
|
+
.stub()
|
|
164
|
+
.returns(20);
|
|
165
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getPageJMT = sinon.stub().returns(30);
|
|
166
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getClientJMT = sinon.stub().returns(5);
|
|
167
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getClickToInterstitial = sinon
|
|
168
|
+
.stub()
|
|
169
|
+
.returns(10);
|
|
170
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getCallInitJoinReq = sinon
|
|
171
|
+
.stub()
|
|
172
|
+
.returns(10);
|
|
173
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDownloadTimeJMT = sinon
|
|
174
|
+
.stub()
|
|
175
|
+
.returns(100);
|
|
176
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
177
|
+
//@ts-ignore
|
|
178
|
+
{event: {name: 'client.locus.join.response'}}
|
|
179
|
+
);
|
|
180
|
+
await flushPromises();
|
|
181
|
+
clock.tick(config.metrics.batcherWait);
|
|
182
|
+
|
|
183
|
+
await promise;
|
|
184
|
+
|
|
185
|
+
//@ts-ignore
|
|
186
|
+
assert.calledOnce(webex.request);
|
|
187
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
188
|
+
name: 'client.locus.join.response',
|
|
189
|
+
joinTimes: {
|
|
190
|
+
callInitJoinReq: 10,
|
|
191
|
+
clickToInterstitial: 10,
|
|
192
|
+
interstitialToJoinOK: 10,
|
|
193
|
+
joinReqResp: 10,
|
|
194
|
+
joinReqSentReceived: 20,
|
|
195
|
+
meetingInfoReqResp: 10,
|
|
196
|
+
pageJmt: 30,
|
|
197
|
+
totalJmt: 20,
|
|
198
|
+
clientJmt: 5,
|
|
199
|
+
downloadTime: 100,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
assert.lengthOf(
|
|
203
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
204
|
+
0
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('appends the correct join times to the request for client.ice.end', async () => {
|
|
209
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
210
|
+
.stub()
|
|
211
|
+
.returns(10);
|
|
212
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
213
|
+
//@ts-ignore
|
|
214
|
+
{event: {name: 'client.ice.end'}}
|
|
215
|
+
);
|
|
216
|
+
await flushPromises();
|
|
217
|
+
clock.tick(config.metrics.batcherWait);
|
|
218
|
+
|
|
219
|
+
await promise;
|
|
220
|
+
|
|
221
|
+
//@ts-ignore
|
|
222
|
+
assert.calledOnce(webex.request);
|
|
223
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
224
|
+
name: 'client.ice.end',
|
|
225
|
+
joinTimes: {
|
|
226
|
+
ICESetupTime: 10,
|
|
227
|
+
audioICESetupTime: 10,
|
|
228
|
+
shareICESetupTime: 10,
|
|
229
|
+
videoICESetupTime: 10,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
assert.lengthOf(
|
|
233
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
234
|
+
0
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('appends the correct join times to the request for client.media.rx.start', async () => {
|
|
239
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
240
|
+
.stub()
|
|
241
|
+
.returns(10);
|
|
242
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
243
|
+
//@ts-ignore
|
|
244
|
+
{event: {name: 'client.media.rx.start'}}
|
|
245
|
+
);
|
|
246
|
+
await flushPromises();
|
|
247
|
+
clock.tick(config.metrics.batcherWait);
|
|
248
|
+
|
|
249
|
+
await promise;
|
|
250
|
+
|
|
251
|
+
//@ts-ignore
|
|
252
|
+
assert.calledOnce(webex.request);
|
|
253
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
254
|
+
name: 'client.media.rx.start',
|
|
255
|
+
joinTimes: {
|
|
256
|
+
localSDPGenRemoteSDPRecv: 10,
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
assert.lengthOf(
|
|
260
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
261
|
+
0
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('appends the correct join times to the request for client.media-engine.ready', async () => {
|
|
266
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
267
|
+
.stub()
|
|
268
|
+
.returns(10);
|
|
269
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getInterstitialToMediaOKJMT = sinon
|
|
270
|
+
.stub()
|
|
271
|
+
.returns(10);
|
|
272
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getClickToInterstitial = sinon
|
|
273
|
+
.stub()
|
|
274
|
+
.returns(10);
|
|
275
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
276
|
+
//@ts-ignore
|
|
277
|
+
{event: {name: 'client.media-engine.ready'}}
|
|
278
|
+
);
|
|
279
|
+
await flushPromises();
|
|
280
|
+
clock.tick(config.metrics.batcherWait);
|
|
281
|
+
|
|
282
|
+
await promise;
|
|
283
|
+
|
|
284
|
+
//@ts-ignore
|
|
285
|
+
assert.calledOnce(webex.request);
|
|
286
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
287
|
+
name: 'client.media-engine.ready',
|
|
288
|
+
joinTimes: {
|
|
289
|
+
totalMediaJMT: 30,
|
|
290
|
+
interstitialToMediaOKJMT: 10,
|
|
291
|
+
callInitMediaEngineReady: 10,
|
|
292
|
+
stayLobbyTime: 10,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
assert.lengthOf(
|
|
296
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
297
|
+
0
|
|
298
|
+
);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('appends the correct audio and video setup delays to the request for client.mediaquality.event', async () => {
|
|
302
|
+
webex.internal.newMetrics.callDiagnosticLatencies.getDiffBetweenTimestamps = sinon
|
|
303
|
+
.stub()
|
|
304
|
+
.returns(10);
|
|
305
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
306
|
+
//@ts-ignore
|
|
307
|
+
{event: {name: 'client.mediaquality.event'}}
|
|
308
|
+
);
|
|
309
|
+
await flushPromises();
|
|
310
|
+
clock.tick(config.metrics.batcherWait);
|
|
311
|
+
|
|
312
|
+
await promise;
|
|
313
|
+
|
|
314
|
+
//@ts-ignore
|
|
315
|
+
assert.calledOnce(webex.request);
|
|
316
|
+
assert.deepEqual(webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event, {
|
|
317
|
+
name: 'client.mediaquality.event',
|
|
318
|
+
audioSetupDelay: {
|
|
319
|
+
joinRespRxStart: 10,
|
|
320
|
+
joinRespTxStart: 10,
|
|
321
|
+
},
|
|
322
|
+
videoSetupDelay: {
|
|
323
|
+
joinRespRxStart: 10,
|
|
324
|
+
joinRespTxStart: 10,
|
|
325
|
+
},
|
|
326
|
+
});
|
|
327
|
+
assert.lengthOf(
|
|
328
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
329
|
+
0
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('doesnt include audioSetup and videoSetup delays for other events', async () => {
|
|
334
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics(
|
|
335
|
+
//@ts-ignore
|
|
336
|
+
{event: {name: 'client.alert.displayed'}}
|
|
337
|
+
);
|
|
338
|
+
await flushPromises();
|
|
339
|
+
clock.tick(config.metrics.batcherWait);
|
|
340
|
+
|
|
341
|
+
await promise;
|
|
342
|
+
|
|
343
|
+
//@ts-ignore
|
|
344
|
+
assert.calledOnce(webex.request);
|
|
345
|
+
assert.deepEqual(
|
|
346
|
+
webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event.audioSetupDelay,
|
|
347
|
+
undefined
|
|
348
|
+
);
|
|
349
|
+
assert.deepEqual(
|
|
350
|
+
webex.request.getCalls()[0].args[0].body.metrics[0].eventPayload.event.videoSetupDelay,
|
|
351
|
+
undefined
|
|
352
|
+
);
|
|
353
|
+
assert.lengthOf(
|
|
354
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
355
|
+
0
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
//TODO: The following two skipped tests needs investigation: https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-485382
|
|
361
|
+
describe('when the request fails', () => {
|
|
362
|
+
it.skip('does not clear the queue', async () => {
|
|
363
|
+
// avoid setting .sent timestamp
|
|
364
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.prepareRequest =
|
|
365
|
+
(q) => Promise.resolve(q);
|
|
366
|
+
|
|
367
|
+
const err = new Error('error');
|
|
368
|
+
webex.request = sinon.stub().returns(Promise.reject(err));
|
|
369
|
+
|
|
370
|
+
webex.logger.error = sinon.stub();
|
|
371
|
+
webex.logger.log = sinon.stub();
|
|
372
|
+
sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError');
|
|
373
|
+
|
|
374
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics({
|
|
375
|
+
event: 'my.event',
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
await flushPromises();
|
|
379
|
+
clock.tick(config.metrics.batcherWait);
|
|
380
|
+
|
|
381
|
+
let error;
|
|
382
|
+
|
|
383
|
+
// catch the expected error and store it
|
|
384
|
+
await promise.catch((e) => {
|
|
385
|
+
error = e;
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// This is horrific, but stubbing lodash is proving difficult
|
|
389
|
+
const expectedBatchId = parseInt(uniqueId()) - 1;
|
|
390
|
+
|
|
391
|
+
// check that promise was rejected with the original error of the webex.request
|
|
392
|
+
assert.deepEqual(err, error);
|
|
393
|
+
|
|
394
|
+
assert.calledOnceWithExactly(
|
|
395
|
+
webex.logger.error,
|
|
396
|
+
'call-diagnostic-events -> ',
|
|
397
|
+
`CallDiagnosticEventsBatcher: @submitHttpRequest#ca-batch-${expectedBatchId}. Request failed:`,
|
|
398
|
+
`error: formattedError`
|
|
399
|
+
);
|
|
400
|
+
assert.lengthOf(
|
|
401
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.queue,
|
|
402
|
+
0
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
describe('prepareItem', () => {
|
|
409
|
+
it.skip('calls prepareDiagnosticMetricItem correctly', async () => {
|
|
410
|
+
// avoid setting .sent timestamp
|
|
411
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher.prepareRequest =
|
|
412
|
+
(q) => Promise.resolve(q);
|
|
413
|
+
|
|
414
|
+
const prepareItemSpy = sinon.spy(
|
|
415
|
+
webex.internal.newMetrics.callDiagnosticMetrics.callDiagnosticEventsBatcher,
|
|
416
|
+
'prepareItem'
|
|
417
|
+
);
|
|
418
|
+
const prepareDiagnosticMetricItemSpy = sinon.spy(
|
|
419
|
+
CallDiagnosticUtils,
|
|
420
|
+
'prepareDiagnosticMetricItem'
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
const promise = webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnostics({
|
|
424
|
+
event: 'my.event',
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
await flushPromises();
|
|
428
|
+
|
|
429
|
+
clock.tick(config.metrics.batcherWait);
|
|
430
|
+
|
|
431
|
+
await promise;
|
|
432
|
+
|
|
433
|
+
const calls = prepareItemSpy.getCalls()[0];
|
|
434
|
+
|
|
435
|
+
// item also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
|
|
436
|
+
assert.deepEqual(calls.args[0].eventPayload, {
|
|
437
|
+
event: 'my.event',
|
|
438
|
+
origin: {buildType: 'test', networkType: 'unknown'},
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
assert.deepEqual(calls.args[0].type, ['diagnostic-event']);
|
|
442
|
+
|
|
443
|
+
const prepareDiagnosticMetricItemCalls = prepareDiagnosticMetricItemSpy.getCalls();
|
|
444
|
+
|
|
445
|
+
// second argument (item) also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
|
|
446
|
+
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[0], webex);
|
|
447
|
+
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].eventPayload, {
|
|
448
|
+
event: 'my.event',
|
|
449
|
+
origin: {
|
|
450
|
+
buildType: 'test',
|
|
451
|
+
networkType: 'unknown',
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].type, ['diagnostic-event']);
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
});
|