@webex/internal-plugin-metrics 3.0.0-beta.22 → 3.0.0-beta.220
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/call-diagnostic/call-diagnostic-metrics-batcher.js +56 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +451 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +645 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +276 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +580 -0
- package/dist/call-diagnostic/config.js.map +1 -0
- package/dist/call-diagnostic/generated-types-temp/ClientEvent.js +7 -0
- package/dist/call-diagnostic/generated-types-temp/ClientEvent.js.map +1 -0
- package/dist/call-diagnostic/generated-types-temp/Event.js +7 -0
- package/dist/call-diagnostic/generated-types-temp/Event.js.map +1 -0
- package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js +7 -0
- package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js.map +1 -0
- package/dist/config.js +20 -1
- package/dist/config.js.map +1 -1
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +30 -30
- 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 +249 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/types/batcher.d.ts +2 -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 +189 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +356 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +73 -0
- package/dist/types/call-diagnostic/config.d.ts +86 -0
- package/dist/types/call-diagnostic/generated-types-temp/ClientEvent.d.ts +1112 -0
- package/dist/types/call-diagnostic/generated-types-temp/Event.d.ts +4851 -0
- package/dist/types/call-diagnostic/generated-types-temp/MediaQualityEvent.d.ts +2121 -0
- package/dist/types/client-metrics-batcher.d.ts +2 -0
- package/dist/types/config.d.ts +35 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/metrics.d.ts +3 -0
- package/dist/types/metrics.types.d.ts +95 -0
- package/dist/types/new-metrics.d.ts +119 -0
- package/package.json +12 -8
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +51 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +408 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +655 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +280 -0
- package/src/call-diagnostic/config.ts +578 -0
- package/src/call-diagnostic/generated-types-temp/ClientEvent.ts +2395 -0
- package/src/call-diagnostic/generated-types-temp/Event.ts +7762 -0
- package/src/call-diagnostic/generated-types-temp/MediaQualityEvent.ts +2321 -0
- package/src/config.js +19 -0
- package/src/index.ts +41 -0
- package/src/metrics.js +25 -27
- package/src/metrics.types.ts +140 -0
- package/src/new-metrics.ts +223 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +243 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +474 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1015 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +454 -0
- package/test/unit/spec/metrics.js +65 -97
- package/test/unit/spec/new-metrics.ts +155 -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
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import {assert} from '@webex/test-helper-chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import {
|
|
4
|
+
clearEmptyKeysRecursively,
|
|
5
|
+
extractVersionMetadata,
|
|
6
|
+
getBuildType,
|
|
7
|
+
isBrowserMediaErrorName,
|
|
8
|
+
isLocusServiceErrorCode,
|
|
9
|
+
isMeetingInfoServiceError,
|
|
10
|
+
prepareDiagnosticMetricItem,
|
|
11
|
+
setMetricTimings,
|
|
12
|
+
} from '../../../../src/call-diagnostic/call-diagnostic-metrics.util';
|
|
13
|
+
import CallDiagnosticLatencies from '../../../../src/call-diagnostic/call-diagnostic-metrics-latencies';
|
|
14
|
+
|
|
15
|
+
describe('internal-plugin-metrics', () => {
|
|
16
|
+
describe('clearEmptyKeysRecursively', () => {
|
|
17
|
+
it('should clear empty objects and empty nested objects recursively', () => {
|
|
18
|
+
const obj: any = {
|
|
19
|
+
foo: '',
|
|
20
|
+
bar: {},
|
|
21
|
+
baz: [],
|
|
22
|
+
nested: {
|
|
23
|
+
prop: {},
|
|
24
|
+
arr: ['test'],
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
clearEmptyKeysRecursively(obj);
|
|
28
|
+
console.log(obj);
|
|
29
|
+
assert.deepEqual(obj, {nested: {arr: ['test']}});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should not modify non-empty objects and arrays', () => {
|
|
33
|
+
const obj = {
|
|
34
|
+
foo: 'bar',
|
|
35
|
+
arr: [1, 2, 3],
|
|
36
|
+
};
|
|
37
|
+
clearEmptyKeysRecursively(obj);
|
|
38
|
+
assert.deepEqual(obj, {foo: 'bar', arr: [1, 2, 3]});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should not modify non-object and non-array values', () => {
|
|
42
|
+
const obj = {
|
|
43
|
+
prop1: 'value1',
|
|
44
|
+
prop2: 123,
|
|
45
|
+
};
|
|
46
|
+
clearEmptyKeysRecursively(obj);
|
|
47
|
+
assert.deepEqual(obj, {prop1: 'value1', prop2: 123});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should handle nested empty objects and arrays', () => {
|
|
51
|
+
const obj: any = {
|
|
52
|
+
foo: {
|
|
53
|
+
bar: {},
|
|
54
|
+
baz: [],
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
clearEmptyKeysRecursively(obj);
|
|
58
|
+
assert.deepEqual(obj, {foo: {}});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should handle an empty input object', () => {
|
|
62
|
+
const obj = {};
|
|
63
|
+
clearEmptyKeysRecursively(obj);
|
|
64
|
+
assert.deepEqual(obj, {});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('isLocusServiceErrorCode', () => {
|
|
69
|
+
[
|
|
70
|
+
[10000, false],
|
|
71
|
+
[2400000, true],
|
|
72
|
+
['2400000', true],
|
|
73
|
+
[2400001, true],
|
|
74
|
+
['2400001', true],
|
|
75
|
+
[240000, false],
|
|
76
|
+
[14000000, false],
|
|
77
|
+
].forEach(([error, expected]) => {
|
|
78
|
+
it(`for code ${error} returns the correct result`, () => {
|
|
79
|
+
//@ts-ignore
|
|
80
|
+
assert.deepEqual(isLocusServiceErrorCode(error), expected);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('isMeetingInfoServiceError', () => {
|
|
86
|
+
[
|
|
87
|
+
[{body: {data: {meetingInfo: 'something'}}}, true],
|
|
88
|
+
[{body: {url: 'abcde-123-wbxappapi-efgh'}}, true],
|
|
89
|
+
[{body: {data: {meetingInformation: 'something'}}}, false],
|
|
90
|
+
[{body: {uri: 'abcde-123-wbxappap-efgh'}}, false],
|
|
91
|
+
['2400001', false],
|
|
92
|
+
[2400001, false],
|
|
93
|
+
[{}, false],
|
|
94
|
+
].forEach(([rawError, expected]) => {
|
|
95
|
+
it(`for rawError ${rawError} returns the correct result`, () => {
|
|
96
|
+
//@ts-ignore
|
|
97
|
+
assert.deepEqual(isMeetingInfoServiceError(rawError), expected);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('isBrowserMediaErrorName', () => {
|
|
103
|
+
[
|
|
104
|
+
['PermissionDeniedError', true],
|
|
105
|
+
['PermissionDeniedErrors', false],
|
|
106
|
+
['NotAllowedError', true],
|
|
107
|
+
['NotAllowedErrors', false],
|
|
108
|
+
['NotReadableError', true],
|
|
109
|
+
['NotReadableErrors', false],
|
|
110
|
+
['AbortError', true],
|
|
111
|
+
['AbortErrors', false],
|
|
112
|
+
['NotFoundError', true],
|
|
113
|
+
['NotFoundErrors', false],
|
|
114
|
+
['OverconstrainedError', true],
|
|
115
|
+
['OverconstrainedErrors', false],
|
|
116
|
+
['SecurityError', true],
|
|
117
|
+
['SecurityErrors', false],
|
|
118
|
+
['TypeError', true],
|
|
119
|
+
['TypeErrors', false],
|
|
120
|
+
['', false],
|
|
121
|
+
['SomethingElse', false],
|
|
122
|
+
[{name: 'SomethingElse'}, false],
|
|
123
|
+
|
|
124
|
+
].forEach(([errorName, expected]) => {
|
|
125
|
+
it(`for rawError ${errorName} returns the correct result`, () => {
|
|
126
|
+
//@ts-ignore
|
|
127
|
+
assert.deepEqual(isBrowserMediaErrorName(errorName), expected);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('getBuildType', () => {
|
|
133
|
+
beforeEach(() => {
|
|
134
|
+
process.env.NODE_ENV = 'production';
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
[
|
|
138
|
+
['https://localhost', 'test'],
|
|
139
|
+
['https://127.0.0.1', 'test'],
|
|
140
|
+
['https://web.webex.com', 'prod'],
|
|
141
|
+
].forEach(([webClientDomain, expected]) => {
|
|
142
|
+
it(`returns expected result for ${webClientDomain}`, () => {
|
|
143
|
+
assert.deepEqual(getBuildType(webClientDomain), expected);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('returns "test" for NODE_ENV "foo"', () => {
|
|
148
|
+
process.env.NODE_ENV = 'foo';
|
|
149
|
+
assert.deepEqual(getBuildType('production'), 'test');
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('prepareDiagnosticMetricItem', async () => {
|
|
154
|
+
let webex: any;
|
|
155
|
+
|
|
156
|
+
const check = (eventName: string, expectedEvent: any) => {
|
|
157
|
+
const eventPayload = {event: {name: eventName}};
|
|
158
|
+
const item = prepareDiagnosticMetricItem(webex, {
|
|
159
|
+
eventPayload,
|
|
160
|
+
type: ['diagnostic-event'],
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
assert.deepEqual(item, {
|
|
164
|
+
eventPayload: {
|
|
165
|
+
origin: {
|
|
166
|
+
buildType: 'prod',
|
|
167
|
+
networkType: 'unknown',
|
|
168
|
+
},
|
|
169
|
+
event: {name: eventName, ...expectedEvent},
|
|
170
|
+
},
|
|
171
|
+
type: ['diagnostic-event'],
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
before(async () => {
|
|
176
|
+
webex = {internal: {newMetrics: {}}};
|
|
177
|
+
webex.internal.newMetrics.callDiagnosticLatencies = new CallDiagnosticLatencies(
|
|
178
|
+
{},
|
|
179
|
+
{parent: webex}
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
beforeEach(() => {
|
|
184
|
+
process.env.NODE_ENV = 'production';
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
afterEach(() => {
|
|
188
|
+
process.env.NODE_ENV = 'test';
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
[
|
|
192
|
+
['client.exit.app', {}],
|
|
193
|
+
[
|
|
194
|
+
'client.interstitial-window.launched',
|
|
195
|
+
{
|
|
196
|
+
joinTimes: {
|
|
197
|
+
clickToInterstitial: undefined,
|
|
198
|
+
meetingInfoReqResp: undefined,
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
[
|
|
203
|
+
'client.call.initiated',
|
|
204
|
+
{
|
|
205
|
+
joinTimes: {
|
|
206
|
+
showInterstitialTime: undefined,
|
|
207
|
+
meetingInfoReqResp: undefined,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
'client.locus.join.response',
|
|
213
|
+
{
|
|
214
|
+
joinTimes: {
|
|
215
|
+
meetingInfoReqResp: undefined,
|
|
216
|
+
callInitJoinReq: undefined,
|
|
217
|
+
joinReqResp: undefined,
|
|
218
|
+
joinReqSentReceived: undefined,
|
|
219
|
+
pageJmt: undefined,
|
|
220
|
+
clickToInterstitial: undefined,
|
|
221
|
+
interstitialToJoinOK: undefined,
|
|
222
|
+
totalJmt: undefined,
|
|
223
|
+
clientJmt: undefined,
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
[
|
|
228
|
+
'client.ice.end',
|
|
229
|
+
{
|
|
230
|
+
joinTimes: {
|
|
231
|
+
ICESetupTime: undefined,
|
|
232
|
+
audioICESetupTime: undefined,
|
|
233
|
+
videoICESetupTime: undefined,
|
|
234
|
+
shareICESetupTime: undefined,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
'client.media.rx.start',
|
|
240
|
+
{
|
|
241
|
+
joinTimes: {
|
|
242
|
+
localSDPGenRemoteSDPRecv: undefined,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
'client.media-engine.ready',
|
|
248
|
+
{
|
|
249
|
+
joinTimes: {
|
|
250
|
+
totalMediaJMT: undefined,
|
|
251
|
+
interstitialToMediaOKJMT: undefined,
|
|
252
|
+
callInitMediaEngineReady: undefined,
|
|
253
|
+
stayLobbyTime: undefined,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
[
|
|
258
|
+
'client.mediaquality.event',
|
|
259
|
+
{
|
|
260
|
+
audioSetupDelay: {
|
|
261
|
+
joinRespRxStart: undefined,
|
|
262
|
+
joinRespTxStart: undefined,
|
|
263
|
+
},
|
|
264
|
+
videoSetupDelay: {
|
|
265
|
+
joinRespRxStart: undefined,
|
|
266
|
+
joinRespTxStart: undefined,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
].forEach(([eventName, expectedEvent]) => {
|
|
271
|
+
it(`returns expected result for ${eventName}`, () => {
|
|
272
|
+
check(eventName as string, expectedEvent);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('setMetricTimings', async () => {
|
|
278
|
+
let webex: any;
|
|
279
|
+
|
|
280
|
+
const check = (options: any, expectedOptions: any) => {
|
|
281
|
+
const newOptions = setMetricTimings(options);
|
|
282
|
+
|
|
283
|
+
assert.deepEqual(newOptions, expectedOptions);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
it(`returns expected options`, () => {
|
|
287
|
+
const now = new Date();
|
|
288
|
+
sinon.useFakeTimers(now.getTime());
|
|
289
|
+
|
|
290
|
+
const options = {
|
|
291
|
+
json: true,
|
|
292
|
+
body: JSON.stringify({
|
|
293
|
+
metrics: [
|
|
294
|
+
{
|
|
295
|
+
eventPayload: {
|
|
296
|
+
originTime: {
|
|
297
|
+
triggered: 555,
|
|
298
|
+
sent: 666,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
}),
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const expectedOptions = {
|
|
307
|
+
json: true,
|
|
308
|
+
body: JSON.stringify({
|
|
309
|
+
metrics: [
|
|
310
|
+
{
|
|
311
|
+
eventPayload: {
|
|
312
|
+
originTime: {
|
|
313
|
+
triggered: now.toISOString(),
|
|
314
|
+
sent: now.toISOString(),
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
}),
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
check(options, expectedOptions);
|
|
323
|
+
sinon.restore();
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it(`returns expected options for multiple metrics`, () => {
|
|
327
|
+
const now = new Date();
|
|
328
|
+
sinon.useFakeTimers(now.getTime());
|
|
329
|
+
|
|
330
|
+
const options = {
|
|
331
|
+
json: true,
|
|
332
|
+
body: JSON.stringify({
|
|
333
|
+
metrics: [
|
|
334
|
+
{
|
|
335
|
+
eventPayload: {
|
|
336
|
+
originTime: {
|
|
337
|
+
triggered: 555,
|
|
338
|
+
sent: 666,
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
eventPayload: {
|
|
344
|
+
originTime: {
|
|
345
|
+
triggered: 777,
|
|
346
|
+
sent: 888,
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
}),
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
const expectedOptions = {
|
|
355
|
+
json: true,
|
|
356
|
+
body: JSON.stringify({
|
|
357
|
+
metrics: [
|
|
358
|
+
{
|
|
359
|
+
eventPayload: {
|
|
360
|
+
originTime: {
|
|
361
|
+
triggered: now.toISOString(),
|
|
362
|
+
sent: now.toISOString(),
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
eventPayload: {
|
|
368
|
+
originTime: {
|
|
369
|
+
triggered: now.toISOString(),
|
|
370
|
+
sent: now.toISOString(),
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
],
|
|
375
|
+
}),
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
check(options, expectedOptions);
|
|
379
|
+
sinon.restore();
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it(`returns expected options when json is falsey`, () => {
|
|
383
|
+
const now = new Date();
|
|
384
|
+
sinon.useFakeTimers(now.getTime());
|
|
385
|
+
|
|
386
|
+
const options = {
|
|
387
|
+
body: JSON.stringify({
|
|
388
|
+
metrics: [
|
|
389
|
+
{
|
|
390
|
+
eventPayload: {
|
|
391
|
+
originTime: {
|
|
392
|
+
triggered: 555,
|
|
393
|
+
sent: 666,
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
}),
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const expectedOptions = {
|
|
402
|
+
body: JSON.stringify({
|
|
403
|
+
metrics: [
|
|
404
|
+
{
|
|
405
|
+
eventPayload: {
|
|
406
|
+
originTime: {
|
|
407
|
+
triggered: 555,
|
|
408
|
+
sent: 666,
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
}),
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
check(options, expectedOptions);
|
|
417
|
+
sinon.restore();
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it(`does not throw when there is no body`, () => {
|
|
421
|
+
const options = {};
|
|
422
|
+
|
|
423
|
+
const expectedOptions = {};
|
|
424
|
+
|
|
425
|
+
check(options, expectedOptions);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it(`does not throw when body is empty`, () => {
|
|
429
|
+
const options = {body: '"{}"'};
|
|
430
|
+
|
|
431
|
+
const expectedOptions = {body: '"{}"'};
|
|
432
|
+
|
|
433
|
+
check(options, expectedOptions);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe('extractVersionMetadata', () => {
|
|
438
|
+
[
|
|
439
|
+
['1.2.3', {majorVersion: 1, minorVersion: 2}],
|
|
440
|
+
['0.0.1', {majorVersion: 0, minorVersion: 0}],
|
|
441
|
+
['0.0.0', {majorVersion: 0, minorVersion: 0}],
|
|
442
|
+
['1.2', {majorVersion: 1, minorVersion: 2}],
|
|
443
|
+
['1', {majorVersion: 1, minorVersion: NaN}],
|
|
444
|
+
['foo', {majorVersion: NaN, minorVersion: NaN}],
|
|
445
|
+
['1.foo', {majorVersion: 1, minorVersion: NaN}],
|
|
446
|
+
['foo.1', {majorVersion: NaN, minorVersion: 1}],
|
|
447
|
+
['foo.bar', {majorVersion: NaN, minorVersion: NaN}],
|
|
448
|
+
].forEach(([version, expected]) => {
|
|
449
|
+
it(`returns expected result for ${version}`, () => {
|
|
450
|
+
assert.deepEqual(extractVersionMetadata(version as string), expected);
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
});
|
|
@@ -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();
|
|
@@ -102,7 +105,6 @@ describe('plugin-metrics', () => {
|
|
|
102
105
|
sinon.spy(webex, 'request');
|
|
103
106
|
sinon.spy(metrics, 'postPreLoginMetric');
|
|
104
107
|
sinon.spy(metrics, 'aliasUser');
|
|
105
|
-
sinon.spy(metrics, 'submitCallDiagnosticEvents');
|
|
106
108
|
});
|
|
107
109
|
|
|
108
110
|
describe('#submit()', () => {
|
|
@@ -131,6 +133,67 @@ describe('plugin-metrics', () => {
|
|
|
131
133
|
});
|
|
132
134
|
});
|
|
133
135
|
|
|
136
|
+
describe('#getClientMetricsPayload()', () => {
|
|
137
|
+
it('returns the expected payload', () => {
|
|
138
|
+
webex.credentials.supertoken = new Token(
|
|
139
|
+
{
|
|
140
|
+
access_token: 'a_b_orgid',
|
|
141
|
+
},
|
|
142
|
+
{parent: webex}
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const testPayload = {
|
|
146
|
+
tags: {success: true},
|
|
147
|
+
fields: {perceivedDurationInMillis: 314},
|
|
148
|
+
context: {},
|
|
149
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
150
|
+
};
|
|
151
|
+
const date = clock.now;
|
|
152
|
+
|
|
153
|
+
const result = metrics.getClientMetricsPayload('test', testPayload);
|
|
154
|
+
|
|
155
|
+
assert.deepEqual(result, {
|
|
156
|
+
context: {
|
|
157
|
+
app: {
|
|
158
|
+
version: undefined,
|
|
159
|
+
},
|
|
160
|
+
locale: 'en-US',
|
|
161
|
+
os: {
|
|
162
|
+
name: 'other',
|
|
163
|
+
version: getOSVersion(),
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
eventPayload: {
|
|
167
|
+
value: 'splunk business metric payload',
|
|
168
|
+
},
|
|
169
|
+
fields: {
|
|
170
|
+
browser_version: '',
|
|
171
|
+
client_id: 'fake',
|
|
172
|
+
os_version: getOSVersion(),
|
|
173
|
+
perceivedDurationInMillis: 314,
|
|
174
|
+
platform: 'Web',
|
|
175
|
+
sdk_version: undefined,
|
|
176
|
+
spark_user_agent: 'webex-js-sdk appName/appVersion appPlatform',
|
|
177
|
+
},
|
|
178
|
+
metricName: 'test',
|
|
179
|
+
tags: {
|
|
180
|
+
browser: '',
|
|
181
|
+
domain: 'whatever',
|
|
182
|
+
os: 'other',
|
|
183
|
+
success: true,
|
|
184
|
+
},
|
|
185
|
+
timestamp: 0,
|
|
186
|
+
type: ['operational'],
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('throws when no event name is specified', () => {
|
|
191
|
+
assert.throws(() => {
|
|
192
|
+
metrics.getClientMetricsPayload();
|
|
193
|
+
}, 'Missing behavioral metric name. Please provide one');
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
134
197
|
describe('#submitClientMetrics()', () => {
|
|
135
198
|
describe('before login', () => {
|
|
136
199
|
it('posts pre-login metric', () => {
|
|
@@ -199,17 +262,15 @@ describe('plugin-metrics', () => {
|
|
|
199
262
|
assert.property(metric, 'eventPayload');
|
|
200
263
|
|
|
201
264
|
assert.property(metric.tags, 'browser');
|
|
202
|
-
assert.property(metric.tags, 'org_id');
|
|
203
265
|
assert.property(metric.tags, 'os');
|
|
204
266
|
assert.property(metric.tags, 'domain');
|
|
205
|
-
assert.property(metric.tags, 'client_id');
|
|
206
|
-
assert.property(metric.tags, 'user_id');
|
|
207
267
|
|
|
208
268
|
assert.property(metric.fields, 'browser_version');
|
|
209
269
|
assert.property(metric.fields, 'os_version');
|
|
210
270
|
assert.property(metric.fields, 'sdk_version');
|
|
211
271
|
assert.property(metric.fields, 'platform');
|
|
212
272
|
assert.property(metric.fields, 'spark_user_agent');
|
|
273
|
+
assert.property(metric.fields, 'client_id');
|
|
213
274
|
|
|
214
275
|
assert.property(metric.context, 'app');
|
|
215
276
|
assert.property(metric.context, 'locale');
|
|
@@ -269,98 +330,5 @@ describe('plugin-metrics', () => {
|
|
|
269
330
|
assert.match(params, {alias: true});
|
|
270
331
|
}));
|
|
271
332
|
});
|
|
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
333
|
});
|
|
366
334
|
});
|