@webex/internal-plugin-metrics 3.0.0-beta.3 → 3.0.0-beta.300
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 +5 -23
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +66 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +456 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +798 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +337 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +604 -0
- package/dist/call-diagnostic/config.js.map +1 -0
- package/dist/client-metrics-batcher.js +3 -8
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +23 -6
- package/dist/config.js.map +1 -1
- package/dist/index.js +31 -10
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +43 -80
- 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 +333 -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 +194 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +405 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +96 -0
- package/dist/types/call-diagnostic/config.d.ts +171 -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 +13 -0
- package/dist/types/metrics.d.ts +3 -0
- package/dist/types/metrics.types.d.ts +103 -0
- package/dist/types/new-metrics.d.ts +139 -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 +13 -8
- package/src/batcher.js +34 -26
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +83 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +414 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +863 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
- package/src/call-diagnostic/config.ts +660 -0
- package/src/client-metrics-batcher.js +4 -4
- package/src/config.js +26 -5
- package/src/index.ts +43 -0
- package/src/metrics.js +44 -58
- package/src/metrics.types.ts +159 -0
- package/src/new-metrics.ts +317 -0
- package/src/utils.ts +17 -0
- package/test/unit/spec/batcher.js +28 -15
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +465 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +477 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1943 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
- package/test/unit/spec/client-metrics-batcher.js +28 -15
- package/test/unit/spec/metrics.js +86 -116
- package/test/unit/spec/new-metrics.ts +269 -0
- package/test/unit/spec/utils.ts +22 -0
- package/tsconfig.json +6 -0
- package/dist/call-diagnostic-events-batcher.js +0 -70
- 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 -180
|
@@ -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();
|
|
@@ -29,35 +32,35 @@ describe('plugin-metrics', () => {
|
|
|
29
32
|
const eventName = 'test_event';
|
|
30
33
|
const mockPayload = {
|
|
31
34
|
fields: {
|
|
32
|
-
testField: 123
|
|
35
|
+
testField: 123,
|
|
33
36
|
},
|
|
34
37
|
tags: {
|
|
35
|
-
testTag: 'tag value'
|
|
38
|
+
testTag: 'tag value',
|
|
36
39
|
},
|
|
37
40
|
metricName: eventName,
|
|
38
41
|
test: 'this field should not be included in final payload',
|
|
39
42
|
type: 'behavioral',
|
|
40
|
-
eventPayload: {value: 'splunk business metric payload'}
|
|
43
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
41
44
|
};
|
|
42
45
|
const transformedProps = {
|
|
43
46
|
fields: {
|
|
44
|
-
testField: 123
|
|
47
|
+
testField: 123,
|
|
45
48
|
},
|
|
46
49
|
tags: {
|
|
47
|
-
testTag: 'tag value'
|
|
50
|
+
testTag: 'tag value',
|
|
48
51
|
},
|
|
49
52
|
metricName: eventName,
|
|
50
53
|
type: 'behavioral',
|
|
51
|
-
timestamp: Date.now()
|
|
54
|
+
timestamp: Date.now(),
|
|
52
55
|
};
|
|
53
56
|
const preLoginId = '1b90cf5e-27a6-41aa-a208-1f6eb6b9e6b6';
|
|
54
57
|
const preLoginProps = {
|
|
55
|
-
metrics: [transformedProps]
|
|
58
|
+
metrics: [transformedProps],
|
|
56
59
|
};
|
|
57
60
|
const mockCallDiagnosticEvent = {
|
|
58
61
|
originTime: {
|
|
59
|
-
triggered: 'mock triggered timestamp'
|
|
60
|
-
}
|
|
62
|
+
triggered: 'mock triggered timestamp',
|
|
63
|
+
},
|
|
61
64
|
};
|
|
62
65
|
|
|
63
66
|
beforeEach(() => {
|
|
@@ -71,8 +74,8 @@ describe('plugin-metrics', () => {
|
|
|
71
74
|
beforeEach(() => {
|
|
72
75
|
webex = new MockWebex({
|
|
73
76
|
children: {
|
|
74
|
-
metrics: Metrics
|
|
75
|
-
}
|
|
77
|
+
metrics: Metrics,
|
|
78
|
+
},
|
|
76
79
|
});
|
|
77
80
|
|
|
78
81
|
webex.config.metrics = config.metrics;
|
|
@@ -82,7 +85,8 @@ describe('plugin-metrics', () => {
|
|
|
82
85
|
return Promise.resolve({
|
|
83
86
|
statusCode: 204,
|
|
84
87
|
body: undefined,
|
|
85
|
-
|
|
88
|
+
waitForServiceTimeout: 15,
|
|
89
|
+
options,
|
|
86
90
|
});
|
|
87
91
|
};
|
|
88
92
|
|
|
@@ -94,8 +98,7 @@ describe('plugin-metrics', () => {
|
|
|
94
98
|
...webex.config,
|
|
95
99
|
appName: 'appName',
|
|
96
100
|
appPlatform: 'appPlatform',
|
|
97
|
-
appVersion: 'appVersion'
|
|
98
|
-
|
|
101
|
+
appVersion: 'appVersion',
|
|
99
102
|
};
|
|
100
103
|
webex.config.metrics.type = ['operational'];
|
|
101
104
|
webex.config.metrics.appType = 'sdk';
|
|
@@ -103,7 +106,6 @@ describe('plugin-metrics', () => {
|
|
|
103
106
|
sinon.spy(webex, 'request');
|
|
104
107
|
sinon.spy(metrics, 'postPreLoginMetric');
|
|
105
108
|
sinon.spy(metrics, 'aliasUser');
|
|
106
|
-
sinon.spy(metrics, 'submitCallDiagnosticEvents');
|
|
107
109
|
});
|
|
108
110
|
|
|
109
111
|
describe('#submit()', () => {
|
|
@@ -132,6 +134,67 @@ describe('plugin-metrics', () => {
|
|
|
132
134
|
});
|
|
133
135
|
});
|
|
134
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
|
+
|
|
135
198
|
describe('#submitClientMetrics()', () => {
|
|
136
199
|
describe('before login', () => {
|
|
137
200
|
it('posts pre-login metric', () => {
|
|
@@ -167,15 +230,18 @@ describe('plugin-metrics', () => {
|
|
|
167
230
|
});
|
|
168
231
|
describe('after login', () => {
|
|
169
232
|
it('submits a metric to clientmetrics', () => {
|
|
170
|
-
webex.credentials.supertoken = new Token(
|
|
171
|
-
|
|
172
|
-
|
|
233
|
+
webex.credentials.supertoken = new Token(
|
|
234
|
+
{
|
|
235
|
+
access_token: 'a_b_orgid',
|
|
236
|
+
},
|
|
237
|
+
{parent: webex}
|
|
238
|
+
);
|
|
173
239
|
|
|
174
240
|
const testPayload = {
|
|
175
241
|
tags: {success: true},
|
|
176
242
|
fields: {perceivedDurationInMillis: 314},
|
|
177
243
|
context: {},
|
|
178
|
-
eventPayload: {value: 'splunk business metric payload'}
|
|
244
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
179
245
|
};
|
|
180
246
|
const date = clock.now;
|
|
181
247
|
|
|
@@ -197,23 +263,20 @@ describe('plugin-metrics', () => {
|
|
|
197
263
|
assert.property(metric, 'eventPayload');
|
|
198
264
|
|
|
199
265
|
assert.property(metric.tags, 'browser');
|
|
200
|
-
assert.property(metric.tags, 'org_id');
|
|
201
266
|
assert.property(metric.tags, 'os');
|
|
202
267
|
assert.property(metric.tags, 'domain');
|
|
203
|
-
assert.property(metric.tags, 'client_id');
|
|
204
|
-
assert.property(metric.tags, 'user_id');
|
|
205
268
|
|
|
206
269
|
assert.property(metric.fields, 'browser_version');
|
|
207
270
|
assert.property(metric.fields, 'os_version');
|
|
208
271
|
assert.property(metric.fields, 'sdk_version');
|
|
209
272
|
assert.property(metric.fields, 'platform');
|
|
210
273
|
assert.property(metric.fields, 'spark_user_agent');
|
|
274
|
+
assert.property(metric.fields, 'client_id');
|
|
211
275
|
|
|
212
276
|
assert.property(metric.context, 'app');
|
|
213
277
|
assert.property(metric.context, 'locale');
|
|
214
278
|
assert.property(metric.context, 'os');
|
|
215
279
|
|
|
216
|
-
|
|
217
280
|
assert.equal(metric.timestamp, date);
|
|
218
281
|
assert.equal(metric.metricName, 'test');
|
|
219
282
|
assert.equal(metric.tags.success, true);
|
|
@@ -268,98 +331,5 @@ describe('plugin-metrics', () => {
|
|
|
268
331
|
assert.match(params, {alias: true});
|
|
269
332
|
}));
|
|
270
333
|
});
|
|
271
|
-
|
|
272
|
-
describe('#submitCallDiagnosticEvents()', () => {
|
|
273
|
-
it('submits a call diagnostic event', () => {
|
|
274
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
275
|
-
|
|
276
|
-
return promiseTick(50)
|
|
277
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
278
|
-
.then(() => promise)
|
|
279
|
-
.then(() => {
|
|
280
|
-
assert.calledOnce(webex.request);
|
|
281
|
-
const req = webex.request.args[0][0];
|
|
282
|
-
const metric = req.body.metrics[0];
|
|
283
|
-
|
|
284
|
-
assert.property(metric.eventPayload, 'origin');
|
|
285
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
286
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
287
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
288
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
289
|
-
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('submits a call diagnostic event with buildType set in the payload', () => {
|
|
294
|
-
const promise = metrics.submitCallDiagnosticEvents({
|
|
295
|
-
...mockCallDiagnosticEvent,
|
|
296
|
-
origin: {
|
|
297
|
-
buildType: 'prod'
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
return promiseTick(50)
|
|
302
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
303
|
-
.then(() => promise)
|
|
304
|
-
.then(() => {
|
|
305
|
-
assert.calledOnce(webex.request);
|
|
306
|
-
const req = webex.request.args[0][0];
|
|
307
|
-
const metric = req.body.metrics[0];
|
|
308
|
-
|
|
309
|
-
assert.property(metric.eventPayload, 'origin');
|
|
310
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
311
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
312
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
313
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
314
|
-
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
xit('submits a call diagnostic event with a test domain', () => {
|
|
319
|
-
global.window.location.hostname = 'test.webex.com';
|
|
320
|
-
|
|
321
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
322
|
-
|
|
323
|
-
return promiseTick(50)
|
|
324
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
325
|
-
.then(() => promise)
|
|
326
|
-
.then(() => {
|
|
327
|
-
assert.calledOnce(webex.request);
|
|
328
|
-
const req = webex.request.args[0][0];
|
|
329
|
-
const metric = req.body.metrics[0];
|
|
330
|
-
|
|
331
|
-
assert.property(metric.eventPayload, 'origin');
|
|
332
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
333
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
334
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
335
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
336
|
-
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// Skip because it's current unable to overwrite NODE_ENV
|
|
341
|
-
// However doing `NODE_ENV=test npm run test ...` will get this test case to pass
|
|
342
|
-
xit('submits a call diagnostic event with a NODE_ENV=production', () => {
|
|
343
|
-
process.env.NODE_ENV = 'production';
|
|
344
|
-
|
|
345
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
346
|
-
|
|
347
|
-
return promiseTick(50)
|
|
348
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
349
|
-
.then(() => promise)
|
|
350
|
-
.then(() => {
|
|
351
|
-
assert.calledOnce(webex.request);
|
|
352
|
-
const req = webex.request.args[0][0];
|
|
353
|
-
const metric = req.body.metrics[0];
|
|
354
|
-
|
|
355
|
-
assert.property(metric.eventPayload, 'origin');
|
|
356
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
357
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
358
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
359
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
360
|
-
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
334
|
});
|
|
365
335
|
});
|
|
@@ -0,0 +1,269 @@
|
|
|
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.postPreLoginMetric = sinon.stub();
|
|
71
|
+
webex.internal.newMetrics.callDiagnosticMetrics.buildClientEventFetchRequestOptions =
|
|
72
|
+
sinon.stub();
|
|
73
|
+
webex.setTimingsAndFetch = sinon.stub();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
sinon.restore();
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('submits Client Event successfully', () => {
|
|
81
|
+
webex.internal.newMetrics.submitClientEvent({
|
|
82
|
+
name: 'client.alert.displayed',
|
|
83
|
+
options: {
|
|
84
|
+
meetingId: '123',
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, {
|
|
89
|
+
key: 'client.alert.displayed',
|
|
90
|
+
options: {meetingId: '123'},
|
|
91
|
+
});
|
|
92
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent, {
|
|
93
|
+
name: 'client.alert.displayed',
|
|
94
|
+
payload: undefined,
|
|
95
|
+
options: {meetingId: '123'},
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
it('submits MQE successfully', () => {
|
|
101
|
+
webex.internal.newMetrics.submitMQE({
|
|
102
|
+
name: 'client.mediaquality.event',
|
|
103
|
+
//@ts-ignore
|
|
104
|
+
payload: {intervals: [{}]},
|
|
105
|
+
options: {
|
|
106
|
+
meetingId: '123',
|
|
107
|
+
networkType: 'wifi',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, {
|
|
112
|
+
key: 'client.mediaquality.event',
|
|
113
|
+
});
|
|
114
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitMQE, {
|
|
115
|
+
name: 'client.mediaquality.event',
|
|
116
|
+
//@ts-ignore
|
|
117
|
+
payload: {intervals: [{}]},
|
|
118
|
+
options: {
|
|
119
|
+
meetingId: '123',
|
|
120
|
+
networkType: 'wifi',
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('submits Internal Event successfully', () => {
|
|
126
|
+
webex.internal.newMetrics.submitInternalEvent({
|
|
127
|
+
name: 'client.mediaquality.event',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, {
|
|
131
|
+
key: 'client.mediaquality.event',
|
|
132
|
+
});
|
|
133
|
+
assert.notCalled(webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('submits Internal Event successfully for clearing the join latencies', () => {
|
|
137
|
+
webex.internal.newMetrics.submitInternalEvent({
|
|
138
|
+
name: 'internal.reset.join.latencies',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
assert.notCalled(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp);
|
|
142
|
+
assert.calledOnce(webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('#clientMetricsAliasUser', () => {
|
|
146
|
+
it('aliases the user correctly', async () => {
|
|
147
|
+
webex.request.resolves({response: 'abc'});
|
|
148
|
+
await webex.internal.newMetrics.clientMetricsAliasUser('my-id');
|
|
149
|
+
assert.calledWith(webex.request, {
|
|
150
|
+
method: 'POST',
|
|
151
|
+
api: 'metrics',
|
|
152
|
+
resource: 'clientmetrics',
|
|
153
|
+
headers: { 'x-prelogin-userid': 'my-id' },
|
|
154
|
+
body: {},
|
|
155
|
+
qs: { alias: true },
|
|
156
|
+
});
|
|
157
|
+
assert.calledWith(
|
|
158
|
+
webex.logger.log,
|
|
159
|
+
'NewMetrics: @clientMetricsAliasUser. Request successful:',
|
|
160
|
+
{ response: 'abc' }
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('handles failed request correctly', async () => {
|
|
165
|
+
webex.request.rejects(new Error("test error"));
|
|
166
|
+
sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError')
|
|
167
|
+
try {
|
|
168
|
+
await webex.internal.newMetrics.clientMetricsAliasUser({event: 'test'}, 'my-id');
|
|
169
|
+
} catch (err) {
|
|
170
|
+
assert.calledWith(
|
|
171
|
+
webex.logger.error,
|
|
172
|
+
'NewMetrics: @clientMetricsAliasUser. Request failed:',
|
|
173
|
+
`err: formattedError`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('#postPreLoginMetric', () => {
|
|
180
|
+
it('sends the request correctly', async () => {
|
|
181
|
+
webex.request.resolves({response: 'abc'});
|
|
182
|
+
await webex.internal.newMetrics.postPreLoginMetric({event: 'test'}, 'my-id');
|
|
183
|
+
assert.calledWith(webex.request, {
|
|
184
|
+
method: 'POST',
|
|
185
|
+
api: 'metrics',
|
|
186
|
+
resource: 'clientmetrics-prelogin',
|
|
187
|
+
headers: { 'x-prelogin-userid': 'my-id', authorization: false },
|
|
188
|
+
body: {metrics: [{event: 'test'}]},
|
|
189
|
+
});
|
|
190
|
+
assert.calledWith(
|
|
191
|
+
webex.logger.log,
|
|
192
|
+
'NewMetrics: @postPreLoginMetric. Request successful:',
|
|
193
|
+
{ response: 'abc' }
|
|
194
|
+
);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('handles failed request correctly', async () => {
|
|
198
|
+
webex.request.rejects(new Error("test error"));
|
|
199
|
+
sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError')
|
|
200
|
+
try {
|
|
201
|
+
await webex.internal.newMetrics.postPreLoginMetric({event: 'test'}, 'my-id');
|
|
202
|
+
} catch (err) {
|
|
203
|
+
assert.calledWith(
|
|
204
|
+
webex.logger.error,
|
|
205
|
+
'NewMetrics: @postPreLoginMetric. Request failed:',
|
|
206
|
+
`err: formattedError`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
describe('#buildClientEventFetchRequestOptions', () => {
|
|
213
|
+
it('builds client event fetch options successfully', () => {
|
|
214
|
+
webex.internal.newMetrics.buildClientEventFetchRequestOptions({
|
|
215
|
+
name: 'client.alert.displayed',
|
|
216
|
+
options: {
|
|
217
|
+
meetingId: '123',
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
assert.calledWith(
|
|
222
|
+
webex.internal.newMetrics.callDiagnosticMetrics.buildClientEventFetchRequestOptions,
|
|
223
|
+
{
|
|
224
|
+
name: 'client.alert.displayed',
|
|
225
|
+
payload: undefined,
|
|
226
|
+
options: {meetingId: '123'},
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('#setMetricTimingsAndFetch', () => {
|
|
233
|
+
beforeEach(() => {
|
|
234
|
+
global.fetch = sinon.stub();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('calls fetch with the expected options', () => {
|
|
238
|
+
const now = new Date();
|
|
239
|
+
sinon.useFakeTimers(now.getTime());
|
|
240
|
+
|
|
241
|
+
webex.internal.newMetrics.setMetricTimingsAndFetch({
|
|
242
|
+
json: true,
|
|
243
|
+
body: JSON.stringify({metrics: [{eventPayload: {}}]}),
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const expected = {
|
|
247
|
+
json: true,
|
|
248
|
+
body: JSON.stringify({
|
|
249
|
+
metrics: [
|
|
250
|
+
{
|
|
251
|
+
eventPayload: {
|
|
252
|
+
originTime: {
|
|
253
|
+
triggered: now.toISOString(),
|
|
254
|
+
sent: now.toISOString(),
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
}),
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
sinon.assert.calledOnce(webex.setTimingsAndFetch);
|
|
263
|
+
sinon.assert.calledWith(webex.setTimingsAndFetch, expected);
|
|
264
|
+
|
|
265
|
+
sinon.restore();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {assert} from '@webex/test-helper-chai';
|
|
2
|
+
import {Utils} from '@webex/internal-plugin-metrics';
|
|
3
|
+
|
|
4
|
+
describe('internal-plugin-metrics', () => {
|
|
5
|
+
describe('generateCommonErrorMetadata', () => {
|
|
6
|
+
it('should return JSON stringified error object', () => {
|
|
7
|
+
const error = new Error('test error');
|
|
8
|
+
const result = Utils.generateCommonErrorMetadata(error);
|
|
9
|
+
assert.deepEqual(result, JSON.stringify({
|
|
10
|
+
message: 'test error',
|
|
11
|
+
name: 'Error',
|
|
12
|
+
stack: error.stack
|
|
13
|
+
}))
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return error if not instanceof Error', () => {
|
|
17
|
+
const error = 'test error';
|
|
18
|
+
const result = Utils.generateCommonErrorMetadata(error);
|
|
19
|
+
assert.deepEqual(result, 'test error')
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
|
|
5
|
-
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
6
|
-
|
|
7
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
exports.default = void 0;
|
|
12
|
-
|
|
13
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
14
|
-
|
|
15
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
16
|
-
|
|
17
|
-
var _batcher = _interopRequireDefault(require("./batcher"));
|
|
18
|
-
|
|
19
|
-
/*!
|
|
20
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
21
|
-
*/
|
|
22
|
-
var CallDiagnosticEventsBatcher = _batcher.default.extend({
|
|
23
|
-
namespace: 'Metrics',
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {string} webClientDomain
|
|
27
|
-
* @returns {string}
|
|
28
|
-
*/
|
|
29
|
-
getBuildType: function getBuildType(webClientDomain) {
|
|
30
|
-
if (webClientDomain !== null && webClientDomain !== void 0 && webClientDomain.includes('teams.webex.com') || webClientDomain !== null && webClientDomain !== void 0 && webClientDomain.includes('localhost') || webClientDomain !== null && webClientDomain !== void 0 && webClientDomain.includes('127.0.0.1') || process.env.NODE_ENV !== 'production') {
|
|
31
|
-
return 'test';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return process.env.NODE_ENV === 'production' ? 'prod' : 'test';
|
|
35
|
-
},
|
|
36
|
-
prepareItem: function prepareItem(item) {
|
|
37
|
-
var _item$event, _item$event$eventData;
|
|
38
|
-
|
|
39
|
-
// networkType should be a enum value: `wifi`, `ethernet`, `cellular`, or `unknown`.
|
|
40
|
-
// Browsers cannot provide such information right now. However, it is a required field.
|
|
41
|
-
var origin = {
|
|
42
|
-
buildType: this.getBuildType((_item$event = item.event) === null || _item$event === void 0 ? void 0 : (_item$event$eventData = _item$event.eventData) === null || _item$event$eventData === void 0 ? void 0 : _item$event$eventData.webClientDomain),
|
|
43
|
-
networkType: 'unknown'
|
|
44
|
-
};
|
|
45
|
-
item.eventPayload.origin = (0, _assign.default)(origin, item.eventPayload.origin);
|
|
46
|
-
return _promise.default.resolve(item);
|
|
47
|
-
},
|
|
48
|
-
prepareRequest: function prepareRequest(queue) {
|
|
49
|
-
// Add sent timestamp
|
|
50
|
-
queue.forEach(function (item) {
|
|
51
|
-
item.eventPayload.originTime = item.eventPayload.originTime || {};
|
|
52
|
-
item.eventPayload.originTime.sent = new Date().toISOString();
|
|
53
|
-
});
|
|
54
|
-
return _promise.default.resolve(queue);
|
|
55
|
-
},
|
|
56
|
-
submitHttpRequest: function submitHttpRequest(payload) {
|
|
57
|
-
return this.webex.request({
|
|
58
|
-
method: 'POST',
|
|
59
|
-
service: 'metrics',
|
|
60
|
-
resource: 'clientmetrics',
|
|
61
|
-
body: {
|
|
62
|
-
metrics: payload
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
var _default = CallDiagnosticEventsBatcher;
|
|
69
|
-
exports.default = _default;
|
|
70
|
-
//# sourceMappingURL=call-diagnostic-events-batcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["CallDiagnosticEventsBatcher","Batcher","extend","namespace","getBuildType","webClientDomain","includes","process","env","NODE_ENV","prepareItem","item","origin","buildType","event","eventData","networkType","eventPayload","resolve","prepareRequest","queue","forEach","originTime","sent","Date","toISOString","submitHttpRequest","payload","webex","request","method","service","resource","body","metrics"],"sources":["call-diagnostic-events-batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport Batcher from './batcher';\n\nconst CallDiagnosticEventsBatcher = Batcher.extend({\n namespace: 'Metrics',\n\n /**\n * @param {string} webClientDomain\n * @returns {string}\n */\n getBuildType(webClientDomain) {\n if (\n webClientDomain?.includes('teams.webex.com') ||\n webClientDomain?.includes('localhost') ||\n webClientDomain?.includes('127.0.0.1') ||\n process.env.NODE_ENV !== 'production'\n ) {\n return 'test';\n }\n\n return process.env.NODE_ENV === 'production' ? 'prod' : 'test';\n },\n\n prepareItem(item) {\n // networkType should be a enum value: `wifi`, `ethernet`, `cellular`, or `unknown`.\n // Browsers cannot provide such information right now. However, it is a required field.\n const origin = {\n buildType: this.getBuildType(item.event?.eventData?.webClientDomain),\n networkType: 'unknown'\n };\n\n item.eventPayload.origin = Object.assign(origin, item.eventPayload.origin);\n\n return Promise.resolve(item);\n },\n\n prepareRequest(queue) {\n // Add sent timestamp\n queue.forEach((item) => {\n item.eventPayload.originTime = item.eventPayload.originTime || {};\n item.eventPayload.originTime.sent = new Date().toISOString();\n });\n\n return Promise.resolve(queue);\n },\n\n submitHttpRequest(payload) {\n return this.webex.request({\n method: 'POST',\n service: 'metrics',\n resource: 'clientmetrics',\n body: {\n metrics: payload\n }\n });\n }\n});\n\nexport default CallDiagnosticEventsBatcher;\n"],"mappings":";;;;;;;;;;;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,IAAMA,2BAA2B,GAAGC,gBAAA,CAAQC,MAAR,CAAe;EACjDC,SAAS,EAAE,SADsC;;EAGjD;AACF;AACA;AACA;EACEC,YAPiD,wBAOpCC,eAPoC,EAOnB;IAC5B,IACEA,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAEC,QAAjB,CAA0B,iBAA1B,KACAD,eADA,aACAA,eADA,eACAA,eAAe,CAAEC,QAAjB,CAA0B,WAA1B,CADA,IAEAD,eAFA,aAEAA,eAFA,eAEAA,eAAe,CAAEC,QAAjB,CAA0B,WAA1B,CAFA,IAGAC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAJ3B,EAKE;MACA,OAAO,MAAP;IACD;;IAED,OAAOF,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GAAwC,MAAxC,GAAiD,MAAxD;EACD,CAlBgD;EAoBjDC,WApBiD,uBAoBrCC,IApBqC,EAoB/B;IAAA;;IAChB;IACA;IACA,IAAMC,MAAM,GAAG;MACbC,SAAS,EAAE,KAAKT,YAAL,gBAAkBO,IAAI,CAACG,KAAvB,yEAAkB,YAAYC,SAA9B,0DAAkB,sBAAuBV,eAAzC,CADE;MAEbW,WAAW,EAAE;IAFA,CAAf;IAKAL,IAAI,CAACM,YAAL,CAAkBL,MAAlB,GAA2B,qBAAcA,MAAd,EAAsBD,IAAI,CAACM,YAAL,CAAkBL,MAAxC,CAA3B;IAEA,OAAO,iBAAQM,OAAR,CAAgBP,IAAhB,CAAP;EACD,CA/BgD;EAiCjDQ,cAjCiD,0BAiClCC,KAjCkC,EAiC3B;IACpB;IACAA,KAAK,CAACC,OAAN,CAAc,UAACV,IAAD,EAAU;MACtBA,IAAI,CAACM,YAAL,CAAkBK,UAAlB,GAA+BX,IAAI,CAACM,YAAL,CAAkBK,UAAlB,IAAgC,EAA/D;MACAX,IAAI,CAACM,YAAL,CAAkBK,UAAlB,CAA6BC,IAA7B,GAAoC,IAAIC,IAAJ,GAAWC,WAAX,EAApC;IACD,CAHD;IAKA,OAAO,iBAAQP,OAAR,CAAgBE,KAAhB,CAAP;EACD,CAzCgD;EA2CjDM,iBA3CiD,6BA2C/BC,OA3C+B,EA2CtB;IACzB,OAAO,KAAKC,KAAL,CAAWC,OAAX,CAAmB;MACxBC,MAAM,EAAE,MADgB;MAExBC,OAAO,EAAE,SAFe;MAGxBC,QAAQ,EAAE,eAHc;MAIxBC,IAAI,EAAE;QACJC,OAAO,EAAEP;MADL;IAJkB,CAAnB,CAAP;EAQD;AApDgD,CAAf,CAApC;;eAuDe3B,2B"}
|