@webex/internal-plugin-metrics 3.0.0-beta.13 → 3.0.0-beta.15
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/README.md +1 -3
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic-events-batcher.js +1 -1
- package/dist/call-diagnostic-events-batcher.js.map +1 -1
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +2 -4
- package/dist/metrics.js.map +1 -1
- package/package.json +8 -8
- package/src/batcher.js +33 -26
- package/src/call-diagnostic-events-batcher.js +5 -5
- package/src/client-metrics-batcher.js +3 -4
- package/src/config.js +6 -5
- package/src/index.js +1 -1
- package/src/metrics.js +24 -36
- package/test/unit/spec/batcher.js +26 -15
- package/test/unit/spec/call-diagnostic-events-batcher.js +39 -24
- package/test/unit/spec/client-metrics-batcher.js +26 -15
- package/test/unit/spec/metrics.js +22 -21
package/README.md
CHANGED
|
@@ -21,14 +21,12 @@ npm install --save @webex/internal-plugin-metrics
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
|
|
25
24
|
import '@webex/internal-plugin-metrics';
|
|
26
25
|
|
|
27
26
|
import WebexCore from '@webex/webex-core';
|
|
28
27
|
|
|
29
28
|
const webex = new WebexCore();
|
|
30
|
-
webex.internal.metrics.WHATEVER
|
|
31
|
-
|
|
29
|
+
webex.internal.metrics.WHATEVER;
|
|
32
30
|
```
|
|
33
31
|
|
|
34
32
|
## Maintainers
|
package/dist/batcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sym","MetricsBatcher","Batcher","extend","namespace","prepareItem","item","env","process","NODE_ENV","appType","config","time","version","webex","resolve","prepareRequest","queue","map","postTime","submitHttpRequest","payload","request","method","service","resource","body","metrics","handleHttpSuccess","res","all","options","acceptItem","handleHttpError","reason","WebexHttpError","NetworkOrCORSError","logger","warn","delay","nextDelay","batcherRetryPlateau","safeSetTimeout","rerequest","prototype","getDeferredForRequest","then","defer","req","enqueue","bounce","catch","reject","fingerprintRequest","fingerprintResponse"],"sources":["batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {Batcher, WebexHttpError} from '@webex/webex-core';\nimport {safeSetTimeout} from '@webex/common-timers';\n\nconst sym = Symbol('metric id');\n\nconst MetricsBatcher = Batcher.extend({\n namespace: 'Metrics',\n\n prepareItem(item) {\n // Keep non-prod data out of metrics\n const env = process.env.NODE_ENV === 'production' ? null : 'TEST';\n\n item.appType = item.appType || this.config.appType;\n item.env = item.env || env;\n item.time = item.time || Date.now();\n item.version = item.version || this.webex.version;\n\n return Promise.resolve(item);\n },\n\n prepareRequest(queue) {\n return Promise.resolve(queue.map((item) => {\n
|
|
1
|
+
{"version":3,"names":["sym","MetricsBatcher","Batcher","extend","namespace","prepareItem","item","env","process","NODE_ENV","appType","config","time","version","webex","resolve","prepareRequest","queue","map","postTime","submitHttpRequest","payload","request","method","service","resource","body","metrics","handleHttpSuccess","res","all","options","acceptItem","handleHttpError","reason","WebexHttpError","NetworkOrCORSError","logger","warn","delay","nextDelay","batcherRetryPlateau","safeSetTimeout","rerequest","prototype","getDeferredForRequest","then","defer","req","enqueue","bounce","catch","reject","fingerprintRequest","fingerprintResponse"],"sources":["batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {Batcher, WebexHttpError} from '@webex/webex-core';\nimport {safeSetTimeout} from '@webex/common-timers';\n\nconst sym = Symbol('metric id');\n\nconst MetricsBatcher = Batcher.extend({\n namespace: 'Metrics',\n\n prepareItem(item) {\n // Keep non-prod data out of metrics\n const env = process.env.NODE_ENV === 'production' ? null : 'TEST';\n\n item.appType = item.appType || this.config.appType;\n item.env = item.env || env;\n item.time = item.time || Date.now();\n item.version = item.version || this.webex.version;\n\n return Promise.resolve(item);\n },\n\n prepareRequest(queue) {\n return Promise.resolve(\n queue.map((item) => {\n item.postTime = item.postTime || Date.now();\n\n return item;\n })\n );\n },\n\n submitHttpRequest(payload) {\n return this.webex.request({\n method: 'POST',\n service: 'metrics',\n resource: 'metrics',\n body: {\n metrics: payload,\n },\n });\n },\n\n handleHttpSuccess(res) {\n return Promise.all(res.options.body.metrics.map((item) => this.acceptItem(item)));\n },\n\n handleHttpError(reason) {\n if (reason instanceof WebexHttpError.NetworkOrCORSError) {\n this.logger.warn(\n 'metrics-batcher: received network error submitting metrics, reenqueuing payload'\n );\n\n return Promise.all(\n reason.options.body.metrics.map(\n (item) =>\n new Promise((resolve) => {\n const delay = item[sym].nextDelay;\n\n if (delay < this.config.batcherRetryPlateau) {\n item[sym].nextDelay *= 2;\n }\n safeSetTimeout(() => {\n resolve(this.rerequest(item));\n }, delay);\n })\n )\n );\n }\n\n return Reflect.apply(Batcher.prototype.handleHttpError, this, [reason]);\n },\n\n rerequest(item) {\n return Promise.all([this.getDeferredForRequest(item), this.prepareItem(item)]).then(\n ([defer, req]) => {\n this.enqueue(req)\n .then(() => this.bounce())\n .catch((reason) => defer.reject(reason));\n }\n );\n },\n\n fingerprintRequest(item) {\n item[sym] = item[sym] || {\n nextDelay: 1000,\n };\n\n return Promise.resolve(item[sym]);\n },\n\n fingerprintResponse(item) {\n return Promise.resolve(item[sym]);\n },\n});\n\nexport default MetricsBatcher;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIA;;AACA;;AALA;AACA;AACA;AAKA,IAAMA,GAAG,GAAG,qBAAO,WAAP,CAAZ;;AAEA,IAAMC,cAAc,GAAGC,kBAAA,CAAQC,MAAR,CAAe;EACpCC,SAAS,EAAE,SADyB;EAGpCC,WAHoC,uBAGxBC,IAHwB,EAGlB;IAChB;IACA,IAAMC,GAAG,GAAGC,OAAO,CAACD,GAAR,CAAYE,QAAZ,KAAyB,YAAzB,GAAwC,IAAxC,GAA+C,MAA3D;IA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J,GAAYM,IAAI,CAACN,GAAD,CAAJ,IAAa;MACvBwC,SAAS,EAAE;IADY,CAAzB;IAIA,OAAO,iBAAQzB,OAAR,CAAgBT,IAAI,CAACN,GAAD,CAApB,CAAP;EACD,CAlFmC;EAoFpCsD,mBApFoC,+BAoFhBhD,IApFgB,EAoFV;IACxB,OAAO,iBAAQS,OAAR,CAAgBT,IAAI,CAACN,GAAD,CAApB,CAAP;EACD;AAtFmC,CAAf,CAAvB;;eAyFeC,c"}
|
|
@@ -25,7 +25,7 @@ var CallDiagnosticEventsBatcher = _batcher.default.extend({
|
|
|
25
25
|
/**
|
|
26
26
|
* @param {string} webClientDomain
|
|
27
27
|
* @returns {string}
|
|
28
|
-
|
|
28
|
+
*/
|
|
29
29
|
getBuildType: function getBuildType(webClientDomain) {
|
|
30
30
|
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') {
|
|
31
31
|
return 'test';
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,gBAAA,CAAQC,MAAR,CAAe;EACjDC,SAAS,EAAE,SADsC;;EAGjD;AACF;AACA;AACA;EACEC,YAPiD,wBAOpCC,eAPoC,EAOnB;IAC5B,IACEA,eAAe,SAAf,IAAAA,eAAe,WAAf,IAAAA,eAAe,CAAEC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MADgB;MAExBC,OAAO,EAAE,SAFe;MAGxBC,QAAQ,EAAE,eAHc;MAIxBC,IAAI,EAAE;QACJC,OAAO,EAAEP;MADL;IAJkB,CAAnB,CAAP;EAQD;AApDgD,CAAf,CAApC;;eAuDe3B,2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ClientMetricsBatcher","Batcher","extend","namespace","prepareItem","item","resolve","prepareRequest","queue","submitHttpRequest","payload","webex","request","method","service","resource","body","metrics"],"sources":["client-metrics-batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport Batcher from './batcher';\n\nconst ClientMetricsBatcher = Batcher.extend({\n namespace: 'Metrics',\n\n prepareItem(item) {\n // Add more defaults to payload when the clientmetrics endpoint evolves to support richer payloads\n return Promise.resolve(item);\n },\n\n prepareRequest(queue) {\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
|
|
1
|
+
{"version":3,"names":["ClientMetricsBatcher","Batcher","extend","namespace","prepareItem","item","resolve","prepareRequest","queue","submitHttpRequest","payload","webex","request","method","service","resource","body","metrics"],"sources":["client-metrics-batcher.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport Batcher from './batcher';\n\nconst ClientMetricsBatcher = Batcher.extend({\n namespace: 'Metrics',\n\n prepareItem(item) {\n // Add more defaults to payload when the clientmetrics endpoint evolves to support richer payloads\n return Promise.resolve(item);\n },\n\n prepareRequest(queue) {\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 ClientMetricsBatcher;\n"],"mappings":";;;;;;;;;;;;;;AAIA;;AAJA;AACA;AACA;AAIA,IAAMA,oBAAoB,GAAGC,gBAAA,CAAQC,MAAR,CAAe;EAC1CC,SAAS,EAAE,SAD+B;EAG1CC,WAH0C,uBAG9BC,IAH8B,EAGxB;IAChB;IACA,OAAO,iBAAQC,OAAR,CAAgBD,IAAhB,CAAP;EACD,CANyC;EAQ1CE,cAR0C,0BAQ3BC,KAR2B,EAQpB;IACpB,OAAO,iBAAQF,OAAR,CAAgBE,KAAhB,CAAP;EACD,CAVyC;EAY1CC,iBAZ0C,6BAYxBC,OAZwB,EAYf;IACzB,OAAO,KAAKC,KAAL,CAAWC,OAAX,CAAmB;MACxBC,MAAM,EAAE,MADgB;MAExBC,OAAO,EAAE,SAFe;MAGxBC,QAAQ,EAAE,eAHc;MAIxBC,IAAI,EAAE;QACJC,OAAO,EAAEP;MADL;IAJkB,CAAnB,CAAP;EAQD;AArByC,CAAf,CAA7B;;eAwBeV,oB"}
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["CLIENT_NAME","device","preDiscoveryServices","metricsServiceUrl","process","env","METRICS_SERVICE_URL","metrics","appType","inBrowser","batcherWait","batcherMaxCalls","batcherMaxWait","batcherRetryPlateau"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {inBrowser} from '@webex/common';\n\nexport const CLIENT_NAME = 'webex-js-sdk';\nexport default {\n device: {\n preDiscoveryServices: {\n metricsServiceUrl
|
|
1
|
+
{"version":3,"names":["CLIENT_NAME","device","preDiscoveryServices","metricsServiceUrl","process","env","METRICS_SERVICE_URL","metrics","appType","inBrowser","batcherWait","batcherMaxCalls","batcherMaxWait","batcherRetryPlateau"],"sources":["config.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {inBrowser} from '@webex/common';\n\nexport const CLIENT_NAME = 'webex-js-sdk';\nexport default {\n device: {\n preDiscoveryServices: {\n metricsServiceUrl:\n process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',\n metrics: process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',\n },\n },\n metrics: {\n appType: inBrowser ? 'browser' : 'nodejs',\n batcherWait: 500,\n batcherMaxCalls: 50,\n batcherMaxWait: 1500,\n batcherRetryPlateau: 32000,\n },\n};\n"],"mappings":";;;;;;;;;;AAIA;;AAJA;AACA;AACA;AAIO,IAAMA,WAAW,GAAG,cAApB;;eACQ;EACbC,MAAM,EAAE;IACNC,oBAAoB,EAAE;MACpBC,iBAAiB,EACfC,OAAO,CAACC,GAAR,CAAYC,mBAAZ,IAAmC,2CAFjB;MAGpBC,OAAO,EAAEH,OAAO,CAACC,GAAR,CAAYC,mBAAZ,IAAmC;IAHxB;EADhB,CADK;EAQbC,OAAO,EAAE;IACPC,OAAO,EAAEC,iBAAA,GAAY,SAAZ,GAAwB,QAD1B;IAEPC,WAAW,EAAE,GAFN;IAGPC,eAAe,EAAE,EAHV;IAIPC,cAAc,EAAE,IAJT;IAKPC,mBAAmB,EAAE;EALd;AARI,C"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerInternalPlugin","Metrics","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\n\nimport {registerInternalPlugin} from '@webex/webex-core';\n\nimport Metrics from './metrics';\nimport config from './config';\n\nregisterInternalPlugin('metrics', Metrics, {\n config
|
|
1
|
+
{"version":3,"names":["registerInternalPlugin","Metrics","config"],"sources":["index.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport '@webex/internal-plugin-device';\n\nimport {registerInternalPlugin} from '@webex/webex-core';\n\nimport Metrics from './metrics';\nimport config from './config';\n\nregisterInternalPlugin('metrics', Metrics, {\n config,\n});\n\nexport {default} from './metrics';\nexport {config};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA;;AAEA;;AAEA;;AACA;;AATA;AACA;AACA;AASA,IAAAA,iCAAA,EAAuB,SAAvB,EAAkCC,gBAAlC,EAA2C;EACzCC,MAAM,EAANA;AADyC,CAA3C"}
|
package/dist/metrics.js
CHANGED
|
@@ -22,8 +22,6 @@ exports.default = void 0;
|
|
|
22
22
|
|
|
23
23
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
|
|
24
24
|
|
|
25
|
-
var _assign = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/assign"));
|
|
26
|
-
|
|
27
25
|
var _webexCore = require("@webex/webex-core");
|
|
28
26
|
|
|
29
27
|
var _common = require("@webex/common");
|
|
@@ -75,7 +73,7 @@ var Metrics = _webexCore.WebexPlugin.extend({
|
|
|
75
73
|
},
|
|
76
74
|
namespace: 'Metrics',
|
|
77
75
|
submit: function submit(key, value) {
|
|
78
|
-
return this.batcher.request((
|
|
76
|
+
return this.batcher.request(_objectSpread({
|
|
79
77
|
key: key
|
|
80
78
|
}, value));
|
|
81
79
|
},
|
|
@@ -197,7 +195,7 @@ var Metrics = _webexCore.WebexPlugin.extend({
|
|
|
197
195
|
};
|
|
198
196
|
return this.callDiagnosticEventsBatcher.request(event);
|
|
199
197
|
},
|
|
200
|
-
version: "3.0.0-beta.
|
|
198
|
+
version: "3.0.0-beta.15"
|
|
201
199
|
});
|
|
202
200
|
|
|
203
201
|
var _default = Metrics;
|
package/dist/metrics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BrowserDetection","getOSName","getOSVersion","getBrowserName","getBrowserVersion","getSparkUserAgent","webex","config","appName","appVersion","appPlatform","sparkUserAgent","CLIENT_NAME","Metrics","WebexPlugin","extend","children","batcher","Batcher","clientMetricsBatcher","ClientMetricsBatcher","callDiagnosticEventsBatcher","CallDiagnosticEventsBatcher","namespace","submit","key","value","request","submitClientMetrics","eventName","props","preLoginId","Error","payload","metricName","tags","browser","os","domain","window","location","hostname","client_id","credentials","user_id","internal","device","userId","org_id","getOrgId","logger","info","fields","browser_version","os_version","sdk_version","version","platform","spark_user_agent","type","metrics","context","app","locale","name","eventPayload","timestamp","Date","valueOf","_payload","postPreLoginMetric","aliasUser","method","api","resource","headers","body","qs","alias","getClientToken","then","token","authorization","toString","submitCallDiagnosticEvents","event"],"sources":["metrics.js"],"sourcesContent":["/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {BrowserDetection} from '@webex/common';\n\nimport {CLIENT_NAME} from './config';\nimport Batcher from './batcher';\nimport ClientMetricsBatcher from './client-metrics-batcher';\nimport CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';\n\nconst {
|
|
1
|
+
{"version":3,"names":["BrowserDetection","getOSName","getOSVersion","getBrowserName","getBrowserVersion","getSparkUserAgent","webex","config","appName","appVersion","appPlatform","sparkUserAgent","CLIENT_NAME","Metrics","WebexPlugin","extend","children","batcher","Batcher","clientMetricsBatcher","ClientMetricsBatcher","callDiagnosticEventsBatcher","CallDiagnosticEventsBatcher","namespace","submit","key","value","request","submitClientMetrics","eventName","props","preLoginId","Error","payload","metricName","tags","browser","os","domain","window","location","hostname","client_id","credentials","user_id","internal","device","userId","org_id","getOrgId","logger","info","fields","browser_version","os_version","sdk_version","version","platform","spark_user_agent","type","metrics","context","app","locale","name","eventPayload","timestamp","Date","valueOf","_payload","postPreLoginMetric","aliasUser","method","api","resource","headers","body","qs","alias","getClientToken","then","token","authorization","toString","submitCallDiagnosticEvents","event"],"sources":["metrics.js"],"sourcesContent":["/* eslint-disable default-param-last */\n\n/*!\n * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.\n */\n\nimport {WebexPlugin} from '@webex/webex-core';\nimport {BrowserDetection} from '@webex/common';\n\nimport {CLIENT_NAME} from './config';\nimport Batcher from './batcher';\nimport ClientMetricsBatcher from './client-metrics-batcher';\nimport CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';\n\nconst {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();\n\nfunction getSparkUserAgent(webex) {\n const {appName, appVersion, appPlatform} = webex?.config ?? {};\n\n let sparkUserAgent = CLIENT_NAME;\n\n if (appName) {\n sparkUserAgent += ` ${appName}/${appVersion ?? '0.0'}`;\n }\n\n if (appPlatform) {\n sparkUserAgent += ` ${appPlatform}`;\n }\n\n return sparkUserAgent;\n}\n\nconst Metrics = WebexPlugin.extend({\n children: {\n batcher: Batcher,\n clientMetricsBatcher: ClientMetricsBatcher,\n callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher,\n },\n\n namespace: 'Metrics',\n\n submit(key, value) {\n return this.batcher.request({key, ...value});\n },\n\n /**\n * This corresponds to #sendSemiStructured() in the deprecated metrics handler\n * @param {string} eventName\n * @param {Object} props\n * @param {string} preLoginId\n * @returns {Object} HttpResponse object\n */\n submitClientMetrics(eventName, props = {}, preLoginId) {\n if (!eventName) {\n throw Error('Missing behavioral metric name. Please provide one');\n }\n const payload = {metricName: eventName};\n\n payload.tags = {\n ...props.tags,\n browser: getBrowserName(),\n os: getOSName(),\n\n // Node does not like this so we need to check if it exists or not\n // eslint-disable-next-line no-undef\n domain:\n typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure\n client_id: this.webex.credentials.config.client_id,\n user_id: this.webex.internal.device.userId,\n };\n\n try {\n payload.tags.org_id = this.webex.credentials.getOrgId();\n } catch {\n this.logger.info('metrics: unable to get orgId');\n }\n\n payload.fields = {\n ...props.fields,\n browser_version: getBrowserVersion(),\n os_version: getOSVersion(),\n sdk_version: this.webex.version,\n platform: 'Web',\n spark_user_agent: getSparkUserAgent(this.webex),\n };\n\n payload.type = props.type || this.webex.config.metrics.type;\n\n payload.context = {\n ...props.context,\n app: {\n version: this.webex.version,\n },\n locale: 'en-US',\n os: {\n name: getOSName(),\n version: getOSVersion(),\n },\n };\n\n if (props.eventPayload) {\n payload.eventPayload = props.eventPayload;\n }\n\n // Mocking the time in tests when running in node\n // is impossible so unable to use Date.now()\n payload.timestamp = new Date().valueOf();\n\n if (preLoginId) {\n const _payload = {\n metrics: [payload],\n };\n\n // Do not batch these because pre-login events occur during onboarding, so we will be partially blind\n // to users' progress through the reg flow if we wait to persist pre-login metrics for people who drop off because\n // their metrics will not post from a queue flush in time\n return this.postPreLoginMetric(_payload, preLoginId);\n }\n\n return this.clientMetricsBatcher.request(payload);\n },\n\n /**\n * Issue request to alias a user's pre-login ID with their CI UUID\n * @param {string} preLoginId\n * @returns {Object} HttpResponse object\n */\n aliasUser(preLoginId) {\n return this.request({\n method: 'POST',\n api: 'metrics',\n resource: 'clientmetrics',\n headers: {\n 'x-prelogin-userid': preLoginId,\n },\n body: {},\n qs: {\n alias: true,\n },\n });\n },\n\n postPreLoginMetric(payload, preLoginId) {\n return this.webex.credentials.getClientToken().then((token) =>\n this.request({\n method: 'POST',\n api: 'metrics',\n resource: 'clientmetrics-prelogin',\n headers: {\n authorization: token.toString(),\n 'x-prelogin-userid': preLoginId,\n },\n body: payload,\n })\n );\n },\n\n submitCallDiagnosticEvents(payload) {\n const event = {\n type: 'diagnostic-event',\n eventPayload: payload,\n };\n\n return this.callDiagnosticEventsBatcher.request(event);\n },\n});\n\nexport default Metrics;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA;;AACA;;AAEA;;AACA;;AACA;;AACA;;;;;;AAEA,wBAAqE,IAAAA,wBAAA,GAArE;AAAA,IAAOC,SAAP,qBAAOA,SAAP;AAAA,IAAkBC,YAAlB,qBAAkBA,YAAlB;AAAA,IAAgCC,cAAhC,qBAAgCA,cAAhC;AAAA,IAAgDC,iBAAhD,qBAAgDA,iBAAhD;;AAEA,SAASC,iBAAT,CAA2BC,KAA3B,EAAkC;EAAA;;EAChC,4BAA2CA,KAA3C,aAA2CA,KAA3C,uBAA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A,CAAnB,CAAhB;;eAuIexE,O"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webex/internal-plugin-metrics",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"sinon": "^9.2.4"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@webex/common": "3.0.0-beta.
|
|
28
|
-
"@webex/common-timers": "3.0.0-beta.
|
|
29
|
-
"@webex/internal-plugin-device": "3.0.0-beta.
|
|
30
|
-
"@webex/internal-plugin-metrics": "3.0.0-beta.
|
|
31
|
-
"@webex/test-helper-chai": "3.0.0-beta.
|
|
32
|
-
"@webex/test-helper-mock-webex": "3.0.0-beta.
|
|
33
|
-
"@webex/webex-core": "3.0.0-beta.
|
|
27
|
+
"@webex/common": "3.0.0-beta.15",
|
|
28
|
+
"@webex/common-timers": "3.0.0-beta.15",
|
|
29
|
+
"@webex/internal-plugin-device": "3.0.0-beta.15",
|
|
30
|
+
"@webex/internal-plugin-metrics": "3.0.0-beta.15",
|
|
31
|
+
"@webex/test-helper-chai": "3.0.0-beta.15",
|
|
32
|
+
"@webex/test-helper-mock-webex": "3.0.0-beta.15",
|
|
33
|
+
"@webex/webex-core": "3.0.0-beta.15"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/batcher.js
CHANGED
|
@@ -23,11 +23,13 @@ const MetricsBatcher = Batcher.extend({
|
|
|
23
23
|
},
|
|
24
24
|
|
|
25
25
|
prepareRequest(queue) {
|
|
26
|
-
return Promise.resolve(
|
|
27
|
-
|
|
26
|
+
return Promise.resolve(
|
|
27
|
+
queue.map((item) => {
|
|
28
|
+
item.postTime = item.postTime || Date.now();
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
return item;
|
|
31
|
+
})
|
|
32
|
+
);
|
|
31
33
|
},
|
|
32
34
|
|
|
33
35
|
submitHttpRequest(payload) {
|
|
@@ -36,8 +38,8 @@ const MetricsBatcher = Batcher.extend({
|
|
|
36
38
|
service: 'metrics',
|
|
37
39
|
resource: 'metrics',
|
|
38
40
|
body: {
|
|
39
|
-
metrics: payload
|
|
40
|
-
}
|
|
41
|
+
metrics: payload,
|
|
42
|
+
},
|
|
41
43
|
});
|
|
42
44
|
},
|
|
43
45
|
|
|
@@ -47,38 +49,43 @@ const MetricsBatcher = Batcher.extend({
|
|
|
47
49
|
|
|
48
50
|
handleHttpError(reason) {
|
|
49
51
|
if (reason instanceof WebexHttpError.NetworkOrCORSError) {
|
|
50
|
-
this.logger.warn(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
item
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
this.logger.warn(
|
|
53
|
+
'metrics-batcher: received network error submitting metrics, reenqueuing payload'
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return Promise.all(
|
|
57
|
+
reason.options.body.metrics.map(
|
|
58
|
+
(item) =>
|
|
59
|
+
new Promise((resolve) => {
|
|
60
|
+
const delay = item[sym].nextDelay;
|
|
61
|
+
|
|
62
|
+
if (delay < this.config.batcherRetryPlateau) {
|
|
63
|
+
item[sym].nextDelay *= 2;
|
|
64
|
+
}
|
|
65
|
+
safeSetTimeout(() => {
|
|
66
|
+
resolve(this.rerequest(item));
|
|
67
|
+
}, delay);
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
);
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
return Reflect.apply(Batcher.prototype.handleHttpError, this, [reason]);
|
|
65
74
|
},
|
|
66
75
|
|
|
67
76
|
rerequest(item) {
|
|
68
|
-
return Promise.all([
|
|
69
|
-
|
|
70
|
-
this.prepareItem(item)
|
|
71
|
-
])
|
|
72
|
-
.then(([defer, req]) => {
|
|
77
|
+
return Promise.all([this.getDeferredForRequest(item), this.prepareItem(item)]).then(
|
|
78
|
+
([defer, req]) => {
|
|
73
79
|
this.enqueue(req)
|
|
74
80
|
.then(() => this.bounce())
|
|
75
81
|
.catch((reason) => defer.reject(reason));
|
|
76
|
-
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
77
84
|
},
|
|
78
85
|
|
|
79
86
|
fingerprintRequest(item) {
|
|
80
87
|
item[sym] = item[sym] || {
|
|
81
|
-
nextDelay: 1000
|
|
88
|
+
nextDelay: 1000,
|
|
82
89
|
};
|
|
83
90
|
|
|
84
91
|
return Promise.resolve(item[sym]);
|
|
@@ -86,7 +93,7 @@ const MetricsBatcher = Batcher.extend({
|
|
|
86
93
|
|
|
87
94
|
fingerprintResponse(item) {
|
|
88
95
|
return Promise.resolve(item[sym]);
|
|
89
|
-
}
|
|
96
|
+
},
|
|
90
97
|
});
|
|
91
98
|
|
|
92
99
|
export default MetricsBatcher;
|
|
@@ -10,7 +10,7 @@ const CallDiagnosticEventsBatcher = Batcher.extend({
|
|
|
10
10
|
/**
|
|
11
11
|
* @param {string} webClientDomain
|
|
12
12
|
* @returns {string}
|
|
13
|
-
|
|
13
|
+
*/
|
|
14
14
|
getBuildType(webClientDomain) {
|
|
15
15
|
if (
|
|
16
16
|
webClientDomain?.includes('teams.webex.com') ||
|
|
@@ -29,7 +29,7 @@ const CallDiagnosticEventsBatcher = Batcher.extend({
|
|
|
29
29
|
// Browsers cannot provide such information right now. However, it is a required field.
|
|
30
30
|
const origin = {
|
|
31
31
|
buildType: this.getBuildType(item.event?.eventData?.webClientDomain),
|
|
32
|
-
networkType: 'unknown'
|
|
32
|
+
networkType: 'unknown',
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
item.eventPayload.origin = Object.assign(origin, item.eventPayload.origin);
|
|
@@ -53,10 +53,10 @@ const CallDiagnosticEventsBatcher = Batcher.extend({
|
|
|
53
53
|
service: 'metrics',
|
|
54
54
|
resource: 'clientmetrics',
|
|
55
55
|
body: {
|
|
56
|
-
metrics: payload
|
|
57
|
-
}
|
|
56
|
+
metrics: payload,
|
|
57
|
+
},
|
|
58
58
|
});
|
|
59
|
-
}
|
|
59
|
+
},
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
export default CallDiagnosticEventsBatcher;
|
package/src/config.js
CHANGED
|
@@ -8,15 +8,16 @@ export const CLIENT_NAME = 'webex-js-sdk';
|
|
|
8
8
|
export default {
|
|
9
9
|
device: {
|
|
10
10
|
preDiscoveryServices: {
|
|
11
|
-
metricsServiceUrl:
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
metricsServiceUrl:
|
|
12
|
+
process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',
|
|
13
|
+
metrics: process.env.METRICS_SERVICE_URL || 'https://metrics-a.wbx2.com/metrics/api/v1',
|
|
14
|
+
},
|
|
14
15
|
},
|
|
15
16
|
metrics: {
|
|
16
17
|
appType: inBrowser ? 'browser' : 'nodejs',
|
|
17
18
|
batcherWait: 500,
|
|
18
19
|
batcherMaxCalls: 50,
|
|
19
20
|
batcherMaxWait: 1500,
|
|
20
|
-
batcherRetryPlateau: 32000
|
|
21
|
-
}
|
|
21
|
+
batcherRetryPlateau: 32000,
|
|
22
|
+
},
|
|
22
23
|
};
|
package/src/index.js
CHANGED
package/src/metrics.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable default-param-last */
|
|
2
|
+
|
|
1
3
|
/*!
|
|
2
4
|
* Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
|
|
3
5
|
*/
|
|
@@ -10,19 +12,10 @@ import Batcher from './batcher';
|
|
|
10
12
|
import ClientMetricsBatcher from './client-metrics-batcher';
|
|
11
13
|
import CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';
|
|
12
14
|
|
|
13
|
-
const {
|
|
14
|
-
getOSName,
|
|
15
|
-
getOSVersion,
|
|
16
|
-
getBrowserName,
|
|
17
|
-
getBrowserVersion
|
|
18
|
-
} = BrowserDetection();
|
|
15
|
+
const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
|
|
19
16
|
|
|
20
17
|
function getSparkUserAgent(webex) {
|
|
21
|
-
const {
|
|
22
|
-
appName,
|
|
23
|
-
appVersion,
|
|
24
|
-
appPlatform
|
|
25
|
-
} = webex?.config ?? {};
|
|
18
|
+
const {appName, appVersion, appPlatform} = webex?.config ?? {};
|
|
26
19
|
|
|
27
20
|
let sparkUserAgent = CLIENT_NAME;
|
|
28
21
|
|
|
@@ -37,21 +30,19 @@ function getSparkUserAgent(webex) {
|
|
|
37
30
|
return sparkUserAgent;
|
|
38
31
|
}
|
|
39
32
|
|
|
40
|
-
|
|
41
33
|
const Metrics = WebexPlugin.extend({
|
|
42
34
|
children: {
|
|
43
35
|
batcher: Batcher,
|
|
44
36
|
clientMetricsBatcher: ClientMetricsBatcher,
|
|
45
|
-
callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher
|
|
37
|
+
callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher,
|
|
46
38
|
},
|
|
47
39
|
|
|
48
40
|
namespace: 'Metrics',
|
|
49
41
|
|
|
50
42
|
submit(key, value) {
|
|
51
|
-
return this.batcher.request(
|
|
43
|
+
return this.batcher.request({key, ...value});
|
|
52
44
|
},
|
|
53
45
|
|
|
54
|
-
|
|
55
46
|
/**
|
|
56
47
|
* This corresponds to #sendSemiStructured() in the deprecated metrics handler
|
|
57
48
|
* @param {string} eventName
|
|
@@ -72,45 +63,41 @@ const Metrics = WebexPlugin.extend({
|
|
|
72
63
|
|
|
73
64
|
// Node does not like this so we need to check if it exists or not
|
|
74
65
|
// eslint-disable-next-line no-undef
|
|
75
|
-
domain:
|
|
66
|
+
domain:
|
|
67
|
+
typeof window !== 'undefined' ? window.location.hostname || 'non-browser' : 'non-browser', // Check what else we could measure
|
|
76
68
|
client_id: this.webex.credentials.config.client_id,
|
|
77
|
-
user_id: this.webex.internal.device.userId
|
|
69
|
+
user_id: this.webex.internal.device.userId,
|
|
78
70
|
};
|
|
79
71
|
|
|
80
72
|
try {
|
|
81
73
|
payload.tags.org_id = this.webex.credentials.getOrgId();
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
74
|
+
} catch {
|
|
84
75
|
this.logger.info('metrics: unable to get orgId');
|
|
85
76
|
}
|
|
86
77
|
|
|
87
|
-
|
|
88
78
|
payload.fields = {
|
|
89
79
|
...props.fields,
|
|
90
80
|
browser_version: getBrowserVersion(),
|
|
91
81
|
os_version: getOSVersion(),
|
|
92
82
|
sdk_version: this.webex.version,
|
|
93
83
|
platform: 'Web',
|
|
94
|
-
spark_user_agent: getSparkUserAgent(this.webex)
|
|
84
|
+
spark_user_agent: getSparkUserAgent(this.webex),
|
|
95
85
|
};
|
|
96
86
|
|
|
97
|
-
|
|
98
87
|
payload.type = props.type || this.webex.config.metrics.type;
|
|
99
88
|
|
|
100
|
-
|
|
101
89
|
payload.context = {
|
|
102
90
|
...props.context,
|
|
103
91
|
app: {
|
|
104
|
-
version: this.webex.version
|
|
92
|
+
version: this.webex.version,
|
|
105
93
|
},
|
|
106
94
|
locale: 'en-US',
|
|
107
95
|
os: {
|
|
108
96
|
name: getOSName(),
|
|
109
|
-
version: getOSVersion()
|
|
110
|
-
}
|
|
97
|
+
version: getOSVersion(),
|
|
98
|
+
},
|
|
111
99
|
};
|
|
112
100
|
|
|
113
|
-
|
|
114
101
|
if (props.eventPayload) {
|
|
115
102
|
payload.eventPayload = props.eventPayload;
|
|
116
103
|
}
|
|
@@ -121,7 +108,7 @@ const Metrics = WebexPlugin.extend({
|
|
|
121
108
|
|
|
122
109
|
if (preLoginId) {
|
|
123
110
|
const _payload = {
|
|
124
|
-
metrics: [payload]
|
|
111
|
+
metrics: [payload],
|
|
125
112
|
};
|
|
126
113
|
|
|
127
114
|
// Do not batch these because pre-login events occur during onboarding, so we will be partially blind
|
|
@@ -144,12 +131,12 @@ const Metrics = WebexPlugin.extend({
|
|
|
144
131
|
api: 'metrics',
|
|
145
132
|
resource: 'clientmetrics',
|
|
146
133
|
headers: {
|
|
147
|
-
'x-prelogin-userid': preLoginId
|
|
134
|
+
'x-prelogin-userid': preLoginId,
|
|
148
135
|
},
|
|
149
136
|
body: {},
|
|
150
137
|
qs: {
|
|
151
|
-
alias: true
|
|
152
|
-
}
|
|
138
|
+
alias: true,
|
|
139
|
+
},
|
|
153
140
|
});
|
|
154
141
|
},
|
|
155
142
|
|
|
@@ -161,20 +148,21 @@ const Metrics = WebexPlugin.extend({
|
|
|
161
148
|
resource: 'clientmetrics-prelogin',
|
|
162
149
|
headers: {
|
|
163
150
|
authorization: token.toString(),
|
|
164
|
-
'x-prelogin-userid': preLoginId
|
|
151
|
+
'x-prelogin-userid': preLoginId,
|
|
165
152
|
},
|
|
166
|
-
body: payload
|
|
167
|
-
})
|
|
153
|
+
body: payload,
|
|
154
|
+
})
|
|
155
|
+
);
|
|
168
156
|
},
|
|
169
157
|
|
|
170
158
|
submitCallDiagnosticEvents(payload) {
|
|
171
159
|
const event = {
|
|
172
160
|
type: 'diagnostic-event',
|
|
173
|
-
eventPayload: payload
|
|
161
|
+
eventPayload: payload,
|
|
174
162
|
};
|
|
175
163
|
|
|
176
164
|
return this.callDiagnosticEventsBatcher.request(event);
|
|
177
|
-
}
|
|
165
|
+
},
|
|
178
166
|
});
|
|
179
167
|
|
|
180
168
|
export default Metrics;
|
|
@@ -27,8 +27,8 @@ describe('plugin-metrics', () => {
|
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
webex = new MockWebex({
|
|
29
29
|
children: {
|
|
30
|
-
metrics: Metrics
|
|
31
|
-
}
|
|
30
|
+
metrics: Metrics,
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
webex.config.metrics = config.metrics;
|
|
@@ -37,7 +37,7 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
options
|
|
40
|
+
options,
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
sinon.spy(webex, 'request');
|
|
@@ -58,9 +58,10 @@ describe('plugin-metrics', () => {
|
|
|
58
58
|
it('clears the queue', () => {
|
|
59
59
|
clock.uninstall();
|
|
60
60
|
|
|
61
|
-
return webex.internal.metrics.batcher
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
return webex.internal.metrics.batcher
|
|
62
|
+
.request({
|
|
63
|
+
key: 'testMetric',
|
|
64
|
+
})
|
|
64
65
|
.then(() => {
|
|
65
66
|
assert.calledOnce(webex.request);
|
|
66
67
|
assert.lengthOf(webex.internal.metrics.batcher.queue, 0);
|
|
@@ -80,26 +81,28 @@ describe('plugin-metrics', () => {
|
|
|
80
81
|
|
|
81
82
|
sinon.stub(webex, 'request').callsFake((options) => {
|
|
82
83
|
options.headers = {
|
|
83
|
-
trackingid: count
|
|
84
|
+
trackingid: count,
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
count += 1;
|
|
87
88
|
if (count < 9) {
|
|
88
|
-
return Promise.reject(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
return Promise.reject(
|
|
90
|
+
new WebexHttpError.NetworkOrCORSError({
|
|
91
|
+
statusCode: 0,
|
|
92
|
+
options,
|
|
93
|
+
})
|
|
94
|
+
);
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
return Promise.resolve({
|
|
95
98
|
statusCode: 204,
|
|
96
99
|
body: undefined,
|
|
97
|
-
options
|
|
100
|
+
options,
|
|
98
101
|
});
|
|
99
102
|
});
|
|
100
103
|
|
|
101
104
|
const promise = webex.internal.metrics.batcher.request({
|
|
102
|
-
key: 'testMetric'
|
|
105
|
+
key: 'testMetric',
|
|
103
106
|
});
|
|
104
107
|
|
|
105
108
|
return promiseTick(50)
|
|
@@ -159,8 +162,16 @@ describe('plugin-metrics', () => {
|
|
|
159
162
|
.then(() => assert.lengthOf(webex.internal.metrics.batcher.queue, 0))
|
|
160
163
|
.then(() => promise)
|
|
161
164
|
.then(() => {
|
|
162
|
-
assert.lengthOf(
|
|
163
|
-
|
|
165
|
+
assert.lengthOf(
|
|
166
|
+
webex.request.args[1][0].body.metrics,
|
|
167
|
+
1,
|
|
168
|
+
'Reenqueuing the metric once did not increase the number of metrics to be submitted'
|
|
169
|
+
);
|
|
170
|
+
assert.lengthOf(
|
|
171
|
+
webex.request.args[2][0].body.metrics,
|
|
172
|
+
1,
|
|
173
|
+
'Reenqueuing the metric twice did not increase the number of metrics to be submitted'
|
|
174
|
+
);
|
|
164
175
|
assert.lengthOf(webex.internal.metrics.batcher.queue, 0);
|
|
165
176
|
});
|
|
166
177
|
});
|
|
@@ -27,8 +27,8 @@ describe('plugin-metrics', () => {
|
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
webex = new MockWebex({
|
|
29
29
|
children: {
|
|
30
|
-
metrics: Metrics
|
|
31
|
-
}
|
|
30
|
+
metrics: Metrics,
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
webex.config.metrics = config.metrics;
|
|
@@ -37,7 +37,7 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
options
|
|
40
|
+
options,
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
sinon.spy(webex, 'request');
|
|
@@ -58,14 +58,15 @@ describe('plugin-metrics', () => {
|
|
|
58
58
|
it('clears the queue', () => {
|
|
59
59
|
clock.uninstall();
|
|
60
60
|
|
|
61
|
-
return webex.internal.metrics.callDiagnosticEventsBatcher
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
return webex.internal.metrics.callDiagnosticEventsBatcher
|
|
62
|
+
.request({
|
|
63
|
+
type: 'diagnostic-event',
|
|
64
|
+
eventPayload: {
|
|
65
|
+
originTime: {
|
|
66
|
+
triggered: 'mock triggered timestamp',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
})
|
|
69
70
|
.then(() => {
|
|
70
71
|
assert.calledOnce(webex.request);
|
|
71
72
|
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
|
|
@@ -85,21 +86,23 @@ describe('plugin-metrics', () => {
|
|
|
85
86
|
|
|
86
87
|
sinon.stub(webex, 'request').callsFake((options) => {
|
|
87
88
|
options.headers = {
|
|
88
|
-
trackingid: count
|
|
89
|
+
trackingid: count,
|
|
89
90
|
};
|
|
90
91
|
|
|
91
92
|
count += 1;
|
|
92
93
|
if (count < 9) {
|
|
93
|
-
return Promise.reject(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
return Promise.reject(
|
|
95
|
+
new WebexHttpError.NetworkOrCORSError({
|
|
96
|
+
statusCode: 0,
|
|
97
|
+
options,
|
|
98
|
+
})
|
|
99
|
+
);
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
return Promise.resolve({
|
|
100
103
|
statusCode: 204,
|
|
101
104
|
body: undefined,
|
|
102
|
-
options
|
|
105
|
+
options,
|
|
103
106
|
});
|
|
104
107
|
});
|
|
105
108
|
|
|
@@ -107,13 +110,15 @@ describe('plugin-metrics', () => {
|
|
|
107
110
|
type: 'diagnostic-event',
|
|
108
111
|
eventPayload: {
|
|
109
112
|
originTime: {
|
|
110
|
-
triggered: 'mock triggered timestamp'
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
+
triggered: 'mock triggered timestamp',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
113
116
|
});
|
|
114
117
|
|
|
115
118
|
return promiseTick(50)
|
|
116
|
-
.then(() =>
|
|
119
|
+
.then(() =>
|
|
120
|
+
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 1)
|
|
121
|
+
)
|
|
117
122
|
.then(() => clock.tick(config.metrics.batcherWait))
|
|
118
123
|
.then(() => assert.calledOnce(webex.request))
|
|
119
124
|
|
|
@@ -166,11 +171,21 @@ describe('plugin-metrics', () => {
|
|
|
166
171
|
.then(() => assert.callCount(webex.request, 9))
|
|
167
172
|
|
|
168
173
|
.then(() => promiseTick(50))
|
|
169
|
-
.then(() =>
|
|
174
|
+
.then(() =>
|
|
175
|
+
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0)
|
|
176
|
+
)
|
|
170
177
|
.then(() => promise)
|
|
171
178
|
.then(() => {
|
|
172
|
-
assert.lengthOf(
|
|
173
|
-
|
|
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
|
+
);
|
|
174
189
|
assert.lengthOf(webex.internal.metrics.callDiagnosticEventsBatcher.queue, 0);
|
|
175
190
|
});
|
|
176
191
|
});
|
|
@@ -27,8 +27,8 @@ describe('plugin-metrics', () => {
|
|
|
27
27
|
beforeEach(() => {
|
|
28
28
|
webex = new MockWebex({
|
|
29
29
|
children: {
|
|
30
|
-
metrics: Metrics
|
|
31
|
-
}
|
|
30
|
+
metrics: Metrics,
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
webex.config.metrics = config.metrics;
|
|
@@ -37,7 +37,7 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
options
|
|
40
|
+
options,
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
sinon.spy(webex, 'request');
|
|
@@ -58,9 +58,10 @@ describe('plugin-metrics', () => {
|
|
|
58
58
|
it('clears the queue', () => {
|
|
59
59
|
clock.uninstall();
|
|
60
60
|
|
|
61
|
-
return webex.internal.metrics.clientMetricsBatcher
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
return webex.internal.metrics.clientMetricsBatcher
|
|
62
|
+
.request({
|
|
63
|
+
key: 'testMetric',
|
|
64
|
+
})
|
|
64
65
|
.then(() => {
|
|
65
66
|
assert.calledOnce(webex.request);
|
|
66
67
|
assert.lengthOf(webex.internal.metrics.clientMetricsBatcher.queue, 0);
|
|
@@ -80,26 +81,28 @@ describe('plugin-metrics', () => {
|
|
|
80
81
|
|
|
81
82
|
sinon.stub(webex, 'request').callsFake((options) => {
|
|
82
83
|
options.headers = {
|
|
83
|
-
trackingid: count
|
|
84
|
+
trackingid: count,
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
count += 1;
|
|
87
88
|
if (count < 9) {
|
|
88
|
-
return Promise.reject(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
return Promise.reject(
|
|
90
|
+
new WebexHttpError.NetworkOrCORSError({
|
|
91
|
+
statusCode: 0,
|
|
92
|
+
options,
|
|
93
|
+
})
|
|
94
|
+
);
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
return Promise.resolve({
|
|
95
98
|
statusCode: 204,
|
|
96
99
|
body: undefined,
|
|
97
|
-
options
|
|
100
|
+
options,
|
|
98
101
|
});
|
|
99
102
|
});
|
|
100
103
|
|
|
101
104
|
const promise = webex.internal.metrics.clientMetricsBatcher.request({
|
|
102
|
-
key: 'testMetric'
|
|
105
|
+
key: 'testMetric',
|
|
103
106
|
});
|
|
104
107
|
|
|
105
108
|
return promiseTick(50)
|
|
@@ -159,8 +162,16 @@ describe('plugin-metrics', () => {
|
|
|
159
162
|
.then(() => assert.lengthOf(webex.internal.metrics.clientMetricsBatcher.queue, 0))
|
|
160
163
|
.then(() => promise)
|
|
161
164
|
.then(() => {
|
|
162
|
-
assert.lengthOf(
|
|
163
|
-
|
|
165
|
+
assert.lengthOf(
|
|
166
|
+
webex.request.args[1][0].body.metrics,
|
|
167
|
+
1,
|
|
168
|
+
'Reenqueuing the metric once did not increase the number of metrics to be submitted'
|
|
169
|
+
);
|
|
170
|
+
assert.lengthOf(
|
|
171
|
+
webex.request.args[2][0].body.metrics,
|
|
172
|
+
1,
|
|
173
|
+
'Reenqueuing the metric twice did not increase the number of metrics to be submitted'
|
|
174
|
+
);
|
|
164
175
|
assert.lengthOf(webex.internal.metrics.clientMetricsBatcher.queue, 0);
|
|
165
176
|
});
|
|
166
177
|
});
|
|
@@ -29,35 +29,35 @@ describe('plugin-metrics', () => {
|
|
|
29
29
|
const eventName = 'test_event';
|
|
30
30
|
const mockPayload = {
|
|
31
31
|
fields: {
|
|
32
|
-
testField: 123
|
|
32
|
+
testField: 123,
|
|
33
33
|
},
|
|
34
34
|
tags: {
|
|
35
|
-
testTag: 'tag value'
|
|
35
|
+
testTag: 'tag value',
|
|
36
36
|
},
|
|
37
37
|
metricName: eventName,
|
|
38
38
|
test: 'this field should not be included in final payload',
|
|
39
39
|
type: 'behavioral',
|
|
40
|
-
eventPayload: {value: 'splunk business metric payload'}
|
|
40
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
41
41
|
};
|
|
42
42
|
const transformedProps = {
|
|
43
43
|
fields: {
|
|
44
|
-
testField: 123
|
|
44
|
+
testField: 123,
|
|
45
45
|
},
|
|
46
46
|
tags: {
|
|
47
|
-
testTag: 'tag value'
|
|
47
|
+
testTag: 'tag value',
|
|
48
48
|
},
|
|
49
49
|
metricName: eventName,
|
|
50
50
|
type: 'behavioral',
|
|
51
|
-
timestamp: Date.now()
|
|
51
|
+
timestamp: Date.now(),
|
|
52
52
|
};
|
|
53
53
|
const preLoginId = '1b90cf5e-27a6-41aa-a208-1f6eb6b9e6b6';
|
|
54
54
|
const preLoginProps = {
|
|
55
|
-
metrics: [transformedProps]
|
|
55
|
+
metrics: [transformedProps],
|
|
56
56
|
};
|
|
57
57
|
const mockCallDiagnosticEvent = {
|
|
58
58
|
originTime: {
|
|
59
|
-
triggered: 'mock triggered timestamp'
|
|
60
|
-
}
|
|
59
|
+
triggered: 'mock triggered timestamp',
|
|
60
|
+
},
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
beforeEach(() => {
|
|
@@ -71,8 +71,8 @@ describe('plugin-metrics', () => {
|
|
|
71
71
|
beforeEach(() => {
|
|
72
72
|
webex = new MockWebex({
|
|
73
73
|
children: {
|
|
74
|
-
metrics: Metrics
|
|
75
|
-
}
|
|
74
|
+
metrics: Metrics,
|
|
75
|
+
},
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
webex.config.metrics = config.metrics;
|
|
@@ -82,7 +82,7 @@ describe('plugin-metrics', () => {
|
|
|
82
82
|
return Promise.resolve({
|
|
83
83
|
statusCode: 204,
|
|
84
84
|
body: undefined,
|
|
85
|
-
options
|
|
85
|
+
options,
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
|
|
@@ -94,8 +94,7 @@ describe('plugin-metrics', () => {
|
|
|
94
94
|
...webex.config,
|
|
95
95
|
appName: 'appName',
|
|
96
96
|
appPlatform: 'appPlatform',
|
|
97
|
-
appVersion: 'appVersion'
|
|
98
|
-
|
|
97
|
+
appVersion: 'appVersion',
|
|
99
98
|
};
|
|
100
99
|
webex.config.metrics.type = ['operational'];
|
|
101
100
|
webex.config.metrics.appType = 'sdk';
|
|
@@ -167,15 +166,18 @@ describe('plugin-metrics', () => {
|
|
|
167
166
|
});
|
|
168
167
|
describe('after login', () => {
|
|
169
168
|
it('submits a metric to clientmetrics', () => {
|
|
170
|
-
webex.credentials.supertoken = new Token(
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
webex.credentials.supertoken = new Token(
|
|
170
|
+
{
|
|
171
|
+
access_token: 'a_b_orgid',
|
|
172
|
+
},
|
|
173
|
+
{parent: webex}
|
|
174
|
+
);
|
|
173
175
|
|
|
174
176
|
const testPayload = {
|
|
175
177
|
tags: {success: true},
|
|
176
178
|
fields: {perceivedDurationInMillis: 314},
|
|
177
179
|
context: {},
|
|
178
|
-
eventPayload: {value: 'splunk business metric payload'}
|
|
180
|
+
eventPayload: {value: 'splunk business metric payload'},
|
|
179
181
|
};
|
|
180
182
|
const date = clock.now;
|
|
181
183
|
|
|
@@ -213,7 +215,6 @@ describe('plugin-metrics', () => {
|
|
|
213
215
|
assert.property(metric.context, 'locale');
|
|
214
216
|
assert.property(metric.context, 'os');
|
|
215
217
|
|
|
216
|
-
|
|
217
218
|
assert.equal(metric.timestamp, date);
|
|
218
219
|
assert.equal(metric.metricName, 'test');
|
|
219
220
|
assert.equal(metric.tags.success, true);
|
|
@@ -294,8 +295,8 @@ describe('plugin-metrics', () => {
|
|
|
294
295
|
const promise = metrics.submitCallDiagnosticEvents({
|
|
295
296
|
...mockCallDiagnosticEvent,
|
|
296
297
|
origin: {
|
|
297
|
-
buildType: 'prod'
|
|
298
|
-
}
|
|
298
|
+
buildType: 'prod',
|
|
299
|
+
},
|
|
299
300
|
});
|
|
300
301
|
|
|
301
302
|
return promiseTick(50)
|