@webex/internal-plugin-metrics 3.0.0-beta.162 → 3.0.0-beta.164

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 (64) hide show
  1. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +132 -0
  2. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  3. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +329 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics.js +511 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +106 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  9. package/dist/call-diagnostic/config.js +461 -0
  10. package/dist/call-diagnostic/config.js.map +1 -0
  11. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js +7 -0
  12. package/dist/call-diagnostic/generated-types-temp/ClientEvent.js.map +1 -0
  13. package/dist/call-diagnostic/generated-types-temp/Event.js +7 -0
  14. package/dist/call-diagnostic/generated-types-temp/Event.js.map +1 -0
  15. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js +7 -0
  16. package/dist/call-diagnostic/generated-types-temp/MediaQualityEvent.js.map +1 -0
  17. package/dist/index.js +13 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/metrics.js +2 -11
  20. package/dist/metrics.js.map +1 -1
  21. package/dist/metrics.types.js +7 -0
  22. package/dist/metrics.types.js.map +1 -0
  23. package/dist/new-metrics.js +171 -0
  24. package/dist/new-metrics.js.map +1 -0
  25. package/dist/types/batcher.d.ts +2 -0
  26. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  27. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +149 -0
  28. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +324 -0
  29. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +31 -0
  30. package/dist/types/call-diagnostic/config.d.ts +57 -0
  31. package/dist/types/call-diagnostic/generated-types-temp/ClientEvent.d.ts +1112 -0
  32. package/dist/types/call-diagnostic/generated-types-temp/Event.d.ts +4851 -0
  33. package/dist/types/call-diagnostic/generated-types-temp/MediaQualityEvent.d.ts +2121 -0
  34. package/dist/types/client-metrics-batcher.d.ts +2 -0
  35. package/dist/types/config.d.ts +35 -0
  36. package/dist/types/index.d.ts +11 -0
  37. package/dist/types/metrics.d.ts +3 -0
  38. package/dist/types/metrics.types.d.ts +89 -0
  39. package/dist/types/new-metrics.d.ts +83 -0
  40. package/package.json +12 -8
  41. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +145 -0
  42. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +297 -0
  43. package/src/call-diagnostic/call-diagnostic-metrics.ts +528 -0
  44. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +102 -0
  45. package/src/call-diagnostic/config.ts +455 -0
  46. package/src/call-diagnostic/generated-types-temp/ClientEvent.ts +2357 -0
  47. package/src/call-diagnostic/generated-types-temp/Event.ts +7669 -0
  48. package/src/call-diagnostic/generated-types-temp/MediaQualityEvent.ts +2321 -0
  49. package/src/index.ts +39 -0
  50. package/src/metrics.js +0 -11
  51. package/src/metrics.types.ts +132 -0
  52. package/src/new-metrics.ts +167 -0
  53. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +233 -0
  54. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +193 -0
  55. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +722 -0
  56. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +76 -0
  57. package/test/unit/spec/metrics.js +2 -96
  58. package/test/unit/spec/new-metrics.ts +88 -0
  59. package/tsconfig.json +6 -0
  60. package/dist/call-diagnostic-events-batcher.js +0 -60
  61. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  62. package/src/call-diagnostic-events-batcher.js +0 -62
  63. package/src/index.js +0 -17
  64. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
@@ -0,0 +1,76 @@
1
+ import {assert} from '@webex/test-helper-chai';
2
+ import {
3
+ clearEmptyKeysRecursively,
4
+ isLocusServiceErrorCode,
5
+ } from '../../../../src/call-diagnostic/call-diagnostic-metrics.util';
6
+
7
+ describe('internal-plugin-metrics', () => {
8
+ describe('clearEmptyKeysRecursively', () => {
9
+ it('should clear empty objects and empty nested objects recursively', () => {
10
+ const obj = {
11
+ foo: '',
12
+ bar: {},
13
+ baz: [],
14
+ nested: {
15
+ prop: {},
16
+ arr: ['test'],
17
+ },
18
+ };
19
+ clearEmptyKeysRecursively(obj);
20
+ console.log(obj);
21
+ assert.deepEqual(obj, {nested: {arr: ['test']}});
22
+ });
23
+
24
+ it('should not modify non-empty objects and arrays', () => {
25
+ const obj = {
26
+ foo: 'bar',
27
+ arr: [1, 2, 3],
28
+ };
29
+ clearEmptyKeysRecursively(obj);
30
+ assert.deepEqual(obj, {foo: 'bar', arr: [1, 2, 3]});
31
+ });
32
+
33
+ it('should not modify non-object and non-array values', () => {
34
+ const obj = {
35
+ prop1: 'value1',
36
+ prop2: 123,
37
+ };
38
+ clearEmptyKeysRecursively(obj);
39
+ assert.deepEqual(obj, {prop1: 'value1', prop2: 123});
40
+ });
41
+
42
+ it('should handle nested empty objects and arrays', () => {
43
+ const obj = {
44
+ foo: {
45
+ bar: {},
46
+ baz: [],
47
+ },
48
+ };
49
+ clearEmptyKeysRecursively(obj);
50
+ assert.deepEqual(obj, {foo: {}});
51
+ });
52
+
53
+ it('should handle an empty input object', () => {
54
+ const obj = {};
55
+ clearEmptyKeysRecursively(obj);
56
+ assert.deepEqual(obj, {});
57
+ });
58
+ });
59
+
60
+ describe('isLocusServiceErrorCode', () => {
61
+ [
62
+ [10000, false],
63
+ [2400000, true],
64
+ ['2400000', true],
65
+ [2400001, true],
66
+ ['2400001', true],
67
+ [240000, false],
68
+ [14000000, false],
69
+ ].forEach(([error, expected]) => {
70
+ it(`for code ${error} returns the correct result`, () => {
71
+ //@ts-ignore
72
+ assert.deepEqual(isLocusServiceErrorCode(error), expected);
73
+ });
74
+ });
75
+ });
76
+ });
@@ -105,7 +105,6 @@ describe('plugin-metrics', () => {
105
105
  sinon.spy(webex, 'request');
106
106
  sinon.spy(metrics, 'postPreLoginMetric');
107
107
  sinon.spy(metrics, 'aliasUser');
108
- sinon.spy(metrics, 'submitCallDiagnosticEvents');
109
108
  });
110
109
 
111
110
  describe('#submit()', () => {
@@ -134,7 +133,7 @@ describe('plugin-metrics', () => {
134
133
  });
135
134
  });
136
135
 
137
- describe.only('#getClientMetricsPayload()', () => {
136
+ describe('#getClientMetricsPayload()', () => {
138
137
  it('returns the expected payload', () => {
139
138
  webex.credentials.supertoken = new Token(
140
139
  {
@@ -179,7 +178,7 @@ describe('plugin-metrics', () => {
179
178
  metricName: 'test',
180
179
  tags: {
181
180
  browser: '',
182
- domain: 'non-browser',
181
+ domain: 'whatever',
183
182
  os: 'other',
184
183
  success: true,
185
184
  },
@@ -331,98 +330,5 @@ describe('plugin-metrics', () => {
331
330
  assert.match(params, {alias: true});
332
331
  }));
333
332
  });
334
-
335
- describe('#submitCallDiagnosticEvents()', () => {
336
- it('submits a call diagnostic event', () => {
337
- const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
338
-
339
- return promiseTick(50)
340
- .then(() => clock.tick(config.metrics.batcherWait))
341
- .then(() => promise)
342
- .then(() => {
343
- assert.calledOnce(webex.request);
344
- const req = webex.request.args[0][0];
345
- const metric = req.body.metrics[0];
346
-
347
- assert.property(metric.eventPayload, 'origin');
348
- assert.property(metric.eventPayload, 'originTime');
349
- assert.property(metric.eventPayload.origin, 'buildType');
350
- assert.property(metric.eventPayload.origin, 'networkType');
351
- assert.property(metric.eventPayload.originTime, 'sent');
352
- assert.equal(metric.eventPayload.origin.buildType, 'test');
353
- });
354
- });
355
-
356
- it('submits a call diagnostic event with buildType set in the payload', () => {
357
- const promise = metrics.submitCallDiagnosticEvents({
358
- ...mockCallDiagnosticEvent,
359
- origin: {
360
- buildType: 'prod',
361
- },
362
- });
363
-
364
- return promiseTick(50)
365
- .then(() => clock.tick(config.metrics.batcherWait))
366
- .then(() => promise)
367
- .then(() => {
368
- assert.calledOnce(webex.request);
369
- const req = webex.request.args[0][0];
370
- const metric = req.body.metrics[0];
371
-
372
- assert.property(metric.eventPayload, 'origin');
373
- assert.property(metric.eventPayload, 'originTime');
374
- assert.property(metric.eventPayload.origin, 'buildType');
375
- assert.property(metric.eventPayload.origin, 'networkType');
376
- assert.property(metric.eventPayload.originTime, 'sent');
377
- assert.equal(metric.eventPayload.origin.buildType, 'prod');
378
- });
379
- });
380
-
381
- xit('submits a call diagnostic event with a test domain', () => {
382
- global.window.location.hostname = 'test.webex.com';
383
-
384
- const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
385
-
386
- return promiseTick(50)
387
- .then(() => clock.tick(config.metrics.batcherWait))
388
- .then(() => promise)
389
- .then(() => {
390
- assert.calledOnce(webex.request);
391
- const req = webex.request.args[0][0];
392
- const metric = req.body.metrics[0];
393
-
394
- assert.property(metric.eventPayload, 'origin');
395
- assert.property(metric.eventPayload, 'originTime');
396
- assert.property(metric.eventPayload.origin, 'buildType');
397
- assert.property(metric.eventPayload.origin, 'networkType');
398
- assert.property(metric.eventPayload.originTime, 'sent');
399
- assert.equal(metric.eventPayload.origin.buildType, 'test');
400
- });
401
- });
402
-
403
- // Skip because it's current unable to overwrite NODE_ENV
404
- // However doing `NODE_ENV=test npm run test ...` will get this test case to pass
405
- xit('submits a call diagnostic event with a NODE_ENV=production', () => {
406
- process.env.NODE_ENV = 'production';
407
-
408
- const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
409
-
410
- return promiseTick(50)
411
- .then(() => clock.tick(config.metrics.batcherWait))
412
- .then(() => promise)
413
- .then(() => {
414
- assert.calledOnce(webex.request);
415
- const req = webex.request.args[0][0];
416
- const metric = req.body.metrics[0];
417
-
418
- assert.property(metric.eventPayload, 'origin');
419
- assert.property(metric.eventPayload, 'originTime');
420
- assert.property(metric.eventPayload.origin, 'buildType');
421
- assert.property(metric.eventPayload.origin, 'networkType');
422
- assert.property(metric.eventPayload.originTime, 'sent');
423
- assert.equal(metric.eventPayload.origin.buildType, 'prod');
424
- });
425
- });
426
- });
427
333
  });
428
334
  });
@@ -0,0 +1,88 @@
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
+
6
+ describe("internal-plugin-metrics", () => {
7
+ describe("new-metrics", () => {
8
+ let webex;
9
+
10
+ beforeEach(() => {
11
+ //@ts-ignore
12
+ webex = new MockWebex({
13
+ children: {
14
+ newMetrics: NewMetrics
15
+ },
16
+ meetings: {
17
+ meetingCollection: {
18
+ get: sinon.stub()
19
+ }
20
+ }
21
+ });
22
+
23
+ webex.emit('ready');
24
+
25
+ webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp = sinon.stub();
26
+ webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps = sinon.stub();
27
+ webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent = sinon.stub();
28
+ webex.internal.newMetrics.callDiagnosticMetrics.submitMQE = sinon.stub();
29
+ });
30
+
31
+ it('submits Client Event successfully', () => {
32
+ webex.internal.newMetrics.submitClientEvent({
33
+ name: 'client.alert.displayed',
34
+ options: {
35
+ meetingId: '123',
36
+ }
37
+ });
38
+
39
+ assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, "client.alert.displayed")
40
+ assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitClientEvent, {
41
+ name: 'client.alert.displayed',
42
+ payload: undefined,
43
+ options: { meetingId: '123' }
44
+ })
45
+ });
46
+
47
+ it('submits MQE successfully', () => {
48
+ webex.internal.newMetrics.submitMQE({
49
+ name: 'client.mediaquality.event',
50
+ //@ts-ignore
51
+ payload: {intervals: [{}]},
52
+ options: {
53
+ meetingId: '123',
54
+ networkType: 'wifi'
55
+ }
56
+ });
57
+
58
+ assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, 'client.mediaquality.event')
59
+ assert.calledWith(webex.internal.newMetrics.callDiagnosticMetrics.submitMQE, {
60
+ name: 'client.mediaquality.event',
61
+ //@ts-ignore
62
+ payload: {intervals: [{}]},
63
+ options: {
64
+ meetingId: '123',
65
+ networkType: 'wifi'
66
+ }
67
+ })
68
+ });
69
+
70
+ it('submits Internal Event successfully', () => {
71
+ webex.internal.newMetrics.submitInternalEvent({
72
+ name: 'client.mediaquality.event',
73
+ });
74
+
75
+ assert.calledWith(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp, 'client.mediaquality.event')
76
+ assert.notCalled(webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps)
77
+ });
78
+
79
+ it('submits Internal Event successfully for clearing the join latencies', () => {
80
+ webex.internal.newMetrics.submitInternalEvent({
81
+ name: 'internal.reset.join.latencies',
82
+ });
83
+
84
+ assert.notCalled(webex.internal.newMetrics.callDiagnosticLatencies.saveTimestamp)
85
+ assert.calledOnce(webex.internal.newMetrics.callDiagnosticLatencies.clearTimestamps)
86
+ });
87
+ })
88
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": [
4
+ "src"
5
+ ],
6
+ }
@@ -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":["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,gBAAO,CAACC,MAAM,CAAC;EACjDC,SAAS,EAAE,SAAS;EAEpB;AACF;AACA;AACA;EACEC,YAAY,wBAACC,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,uBAACC,IAAI,EAAE;IAAA;IAChB;IACA;IACA,IAAMC,MAAM,GAAG;MACbC,SAAS,EAAE,IAAI,CAACT,YAAY,gBAACO,IAAI,CAACG,KAAK,yEAAV,YAAYC,SAAS,0DAArB,sBAAuBV,eAAe,CAAC;MACpEW,WAAW,EAAE;IACf,CAAC;IAEDL,IAAI,CAACM,YAAY,CAACL,MAAM,GAAG,qBAAcA,MAAM,EAAED,IAAI,CAACM,YAAY,CAACL,MAAM,CAAC;IAE1E,OAAO,iBAAQM,OAAO,CAACP,IAAI,CAAC;EAC9B,CAAC;EAEDQ,cAAc,0BAACC,KAAK,EAAE;IACpB;IACAA,KAAK,CAACC,OAAO,CAAC,UAACV,IAAI,EAAK;MACtBA,IAAI,CAACM,YAAY,CAACK,UAAU,GAAGX,IAAI,CAACM,YAAY,CAACK,UAAU,IAAI,CAAC,CAAC;MACjEX,IAAI,CAACM,YAAY,CAACK,UAAU,CAACC,IAAI,GAAG,IAAIC,IAAI,EAAE,CAACC,WAAW,EAAE;IAC9D,CAAC,CAAC;IAEF,OAAO,iBAAQP,OAAO,CAACE,KAAK,CAAC;EAC/B,CAAC;EAEDM,iBAAiB,6BAACC,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,eAEY3B,2BAA2B;AAAA"}
@@ -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,17 +0,0 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import '@webex/internal-plugin-device';
6
-
7
- import {registerInternalPlugin} from '@webex/webex-core';
8
-
9
- import Metrics from './metrics';
10
- import config from './config';
11
-
12
- registerInternalPlugin('metrics', Metrics, {
13
- config,
14
- });
15
-
16
- export {default, getOSNameInternal} from './metrics';
17
- export {config};
@@ -1,195 +0,0 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {assert} from '@webex/test-helper-chai';
6
- import FakeTimers from '@sinonjs/fake-timers';
7
- import Metrics, {config} from '@webex/internal-plugin-metrics';
8
- import MockWebex from '@webex/test-helper-mock-webex';
9
- import sinon from 'sinon';
10
- import {WebexHttpError} from '@webex/webex-core';
11
-
12
- function promiseTick(count) {
13
- let promise = Promise.resolve();
14
-
15
- while (count > 1) {
16
- promise = promise.then(() => promiseTick(1));
17
- count -= 1;
18
- }
19
-
20
- return promise;
21
- }
22
-
23
- describe('plugin-metrics', () => {
24
- describe('callDiagnosticEventsBatcher', () => {
25
- let webex;
26
-
27
- beforeEach(() => {
28
- webex = new MockWebex({
29
- children: {
30
- metrics: Metrics,
31
- },
32
- });
33
-
34
- webex.config.metrics = config.metrics;
35
-
36
- webex.request = function (options) {
37
- return Promise.resolve({
38
- statusCode: 204,
39
- body: undefined,
40
- options,
41
- });
42
- };
43
- sinon.spy(webex, 'request');
44
- });
45
-
46
- let clock;
47
-
48
- beforeEach(() => {
49
- clock = FakeTimers.install();
50
- });
51
-
52
- afterEach(() => {
53
- clock.uninstall();
54
- });
55
-
56
- describe('#request()', () => {
57
- describe('when the request completes successfully', () => {
58
- it('clears the queue', () => {
59
- clock.uninstall();
60
-
61
- return webex.internal.metrics.callDiagnosticEventsBatcher
62
- .request({
63
- type: 'diagnostic-event',
64
- eventPayload: {
65
- originTime: {
66
- triggered: 'mock triggered timestamp',
67
- },
68
- },
69
- })
70
- .then(() => {
71
- assert.calledOnce(webex.request);
72
- assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
73
- });
74
- });
75
- });
76
-
77
- describe('when the request fails due to network disconnect', () => {
78
- it('reenqueues the payload', () => {
79
- // sinon appears to have gap in its api where stub.onCall(n) doesn't
80
- // accept a function, so the following is more verbose than one might
81
- // desire
82
- webex.request = function () {
83
- // noop
84
- };
85
- let count = 0;
86
-
87
- sinon.stub(webex, 'request').callsFake((options) => {
88
- options.headers = {
89
- trackingid: count,
90
- };
91
-
92
- count += 1;
93
- if (count < 9) {
94
- return Promise.reject(
95
- new WebexHttpError.NetworkOrCORSError({
96
- statusCode: 0,
97
- options,
98
- })
99
- );
100
- }
101
-
102
- return Promise.resolve({
103
- statusCode: 204,
104
- body: undefined,
105
- options,
106
- });
107
- });
108
-
109
- const promise = webex.internal.metrics.callDiagnosticEventsBatcher.request({
110
- type: 'diagnostic-event',
111
- eventPayload: {
112
- originTime: {
113
- triggered: 'mock triggered timestamp',
114
- },
115
- },
116
- });
117
-
118
- return promiseTick(50)
119
- .then(() =>
120
- assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 1)
121
- )
122
- .then(() => clock.tick(config.metrics.batcherWait))
123
- .then(() => assert.calledOnce(webex.request))
124
-
125
- .then(() => promiseTick(50))
126
- .then(() => clock.tick(1000))
127
- .then(() => promiseTick(50))
128
- .then(() => clock.tick(config.metrics.batcherWait))
129
- .then(() => assert.calledTwice(webex.request))
130
-
131
- .then(() => promiseTick(50))
132
- .then(() => clock.tick(2000))
133
- .then(() => promiseTick(50))
134
- .then(() => clock.tick(config.metrics.batcherWait))
135
- .then(() => assert.calledThrice(webex.request))
136
-
137
- .then(() => promiseTick(50))
138
- .then(() => clock.tick(4000))
139
- .then(() => promiseTick(50))
140
- .then(() => clock.tick(config.metrics.batcherWait))
141
- .then(() => assert.callCount(webex.request, 4))
142
-
143
- .then(() => promiseTick(50))
144
- .then(() => clock.tick(8000))
145
- .then(() => promiseTick(50))
146
- .then(() => clock.tick(config.metrics.batcherWait))
147
- .then(() => assert.callCount(webex.request, 5))
148
-
149
- .then(() => promiseTick(50))
150
- .then(() => clock.tick(16000))
151
- .then(() => promiseTick(50))
152
- .then(() => clock.tick(config.metrics.batcherWait))
153
- .then(() => assert.callCount(webex.request, 6))
154
-
155
- .then(() => promiseTick(50))
156
- .then(() => clock.tick(32000))
157
- .then(() => promiseTick(50))
158
- .then(() => clock.tick(config.metrics.batcherWait))
159
- .then(() => assert.callCount(webex.request, 7))
160
-
161
- .then(() => promiseTick(50))
162
- .then(() => clock.tick(32000))
163
- .then(() => promiseTick(50))
164
- .then(() => clock.tick(config.metrics.batcherWait))
165
- .then(() => assert.callCount(webex.request, 8))
166
-
167
- .then(() => promiseTick(50))
168
- .then(() => clock.tick(32000))
169
- .then(() => promiseTick(50))
170
- .then(() => clock.tick(config.metrics.batcherWait))
171
- .then(() => assert.callCount(webex.request, 9))
172
-
173
- .then(() => promiseTick(50))
174
- .then(() =>
175
- assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0)
176
- )
177
- .then(() => promise)
178
- .then(() => {
179
- assert.lengthOf(
180
- webex.request.args[1][0].body.metrics,
181
- 1,
182
- 'Reenqueuing the metric once did not increase the number of metrics to be submitted'
183
- );
184
- assert.lengthOf(
185
- webex.request.args[2][0].body.metrics,
186
- 1,
187
- 'Reenqueuing the metric twice did not increase the number of metrics to be submitted'
188
- );
189
- assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
190
- });
191
- });
192
- });
193
- });
194
- });
195
- });