@webex/internal-plugin-metrics 3.0.0-beta.4 → 3.0.0-beta.400
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 +42 -22
- package/dist/batcher.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +65 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +508 -0
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js +860 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +367 -0
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
- package/dist/call-diagnostic/config.js +627 -0
- package/dist/call-diagnostic/config.js.map +1 -0
- package/dist/client-metrics-batcher.js +3 -8
- package/dist/client-metrics-batcher.js.map +1 -1
- package/dist/config.js +23 -6
- package/dist/config.js.map +1 -1
- package/dist/index.js +46 -10
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +47 -80
- 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 +300 -0
- package/dist/new-metrics.js.map +1 -0
- package/dist/prelogin-metrics-batcher.js +82 -0
- package/dist/prelogin-metrics-batcher.js.map +1 -0
- package/dist/types/batcher.d.ts +7 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics-batcher.d.ts +2 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +218 -0
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +421 -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/client-metrics-batcher.d.ts +2 -0
- package/dist/types/config.d.ts +36 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/metrics.d.ts +3 -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 +27 -0
- package/dist/utils.js.map +1 -0
- package/package.json +16 -8
- package/src/batcher.js +71 -26
- package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +72 -0
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +467 -0
- package/src/call-diagnostic/call-diagnostic-metrics.ts +919 -0
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +395 -0
- package/src/call-diagnostic/config.ts +685 -0
- package/src/client-metrics-batcher.js +4 -4
- package/src/config.js +26 -5
- package/src/index.ts +56 -0
- package/src/metrics.js +47 -58
- package/src/metrics.types.ts +170 -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 +28 -15
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +457 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +657 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2303 -0
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +634 -0
- package/test/unit/spec/client-metrics-batcher.js +28 -15
- package/test/unit/spec/metrics.js +94 -116
- package/test/unit/spec/new-metrics.ts +231 -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 -70
- package/dist/call-diagnostic-events-batcher.js.map +0 -1
- 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 -180
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable class-methods-use-this */
|
|
3
|
+
/* eslint-disable valid-jsdoc */
|
|
4
|
+
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import {WebexPlugin} from '@webex/webex-core';
|
|
7
|
+
|
|
8
|
+
import CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';
|
|
9
|
+
import {
|
|
10
|
+
RecursivePartial,
|
|
11
|
+
ClientEvent,
|
|
12
|
+
FeatureEvent,
|
|
13
|
+
BehavioralEvent,
|
|
14
|
+
OperationalEvent,
|
|
15
|
+
MediaQualityEvent,
|
|
16
|
+
InternalEvent,
|
|
17
|
+
SubmitClientEventOptions,
|
|
18
|
+
} from './metrics.types';
|
|
19
|
+
import CallDiagnosticLatencies from './call-diagnostic/call-diagnostic-metrics-latencies';
|
|
20
|
+
import {setMetricTimings} from './call-diagnostic/call-diagnostic-metrics.util';
|
|
21
|
+
import {generateCommonErrorMetadata} from './utils';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Metrics plugin to centralize all types of metrics.
|
|
25
|
+
* @class
|
|
26
|
+
*/
|
|
27
|
+
class Metrics extends WebexPlugin {
|
|
28
|
+
// eslint-disable-next-line no-use-before-define
|
|
29
|
+
static instance: Metrics;
|
|
30
|
+
|
|
31
|
+
// Call Diagnostic latencies
|
|
32
|
+
callDiagnosticLatencies: CallDiagnosticLatencies;
|
|
33
|
+
// Helper classes to handle the different types of metrics
|
|
34
|
+
callDiagnosticMetrics: CallDiagnosticMetrics;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Constructor
|
|
38
|
+
* @param args
|
|
39
|
+
* @constructor
|
|
40
|
+
* @private
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
constructor(...args) {
|
|
44
|
+
super(...args);
|
|
45
|
+
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
this.callDiagnosticLatencies = new CallDiagnosticLatencies({}, {parent: this.webex});
|
|
48
|
+
this.onReady();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* On Ready
|
|
53
|
+
*/
|
|
54
|
+
private onReady() {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
this.webex.once('ready', () => {
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
this.callDiagnosticMetrics = new CallDiagnosticMetrics({}, {parent: this.webex});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Used for internal purposes only
|
|
64
|
+
* @param args
|
|
65
|
+
*/
|
|
66
|
+
submitInternalEvent({
|
|
67
|
+
name,
|
|
68
|
+
payload,
|
|
69
|
+
options,
|
|
70
|
+
}: {
|
|
71
|
+
name: InternalEvent['name'];
|
|
72
|
+
payload?: RecursivePartial<InternalEvent['payload']>;
|
|
73
|
+
options?: any;
|
|
74
|
+
}) {
|
|
75
|
+
if (name === 'internal.reset.join.latencies') {
|
|
76
|
+
this.callDiagnosticLatencies.clearTimestamps();
|
|
77
|
+
} else {
|
|
78
|
+
this.callDiagnosticLatencies.saveTimestamp({key: name});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Behavioral event
|
|
84
|
+
* @param args
|
|
85
|
+
*/
|
|
86
|
+
submitBehavioralEvent({
|
|
87
|
+
name,
|
|
88
|
+
payload,
|
|
89
|
+
options,
|
|
90
|
+
}: {
|
|
91
|
+
name: BehavioralEvent['name'];
|
|
92
|
+
payload?: RecursivePartial<BehavioralEvent['payload']>;
|
|
93
|
+
options?: any;
|
|
94
|
+
}) {
|
|
95
|
+
this.callDiagnosticLatencies.saveTimestamp({key: name});
|
|
96
|
+
throw new Error('Not implemented.');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Operational event
|
|
101
|
+
* @param args
|
|
102
|
+
*/
|
|
103
|
+
submitOperationalEvent({
|
|
104
|
+
name,
|
|
105
|
+
payload,
|
|
106
|
+
options,
|
|
107
|
+
}: {
|
|
108
|
+
name: OperationalEvent['name'];
|
|
109
|
+
payload?: RecursivePartial<OperationalEvent['payload']>;
|
|
110
|
+
options?: any;
|
|
111
|
+
}) {
|
|
112
|
+
throw new Error('Not implemented.');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Call Analyzer: Media Quality Event
|
|
117
|
+
* @param args
|
|
118
|
+
*/
|
|
119
|
+
submitMQE({
|
|
120
|
+
name,
|
|
121
|
+
payload,
|
|
122
|
+
options,
|
|
123
|
+
}: {
|
|
124
|
+
name: MediaQualityEvent['name'];
|
|
125
|
+
payload: RecursivePartial<MediaQualityEvent['payload']> & {
|
|
126
|
+
intervals: MediaQualityEvent['payload']['intervals'];
|
|
127
|
+
};
|
|
128
|
+
options: any;
|
|
129
|
+
}) {
|
|
130
|
+
this.callDiagnosticLatencies.saveTimestamp({key: name});
|
|
131
|
+
this.callDiagnosticMetrics.submitMQE({name, payload, options});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Call Analyzer: Feature Usage Event
|
|
136
|
+
* @param args
|
|
137
|
+
*/
|
|
138
|
+
submitFeatureEvent({
|
|
139
|
+
name,
|
|
140
|
+
payload,
|
|
141
|
+
options,
|
|
142
|
+
}: {
|
|
143
|
+
name: FeatureEvent['name'];
|
|
144
|
+
payload?: RecursivePartial<FeatureEvent['payload']>;
|
|
145
|
+
options: any;
|
|
146
|
+
}) {
|
|
147
|
+
throw new Error('Not implemented.');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Call Analyzer: Client Event
|
|
152
|
+
* @public
|
|
153
|
+
* @param args
|
|
154
|
+
*/
|
|
155
|
+
public submitClientEvent({
|
|
156
|
+
name,
|
|
157
|
+
payload,
|
|
158
|
+
options,
|
|
159
|
+
}: {
|
|
160
|
+
name: ClientEvent['name'];
|
|
161
|
+
payload?: RecursivePartial<ClientEvent['payload']>;
|
|
162
|
+
options?: SubmitClientEventOptions;
|
|
163
|
+
}): Promise<any> {
|
|
164
|
+
if (!this.callDiagnosticLatencies || !this.callDiagnosticMetrics) {
|
|
165
|
+
// @ts-ignore
|
|
166
|
+
this.webex.logger.log(
|
|
167
|
+
`NewMetrics: @submitClientEvent. Attempted to submit before webex.ready. Event name: ${name}`
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
return Promise.resolve();
|
|
171
|
+
}
|
|
172
|
+
this.callDiagnosticLatencies.saveTimestamp({
|
|
173
|
+
key: name,
|
|
174
|
+
options: {meetingId: options?.meetingId},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return this.callDiagnosticMetrics.submitClientEvent({name, payload, options});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Issue request to alias a user's pre-login ID with their CI UUID
|
|
182
|
+
* @param {string} preLoginId
|
|
183
|
+
* @returns {Object} HttpResponse object
|
|
184
|
+
*/
|
|
185
|
+
public clientMetricsAliasUser(preLoginId: string) {
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
return this.webex
|
|
188
|
+
.request({
|
|
189
|
+
method: 'POST',
|
|
190
|
+
api: 'metrics',
|
|
191
|
+
resource: 'clientmetrics',
|
|
192
|
+
headers: {
|
|
193
|
+
'x-prelogin-userid': preLoginId,
|
|
194
|
+
},
|
|
195
|
+
body: {},
|
|
196
|
+
qs: {
|
|
197
|
+
alias: true,
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
.then((res) => {
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
this.webex.logger.log(`NewMetrics: @clientMetricsAliasUser. Request successful.`);
|
|
203
|
+
|
|
204
|
+
return res;
|
|
205
|
+
})
|
|
206
|
+
.catch((err) => {
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
this.logger.error(
|
|
209
|
+
`NewMetrics: @clientMetricsAliasUser. Request failed:`,
|
|
210
|
+
`err: ${generateCommonErrorMetadata(err)}`
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
return Promise.reject(err);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Returns a promise that will resolve to fetch options for submitting a metric.
|
|
219
|
+
*
|
|
220
|
+
* This is to support quickly submitting metrics when the browser/tab is closing.
|
|
221
|
+
* Calling submitClientEvent will not work because there some async steps that will
|
|
222
|
+
* not complete before the browser is closed. Instead, we pre-gather all the
|
|
223
|
+
* information/options needed for the request(s), and then simply and quickly
|
|
224
|
+
* fire the fetch(es) when beforeUnload is triggered.
|
|
225
|
+
*
|
|
226
|
+
* We must use fetch instead of request because fetch has a keepalive option that
|
|
227
|
+
* allows the request it to outlive the page.
|
|
228
|
+
*
|
|
229
|
+
* Note: the timings values will be wrong, but setMetricTimingsAndFetch() will
|
|
230
|
+
* properly adjust them before submitting.
|
|
231
|
+
*
|
|
232
|
+
* @public
|
|
233
|
+
* @param {Object} arg
|
|
234
|
+
* @param {String} arg.name - event name
|
|
235
|
+
* @param {Object} arg.payload - event payload
|
|
236
|
+
* @param {Object} arg.options - other options
|
|
237
|
+
* @returns {Promise} promise that resolves to options to be used with fetch
|
|
238
|
+
*/
|
|
239
|
+
public async buildClientEventFetchRequestOptions({
|
|
240
|
+
name,
|
|
241
|
+
payload,
|
|
242
|
+
options,
|
|
243
|
+
}: {
|
|
244
|
+
name: ClientEvent['name'];
|
|
245
|
+
payload?: RecursivePartial<ClientEvent['payload']>;
|
|
246
|
+
options?: SubmitClientEventOptions;
|
|
247
|
+
}): Promise<any> {
|
|
248
|
+
return this.callDiagnosticMetrics.buildClientEventFetchRequestOptions({
|
|
249
|
+
name,
|
|
250
|
+
payload,
|
|
251
|
+
options,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Submits a metric from pre-built request options via the fetch API. Updates
|
|
257
|
+
* the "$timings" and "originTime" values to Date.now() since the existing times
|
|
258
|
+
* were set when the options were built (not submitted).
|
|
259
|
+
|
|
260
|
+
* @param {any} options - the pre-built request options for submitting a metric
|
|
261
|
+
* @returns {Promise} promise that resolves to the response object
|
|
262
|
+
*/
|
|
263
|
+
public setMetricTimingsAndFetch(options: any): Promise<any> {
|
|
264
|
+
// @ts-ignore
|
|
265
|
+
return this.webex.setTimingsAndFetch(setMetricTimings(options));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Returns true if the specified serviceErrorCode maps to an expected error.
|
|
270
|
+
* @param {number} serviceErrorCode the service error code
|
|
271
|
+
* @returns {boolean}
|
|
272
|
+
*/
|
|
273
|
+
public isServiceErrorExpected(serviceErrorCode: number): boolean {
|
|
274
|
+
return this.callDiagnosticMetrics.isServiceErrorExpected(serviceErrorCode);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export default Metrics;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {uniqueId} from 'lodash';
|
|
2
|
+
import Batcher from './batcher';
|
|
3
|
+
import {prepareDiagnosticMetricItem} from './call-diagnostic/call-diagnostic-metrics.util';
|
|
4
|
+
import {generateCommonErrorMetadata} from './utils';
|
|
5
|
+
|
|
6
|
+
const PRE_LOGIN_METRICS_IDENTIFIER = 'Pre Login Metrics -->';
|
|
7
|
+
|
|
8
|
+
const PreLoginMetricsBatcher = Batcher.extend({
|
|
9
|
+
namespace: 'Metrics',
|
|
10
|
+
preLoginId: undefined,
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Save the pre-login ID.
|
|
14
|
+
* @param {string} preLoginId The pre-login ID to be saved.
|
|
15
|
+
* @returns {void}
|
|
16
|
+
*/
|
|
17
|
+
savePreLoginId(preLoginId) {
|
|
18
|
+
this.preLoginId = preLoginId;
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Prepare item
|
|
23
|
+
* @param {any} item
|
|
24
|
+
* @returns {Promise<any>}
|
|
25
|
+
*/
|
|
26
|
+
prepareItem(item) {
|
|
27
|
+
return Promise.resolve(prepareDiagnosticMetricItem(this.webex, item));
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Prepare request, add time sensitive date etc.
|
|
32
|
+
* @param {any[]} queue
|
|
33
|
+
* @returns {Promise<any[]>}
|
|
34
|
+
*/
|
|
35
|
+
prepareRequest(queue) {
|
|
36
|
+
// Add sent timestamp
|
|
37
|
+
queue.forEach((item) => {
|
|
38
|
+
item.eventPayload.originTime = item.eventPayload.originTime || {};
|
|
39
|
+
item.eventPayload.originTime.sent = new Date().toISOString();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return Promise.resolve(queue);
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {any} payload
|
|
48
|
+
* @returns {Promise<any>}
|
|
49
|
+
*/
|
|
50
|
+
submitHttpRequest(payload: any) {
|
|
51
|
+
const batchId = uniqueId('prelogin-ca-batch-');
|
|
52
|
+
if (this.preLoginId === undefined) {
|
|
53
|
+
this.webex.logger.error(
|
|
54
|
+
PRE_LOGIN_METRICS_IDENTIFIER,
|
|
55
|
+
`PreLoginMetricsBatcher: @submitHttpRequest#${batchId}. PreLoginId is not set.`
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return Promise.reject(new Error('PreLoginId is not set.'));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return this.webex
|
|
62
|
+
.request({
|
|
63
|
+
method: 'POST',
|
|
64
|
+
service: 'metrics',
|
|
65
|
+
resource: 'clientmetrics-prelogin',
|
|
66
|
+
headers: {
|
|
67
|
+
authorization: false,
|
|
68
|
+
'x-prelogin-userid': this.preLoginId,
|
|
69
|
+
},
|
|
70
|
+
body: {
|
|
71
|
+
metrics: payload,
|
|
72
|
+
},
|
|
73
|
+
waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout,
|
|
74
|
+
})
|
|
75
|
+
.then((res) => {
|
|
76
|
+
this.webex.logger.log(
|
|
77
|
+
PRE_LOGIN_METRICS_IDENTIFIER,
|
|
78
|
+
`PreLoginMetricsBatcher: @submitHttpRequest#${batchId}. Request successful.`
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return res;
|
|
82
|
+
})
|
|
83
|
+
.catch((err) => {
|
|
84
|
+
this.webex.logger.error(
|
|
85
|
+
PRE_LOGIN_METRICS_IDENTIFIER,
|
|
86
|
+
`PreLoginMetricsBatcher: @submitHttpRequest#${batchId}. Request failed:`,
|
|
87
|
+
`error: ${generateCommonErrorMetadata(err)}`
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return Promise.reject(err);
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export default PreLoginMetricsBatcher;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
/**
|
|
3
|
+
* Generates common metadata for errors
|
|
4
|
+
* @param {any} error
|
|
5
|
+
* @returns {object}
|
|
6
|
+
*/
|
|
7
|
+
export const generateCommonErrorMetadata = (error) => {
|
|
8
|
+
if (error instanceof Error) {
|
|
9
|
+
return JSON.stringify({
|
|
10
|
+
message: error?.message,
|
|
11
|
+
name: error?.name,
|
|
12
|
+
stack: error?.stack,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return error;
|
|
17
|
+
};
|
|
@@ -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,8 @@ describe('plugin-metrics', () => {
|
|
|
37
37
|
return Promise.resolve({
|
|
38
38
|
statusCode: 204,
|
|
39
39
|
body: undefined,
|
|
40
|
-
|
|
40
|
+
waitForServiceTimeout: 30,
|
|
41
|
+
options,
|
|
41
42
|
});
|
|
42
43
|
};
|
|
43
44
|
sinon.spy(webex, 'request');
|
|
@@ -58,9 +59,10 @@ describe('plugin-metrics', () => {
|
|
|
58
59
|
it('clears the queue', () => {
|
|
59
60
|
clock.uninstall();
|
|
60
61
|
|
|
61
|
-
return webex.internal.metrics.batcher
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
return webex.internal.metrics.batcher
|
|
63
|
+
.request({
|
|
64
|
+
key: 'testMetric',
|
|
65
|
+
})
|
|
64
66
|
.then(() => {
|
|
65
67
|
assert.calledOnce(webex.request);
|
|
66
68
|
assert.lengthOf(webex.internal.metrics.batcher.queue, 0);
|
|
@@ -80,26 +82,29 @@ describe('plugin-metrics', () => {
|
|
|
80
82
|
|
|
81
83
|
sinon.stub(webex, 'request').callsFake((options) => {
|
|
82
84
|
options.headers = {
|
|
83
|
-
trackingid: count
|
|
85
|
+
trackingid: count,
|
|
84
86
|
};
|
|
85
87
|
|
|
86
88
|
count += 1;
|
|
87
89
|
if (count < 9) {
|
|
88
|
-
return Promise.reject(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
return Promise.reject(
|
|
91
|
+
new WebexHttpError.NetworkOrCORSError({
|
|
92
|
+
statusCode: 0,
|
|
93
|
+
options,
|
|
94
|
+
})
|
|
95
|
+
);
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
return Promise.resolve({
|
|
95
99
|
statusCode: 204,
|
|
96
100
|
body: undefined,
|
|
97
|
-
|
|
101
|
+
waitForServiceTimeout: 30,
|
|
102
|
+
options,
|
|
98
103
|
});
|
|
99
104
|
});
|
|
100
105
|
|
|
101
106
|
const promise = webex.internal.metrics.batcher.request({
|
|
102
|
-
key: 'testMetric'
|
|
107
|
+
key: 'testMetric',
|
|
103
108
|
});
|
|
104
109
|
|
|
105
110
|
return promiseTick(50)
|
|
@@ -159,8 +164,16 @@ describe('plugin-metrics', () => {
|
|
|
159
164
|
.then(() => assert.lengthOf(webex.internal.metrics.batcher.queue, 0))
|
|
160
165
|
.then(() => promise)
|
|
161
166
|
.then(() => {
|
|
162
|
-
assert.lengthOf(
|
|
163
|
-
|
|
167
|
+
assert.lengthOf(
|
|
168
|
+
webex.request.args[1][0].body.metrics,
|
|
169
|
+
1,
|
|
170
|
+
'Reenqueuing the metric once did not increase the number of metrics to be submitted'
|
|
171
|
+
);
|
|
172
|
+
assert.lengthOf(
|
|
173
|
+
webex.request.args[2][0].body.metrics,
|
|
174
|
+
1,
|
|
175
|
+
'Reenqueuing the metric twice did not increase the number of metrics to be submitted'
|
|
176
|
+
);
|
|
164
177
|
assert.lengthOf(webex.internal.metrics.batcher.queue, 0);
|
|
165
178
|
});
|
|
166
179
|
});
|