@webex/internal-plugin-metrics 2.59.1 → 2.59.3-next.1

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/src/batcher.js CHANGED
@@ -1,99 +1,99 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {Batcher, WebexHttpError} from '@webex/webex-core';
6
- import {safeSetTimeout} from '@webex/common-timers';
7
-
8
- const sym = Symbol('metric id');
9
-
10
- const MetricsBatcher = Batcher.extend({
11
- namespace: 'Metrics',
12
-
13
- prepareItem(item) {
14
- // Keep non-prod data out of metrics
15
- const env = process.env.NODE_ENV === 'production' ? null : 'TEST';
16
-
17
- item.appType = item.appType || this.config.appType;
18
- item.env = item.env || env;
19
- item.time = item.time || Date.now();
20
- item.version = item.version || this.webex.version;
21
-
22
- return Promise.resolve(item);
23
- },
24
-
25
- prepareRequest(queue) {
26
- return Promise.resolve(
27
- queue.map((item) => {
28
- item.postTime = item.postTime || Date.now();
29
-
30
- return item;
31
- })
32
- );
33
- },
34
-
35
- submitHttpRequest(payload) {
36
- return this.webex.request({
37
- method: 'POST',
38
- service: 'metrics',
39
- resource: 'metrics',
40
- body: {
41
- metrics: payload,
42
- },
43
- });
44
- },
45
-
46
- handleHttpSuccess(res) {
47
- return Promise.all(res.options.body.metrics.map((item) => this.acceptItem(item)));
48
- },
49
-
50
- handleHttpError(reason) {
51
- if (reason instanceof WebexHttpError.NetworkOrCORSError) {
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
- );
71
- }
72
-
73
- return Reflect.apply(Batcher.prototype.handleHttpError, this, [reason]);
74
- },
75
-
76
- rerequest(item) {
77
- return Promise.all([this.getDeferredForRequest(item), this.prepareItem(item)]).then(
78
- ([defer, req]) => {
79
- this.enqueue(req)
80
- .then(() => this.bounce())
81
- .catch((reason) => defer.reject(reason));
82
- }
83
- );
84
- },
85
-
86
- fingerprintRequest(item) {
87
- item[sym] = item[sym] || {
88
- nextDelay: 1000,
89
- };
90
-
91
- return Promise.resolve(item[sym]);
92
- },
93
-
94
- fingerprintResponse(item) {
95
- return Promise.resolve(item[sym]);
96
- },
97
- });
98
-
99
- export default MetricsBatcher;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {Batcher, WebexHttpError} from '@webex/webex-core';
6
+ import {safeSetTimeout} from '@webex/common-timers';
7
+
8
+ const sym = Symbol('metric id');
9
+
10
+ const MetricsBatcher = Batcher.extend({
11
+ namespace: 'Metrics',
12
+
13
+ prepareItem(item) {
14
+ // Keep non-prod data out of metrics
15
+ const env = process.env.NODE_ENV === 'production' ? null : 'TEST';
16
+
17
+ item.appType = item.appType || this.config.appType;
18
+ item.env = item.env || env;
19
+ item.time = item.time || Date.now();
20
+ item.version = item.version || this.webex.version;
21
+
22
+ return Promise.resolve(item);
23
+ },
24
+
25
+ prepareRequest(queue) {
26
+ return Promise.resolve(
27
+ queue.map((item) => {
28
+ item.postTime = item.postTime || Date.now();
29
+
30
+ return item;
31
+ })
32
+ );
33
+ },
34
+
35
+ submitHttpRequest(payload) {
36
+ return this.webex.request({
37
+ method: 'POST',
38
+ service: 'metrics',
39
+ resource: 'metrics',
40
+ body: {
41
+ metrics: payload,
42
+ },
43
+ });
44
+ },
45
+
46
+ handleHttpSuccess(res) {
47
+ return Promise.all(res.options.body.metrics.map((item) => this.acceptItem(item)));
48
+ },
49
+
50
+ handleHttpError(reason) {
51
+ if (reason instanceof WebexHttpError.NetworkOrCORSError) {
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
+ );
71
+ }
72
+
73
+ return Reflect.apply(Batcher.prototype.handleHttpError, this, [reason]);
74
+ },
75
+
76
+ rerequest(item) {
77
+ return Promise.all([this.getDeferredForRequest(item), this.prepareItem(item)]).then(
78
+ ([defer, req]) => {
79
+ this.enqueue(req)
80
+ .then(() => this.bounce())
81
+ .catch((reason) => defer.reject(reason));
82
+ }
83
+ );
84
+ },
85
+
86
+ fingerprintRequest(item) {
87
+ item[sym] = item[sym] || {
88
+ nextDelay: 1000,
89
+ };
90
+
91
+ return Promise.resolve(item[sym]);
92
+ },
93
+
94
+ fingerprintResponse(item) {
95
+ return Promise.resolve(item[sym]);
96
+ },
97
+ });
98
+
99
+ export default MetricsBatcher;
@@ -1,62 +1,62 @@
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;
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;
@@ -1,31 +1,31 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import Batcher from './batcher';
6
-
7
- const ClientMetricsBatcher = Batcher.extend({
8
- namespace: 'Metrics',
9
-
10
- prepareItem(item) {
11
- // Add more defaults to payload when the clientmetrics endpoint evolves to support richer payloads
12
- return Promise.resolve(item);
13
- },
14
-
15
- prepareRequest(queue) {
16
- return Promise.resolve(queue);
17
- },
18
-
19
- submitHttpRequest(payload) {
20
- return this.webex.request({
21
- method: 'POST',
22
- service: 'metrics',
23
- resource: 'clientmetrics',
24
- body: {
25
- metrics: payload,
26
- },
27
- });
28
- },
29
- });
30
-
31
- export default ClientMetricsBatcher;
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import Batcher from './batcher';
6
+
7
+ const ClientMetricsBatcher = Batcher.extend({
8
+ namespace: 'Metrics',
9
+
10
+ prepareItem(item) {
11
+ // Add more defaults to payload when the clientmetrics endpoint evolves to support richer payloads
12
+ return Promise.resolve(item);
13
+ },
14
+
15
+ prepareRequest(queue) {
16
+ return Promise.resolve(queue);
17
+ },
18
+
19
+ submitHttpRequest(payload) {
20
+ return this.webex.request({
21
+ method: 'POST',
22
+ service: 'metrics',
23
+ resource: 'clientmetrics',
24
+ body: {
25
+ metrics: payload,
26
+ },
27
+ });
28
+ },
29
+ });
30
+
31
+ export default ClientMetricsBatcher;
package/src/config.js CHANGED
@@ -1,42 +1,42 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {inBrowser} from '@webex/common';
6
-
7
- export const CLIENT_NAME = 'webex-js-sdk';
8
- export default {
9
- device: {
10
- preDiscoveryServices: {
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
- },
15
- },
16
- metrics: {
17
- appType: inBrowser ? 'browser' : 'nodejs',
18
- batcherWait: 500,
19
- batcherMaxCalls: 50,
20
- batcherMaxWait: 1500,
21
- batcherRetryPlateau: 32000,
22
- },
23
- };
24
-
25
- export const OS_NAME = {
26
- WINDOWS: 'windows',
27
- MAC: 'mac',
28
- IOS: 'ios',
29
- ANDROID: 'android',
30
- CHROME: 'chrome',
31
- LINUX: 'linux',
32
- OTHERS: 'other',
33
- };
34
-
35
- export const OSMap = {
36
- 'Chrome OS': OS_NAME.CHROME,
37
- macOS: OS_NAME.MAC,
38
- Windows: OS_NAME.WINDOWS,
39
- iOS: OS_NAME.IOS,
40
- Android: OS_NAME.ANDROID,
41
- Linux: OS_NAME.LINUX,
42
- };
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {inBrowser} from '@webex/common';
6
+
7
+ export const CLIENT_NAME = 'webex-js-sdk';
8
+ export default {
9
+ device: {
10
+ preDiscoveryServices: {
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
+ },
15
+ },
16
+ metrics: {
17
+ appType: inBrowser ? 'browser' : 'nodejs',
18
+ batcherWait: 500,
19
+ batcherMaxCalls: 50,
20
+ batcherMaxWait: 1500,
21
+ batcherRetryPlateau: 32000,
22
+ },
23
+ };
24
+
25
+ export const OS_NAME = {
26
+ WINDOWS: 'windows',
27
+ MAC: 'mac',
28
+ IOS: 'ios',
29
+ ANDROID: 'android',
30
+ CHROME: 'chrome',
31
+ LINUX: 'linux',
32
+ OTHERS: 'other',
33
+ };
34
+
35
+ export const OSMap = {
36
+ 'Chrome OS': OS_NAME.CHROME,
37
+ macOS: OS_NAME.MAC,
38
+ Windows: OS_NAME.WINDOWS,
39
+ iOS: OS_NAME.IOS,
40
+ Android: OS_NAME.ANDROID,
41
+ Linux: OS_NAME.LINUX,
42
+ };
package/src/index.js CHANGED
@@ -1,15 +1,15 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {registerInternalPlugin} from '@webex/webex-core';
6
-
7
- import Metrics from './metrics';
8
- import config from './config';
9
-
10
- registerInternalPlugin('metrics', Metrics, {
11
- config,
12
- });
13
-
14
- export {default, getOSNameInternal} from './metrics';
15
- export {config};
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {registerInternalPlugin} from '@webex/webex-core';
6
+
7
+ import Metrics from './metrics';
8
+ import config from './config';
9
+
10
+ registerInternalPlugin('metrics', Metrics, {
11
+ config,
12
+ });
13
+
14
+ export {default, getOSNameInternal} from './metrics';
15
+ export {config};