@webex/internal-plugin-metrics 3.0.0-next.9 → 3.1.0

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.
Files changed (29) hide show
  1. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +33 -9
  2. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -1
  3. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +4 -2
  4. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -1
  5. package/dist/client-metrics-prelogin-batcher.js +32 -0
  6. package/dist/client-metrics-prelogin-batcher.js.map +1 -0
  7. package/dist/metrics.js +6 -25
  8. package/dist/metrics.js.map +1 -1
  9. package/dist/metrics.types.js.map +1 -1
  10. package/dist/prelogin-metrics-batcher.js +1 -1
  11. package/dist/prelogin-metrics-batcher.js.map +1 -1
  12. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +18 -7
  13. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +2 -2
  14. package/dist/types/client-metrics-prelogin-batcher.d.ts +2 -0
  15. package/dist/types/metrics.types.d.ts +1 -1
  16. package/package.json +12 -12
  17. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +36 -10
  18. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +11 -2
  19. package/src/client-metrics-prelogin-batcher.ts +26 -0
  20. package/src/metrics.js +5 -23
  21. package/src/metrics.types.ts +3 -1
  22. package/src/prelogin-metrics-batcher.ts +1 -1
  23. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +9 -1
  24. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +47 -22
  25. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +54 -23
  26. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +27 -13
  27. package/test/unit/spec/client-metrics-prelogin-batcher.ts +54 -0
  28. package/test/unit/spec/metrics.js +1 -31
  29. package/test/unit/spec/prelogin-metrics-batcher.ts +5 -3
@@ -541,7 +541,10 @@ describe('internal-plugin-metrics', () => {
541
541
  it('should prepare diagnostic event successfully', () => {
542
542
  const options = {meetingId: fakeMeeting.id};
543
543
  const getOriginStub = sinon.stub(cd, 'getOrigin').returns({origin: 'fake-origin'});
544
- const clearEmptyKeysRecursivelyStub = sinon.stub(CallDiagnosticUtils, 'clearEmptyKeysRecursively');
544
+ const clearEmptyKeysRecursivelyStub = sinon.stub(
545
+ CallDiagnosticUtils,
546
+ 'clearEmptyKeysRecursively'
547
+ );
545
548
 
546
549
  const res = cd.prepareDiagnosticEvent(
547
550
  {
@@ -896,11 +899,13 @@ describe('internal-plugin-metrics', () => {
896
899
  options
897
900
  );
898
901
  assert.notCalled(submitToCallDiagnosticsSpy);
899
- assert.calledWith(submitToCallDiagnosticsPreLoginSpy, {
902
+ assert.calledWith(
903
+ submitToCallDiagnosticsPreLoginSpy,
904
+ {
900
905
  eventId: 'my-fake-id',
901
906
  version: 1,
902
- origin: { origin: 'fake-origin' },
903
- originTime: { triggered: now.toISOString(), sent: 'not_defined_yet' },
907
+ origin: {origin: 'fake-origin'},
908
+ originTime: {triggered: now.toISOString(), sent: 'not_defined_yet'},
904
909
  senderCountryCode: 'UK',
905
910
  event: {
906
911
  name: 'client.alert.displayed',
@@ -912,12 +917,14 @@ describe('internal-plugin-metrics', () => {
912
917
  orgId: 'orgId',
913
918
  locusUrl: 'locus-url',
914
919
  webexConferenceIdStr: 'webexConferenceIdStr1',
915
- globalMeetingId: 'globalMeetingId1'
920
+ globalMeetingId: 'globalMeetingId1',
916
921
  },
917
- eventData: { webClientDomain: 'whatever' },
918
- loginType: 'login-ci'
922
+ eventData: {webClientDomain: 'whatever'},
923
+ loginType: 'login-ci',
919
924
  },
920
- }, options.preLoginId);
925
+ },
926
+ options.preLoginId
927
+ );
921
928
  });
922
929
 
923
930
  it('should use meeting loginType if present and meetingId provided', () => {
@@ -1382,7 +1389,7 @@ describe('internal-plugin-metrics', () => {
1382
1389
  });
1383
1390
  });
1384
1391
 
1385
- describe("#submitToCallDiagnostics", () => {
1392
+ describe('#submitToCallDiagnostics', () => {
1386
1393
  it('should send request to call diagnostic batcher', () => {
1387
1394
  const requestStub = sinon.stub();
1388
1395
  //@ts-ignore
@@ -1391,7 +1398,7 @@ describe('internal-plugin-metrics', () => {
1391
1398
  cd.submitToCallDiagnostics({event: 'test'});
1392
1399
  assert.calledWith(requestStub, {eventPayload: {event: 'test'}, type: ['diagnostic-event']});
1393
1400
  });
1394
- })
1401
+ });
1395
1402
 
1396
1403
  describe('#submitMQE', () => {
1397
1404
  it('submits the event correctly', () => {
@@ -2006,12 +2013,16 @@ describe('internal-plugin-metrics', () => {
2006
2013
 
2007
2014
  describe('httpStatusCode', () => {
2008
2015
  it('should include httpStatusCode for browser media errors', () => {
2009
- const res = cd.generateClientEventErrorPayload({name: 'PermissionDeniedError', message: 'bad times', statusCode: 401});
2016
+ const res = cd.generateClientEventErrorPayload({
2017
+ name: 'PermissionDeniedError',
2018
+ message: 'bad times',
2019
+ statusCode: 401,
2020
+ });
2010
2021
  assert.deepEqual(res, {
2011
2022
  category: 'expected',
2012
2023
  errorCode: 4032,
2013
2024
  errorData: {
2014
- errorName: 'PermissionDeniedError'
2025
+ errorName: 'PermissionDeniedError',
2015
2026
  },
2016
2027
  errorDescription: 'CameraPermissionDenied',
2017
2028
  fatal: true,
@@ -2024,12 +2035,16 @@ describe('internal-plugin-metrics', () => {
2024
2035
  });
2025
2036
 
2026
2037
  it('should include httpStatusCode for SdpOfferCreationErrors', () => {
2027
- const res = cd.generateClientEventErrorPayload({name: 'SdpOfferCreationError', message: 'bad times', statusCode: 404});
2038
+ const res = cd.generateClientEventErrorPayload({
2039
+ name: 'SdpOfferCreationError',
2040
+ message: 'bad times',
2041
+ statusCode: 404,
2042
+ });
2028
2043
  assert.deepEqual(res, {
2029
2044
  category: 'media',
2030
2045
  errorCode: 2050,
2031
2046
  errorData: {
2032
- errorName: 'SdpOfferCreationError'
2047
+ errorName: 'SdpOfferCreationError',
2033
2048
  },
2034
2049
  errorDescription: 'SdpOfferCreationError',
2035
2050
  fatal: true,
@@ -2042,7 +2057,11 @@ describe('internal-plugin-metrics', () => {
2042
2057
  });
2043
2058
 
2044
2059
  it('should include httpStatusCode for service error codes', () => {
2045
- const res = cd.generateClientEventErrorPayload({body: {errorCode: 58400}, message: 'bad times', statusCode: 400});
2060
+ const res = cd.generateClientEventErrorPayload({
2061
+ body: {errorCode: 58400},
2062
+ message: 'bad times',
2063
+ statusCode: 400,
2064
+ });
2046
2065
  assert.deepEqual(res, {
2047
2066
  category: 'signaling',
2048
2067
  errorCode: 4100,
@@ -2057,7 +2076,11 @@ describe('internal-plugin-metrics', () => {
2057
2076
  });
2058
2077
 
2059
2078
  it('should include httpStatusCode for locus service error codes', () => {
2060
- const res = cd.generateClientEventErrorPayload({body: {errorCode: 2403001}, message: 'bad times', statusCode: 400});
2079
+ const res = cd.generateClientEventErrorPayload({
2080
+ body: {errorCode: 2403001},
2081
+ message: 'bad times',
2082
+ statusCode: 400,
2083
+ });
2061
2084
  assert.deepEqual(res, {
2062
2085
  category: 'expected',
2063
2086
  errorCode: 3007,
@@ -2072,7 +2095,11 @@ describe('internal-plugin-metrics', () => {
2072
2095
  });
2073
2096
 
2074
2097
  it('should include httpStatusCode for meetingInfo service error codes', () => {
2075
- const res = cd.generateClientEventErrorPayload({body: {data: {meetingInfo: {}}}, message: 'bad times', statusCode: 400});
2098
+ const res = cd.generateClientEventErrorPayload({
2099
+ body: {data: {meetingInfo: {}}},
2100
+ message: 'bad times',
2101
+ statusCode: 400,
2102
+ });
2076
2103
  assert.deepEqual(res, {
2077
2104
  category: 'signaling',
2078
2105
  errorCode: 4100,
@@ -2087,8 +2114,10 @@ describe('internal-plugin-metrics', () => {
2087
2114
  });
2088
2115
 
2089
2116
  it('should include httpStatusCode for network errors', () => {
2090
- const error = new WebexHttpError.NetworkOrCORSError(
2091
- {statusCode: 400, options: {service: '', headers: {}}});
2117
+ const error = new WebexHttpError.NetworkOrCORSError({
2118
+ statusCode: 400,
2119
+ options: {service: '', headers: {}},
2120
+ });
2092
2121
  const res = cd.generateClientEventErrorPayload(error);
2093
2122
  assert.deepEqual(res, {
2094
2123
  category: 'network',
@@ -2104,8 +2133,10 @@ describe('internal-plugin-metrics', () => {
2104
2133
  });
2105
2134
 
2106
2135
  it('should include httpStatusCode for unauthorized errors', () => {
2107
- const error = new WebexHttpError.Unauthorized(
2108
- {statusCode: 401, options: {service: '', headers: {}}});
2136
+ const error = new WebexHttpError.Unauthorized({
2137
+ statusCode: 401,
2138
+ options: {service: '', headers: {}},
2139
+ });
2109
2140
  const res = cd.generateClientEventErrorPayload(error);
2110
2141
  assert.deepEqual(res, {
2111
2142
  category: 'network',
@@ -2308,7 +2339,7 @@ describe('internal-plugin-metrics', () => {
2308
2339
  });
2309
2340
  });
2310
2341
 
2311
- describe("#submitToCallDiagnosticsPreLogin", () => {
2342
+ describe('#submitToCallDiagnosticsPreLogin', () => {
2312
2343
  it('should send request to call diagnostic batcher and saves preLoginId', () => {
2313
2344
  const requestStub = sinon.stub();
2314
2345
  //@ts-ignore
@@ -2321,7 +2352,7 @@ describe('internal-plugin-metrics', () => {
2321
2352
  assert.calledWith(cd.preLoginMetricsBatcher.savePreLoginId, preLoginId);
2322
2353
  assert.calledWith(requestStub, {eventPayload: {event: 'test'}, type: ['diagnostic-event']});
2323
2354
  });
2324
- })
2355
+ });
2325
2356
 
2326
2357
  describe('#isServiceErrorExpected', () => {
2327
2358
  it('returns true for code mapped to "expected"', () => {
@@ -301,17 +301,23 @@ describe('internal-plugin-metrics', () => {
301
301
 
302
302
  [
303
303
  ['client.exit.app', {}],
304
- ['client.login.end', {
305
- joinTimes: {
306
- otherAppApiReqResp: undefined,
307
- exchangeCITokenJMT: undefined,
308
- }
309
- }],
310
- ['client.webexapp.launched', {
311
- joinTimes: {
312
- downloadTime: undefined,
313
- }
314
- }],
304
+ [
305
+ 'client.login.end',
306
+ {
307
+ joinTimes: {
308
+ otherAppApiReqResp: undefined,
309
+ exchangeCITokenJMT: undefined,
310
+ },
311
+ },
312
+ ],
313
+ [
314
+ 'client.webexapp.launched',
315
+ {
316
+ joinTimes: {
317
+ downloadTime: undefined,
318
+ },
319
+ },
320
+ ],
315
321
  [
316
322
  'client.interstitial-window.launched',
317
323
  {
@@ -319,6 +325,7 @@ describe('internal-plugin-metrics', () => {
319
325
  clickToInterstitial: undefined,
320
326
  meetingInfoReqResp: undefined,
321
327
  refreshCaptchaServiceReqResp: undefined,
328
+ downloadIntelligenceModelsReqResp: undefined,
322
329
  },
323
330
  },
324
331
  ],
@@ -329,7 +336,8 @@ describe('internal-plugin-metrics', () => {
329
336
  showInterstitialTime: undefined,
330
337
  meetingInfoReqResp: undefined,
331
338
  registerWDMDeviceJMT: undefined,
332
- getU2CTime: undefined
339
+ getU2CTime: undefined,
340
+ getReachabilityClustersReqResp: undefined,
333
341
  },
334
342
  },
335
343
  ],
@@ -345,7 +353,7 @@ describe('internal-plugin-metrics', () => {
345
353
  interstitialToJoinOK: undefined,
346
354
  totalJmt: undefined,
347
355
  clientJmt: undefined,
348
- downloadTime: undefined
356
+ downloadTime: undefined,
349
357
  },
350
358
  },
351
359
  ],
@@ -607,6 +615,12 @@ describe('internal-plugin-metrics', () => {
607
615
  turnServerUsed: true,
608
616
  errorCode: DTLS_HANDSHAKE_FAILED_CLIENT_CODE,
609
617
  },
618
+ {
619
+ signalingState: 'stable',
620
+ iceConnectionState: 'disconnected',
621
+ turnServerUsed: true,
622
+ errorCode: DTLS_HANDSHAKE_FAILED_CLIENT_CODE,
623
+ },
610
624
  {
611
625
  signalingState: 'stable',
612
626
  iceConnectionState: 'failed',
@@ -0,0 +1,54 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import MockWebex from '@webex/test-helper-mock-webex';
7
+ import sinon from 'sinon';
8
+ import Metrics from '@webex/internal-plugin-metrics';
9
+ import PreLoginMetricsBatcher from '@webex/internal-plugin-metrics';
10
+ import ClientMetricsPreloginBatcher from '@webex/internal-plugin-metrics';
11
+
12
+
13
+ describe('internal-plugin-metrics', () => {
14
+ describe('ClientMetricsPreloginBatcher', () => {
15
+ let webex;
16
+
17
+ beforeEach(() => {
18
+ //@ts-ignore
19
+ webex = new MockWebex({
20
+ children: {
21
+ metrics: Metrics,
22
+ },
23
+ });
24
+
25
+ webex.request = (options) =>
26
+ Promise.resolve({body: {items: []}, waitForServiceTimeout: 15, options});
27
+
28
+ sinon.spy(webex, 'request');
29
+ });
30
+
31
+ afterEach(() => {
32
+ sinon.restore();
33
+ });
34
+
35
+ it('should be an instance of PreLoginMetricsBatcher', () => {
36
+ const clientMetricsPreloginBatcher = new ClientMetricsPreloginBatcher();
37
+ assert.instanceOf(clientMetricsPreloginBatcher, PreLoginMetricsBatcher);
38
+ });
39
+
40
+
41
+ it('checks prepareItem', async () => {
42
+ const testItem = {id: 1};
43
+ const resultPromise = await webex.internal.metrics.clientMetricsPreloginBatcher.prepareItem(testItem);
44
+ assert.strictEqual(resultPromise, testItem);
45
+ });
46
+
47
+ it('checks prepareRequest', async () => {
48
+ const testQueue = [];
49
+
50
+ const resultPromise = await webex.internal.metrics.clientMetricsPreloginBatcher.prepareRequest(testQueue);
51
+ assert.strictEqual(resultPromise, testQueue);
52
+ });
53
+ });
54
+ });
@@ -113,7 +113,6 @@ describe('plugin-metrics', () => {
113
113
  }
114
114
 
115
115
  sinon.spy(webex, 'request');
116
- sinon.spy(metrics, 'postPreLoginMetric');
117
116
  sinon.spy(metrics, 'aliasUser');
118
117
  });
119
118
 
@@ -207,7 +206,7 @@ describe('plugin-metrics', () => {
207
206
 
208
207
  describe('#submitClientMetrics()', () => {
209
208
  describe('before login', () => {
210
- it('posts pre-login metric', () => {
209
+ it('clientMetricsPreloginBatcher pre-login metric', () => {
211
210
  const date = clock.now;
212
211
  const promise = metrics.submitClientMetrics(eventName, mockPayload, preLoginId);
213
212
 
@@ -215,8 +214,6 @@ describe('plugin-metrics', () => {
215
214
  .then(() => clock.tick(config.metrics.batcherWait))
216
215
  .then(() => promise)
217
216
  .then(() => {
218
- assert.called(metrics.postPreLoginMetric);
219
- assert.calledOnce(webex.credentials.getClientToken);
220
217
  assert.calledOnce(webex.request);
221
218
  const req = webex.request.args[0][0];
222
219
  const metric = req.body.metrics[0];
@@ -304,33 +301,6 @@ describe('plugin-metrics', () => {
304
301
  });
305
302
  });
306
303
 
307
- describe('#postPreLoginMetric()', () => {
308
- it('returns an HttpResponse object', () => {
309
- const promise = metrics.postPreLoginMetric(preLoginProps, preLoginId);
310
-
311
- return promiseTick(50)
312
- .then(() => clock.tick(config.metrics.batcherWait))
313
- .then(() => promise)
314
- .then(() => {
315
- assert.calledOnce(webex.request);
316
- const req = webex.request.args[0][0];
317
- const metric = req.body.metrics[0];
318
- const {headers} = req;
319
-
320
- assert.property(headers, 'x-prelogin-userid');
321
- assert.property(metric, 'metricName');
322
- assert.property(metric, 'tags');
323
- assert.property(metric, 'fields');
324
- assert.property(metric, 'timestamp');
325
-
326
- assert.equal(metric.timestamp, transformedProps.timestamp);
327
- assert.equal(metric.metricName, eventName);
328
- assert.equal(metric.tags.testTag, 'tag value');
329
- assert.equal(metric.fields.testField, 123);
330
- });
331
- });
332
- });
333
-
334
304
  describe('#aliasUser()', () => {
335
305
  it('returns an HttpResponse object', () =>
336
306
  metrics.aliasUser(preLoginId).then(() => {
@@ -75,6 +75,7 @@ describe('internal-plugin-metrics', () => {
75
75
  meetingInfoReqResp: undefined,
76
76
  clickToInterstitial: undefined,
77
77
  refreshCaptchaServiceReqResp: undefined,
78
+ downloadIntelligenceModelsReqResp: undefined,
78
79
  },
79
80
  name: 'client.interstitial-window.launched',
80
81
  },
@@ -139,7 +140,7 @@ describe('internal-plugin-metrics', () => {
139
140
  assert.calledOnceWithExactly(
140
141
  webex.logger.error,
141
142
  'Pre Login Metrics -->',
142
- `PreLoginMetricsBatcher: @submitHttpRequest#prelogin-ca-batch-${expectedBatchId}. Request failed:`,
143
+ `PreLoginMetricsBatcher: @submitHttpRequest#prelogin-batch-${expectedBatchId}. Request failed:`,
143
144
  `error: formattedError`
144
145
  );
145
146
  assert.lengthOf(
@@ -149,7 +150,8 @@ describe('internal-plugin-metrics', () => {
149
150
  });
150
151
 
151
152
  it('fails if preLoinId is not set', async () => {
152
- webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId = undefined;
153
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId =
154
+ undefined;
153
155
 
154
156
  const promise =
155
157
  webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
@@ -177,7 +179,7 @@ describe('internal-plugin-metrics', () => {
177
179
 
178
180
  describe('prepareItem', () => {
179
181
  it('calls prepareDiagnosticMetricItem correctly', async () => {
180
- // avoid setting .sent timestamp
182
+ // avoid setting .sent timestamp
181
183
  webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.prepareRequest = (q) =>
182
184
  Promise.resolve(q);
183
185