@webex/internal-plugin-metrics 2.60.0-next.8 → 2.60.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/dist/batcher.js +3 -3
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic-events-batcher.js +60 -0
- package/dist/call-diagnostic-events-batcher.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 +9 -6
- package/dist/config.js.map +1 -1
- package/dist/index.js +2 -21
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +22 -24
- package/dist/metrics.js.map +1 -1
- package/package.json +19 -24
- package/src/batcher.js +0 -1
- package/src/call-diagnostic-events-batcher.js +62 -0
- package/src/client-metrics-batcher.js +0 -1
- package/src/config.js +0 -1
- package/src/index.js +15 -0
- package/src/metrics.js +16 -17
- package/test/unit/spec/batcher.js +0 -2
- package/test/unit/spec/call-diagnostic-events-batcher.js +195 -0
- package/test/unit/spec/client-metrics-batcher.js +0 -2
- package/test/unit/spec/metrics.js +94 -65
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +0 -67
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +0 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +0 -454
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +0 -1
- package/dist/call-diagnostic/call-diagnostic-metrics.js +0 -821
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +0 -1
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +0 -323
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +0 -1
- package/dist/call-diagnostic/config.js +0 -593
- package/dist/call-diagnostic/config.js.map +0 -1
- package/dist/metrics.types.js +0 -7
- package/dist/metrics.types.js.map +0 -1
- package/dist/new-metrics.js +0 -336
- package/dist/new-metrics.js.map +0 -1
- package/dist/types/batcher.d.ts +0 -2
- package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +0 -2
- package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +0 -194
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +0 -418
- package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +0 -96
- package/dist/types/call-diagnostic/config.d.ts +0 -172
- package/dist/types/client-metrics-batcher.d.ts +0 -2
- package/dist/types/config.d.ts +0 -36
- package/dist/types/index.d.ts +0 -13
- package/dist/types/metrics.d.ts +0 -3
- package/dist/types/metrics.types.d.ts +0 -104
- package/dist/types/new-metrics.d.ts +0 -139
- package/dist/types/utils.d.ts +0 -6
- package/dist/utils.js +0 -26
- package/dist/utils.js.map +0 -1
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +0 -75
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +0 -419
- package/src/call-diagnostic/call-diagnostic-metrics.ts +0 -875
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +0 -362
- package/src/call-diagnostic/config.ts +0 -666
- package/src/index.ts +0 -43
- package/src/metrics.types.ts +0 -160
- package/src/new-metrics.ts +0 -317
- package/src/utils.ts +0 -17
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +0 -453
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +0 -506
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +0 -2078
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +0 -565
- package/test/unit/spec/new-metrics.ts +0 -266
- package/test/unit/spec/utils.ts +0 -22
- package/tsconfig.json +0 -6
package/src/metrics.js
CHANGED
|
@@ -10,6 +10,7 @@ import {OS_NAME, OSMap, CLIENT_NAME} from './config';
|
|
|
10
10
|
|
|
11
11
|
import Batcher from './batcher';
|
|
12
12
|
import ClientMetricsBatcher from './client-metrics-batcher';
|
|
13
|
+
import CallDiagnosticEventsBatcher from './call-diagnostic-events-batcher';
|
|
13
14
|
|
|
14
15
|
const {getOSName, getOSVersion, getBrowserName, getBrowserVersion} = BrowserDetection();
|
|
15
16
|
|
|
@@ -37,6 +38,7 @@ const Metrics = WebexPlugin.extend({
|
|
|
37
38
|
children: {
|
|
38
39
|
batcher: Batcher,
|
|
39
40
|
clientMetricsBatcher: ClientMetricsBatcher,
|
|
41
|
+
callDiagnosticEventsBatcher: CallDiagnosticEventsBatcher,
|
|
40
42
|
},
|
|
41
43
|
|
|
42
44
|
namespace: 'Metrics',
|
|
@@ -46,12 +48,13 @@ const Metrics = WebexPlugin.extend({
|
|
|
46
48
|
},
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
|
-
*
|
|
51
|
+
* This corresponds to #sendSemiStructured() in the deprecated metrics handler
|
|
50
52
|
* @param {string} eventName
|
|
51
|
-
* @param {
|
|
52
|
-
* @
|
|
53
|
+
* @param {Object} props
|
|
54
|
+
* @param {string} preLoginId
|
|
55
|
+
* @returns {Object} HttpResponse object
|
|
53
56
|
*/
|
|
54
|
-
|
|
57
|
+
submitClientMetrics(eventName, props = {}, preLoginId) {
|
|
55
58
|
if (!eventName) {
|
|
56
59
|
throw Error('Missing behavioral metric name. Please provide one');
|
|
57
60
|
}
|
|
@@ -100,19 +103,6 @@ const Metrics = WebexPlugin.extend({
|
|
|
100
103
|
// is impossible so unable to use Date.now()
|
|
101
104
|
payload.timestamp = new Date().valueOf();
|
|
102
105
|
|
|
103
|
-
return payload;
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* This corresponds to #sendSemiStructured() in the deprecated metrics handler
|
|
108
|
-
* @param {string} eventName
|
|
109
|
-
* @param {Object} props
|
|
110
|
-
* @param {string} preLoginId
|
|
111
|
-
* @returns {Object} HttpResponse object
|
|
112
|
-
*/
|
|
113
|
-
submitClientMetrics(eventName, props = {}, preLoginId) {
|
|
114
|
-
const payload = this.getClientMetricsPayload(eventName, props);
|
|
115
|
-
|
|
116
106
|
if (preLoginId) {
|
|
117
107
|
const _payload = {
|
|
118
108
|
metrics: [payload],
|
|
@@ -161,6 +151,15 @@ const Metrics = WebexPlugin.extend({
|
|
|
161
151
|
})
|
|
162
152
|
);
|
|
163
153
|
},
|
|
154
|
+
|
|
155
|
+
submitCallDiagnosticEvents(payload) {
|
|
156
|
+
const event = {
|
|
157
|
+
type: 'diagnostic-event',
|
|
158
|
+
eventPayload: payload,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return this.callDiagnosticEventsBatcher.request(event);
|
|
162
|
+
},
|
|
164
163
|
});
|
|
165
164
|
|
|
166
165
|
export default Metrics;
|
|
@@ -37,7 +37,6 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
waitForServiceTimeout: 30,
|
|
41
40
|
options,
|
|
42
41
|
});
|
|
43
42
|
};
|
|
@@ -98,7 +97,6 @@ describe('plugin-metrics', () => {
|
|
|
98
97
|
return Promise.resolve({
|
|
99
98
|
statusCode: 204,
|
|
100
99
|
body: undefined,
|
|
101
|
-
waitForServiceTimeout: 30,
|
|
102
100
|
options,
|
|
103
101
|
});
|
|
104
102
|
});
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
});
|
|
@@ -37,7 +37,6 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
waitForServiceTimeout: 30,
|
|
41
40
|
options,
|
|
42
41
|
});
|
|
43
42
|
};
|
|
@@ -98,7 +97,6 @@ describe('plugin-metrics', () => {
|
|
|
98
97
|
return Promise.resolve({
|
|
99
98
|
statusCode: 204,
|
|
100
99
|
body: undefined,
|
|
101
|
-
waitForServiceTimeout: 30,
|
|
102
100
|
options,
|
|
103
101
|
});
|
|
104
102
|
});
|
|
@@ -8,9 +8,6 @@ import {Token, Credentials} from '@webex/webex-core';
|
|
|
8
8
|
import FakeTimers from '@sinonjs/fake-timers';
|
|
9
9
|
import sinon from 'sinon';
|
|
10
10
|
import Metrics, {config} from '@webex/internal-plugin-metrics';
|
|
11
|
-
import {BrowserDetection} from '@webex/common';
|
|
12
|
-
|
|
13
|
-
const {getOSVersion} = BrowserDetection();
|
|
14
11
|
|
|
15
12
|
function promiseTick(count) {
|
|
16
13
|
let promise = Promise.resolve();
|
|
@@ -85,7 +82,6 @@ describe('plugin-metrics', () => {
|
|
|
85
82
|
return Promise.resolve({
|
|
86
83
|
statusCode: 204,
|
|
87
84
|
body: undefined,
|
|
88
|
-
waitForServiceTimeout: 30,
|
|
89
85
|
options,
|
|
90
86
|
});
|
|
91
87
|
};
|
|
@@ -106,6 +102,7 @@ describe('plugin-metrics', () => {
|
|
|
106
102
|
sinon.spy(webex, 'request');
|
|
107
103
|
sinon.spy(metrics, 'postPreLoginMetric');
|
|
108
104
|
sinon.spy(metrics, 'aliasUser');
|
|
105
|
+
sinon.spy(metrics, 'submitCallDiagnosticEvents');
|
|
109
106
|
});
|
|
110
107
|
|
|
111
108
|
describe('#submit()', () => {
|
|
@@ -134,67 +131,6 @@ describe('plugin-metrics', () => {
|
|
|
134
131
|
});
|
|
135
132
|
});
|
|
136
133
|
|
|
137
|
-
describe('#getClientMetricsPayload()', () => {
|
|
138
|
-
it('returns the expected payload', () => {
|
|
139
|
-
webex.credentials.supertoken = new Token(
|
|
140
|
-
{
|
|
141
|
-
access_token: 'a_b_orgid',
|
|
142
|
-
},
|
|
143
|
-
{parent: webex}
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const testPayload = {
|
|
147
|
-
tags: {success: true},
|
|
148
|
-
fields: {perceivedDurationInMillis: 314},
|
|
149
|
-
context: {},
|
|
150
|
-
eventPayload: {value: 'splunk business metric payload'},
|
|
151
|
-
};
|
|
152
|
-
const date = clock.now;
|
|
153
|
-
|
|
154
|
-
const result = metrics.getClientMetricsPayload('test', testPayload);
|
|
155
|
-
|
|
156
|
-
assert.deepEqual(result, {
|
|
157
|
-
context: {
|
|
158
|
-
app: {
|
|
159
|
-
version: undefined,
|
|
160
|
-
},
|
|
161
|
-
locale: 'en-US',
|
|
162
|
-
os: {
|
|
163
|
-
name: 'other',
|
|
164
|
-
version: getOSVersion(),
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
eventPayload: {
|
|
168
|
-
value: 'splunk business metric payload',
|
|
169
|
-
},
|
|
170
|
-
fields: {
|
|
171
|
-
browser_version: '',
|
|
172
|
-
client_id: 'fake',
|
|
173
|
-
os_version: getOSVersion(),
|
|
174
|
-
perceivedDurationInMillis: 314,
|
|
175
|
-
platform: 'Web',
|
|
176
|
-
sdk_version: undefined,
|
|
177
|
-
spark_user_agent: 'webex-js-sdk appName/appVersion appPlatform',
|
|
178
|
-
},
|
|
179
|
-
metricName: 'test',
|
|
180
|
-
tags: {
|
|
181
|
-
browser: '',
|
|
182
|
-
domain: 'whatever',
|
|
183
|
-
os: 'other',
|
|
184
|
-
success: true,
|
|
185
|
-
},
|
|
186
|
-
timestamp: 0,
|
|
187
|
-
type: ['operational'],
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('throws when no event name is specified', () => {
|
|
192
|
-
assert.throws(() => {
|
|
193
|
-
metrics.getClientMetricsPayload();
|
|
194
|
-
}, 'Missing behavioral metric name. Please provide one');
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
134
|
describe('#submitClientMetrics()', () => {
|
|
199
135
|
describe('before login', () => {
|
|
200
136
|
it('posts pre-login metric', () => {
|
|
@@ -331,5 +267,98 @@ describe('plugin-metrics', () => {
|
|
|
331
267
|
assert.match(params, {alias: true});
|
|
332
268
|
}));
|
|
333
269
|
});
|
|
270
|
+
|
|
271
|
+
describe('#submitCallDiagnosticEvents()', () => {
|
|
272
|
+
it('submits a call diagnostic event', () => {
|
|
273
|
+
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
274
|
+
|
|
275
|
+
return promiseTick(50)
|
|
276
|
+
.then(() => clock.tick(config.metrics.batcherWait))
|
|
277
|
+
.then(() => promise)
|
|
278
|
+
.then(() => {
|
|
279
|
+
assert.calledOnce(webex.request);
|
|
280
|
+
const req = webex.request.args[0][0];
|
|
281
|
+
const metric = req.body.metrics[0];
|
|
282
|
+
|
|
283
|
+
assert.property(metric.eventPayload, 'origin');
|
|
284
|
+
assert.property(metric.eventPayload, 'originTime');
|
|
285
|
+
assert.property(metric.eventPayload.origin, 'buildType');
|
|
286
|
+
assert.property(metric.eventPayload.origin, 'networkType');
|
|
287
|
+
assert.property(metric.eventPayload.originTime, 'sent');
|
|
288
|
+
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('submits a call diagnostic event with buildType set in the payload', () => {
|
|
293
|
+
const promise = metrics.submitCallDiagnosticEvents({
|
|
294
|
+
...mockCallDiagnosticEvent,
|
|
295
|
+
origin: {
|
|
296
|
+
buildType: 'prod',
|
|
297
|
+
},
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
return promiseTick(50)
|
|
301
|
+
.then(() => clock.tick(config.metrics.batcherWait))
|
|
302
|
+
.then(() => promise)
|
|
303
|
+
.then(() => {
|
|
304
|
+
assert.calledOnce(webex.request);
|
|
305
|
+
const req = webex.request.args[0][0];
|
|
306
|
+
const metric = req.body.metrics[0];
|
|
307
|
+
|
|
308
|
+
assert.property(metric.eventPayload, 'origin');
|
|
309
|
+
assert.property(metric.eventPayload, 'originTime');
|
|
310
|
+
assert.property(metric.eventPayload.origin, 'buildType');
|
|
311
|
+
assert.property(metric.eventPayload.origin, 'networkType');
|
|
312
|
+
assert.property(metric.eventPayload.originTime, 'sent');
|
|
313
|
+
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
xit('submits a call diagnostic event with a test domain', () => {
|
|
318
|
+
global.window.location.hostname = 'test.webex.com';
|
|
319
|
+
|
|
320
|
+
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
321
|
+
|
|
322
|
+
return promiseTick(50)
|
|
323
|
+
.then(() => clock.tick(config.metrics.batcherWait))
|
|
324
|
+
.then(() => promise)
|
|
325
|
+
.then(() => {
|
|
326
|
+
assert.calledOnce(webex.request);
|
|
327
|
+
const req = webex.request.args[0][0];
|
|
328
|
+
const metric = req.body.metrics[0];
|
|
329
|
+
|
|
330
|
+
assert.property(metric.eventPayload, 'origin');
|
|
331
|
+
assert.property(metric.eventPayload, 'originTime');
|
|
332
|
+
assert.property(metric.eventPayload.origin, 'buildType');
|
|
333
|
+
assert.property(metric.eventPayload.origin, 'networkType');
|
|
334
|
+
assert.property(metric.eventPayload.originTime, 'sent');
|
|
335
|
+
assert.equal(metric.eventPayload.origin.buildType, 'test');
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// Skip because it's current unable to overwrite NODE_ENV
|
|
340
|
+
// However doing `NODE_ENV=test npm run test ...` will get this test case to pass
|
|
341
|
+
xit('submits a call diagnostic event with a NODE_ENV=production', () => {
|
|
342
|
+
process.env.NODE_ENV = 'production';
|
|
343
|
+
|
|
344
|
+
const promise = metrics.submitCallDiagnosticEvents(mockCallDiagnosticEvent);
|
|
345
|
+
|
|
346
|
+
return promiseTick(50)
|
|
347
|
+
.then(() => clock.tick(config.metrics.batcherWait))
|
|
348
|
+
.then(() => promise)
|
|
349
|
+
.then(() => {
|
|
350
|
+
assert.calledOnce(webex.request);
|
|
351
|
+
const req = webex.request.args[0][0];
|
|
352
|
+
const metric = req.body.metrics[0];
|
|
353
|
+
|
|
354
|
+
assert.property(metric.eventPayload, 'origin');
|
|
355
|
+
assert.property(metric.eventPayload, 'originTime');
|
|
356
|
+
assert.property(metric.eventPayload.origin, 'buildType');
|
|
357
|
+
assert.property(metric.eventPayload.origin, 'networkType');
|
|
358
|
+
assert.property(metric.eventPayload.originTime, 'sent');
|
|
359
|
+
assert.equal(metric.eventPayload.origin.buildType, 'prod');
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
334
363
|
});
|
|
335
364
|
});
|
|
@@ -1,67 +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 _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));
|
|
10
|
-
var _lodash = require("lodash");
|
|
11
|
-
var _batcher = _interopRequireDefault(require("../batcher"));
|
|
12
|
-
var _callDiagnosticMetrics = require("./call-diagnostic-metrics.util");
|
|
13
|
-
var _config = require("./config");
|
|
14
|
-
var _utils = require("../utils");
|
|
15
|
-
/* eslint-disable class-methods-use-this */
|
|
16
|
-
/* eslint-disable valid-jsdoc */
|
|
17
|
-
|
|
18
|
-
var CallDiagnosticEventsBatcher = _batcher.default.extend({
|
|
19
|
-
namespace: 'Metrics',
|
|
20
|
-
/**
|
|
21
|
-
* Prepare item
|
|
22
|
-
* @param item
|
|
23
|
-
* @returns
|
|
24
|
-
*/
|
|
25
|
-
prepareItem: function prepareItem(item) {
|
|
26
|
-
return _promise.default.resolve((0, _callDiagnosticMetrics.prepareDiagnosticMetricItem)(this.webex, item));
|
|
27
|
-
},
|
|
28
|
-
/**
|
|
29
|
-
* Prepare request, add time sensitive date etc.
|
|
30
|
-
* @param queue
|
|
31
|
-
* @returns
|
|
32
|
-
*/
|
|
33
|
-
prepareRequest: function prepareRequest(queue) {
|
|
34
|
-
// Add sent timestamp
|
|
35
|
-
queue.forEach(function (item) {
|
|
36
|
-
item.eventPayload.originTime = item.eventPayload.originTime || {};
|
|
37
|
-
item.eventPayload.originTime.sent = new Date().toISOString();
|
|
38
|
-
});
|
|
39
|
-
return _promise.default.resolve(queue);
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* @param payload
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
submitHttpRequest: function submitHttpRequest(payload) {
|
|
47
|
-
var _this = this;
|
|
48
|
-
var batchId = (0, _lodash.uniqueId)('ca-batch-');
|
|
49
|
-
return this.webex.request({
|
|
50
|
-
method: 'POST',
|
|
51
|
-
service: 'metrics',
|
|
52
|
-
resource: 'clientmetrics',
|
|
53
|
-
body: {
|
|
54
|
-
metrics: payload
|
|
55
|
-
},
|
|
56
|
-
waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout
|
|
57
|
-
}).then(function (res) {
|
|
58
|
-
_this.webex.logger.log(_config.CALL_DIAGNOSTIC_LOG_IDENTIFIER, "CallDiagnosticEventsBatcher: @submitHttpRequest#".concat(batchId, ". Request successful."));
|
|
59
|
-
return res;
|
|
60
|
-
}).catch(function (err) {
|
|
61
|
-
_this.webex.logger.error(_config.CALL_DIAGNOSTIC_LOG_IDENTIFIER, "CallDiagnosticEventsBatcher: @submitHttpRequest#".concat(batchId, ". Request failed:"), "error: ".concat((0, _utils.generateCommonErrorMetadata)(err)));
|
|
62
|
-
return _promise.default.reject(err);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
var _default = exports.default = CallDiagnosticEventsBatcher;
|
|
67
|
-
//# sourceMappingURL=call-diagnostic-metrics-batcher.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_lodash","require","_batcher","_interopRequireDefault","_callDiagnosticMetrics","_config","_utils","CallDiagnosticEventsBatcher","Batcher","extend","namespace","prepareItem","item","_promise","default","resolve","prepareDiagnosticMetricItem","webex","prepareRequest","queue","forEach","eventPayload","originTime","sent","Date","toISOString","submitHttpRequest","payload","_this","batchId","uniqueId","request","method","service","resource","body","metrics","waitForServiceTimeout","config","then","res","logger","log","CALL_DIAGNOSTIC_LOG_IDENTIFIER","concat","catch","err","error","generateCommonErrorMetadata","reject","_default","exports"],"sources":["call-diagnostic-metrics-batcher.ts"],"sourcesContent":["/* eslint-disable class-methods-use-this */\n/* eslint-disable valid-jsdoc */\n\nimport {uniqueId} from 'lodash';\nimport Batcher from '../batcher';\nimport {prepareDiagnosticMetricItem} from './call-diagnostic-metrics.util';\nimport {CALL_DIAGNOSTIC_LOG_IDENTIFIER} from './config';\nimport {generateCommonErrorMetadata} from '../utils';\n\nconst CallDiagnosticEventsBatcher = Batcher.extend({\n namespace: 'Metrics',\n\n /**\n * Prepare item\n * @param item\n * @returns\n */\n prepareItem(item) {\n return Promise.resolve(prepareDiagnosticMetricItem(this.webex, item));\n },\n\n /**\n * Prepare request, add time sensitive date etc.\n * @param queue\n * @returns\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 /**\n *\n * @param payload\n * @returns\n */\n submitHttpRequest(payload) {\n const batchId = uniqueId('ca-batch-');\n\n return this.webex\n .request({\n method: 'POST',\n service: 'metrics',\n resource: 'clientmetrics',\n body: {\n metrics: payload,\n },\n waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout,\n })\n .then((res) => {\n this.webex.logger.log(\n CALL_DIAGNOSTIC_LOG_IDENTIFIER,\n `CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request successful.`\n );\n\n return res;\n })\n .catch((err) => {\n this.webex.logger.error(\n CALL_DIAGNOSTIC_LOG_IDENTIFIER,\n `CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request failed:`,\n `error: ${generateCommonErrorMetadata(err)}`\n );\n\n return Promise.reject(err);\n });\n },\n});\n\nexport default CallDiagnosticEventsBatcher;\n"],"mappings":";;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAPA;AACA;;AAQA,IAAMM,2BAA2B,GAAGC,gBAAO,CAACC,MAAM,CAAC;EACjDC,SAAS,EAAE,SAAS;EAEpB;AACF;AACA;AACA;AACA;EACEC,WAAW,WAAAA,YAACC,IAAI,EAAE;IAChB,OAAOC,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAAC,IAAAC,kDAA2B,EAAC,IAAI,CAACC,KAAK,EAAEL,IAAI,CAAC,CAAC;EACvE,CAAC;EAED;AACF;AACA;AACA;AACA;EACEM,cAAc,WAAAA,eAACC,KAAK,EAAE;IACpB;IACAA,KAAK,CAACC,OAAO,CAAC,UAACR,IAAI,EAAK;MACtBA,IAAI,CAACS,YAAY,CAACC,UAAU,GAAGV,IAAI,CAACS,YAAY,CAACC,UAAU,IAAI,CAAC,CAAC;MACjEV,IAAI,CAACS,YAAY,CAACC,UAAU,CAACC,IAAI,GAAG,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC;IAC9D,CAAC,CAAC;IAEF,OAAOZ,QAAA,CAAAC,OAAA,CAAQC,OAAO,CAACI,KAAK,CAAC;EAC/B,CAAC;EAED;AACF;AACA;AACA;AACA;EACEO,iBAAiB,WAAAA,kBAACC,OAAO,EAAE;IAAA,IAAAC,KAAA;IACzB,IAAMC,OAAO,GAAG,IAAAC,gBAAQ,EAAC,WAAW,CAAC;IAErC,OAAO,IAAI,CAACb,KAAK,CACdc,OAAO,CAAC;MACPC,MAAM,EAAE,MAAM;MACdC,OAAO,EAAE,SAAS;MAClBC,QAAQ,EAAE,eAAe;MACzBC,IAAI,EAAE;QACJC,OAAO,EAAET;MACX,CAAC;MACDU,qBAAqB,EAAE,IAAI,CAACpB,KAAK,CAACqB,MAAM,CAACF,OAAO,CAACC;IACnD,CAAC,CAAC,CACDE,IAAI,CAAC,UAACC,GAAG,EAAK;MACbZ,KAAI,CAACX,KAAK,CAACwB,MAAM,CAACC,GAAG,CACnBC,sCAA8B,qDAAAC,MAAA,CACqBf,OAAO,0BAC5D,CAAC;MAED,OAAOW,GAAG;IACZ,CAAC,CAAC,CACDK,KAAK,CAAC,UAACC,GAAG,EAAK;MACdlB,KAAI,CAACX,KAAK,CAACwB,MAAM,CAACM,KAAK,CACrBJ,sCAA8B,qDAAAC,MAAA,CACqBf,OAAO,kCAAAe,MAAA,CAChD,IAAAI,kCAA2B,EAACF,GAAG,CAAC,CAC5C,CAAC;MAED,OAAOjC,QAAA,CAAAC,OAAA,CAAQmC,MAAM,CAACH,GAAG,CAAC;IAC5B,CAAC,CAAC;EACN;AACF,CAAC,CAAC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAArC,OAAA,GAEYP,2BAA2B"}
|