@webex/internal-plugin-metrics 3.0.0-bnr.5 → 3.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/.eslintrc.js +6 -0
  2. package/babel.config.js +3 -0
  3. package/dist/batcher.js +41 -3
  4. package/dist/batcher.js.map +1 -1
  5. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js +64 -0
  6. package/dist/call-diagnostic/call-diagnostic-metrics-batcher.js.map +1 -0
  7. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +474 -0
  8. package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -0
  9. package/dist/call-diagnostic/call-diagnostic-metrics.js +850 -0
  10. package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -0
  11. package/dist/call-diagnostic/call-diagnostic-metrics.util.js +349 -0
  12. package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -0
  13. package/dist/call-diagnostic/config.js +609 -0
  14. package/dist/call-diagnostic/config.js.map +1 -0
  15. package/dist/client-metrics-batcher.js +3 -3
  16. package/dist/client-metrics-batcher.js.map +1 -1
  17. package/dist/config.js +6 -9
  18. package/dist/config.js.map +1 -1
  19. package/dist/index.js +35 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/metrics.js +28 -22
  22. package/dist/metrics.js.map +1 -1
  23. package/dist/metrics.types.js +7 -0
  24. package/dist/metrics.types.js.map +1 -0
  25. package/dist/new-metrics.js +302 -0
  26. package/dist/new-metrics.js.map +1 -0
  27. package/dist/prelogin-metrics-batcher.js +81 -0
  28. package/dist/prelogin-metrics-batcher.js.map +1 -0
  29. package/dist/types/batcher.d.ts +5 -0
  30. package/dist/types/call-diagnostic/call-diagnostic-metrics-latencies.d.ts +204 -0
  31. package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +427 -0
  32. package/dist/types/call-diagnostic/call-diagnostic-metrics.util.d.ts +103 -0
  33. package/dist/types/call-diagnostic/config.d.ts +178 -0
  34. package/dist/types/config.d.ts +18 -0
  35. package/dist/types/index.d.ts +15 -3
  36. package/dist/types/metrics.d.ts +1 -0
  37. package/dist/types/metrics.types.d.ts +105 -0
  38. package/dist/types/new-metrics.d.ts +131 -0
  39. package/dist/types/prelogin-metrics-batcher.d.ts +2 -0
  40. package/dist/types/utils.d.ts +6 -0
  41. package/dist/utils.js +26 -0
  42. package/dist/utils.js.map +1 -0
  43. package/jest.config.js +3 -0
  44. package/package.json +34 -10
  45. package/process +1 -0
  46. package/src/batcher.js +38 -0
  47. package/src/call-diagnostic/call-diagnostic-metrics-batcher.ts +72 -0
  48. package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +435 -0
  49. package/src/call-diagnostic/call-diagnostic-metrics.ts +913 -0
  50. package/src/call-diagnostic/call-diagnostic-metrics.util.ts +392 -0
  51. package/src/call-diagnostic/config.ts +685 -0
  52. package/src/client-metrics-batcher.js +1 -0
  53. package/src/config.js +1 -0
  54. package/src/index.ts +54 -0
  55. package/src/metrics.js +20 -16
  56. package/src/metrics.types.ts +168 -0
  57. package/src/new-metrics.ts +278 -0
  58. package/src/prelogin-metrics-batcher.ts +95 -0
  59. package/src/utils.ts +17 -0
  60. package/test/unit/spec/batcher.js +2 -0
  61. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +458 -0
  62. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +520 -0
  63. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +2297 -0
  64. package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +628 -0
  65. package/test/unit/spec/client-metrics-batcher.js +2 -0
  66. package/test/unit/spec/metrics.js +76 -95
  67. package/test/unit/spec/new-metrics.ts +233 -0
  68. package/test/unit/spec/prelogin-metrics-batcher.ts +250 -0
  69. package/test/unit/spec/utils.ts +22 -0
  70. package/tsconfig.json +6 -0
  71. package/dist/call-diagnostic-events-batcher.js +0 -60
  72. package/dist/call-diagnostic-events-batcher.js.map +0 -1
  73. package/dist/internal-plugin-metrics.d.ts +0 -21
  74. package/dist/tsdoc-metadata.json +0 -11
  75. package/src/call-diagnostic-events-batcher.js +0 -62
  76. package/src/index.js +0 -17
  77. package/test/unit/spec/call-diagnostic-events-batcher.js +0 -195
  78. package/dist/types/{call-diagnostic-events-batcher.d.ts → call-diagnostic/call-diagnostic-metrics-batcher.d.ts} +1 -1
@@ -0,0 +1,72 @@
1
+ import {uniqueId} from 'lodash';
2
+ import Batcher from '../batcher';
3
+ import {prepareDiagnosticMetricItem} from './call-diagnostic-metrics.util';
4
+ import {CALL_DIAGNOSTIC_LOG_IDENTIFIER} from './config';
5
+ import {generateCommonErrorMetadata} from '../utils';
6
+
7
+ const CallDiagnosticEventsBatcher = Batcher.extend({
8
+ namespace: 'Metrics',
9
+
10
+ /**
11
+ * Prepare item
12
+ * @param {any} item
13
+ * @returns {Promise<any>}
14
+ */
15
+ prepareItem(item) {
16
+ return Promise.resolve(prepareDiagnosticMetricItem(this.webex, item));
17
+ },
18
+
19
+ /**
20
+ * Prepare request, add time sensitive date etc.
21
+ * @param {any[]} queue
22
+ * @returns {Promise<any[]>}
23
+ */
24
+ prepareRequest(queue) {
25
+ // Add sent timestamp
26
+ queue.forEach((item) => {
27
+ item.eventPayload.originTime = item.eventPayload.originTime || {};
28
+ item.eventPayload.originTime.sent = new Date().toISOString();
29
+ });
30
+
31
+ return Promise.resolve(queue);
32
+ },
33
+
34
+ /**
35
+ *
36
+ * @param {any} payload
37
+ * @returns {Promise<any>}
38
+ */
39
+ submitHttpRequest(payload) {
40
+ const batchId = uniqueId('ca-batch-');
41
+
42
+ return this.webex
43
+ .request({
44
+ method: 'POST',
45
+ service: 'metrics',
46
+ resource: 'clientmetrics',
47
+ body: {
48
+ metrics: payload,
49
+ },
50
+ waitForServiceTimeout: this.webex.config.metrics.waitForServiceTimeout,
51
+ })
52
+ .then((res) => {
53
+ this.webex.logger.log(
54
+ CALL_DIAGNOSTIC_LOG_IDENTIFIER,
55
+ `CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request successful.`
56
+ );
57
+
58
+ return res;
59
+ })
60
+ .catch((err) => {
61
+ this.webex.logger.error(
62
+ CALL_DIAGNOSTIC_LOG_IDENTIFIER,
63
+ `CallDiagnosticEventsBatcher: @submitHttpRequest#${batchId}. Request failed:`,
64
+ `error: ${generateCommonErrorMetadata(err)}`
65
+ );
66
+
67
+ return Promise.reject(err);
68
+ });
69
+ },
70
+ });
71
+
72
+ export default CallDiagnosticEventsBatcher;
@@ -0,0 +1,435 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ /* eslint-disable valid-jsdoc */
3
+ import {WebexPlugin} from '@webex/webex-core';
4
+
5
+ import {MetricEventNames, PreComputedLatencies} from '../metrics.types';
6
+
7
+ // we only care about client event and feature event for now
8
+
9
+ /**
10
+ * @description Helper class to store latencies timestamp and to calculate various latencies for CA.
11
+ * @exports
12
+ * @class CallDiagnosticLatencies
13
+ */
14
+ export default class CallDiagnosticLatencies extends WebexPlugin {
15
+ latencyTimestamps: Map<MetricEventNames, number>;
16
+ precomputedLatencies: Map<PreComputedLatencies, number>;
17
+ // meetingId that the current latencies are for
18
+ private meetingId?: string;
19
+
20
+ /**
21
+ * @constructor
22
+ */
23
+ constructor(...args) {
24
+ super(...args);
25
+ this.latencyTimestamps = new Map();
26
+ this.precomputedLatencies = new Map();
27
+ }
28
+
29
+ /**
30
+ * Clear timestamps
31
+ */
32
+ public clearTimestamps() {
33
+ this.latencyTimestamps.clear();
34
+ }
35
+
36
+ /**
37
+ * Associate current latencies with a meeting id
38
+ * @param meetingId
39
+ */
40
+ private setMeetingId(meetingId: string) {
41
+ this.meetingId = meetingId;
42
+ }
43
+
44
+ /**
45
+ * Returns the meeting object associated with current latencies
46
+ * @returns meeting object
47
+ */
48
+ private getMeeting() {
49
+ if (this.meetingId) {
50
+ // @ts-ignore
51
+ return this.webex.meetings.meetingCollection.get(this.meetingId);
52
+ }
53
+
54
+ return undefined;
55
+ }
56
+
57
+ /**
58
+ * Store timestamp value
59
+ * @param key - key
60
+ * @param value -value
61
+ * @throws
62
+ * @returns
63
+ */
64
+ public saveTimestamp({
65
+ key,
66
+ value = new Date().getTime(),
67
+ options = {},
68
+ }: {
69
+ key: MetricEventNames;
70
+ value?: number;
71
+ options?: {meetingId?: string};
72
+ }) {
73
+ // save the meetingId so we can use the meeting object in latency calculations if needed
74
+ const {meetingId} = options;
75
+ if (meetingId) {
76
+ this.setMeetingId(meetingId);
77
+ }
78
+ // for some events we're only interested in the first timestamp not last
79
+ // as these events can happen multiple times
80
+ if (
81
+ key === 'client.media.rx.start' ||
82
+ key === 'client.media.tx.start' ||
83
+ key === 'internal.client.meetinginfo.request' ||
84
+ key === 'internal.client.meetinginfo.response'
85
+ ) {
86
+ this.saveFirstTimestampOnly(key, value);
87
+ } else {
88
+ this.latencyTimestamps.set(key, value);
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Store precomputed latency value
94
+ * @param key - key
95
+ * @param value -value
96
+ * @throws
97
+ * @returns
98
+ */
99
+ public saveLatency(key: PreComputedLatencies, value: number) {
100
+ this.precomputedLatencies.set(key, value);
101
+ }
102
+
103
+ /**
104
+ * Store only the first timestamp value for the given key
105
+ * @param key - key
106
+ * @param value -value
107
+ * @throws
108
+ * @returns
109
+ */
110
+ saveFirstTimestampOnly(key: MetricEventNames, value: number = new Date().getTime()) {
111
+ if (this.latencyTimestamps.has(key)) {
112
+ return;
113
+ }
114
+ this.latencyTimestamps.set(key, value);
115
+ }
116
+
117
+ /**
118
+ * Helper to calculate end - start
119
+ * @param a start
120
+ * @param b end
121
+ * @returns latency
122
+ */
123
+ public getDiffBetweenTimestamps(a: MetricEventNames, b: MetricEventNames) {
124
+ const start = this.latencyTimestamps.get(a);
125
+ const end = this.latencyTimestamps.get(b);
126
+ if (start && end) {
127
+ return end - start;
128
+ }
129
+
130
+ return undefined;
131
+ }
132
+
133
+ /**
134
+ * Meeting Info Request
135
+ * @note Meeting Info request happen not just in the join phase. CA requires
136
+ * metrics around meeting info request that are only part of join phase.
137
+ * This internal.* event is used to track the real timestamps
138
+ * (when the actual request/response happen). This is because the actual CA event is
139
+ * sent inside the join method on the meeting object based on some logic, but that's not exactly when
140
+ * those events are actually fired. The logic only confirms that they have happened, and we send them over.
141
+ * @returns - latency
142
+ */
143
+ public getMeetingInfoReqResp() {
144
+ return this.getDiffBetweenTimestamps(
145
+ 'internal.client.meetinginfo.request',
146
+ 'internal.client.meetinginfo.response'
147
+ );
148
+ }
149
+
150
+ /**
151
+ * Interstitial Time
152
+ * @returns - latency
153
+ */
154
+ public getShowInterstitialTime() {
155
+ return this.getDiffBetweenTimestamps(
156
+ 'client.interstitial-window.start-launch',
157
+ 'internal.client.interstitial-window.click.joinbutton'
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Device Register Time
163
+ * @returns - latency
164
+ */
165
+ public getRegisterWDMDeviceJMT() {
166
+ return this.getDiffBetweenTimestamps(
167
+ 'internal.register.device.request',
168
+ 'internal.register.device.response'
169
+ );
170
+ }
171
+
172
+ /**
173
+ * Call Init Join Request
174
+ * @returns - latency
175
+ */
176
+ public getCallInitJoinReq() {
177
+ return this.getDiffBetweenTimestamps(
178
+ 'internal.client.interstitial-window.click.joinbutton',
179
+ 'client.locus.join.request'
180
+ );
181
+ }
182
+
183
+ /**
184
+ * Locus Join Request
185
+ * @returns - latency
186
+ */
187
+ public getJoinReqResp() {
188
+ return this.getDiffBetweenTimestamps('client.locus.join.request', 'client.locus.join.response');
189
+ }
190
+
191
+ /**
192
+ * Locus Join Response Sent Received
193
+ * @returns - latency
194
+ */
195
+ public getJoinRespSentReceived() {
196
+ // TODO: not clear SPARK-440554
197
+ return undefined;
198
+ }
199
+
200
+ /**
201
+ * Time taken to do turn discovery
202
+ * @returns - latency
203
+ */
204
+ public getTurnDiscoveryTime() {
205
+ return this.getDiffBetweenTimestamps(
206
+ 'internal.client.add-media.turn-discovery.start',
207
+ 'internal.client.add-media.turn-discovery.end'
208
+ );
209
+ }
210
+
211
+ /**
212
+ * Local SDP Generated Remote SDP REceived
213
+ * @returns - latency
214
+ */
215
+ public getLocalSDPGenRemoteSDPRecv() {
216
+ return this.getDiffBetweenTimestamps(
217
+ 'client.media-engine.local-sdp-generated',
218
+ 'client.media-engine.remote-sdp-received'
219
+ );
220
+ }
221
+
222
+ /**
223
+ * ICE Setup Time
224
+ * @returns - latency
225
+ */
226
+ public getICESetupTime() {
227
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
228
+ }
229
+
230
+ /**
231
+ * Audio ICE time
232
+ * @returns - latency
233
+ */
234
+ public getAudioICESetupTime() {
235
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
236
+ }
237
+
238
+ /**
239
+ * Video ICE Time
240
+ * @returns - latency
241
+ */
242
+ public getVideoICESetupTime() {
243
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
244
+ }
245
+
246
+ /**
247
+ * Share ICE Time
248
+ * @returns - latency
249
+ */
250
+ public getShareICESetupTime() {
251
+ return this.getDiffBetweenTimestamps('client.ice.start', 'client.ice.end');
252
+ }
253
+
254
+ /**
255
+ * Stay Lobby Time
256
+ * @returns - latency
257
+ */
258
+ public getStayLobbyTime() {
259
+ return this.getDiffBetweenTimestamps(
260
+ 'client.locus.join.response',
261
+ 'internal.host.meeting.participant.admitted'
262
+ );
263
+ }
264
+
265
+ /**
266
+ * Page JMT
267
+ * @returns - latency
268
+ */
269
+ public getPageJMT() {
270
+ return this.precomputedLatencies.get('internal.client.pageJMT') || undefined;
271
+ }
272
+
273
+ /**
274
+ * Download Time JMT
275
+ * @returns - latency
276
+ */
277
+ public getDownloadTimeJMT() {
278
+ return this.precomputedLatencies.get('internal.download.time') || undefined;
279
+ }
280
+
281
+ /**
282
+ * Click To Interstitial
283
+ * @returns - latency
284
+ */
285
+ public getClickToInterstitial() {
286
+ // for normal join (where green join button exists before interstitial, i.e reminder, space list etc)
287
+ if (this.latencyTimestamps.get('internal.client.meeting.click.joinbutton')) {
288
+ return this.getDiffBetweenTimestamps(
289
+ 'internal.client.meeting.click.joinbutton',
290
+ 'internal.client.meeting.interstitial-window.showed'
291
+ );
292
+ }
293
+
294
+ // for cross launch and guest flows
295
+ return this.precomputedLatencies.get('internal.click.to.interstitial') || undefined;
296
+ }
297
+
298
+ /**
299
+ * Interstitial To Join Ok
300
+ * @returns - latency
301
+ */
302
+ public getInterstitialToJoinOK() {
303
+ return this.getDiffBetweenTimestamps(
304
+ 'internal.client.interstitial-window.click.joinbutton',
305
+ 'client.locus.join.response'
306
+ );
307
+ }
308
+
309
+ /**
310
+ * Call Init To MediaEngineReady
311
+ * @returns - latency
312
+ */
313
+ public getCallInitMediaEngineReady() {
314
+ return this.getDiffBetweenTimestamps(
315
+ 'internal.client.interstitial-window.click.joinbutton',
316
+ 'client.media-engine.ready'
317
+ );
318
+ }
319
+
320
+ /**
321
+ * Interstitial To Media Ok
322
+ * @returns - latency
323
+ */
324
+ public getInterstitialToMediaOKJMT() {
325
+ const interstitialJoinClickTimestamp = this.latencyTimestamps.get(
326
+ 'internal.client.interstitial-window.click.joinbutton'
327
+ );
328
+
329
+ // get the first timestamp
330
+ const connectedMedia = this.latencyTimestamps.get('client.ice.end');
331
+
332
+ const lobbyTime = this.getStayLobbyTime() || 0;
333
+
334
+ if (interstitialJoinClickTimestamp && connectedMedia) {
335
+ return connectedMedia - interstitialJoinClickTimestamp - lobbyTime;
336
+ }
337
+
338
+ return undefined;
339
+ }
340
+
341
+ /**
342
+ * Total JMT
343
+ * @returns - latency
344
+ */
345
+ public getTotalJMT() {
346
+ const clickToInterstitial = this.getClickToInterstitial();
347
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
348
+
349
+ if (clickToInterstitial && interstitialToJoinOk) {
350
+ return clickToInterstitial + interstitialToJoinOk;
351
+ }
352
+
353
+ return undefined;
354
+ }
355
+
356
+ /**
357
+ * Join Conf JMT
358
+ * @returns - latency
359
+ */
360
+ public getJoinConfJMT() {
361
+ const joinReqResp = this.getJoinReqResp();
362
+ const ICESetupTime = this.getICESetupTime();
363
+
364
+ if (joinReqResp && ICESetupTime) {
365
+ return joinReqResp + ICESetupTime;
366
+ }
367
+
368
+ return undefined;
369
+ }
370
+
371
+ /**
372
+ * Total Media JMT
373
+ * @returns - latency
374
+ */
375
+ public getTotalMediaJMT() {
376
+ const clickToInterstitial = this.getClickToInterstitial();
377
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
378
+ const joinConfJMT = this.getJoinConfJMT();
379
+ const lobbyTime = this.getStayLobbyTime();
380
+
381
+ if (clickToInterstitial && interstitialToJoinOk && joinConfJMT) {
382
+ const totalMediaJMT = clickToInterstitial + interstitialToJoinOk + joinConfJMT;
383
+ if (this.getMeeting()?.allowMediaInLobby) {
384
+ return totalMediaJMT;
385
+ }
386
+
387
+ return totalMediaJMT - lobbyTime;
388
+ }
389
+
390
+ return undefined;
391
+ }
392
+
393
+ /**
394
+ * Client JMT
395
+ * @returns - latency
396
+ */
397
+ public getClientJMT() {
398
+ const interstitialToJoinOk = this.getInterstitialToJoinOK();
399
+ const joinConfJMT = this.getJoinConfJMT();
400
+
401
+ if (interstitialToJoinOk && joinConfJMT) {
402
+ return interstitialToJoinOk - joinConfJMT;
403
+ }
404
+
405
+ return undefined;
406
+ }
407
+
408
+ /**
409
+ * Audio setup delay receive
410
+ */
411
+ public getAudioJoinRespRxStart() {
412
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.rx.start');
413
+ }
414
+
415
+ /**
416
+ * Video setup delay receive
417
+ */
418
+ public getVideoJoinRespRxStart() {
419
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.rx.start');
420
+ }
421
+
422
+ /**
423
+ * Audio setup delay transmit
424
+ */
425
+ public getAudioJoinRespTxStart() {
426
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.tx.start');
427
+ }
428
+
429
+ /**
430
+ * Video setup delay transmit
431
+ */
432
+ public getVideoJoinRespTxStart() {
433
+ return this.getDiffBetweenTimestamps('client.locus.join.response', 'client.media.tx.start');
434
+ }
435
+ }