@webex/internal-plugin-metrics 3.0.0-beta.42 → 3.0.0-beta.421

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 (78) hide show
  1. package/dist/batcher.js +40 -1
  2. package/dist/batcher.js.map +1 -1
  3. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
  4. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  5. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +552 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics.js +863 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +371 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  11. package/dist/call-diagnostic/config.js +627 -0
  12. package/dist/call-diagnostic/config.js.map +1 -0
  13. package/dist/client-metrics-batcher.js +2 -1
  14. package/dist/client-metrics-batcher.js.map +1 -1
  15. package/dist/client-metrics-prelogin-batcher.js +33 -0
  16. package/dist/client-metrics-prelogin-batcher.js.map +1 -0
  17. package/dist/config.js +2 -1
  18. package/dist/config.js.map +1 -1
  19. package/dist/index.js +33 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/metrics.js +30 -50
  22. package/dist/metrics.js.map +1 -1
  23. package/dist/metrics.types.js +7 -0
  24. package/dist/metrics.types.js.map +1 -0
  25. package/dist/new-metrics.js +300 -0
  26. package/dist/new-metrics.js.map +1 -0
  27. package/dist/prelogin-metrics-batcher.js +82 -0
  28. package/dist/prelogin-metrics-batcher.js.map +1 -0
  29. package/dist/types/batcher.d.ts +7 -0
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
  31. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +237 -0
  32. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +425 -0
  33. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +103 -0
  34. package/dist/types/call-diagnostic/config.d.ts +178 -0
  35. package/dist/types/client-metrics-batcher.d.ts +2 -0
  36. package/dist/types/client-metrics-prelogin-batcher.d.ts +2 -0
  37. package/dist/types/config.d.ts +36 -0
  38. package/dist/types/index.d.ts +15 -0
  39. package/dist/types/metrics.d.ts +3 -0
  40. package/dist/types/metrics.types.d.ts +107 -0
  41. package/dist/types/new-metrics.d.ts +131 -0
  42. package/dist/types/prelogin-metrics-batcher.d.ts +2 -0
  43. package/dist/types/utils.d.ts +6 -0
  44. package/dist/utils.js +27 -0
  45. package/dist/utils.js.map +1 -0
  46. package/package.json +15 -8
  47. package/src/batcher.js +38 -0
  48. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +72 -0
  49. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +511 -0
  50. package/src/call-diagnostic/call-diagnostic-metrics.ts +925 -0
  51. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +399 -0
  52. package/src/call-diagnostic/config.ts +685 -0
  53. package/src/client-metrics-batcher.js +1 -0
  54. package/src/client-metrics-prelogin-batcher.ts +26 -0
  55. package/src/config.js +1 -0
  56. package/src/index.ts +56 -0
  57. package/src/metrics.js +26 -47
  58. package/src/metrics.types.ts +179 -0
  59. package/src/new-metrics.ts +278 -0
  60. package/src/prelogin-metrics-batcher.ts +95 -0
  61. package/src/utils.ts +17 -0
  62. package/test/unit/spec/batcher.js +2 -0
  63. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +469 -0
  64. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +718 -0
  65. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2371 -0
  66. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +637 -0
  67. package/test/unit/spec/client-metrics-batcher.js +2 -0
  68. package/test/unit/spec/client-metrics-prelogin-batcher.ts +54 -0
  69. package/test/unit/spec/metrics.js +78 -129
  70. package/test/unit/spec/new-metrics.ts +231 -0
  71. package/test/unit/spec/prelogin-metrics-batcher.ts +253 -0
  72. package/test/unit/spec/utils.ts +22 -0
  73. package/tsconfig.json +6 -0
  74. package/dist/call-diagnostic-events-batcher.js +0 -60
  75. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  76. package/src/call-diagnostic-events-batcher.js +0 -62
  77. package/src/index.js +0 -17
  78. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
@@ -0,0 +1,253 @@
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {assert} from '@webex/test-helper-chai';
6
+ import {config, Utils} from '@webex/internal-plugin-metrics';
7
+ import {CallDiagnosticUtils} from '@webex/internal-plugin-metrics';
8
+ import MockWebex from '@webex/test-helper-mock-webex';
9
+ import sinon from 'sinon';
10
+ import FakeTimers from '@sinonjs/fake-timers';
11
+ import {NewMetrics} from '@webex/internal-plugin-metrics';
12
+ import {uniqueId} from 'lodash';
13
+
14
+ const flushPromises = () => new Promise(setImmediate);
15
+
16
+ describe('internal-plugin-metrics', () => {
17
+ describe('PreLoginMetricsBatcher', () => {
18
+ let webex;
19
+ let clock;
20
+ let now;
21
+
22
+ const preLoginId = 'my_prelogin_id';
23
+
24
+ beforeEach(() => {
25
+ now = new Date();
26
+ clock = FakeTimers.install({now});
27
+
28
+ //@ts-ignore
29
+ webex = new MockWebex({
30
+ children: {
31
+ newMetrics: NewMetrics,
32
+ },
33
+ });
34
+
35
+ webex.request = (options) =>
36
+ Promise.resolve({body: {items: []}, waitForServiceTimeout: 15, options});
37
+
38
+ sinon.spy(webex, 'request');
39
+ webex.emit('ready');
40
+ webex.config.metrics = config.metrics;
41
+ });
42
+
43
+ afterEach(() => {
44
+ sinon.restore();
45
+ clock.uninstall();
46
+ });
47
+
48
+ describe('#request()', () => {
49
+ it('when the request completes successfully, clears the queue', async () => {
50
+ const promise =
51
+ webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
52
+ //@ts-ignore
53
+ {event: {name: 'client.interstitial-window.launched'}},
54
+ preLoginId
55
+ );
56
+ await flushPromises();
57
+ clock.tick(config.metrics.batcherWait);
58
+
59
+ await promise;
60
+
61
+ const webexRequestArgs = webex.request.args[0][0];
62
+
63
+ const dateAfterBatcherWait = new Date(now.getTime() + config.metrics.batcherWait);
64
+ //@ts-ignore
65
+ assert.calledOnce(webex.request);
66
+
67
+ // matching because the request includes a symbol key: value pair and sinon cannot handle to compare it..
68
+ assert.match(webexRequestArgs, {
69
+ body: {
70
+ metrics: [
71
+ {
72
+ eventPayload: {
73
+ event: {
74
+ joinTimes: {
75
+ meetingInfoReqResp: undefined,
76
+ clickToInterstitial: undefined,
77
+ refreshCaptchaServiceReqResp: undefined,
78
+ downloadIntelligenceModelsReqResp: undefined,
79
+ },
80
+ name: 'client.interstitial-window.launched',
81
+ },
82
+ origin: {
83
+ buildType: 'test',
84
+ networkType: 'unknown',
85
+ },
86
+ originTime: {
87
+ sent: dateAfterBatcherWait.toISOString(),
88
+ },
89
+ },
90
+ type: ['diagnostic-event'],
91
+ },
92
+ ],
93
+ },
94
+ headers: {
95
+ authorization: false,
96
+ 'x-prelogin-userid': preLoginId,
97
+ },
98
+ method: 'POST',
99
+ resource: 'clientmetrics-prelogin',
100
+ service: 'metrics',
101
+ waitForServiceTimeout: 30,
102
+ });
103
+ assert.lengthOf(
104
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.queue,
105
+ 0
106
+ );
107
+ });
108
+
109
+ it('when the request fails, does not clear the queue', async () => {
110
+ webex.request = sinon.stub().rejects(new Error('my_error'));
111
+
112
+ webex.logger.error = sinon.stub();
113
+ webex.logger.log = sinon.stub();
114
+ sinon.stub(Utils, 'generateCommonErrorMetadata').returns('formattedError');
115
+
116
+ const promise =
117
+ webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
118
+ {
119
+ event: 'my.event',
120
+ },
121
+ preLoginId
122
+ );
123
+
124
+ await flushPromises();
125
+ clock.tick(config.metrics.batcherWait);
126
+
127
+ let error;
128
+
129
+ // catch the expected error and store it
130
+ try {
131
+ await promise;
132
+ } catch (err) {
133
+ error = err;
134
+ }
135
+
136
+ // This is horrific, but stubbing lodash is proving difficult
137
+ const expectedBatchId = parseInt(uniqueId()) - 1;
138
+
139
+ assert.equal(error.message, 'my_error');
140
+ assert.calledOnceWithExactly(
141
+ webex.logger.error,
142
+ 'Pre Login Metrics -->',
143
+ `PreLoginMetricsBatcher: @submitHttpRequest#prelogin-batch-${expectedBatchId}. Request failed:`,
144
+ `error: formattedError`
145
+ );
146
+ assert.lengthOf(
147
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.queue,
148
+ 0
149
+ );
150
+ });
151
+
152
+ it('fails if preLoinId is not set', async () => {
153
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId =
154
+ undefined;
155
+
156
+ const promise =
157
+ webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
158
+ {
159
+ event: 'my.event',
160
+ },
161
+ undefined
162
+ );
163
+
164
+ await flushPromises();
165
+ clock.tick(config.metrics.batcherWait);
166
+
167
+ let error;
168
+
169
+ // catch the expected error and store it
170
+ try {
171
+ await promise;
172
+ } catch (err) {
173
+ error = err;
174
+ }
175
+
176
+ assert.equal(error.message, 'PreLoginId is not set.');
177
+ });
178
+ });
179
+
180
+ describe('prepareItem', () => {
181
+ it('calls prepareDiagnosticMetricItem correctly', async () => {
182
+ // avoid setting .sent timestamp
183
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.prepareRequest = (q) =>
184
+ Promise.resolve(q);
185
+
186
+ const prepareItemSpy = sinon.spy(
187
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher,
188
+ 'prepareItem'
189
+ );
190
+ const prepareDiagnosticMetricItemSpy = sinon.spy(
191
+ CallDiagnosticUtils,
192
+ 'prepareDiagnosticMetricItem'
193
+ );
194
+
195
+ const promise =
196
+ webex.internal.newMetrics.callDiagnosticMetrics.submitToCallDiagnosticsPreLogin(
197
+ {
198
+ event: 'my.event',
199
+ },
200
+ preLoginId
201
+ );
202
+
203
+ await flushPromises();
204
+
205
+ clock.tick(config.metrics.batcherWait);
206
+
207
+ await promise;
208
+
209
+ const calls = prepareItemSpy.getCalls()[0];
210
+
211
+ // item also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
212
+ assert.deepEqual(calls.args[0].eventPayload, {
213
+ event: 'my.event',
214
+ origin: {buildType: 'test', networkType: 'unknown'},
215
+ });
216
+
217
+ assert.deepEqual(calls.args[0].type, ['diagnostic-event']);
218
+
219
+ const prepareDiagnosticMetricItemCalls = prepareDiagnosticMetricItemSpy.getCalls();
220
+
221
+ // second argument (item) also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
222
+ assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[0], webex);
223
+ assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].eventPayload, {
224
+ event: 'my.event',
225
+ origin: {
226
+ buildType: 'test',
227
+ networkType: 'unknown',
228
+ },
229
+ });
230
+ assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].type, ['diagnostic-event']);
231
+ });
232
+ });
233
+
234
+ describe('savePreLoginId', () => {
235
+ it('saves the preLoginId', () => {
236
+ const preLoginId = 'my_prelogin_id';
237
+
238
+ assert.isUndefined(
239
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId
240
+ );
241
+
242
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.savePreLoginId(
243
+ preLoginId
244
+ );
245
+
246
+ assert.equal(
247
+ webex.internal.newMetrics.callDiagnosticMetrics.preLoginMetricsBatcher.preLoginId,
248
+ preLoginId
249
+ );
250
+ });
251
+ });
252
+ });
253
+ });
@@ -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
@@ -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
- });