@webex/internal-plugin-metrics 2.59.8 → 2.60.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/dist/batcher.js +3 -3
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +67 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +454 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +816 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +323 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +593 -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 +21 -2
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +24 -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 +336 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/package.json +23 -18
- package/src/batcher.js +1 -0
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +75 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +419 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +861 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +362 -0
- package/src/call-diagnostic/config.ts +666 -0
- package/src/client-metrics-batcher.js +1 -0
- package/src/config.js +1 -0
- package/src/index.ts +43 -0
- package/src/metrics.js +17 -16
- package/src/metrics.types.ts +160 -0
- package/src/new-metrics.ts +317 -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 +453 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +506 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +1972 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +565 -0
- package/test/unit/spec/client-metrics-batcher.js +2 -0
- package/test/unit/spec/metrics.js +65 -94
- package/test/unit/spec/new-metrics.ts +266 -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 -15
- 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', () => {
|
|
@@ -267,98 +331,5 @@ describe('plugin-metrics', () => {
|
|
|
267
331
|
assert.match(params, {alias: true});
|
|
268
332
|
}));
|
|
269
333
|
});
|
|
270
|
-
|
|
271
|
-
describe('#submitCallDiagnosticEvents()', () => {
|
|
272
|
-
it('submits a call diagnostic event', () => {
|
|
273
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
274
|
-
|
|
275
|
-
return promiseTick(50)
|
|
276
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
277
|
-
.then(() => promise)
|
|
278
|
-
.then(() => {
|
|
279
|
-
assert.calledOnce(webex.request);
|
|
280
|
-
const req = webex.request.args[0][0];
|
|
281
|
-
const metric = req.body.metrics[0];
|
|
282
|
-
|
|
283
|
-
assert.property(metric.eventPayload, 'origin');
|
|
284
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
285
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
286
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
287
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
288
|
-
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('submits a call diagnostic event with buildType set in the payload', () => {
|
|
293
|
-
const promise = metrics.submitCallDiagnosticEvents({
|
|
294
|
-
...mockCallDiagnosticEvent,
|
|
295
|
-
origin: {
|
|
296
|
-
buildType: 'prod',
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
return promiseTick(50)
|
|
301
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
302
|
-
.then(() => promise)
|
|
303
|
-
.then(() => {
|
|
304
|
-
assert.calledOnce(webex.request);
|
|
305
|
-
const req = webex.request.args[0][0];
|
|
306
|
-
const metric = req.body.metrics[0];
|
|
307
|
-
|
|
308
|
-
assert.property(metric.eventPayload, 'origin');
|
|
309
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
310
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
311
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
312
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
313
|
-
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
xit('submits a call diagnostic event with a test domain', () => {
|
|
318
|
-
global.window.location.hostname = 'test.webex.com';
|
|
319
|
-
|
|
320
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
321
|
-
|
|
322
|
-
return promiseTick(50)
|
|
323
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
324
|
-
.then(() => promise)
|
|
325
|
-
.then(() => {
|
|
326
|
-
assert.calledOnce(webex.request);
|
|
327
|
-
const req = webex.request.args[0][0];
|
|
328
|
-
const metric = req.body.metrics[0];
|
|
329
|
-
|
|
330
|
-
assert.property(metric.eventPayload, 'origin');
|
|
331
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
332
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
333
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
334
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
335
|
-
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
// Skip because it's current unable to overwrite NODE_ENV
|
|
340
|
-
// However doing `NODE_ENV=test npm run test ...` will get this test case to pass
|
|
341
|
-
xit('submits a call diagnostic event with a NODE_ENV=production', () => {
|
|
342
|
-
process.env.NODE_ENV = 'production';
|
|
343
|
-
|
|
344
|
-
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
345
|
-
|
|
346
|
-
return promiseTick(50)
|
|
347
|
-
.then(() => clock.tick(config.metrics.batcherWait))
|
|
348
|
-
.then(() => promise)
|
|
349
|
-
.then(() => {
|
|
350
|
-
assert.calledOnce(webex.request);
|
|
351
|
-
const req = webex.request.args[0][0];
|
|
352
|
-
const metric = req.body.metrics[0];
|
|
353
|
-
|
|
354
|
-
assert.property(metric.eventPayload, 'origin');
|
|
355
|
-
assert.property(metric.eventPayload, 'originTime');
|
|
356
|
-
assert.property(metric.eventPayload.origin, 'buildType');
|
|
357
|
-
assert.property(metric.eventPayload.origin, 'networkType');
|
|
358
|
-
assert.property(metric.eventPayload.originTime, 'sent');
|
|
359
|
-
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
});
|
|
363
334
|
});
|
|
364
335
|
});
|
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
describe('new-metrics', () => {
|
|
42
|
+
let webex;
|
|
43
|
+
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
//@ts-ignore
|
|
46
|
+
webex = new MockWebex({
|
|
47
|
+
children: {
|
|
48
|
+
newMetrics: NewMetrics,
|
|
49
|
+
},
|
|
50
|
+
meetings: {
|
|
51
|
+
meetingCollection: {
|
|
52
|
+
get: sinon.stub(),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
request: sinon.stub().resolves({}),
|
|
56
|
+
logger: {
|
|
57
|
+
log: sinon.stub(),
|
|
58
|
+
error: sinon.stub(),
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
webex.emit('ready');
|
|
63
|
+
|
|
64
|
+
webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp = sinon.stub();
|
|
65
|
+
webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps = sinon.stub();
|
|
66
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent = sinon.stub();
|
|
67
|
+
webex.internal.newMetrics.callDiagnosticMetrics.submitMQE = sinon.stub();
|
|
68
|
+
webex.internal.newMetrics.callDiagnosticMetrics.clientMetricsAliasUser = sinon.stub();
|
|
69
|
+
webex.internal.newMetrics.callDiagnosticMetrics.postPreLoginMetric = 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('#postPreLoginMetric', () => {
|
|
178
|
+
it('sends the request correctly', async () => {
|
|
179
|
+
webex.request.resolves({response: 'abc'});
|
|
180
|
+
await webex.internal.newMetrics.postPreLoginMetric({event: 'test'}, 'my-id');
|
|
181
|
+
assert.calledWith(webex.request, {
|
|
182
|
+
method: 'POST',
|
|
183
|
+
api: 'metrics',
|
|
184
|
+
resource: 'clientmetrics-prelogin',
|
|
185
|
+
headers: { 'x-prelogin-userid': 'my-id', authorization: false },
|
|
186
|
+
body: {metrics: [{event: 'test'}]},
|
|
187
|
+
});
|
|
188
|
+
assert.calledWith(
|
|
189
|
+
webex.logger.log,
|
|
190
|
+
'NewMetrics: @postPreLoginMetric. Request successful.'
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('handles failed request correctly', async () => {
|
|
195
|
+
webex.request.rejects(new Error("test error"));
|
|
196
|
+
sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError')
|
|
197
|
+
try {
|
|
198
|
+
await webex.internal.newMetrics.postPreLoginMetric({event: 'test'}, 'my-id');
|
|
199
|
+
} catch (err) {
|
|
200
|
+
assert.calledWith(
|
|
201
|
+
webex.logger.error,
|
|
202
|
+
'NewMetrics: @postPreLoginMetric. Request failed:',
|
|
203
|
+
`err: formattedError`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe('#buildClientEventFetchRequestOptions', () => {
|
|
210
|
+
it('builds client event fetch options successfully', () => {
|
|
211
|
+
webex.internal.newMetrics.buildClientEventFetchRequestOptions({
|
|
212
|
+
name: 'client.alert.displayed',
|
|
213
|
+
options: {
|
|
214
|
+
meetingId: '123',
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
assert.calledWith(
|
|
219
|
+
webex.internal.newMetrics.callDiagnosticMetrics.buildClientEventFetchRequestOptions,
|
|
220
|
+
{
|
|
221
|
+
name: 'client.alert.displayed',
|
|
222
|
+
payload: undefined,
|
|
223
|
+
options: {meetingId: '123'},
|
|
224
|
+
}
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('#setMetricTimingsAndFetch', () => {
|
|
230
|
+
beforeEach(() => {
|
|
231
|
+
global.fetch = sinon.stub();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('calls fetch with the expected options', () => {
|
|
235
|
+
const now = new Date();
|
|
236
|
+
sinon.useFakeTimers(now.getTime());
|
|
237
|
+
|
|
238
|
+
webex.internal.newMetrics.setMetricTimingsAndFetch({
|
|
239
|
+
json: true,
|
|
240
|
+
body: JSON.stringify({metrics: [{eventPayload: {}}]}),
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const expected = {
|
|
244
|
+
json: true,
|
|
245
|
+
body: JSON.stringify({
|
|
246
|
+
metrics: [
|
|
247
|
+
{
|
|
248
|
+
eventPayload: {
|
|
249
|
+
originTime: {
|
|
250
|
+
triggered: now.toISOString(),
|
|
251
|
+
sent: now.toISOString(),
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
}),
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
sinon.assert.calledOnce(webex.setTimingsAndFetch);
|
|
260
|
+
sinon.assert.calledWith(webex.setTimingsAndFetch, expected);
|
|
261
|
+
|
|
262
|
+
sinon.restore();
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
@@ -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,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
|
|
4
|
-
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
|
5
|
-
_Object$defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
10
|
-
var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
11
|
-
var _batcher = _interopRequireDefault(require("./batcher"));
|
|
12
|
-
/*!
|
|
13
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
var CallDiagnosticEventsBatcher = _batcher.default.extend({
|
|
17
|
-
namespace: 'Metrics',
|
|
18
|
-
/**
|
|
19
|
-
* @param {string} webClientDomain
|
|
20
|
-
* @returns {string}
|
|
21
|
-
*/
|
|
22
|
-
getBuildType: function getBuildType(webClientDomain) {
|
|
23
|
-
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') {
|
|
24
|
-
return 'test';
|
|
25
|
-
}
|
|
26
|
-
return process.env.NODE_ENV === 'production' ? 'prod' : 'test';
|
|
27
|
-
},
|
|
28
|
-
prepareItem: function prepareItem(item) {
|
|
29
|
-
var _item$event, _item$event$eventData;
|
|
30
|
-
// networkType should be a enum value: `wifi`, `ethernet`, `cellular`, or `unknown`.
|
|
31
|
-
// Browsers cannot provide such information right now. However, it is a required field.
|
|
32
|
-
var origin = {
|
|
33
|
-
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),
|
|
34
|
-
networkType: 'unknown'
|
|
35
|
-
};
|
|
36
|
-
item.eventPayload.origin = (0, _assign.default)(origin, item.eventPayload.origin);
|
|
37
|
-
return _promise.default.resolve(item);
|
|
38
|
-
},
|
|
39
|
-
prepareRequest: function prepareRequest(queue) {
|
|
40
|
-
// Add sent timestamp
|
|
41
|
-
queue.forEach(function (item) {
|
|
42
|
-
item.eventPayload.originTime = item.eventPayload.originTime || {};
|
|
43
|
-
item.eventPayload.originTime.sent = new Date().toISOString();
|
|
44
|
-
});
|
|
45
|
-
return _promise.default.resolve(queue);
|
|
46
|
-
},
|
|
47
|
-
submitHttpRequest: function submitHttpRequest(payload) {
|
|
48
|
-
return this.webex.request({
|
|
49
|
-
method: 'POST',
|
|
50
|
-
service: 'metrics',
|
|
51
|
-
resource: 'clientmetrics',
|
|
52
|
-
body: {
|
|
53
|
-
metrics: payload
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
var _default = CallDiagnosticEventsBatcher;
|
|
59
|
-
exports.default = _default;
|
|
60
|
-
//# sourceMappingURL=call-diagnostic-events-batcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_batcher","_interopRequireDefault","require","CallDiagnosticEventsBatcher","Batcher","extend","namespace","getBuildType","webClientDomain","includes","process","env","NODE_ENV","prepareItem","item","_item$event","_item$event$eventData","origin","buildType","event","eventData","networkType","eventPayload","_assign","default","_promise","resolve","prepareRequest","queue","forEach","originTime","sent","Date","toISOString","submitHttpRequest","payload","webex","request","method","service","resource","body","metrics","_default","exports"],"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,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA,IAAMC,2BAA2B,GAAGC,gBAAO,CAACC,MAAM,CAAC;EACjDC,SAAS,EAAE,SAAS;EAEpB;AACF;AACA;AACA;EACEC,YAAY,WAAAA,aAACC,eAAe,EAAE;IAC5B,IACEA,eAAe,aAAfA,eAAe,eAAfA,eAAe,CAAEC,QAAQ,CAAC,iBAAiB,CAAC,IAC5CD,eAAe,aAAfA,eAAe,eAAfA,eAAe,CAAEC,QAAQ,CAAC,WAAW,CAAC,IACtCD,eAAe,aAAfA,eAAe,eAAfA,eAAe,CAAEC,QAAQ,CAAC,WAAW,CAAC,IACtCC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EACrC;MACA,OAAO,MAAM;IACf;IAEA,OAAOF,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAG,MAAM,GAAG,MAAM;EAChE,CAAC;EAEDC,WAAW,WAAAA,YAACC,IAAI,EAAE;IAAA,IAAAC,WAAA,EAAAC,qBAAA;IAChB;IACA;IACA,IAAMC,MAAM,GAAG;MACbC,SAAS,EAAE,IAAI,CAACX,YAAY,EAAAQ,WAAA,GAACD,IAAI,CAACK,KAAK,cAAAJ,WAAA,wBAAAC,qBAAA,GAAVD,WAAA,CAAYK,SAAS,cAAAJ,qBAAA,uBAArBA,qBAAA,CAAuBR,eAAe,CAAC;MACpEa,WAAW,EAAE;IACf,CAAC;IAEDP,IAAI,CAACQ,YAAY,CAACL,MAAM,GAAG,IAAAM,OAAA,CAAAC,OAAA,EAAcP,MAAM,EAAEH,IAAI,CAACQ,YAAY,CAACL,MAAM,CAAC;IAE1E,OAAOQ,QAAA,CAAAD,OAAA,CAAQE,OAAO,CAACZ,IAAI,CAAC;EAC9B,CAAC;EAEDa,cAAc,WAAAA,eAACC,KAAK,EAAE;IACpB;IACAA,KAAK,CAACC,OAAO,CAAC,UAACf,IAAI,EAAK;MACtBA,IAAI,CAACQ,YAAY,CAACQ,UAAU,GAAGhB,IAAI,CAACQ,YAAY,CAACQ,UAAU,IAAI,CAAC,CAAC;MACjEhB,IAAI,CAACQ,YAAY,CAACQ,UAAU,CAACC,IAAI,GAAG,IAAIC,IAAI,EAAE,CAACC,WAAW,EAAE;IAC9D,CAAC,CAAC;IAEF,OAAOR,QAAA,CAAAD,OAAA,CAAQE,OAAO,CAACE,KAAK,CAAC;EAC/B,CAAC;EAEDM,iBAAiB,WAAAA,kBAACC,OAAO,EAAE;IACzB,OAAO,IAAI,CAACC,KAAK,CAACC,OAAO,CAAC;MACxBC,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE,SAAS;MAClBC,QAAQ,EAAE,eAAe;MACzBC,IAAI,EAAE;QACJC,OAAO,EAAEP;MACX;IACF,CAAC,CAAC;EACJ;AACF,CAAC,CAAC;AAAC,IAAAQ,QAAA,GAEYxC,2BAA2B;AAAAyC,OAAA,CAAApB,OAAA,GAAAmB,QAAA"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import Batcher from './batcher';
|
|
6
|
-
|
|
7
|
-
const CallDiagnosticEventsBatcher = Batcher.extend({
|
|
8
|
-
namespace: 'Metrics',
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} webClientDomain
|
|
12
|
-
* @returns {string}
|
|
13
|
-
*/
|
|
14
|
-
getBuildType(webClientDomain) {
|
|
15
|
-
if (
|
|
16
|
-
webClientDomain?.includes('teams.webex.com') ||
|
|
17
|
-
webClientDomain?.includes('localhost') ||
|
|
18
|
-
webClientDomain?.includes('127.0.0.1') ||
|
|
19
|
-
process.env.NODE_ENV !== 'production'
|
|
20
|
-
) {
|
|
21
|
-
return 'test';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return process.env.NODE_ENV === 'production' ? 'prod' : 'test';
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
prepareItem(item) {
|
|
28
|
-
// networkType should be a enum value: `wifi`, `ethernet`, `cellular`, or `unknown`.
|
|
29
|
-
// Browsers cannot provide such information right now. However, it is a required field.
|
|
30
|
-
const origin = {
|
|
31
|
-
buildType: this.getBuildType(item.event?.eventData?.webClientDomain),
|
|
32
|
-
networkType: 'unknown',
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
item.eventPayload.origin = Object.assign(origin, item.eventPayload.origin);
|
|
36
|
-
|
|
37
|
-
return Promise.resolve(item);
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
prepareRequest(queue) {
|
|
41
|
-
// Add sent timestamp
|
|
42
|
-
queue.forEach((item) => {
|
|
43
|
-
item.eventPayload.originTime = item.eventPayload.originTime || {};
|
|
44
|
-
item.eventPayload.originTime.sent = new Date().toISOString();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return Promise.resolve(queue);
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
submitHttpRequest(payload) {
|
|
51
|
-
return this.webex.request({
|
|
52
|
-
method: 'POST',
|
|
53
|
-
service: 'metrics',
|
|
54
|
-
resource: 'clientmetrics',
|
|
55
|
-
body: {
|
|
56
|
-
metrics: payload,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export default CallDiagnosticEventsBatcher;
|
package/src/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {registerInternalPlugin} from '@webex/webex-core';
|
|
6
|
-
|
|
7
|
-
import Metrics from './metrics';
|
|
8
|
-
import config from './config';
|
|
9
|
-
|
|
10
|
-
registerInternalPlugin('metrics', Metrics, {
|
|
11
|
-
config,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export {default, getOSNameInternal} from './metrics';
|
|
15
|
-
export {config};
|