@webex/internal-plugin-metrics 3.0.0-bnr.5 → 3.0.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/.eslintrc.js +6 -0
- package/babel.config.js +3 -0
- package/dist/batcher.js +41 -3
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +64 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +474 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +850 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +349 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +609 -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 +35 -2
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +28 -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 +302 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/prelogin-metrics-batcher.js +81 -0
- package/dist/prelogin-metrics-batcher.js.map +1 -0
- package/dist/types/batcher.d.ts +5 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +204 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +427 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +103 -0
- package/dist/types/call-diagnostic/config.d.ts +178 -0
- package/dist/types/config.d.ts +18 -0
- package/dist/types/index.d.ts +15 -3
- package/dist/types/metrics.d.ts +1 -0
- package/dist/types/metrics.types.d.ts +105 -0
- package/dist/types/new-metrics.d.ts +131 -0
- package/dist/types/prelogin-metrics-batcher.d.ts +2 -0
- package/dist/types/utils.d.ts +6 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/jest.config.js +3 -0
- package/package.json +34 -10
- package/process +1 -0
- package/src/batcher.js +38 -0
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +72 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +435 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +913 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +392 -0
- package/src/call-diagnostic/config.ts +685 -0
- package/src/client-metrics-batcher.js +1 -0
- package/src/config.js +1 -0
- package/src/index.ts +54 -0
- package/src/metrics.js +20 -16
- package/src/metrics.types.ts +168 -0
- package/src/new-metrics.ts +278 -0
- package/src/prelogin-metrics-batcher.ts +95 -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 +458 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +520 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2297 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +628 -0
- package/test/unit/spec/client-metrics-batcher.js +2 -0
- package/test/unit/spec/metrics.js +76 -95
- package/test/unit/spec/new-metrics.ts +233 -0
- package/test/unit/spec/prelogin-metrics-batcher.ts +250 -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/dist/internal-plugin-metrics.d.ts +0 -21
- package/dist/tsdoc-metadata.json +0 -11
- package/src/call-diagnostic-events-batcher.js +0 -62
- package/src/index.js +0 -17
- package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
- package/dist/types/{call-diagnostic-events-batcher.d.ts → call-diagnostic/call-diagnostic-metrics-batcher.d.ts} +1 -1
|
@@ -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":["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,21 +0,0 @@
|
|
|
1
|
-
export declare namespace config {
|
|
2
|
-
export namespace device {
|
|
3
|
-
export namespace preDiscoveryServices {
|
|
4
|
-
const metricsServiceUrl: string;
|
|
5
|
-
const metrics: string;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export namespace metrics_1 {
|
|
9
|
-
const appType: string;
|
|
10
|
-
const batcherWait: number;
|
|
11
|
-
const batcherMaxCalls: number;
|
|
12
|
-
const batcherMaxWait: number;
|
|
13
|
-
const batcherRetryPlateau: number;
|
|
14
|
-
}
|
|
15
|
-
{ metrics_1 as metrics };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare const Metrics: any;
|
|
19
|
-
export default Metrics;
|
|
20
|
-
|
|
21
|
-
export { }
|
package/dist/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.34.4"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
@@ -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
|
-
});
|