@webex/internal-plugin-metrics 3.12.0-next.34 → 3.12.0-next.36

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.
@@ -1,5 +1,35 @@
1
1
  import { WebexPlugin } from '@webex/webex-core';
2
2
  import { MetricEventNames, PreComputedLatencies } from '../metrics.types';
3
+ type SaveTimestampOptions = {
4
+ meetingId?: string;
5
+ dataSetName?: string;
6
+ trackingId?: string;
7
+ };
8
+ type SaveLatencyOptions = {
9
+ accumulate?: boolean;
10
+ meetingId?: string;
11
+ dataSetName?: string;
12
+ };
13
+ type LocusSyncLatencyRecord = {
14
+ meetingId: string;
15
+ dataSetName: string;
16
+ randomBackoffTime: number;
17
+ trackingId?: string;
18
+ syncStart?: number;
19
+ hashTreeRequest?: number;
20
+ hashTreeResponse?: number;
21
+ syncRequest?: number;
22
+ syncResponse?: number;
23
+ messageReceived?: number;
24
+ };
25
+ /**
26
+ * Container for the latencies tracked for a single meeting. Locus sync is currently the only
27
+ * meeting-specific latency we track, but this wrapper lets us add other latency records in the
28
+ * future without changing the shape of `meetingLatencies`.
29
+ */
30
+ type MeetingLatencyRecord = {
31
+ locusSync: LocusSyncLatencyRecord;
32
+ };
3
33
  /**
4
34
  * @description Helper class to store latencies timestamp and to calculate various latencies for CA.
5
35
  * @exports
@@ -8,8 +38,12 @@ import { MetricEventNames, PreComputedLatencies } from '../metrics.types';
8
38
  export default class CallDiagnosticLatencies extends WebexPlugin {
9
39
  latencyTimestamps: Map<MetricEventNames, number>;
10
40
  precomputedLatencies: Map<PreComputedLatencies, number>;
41
+ meetingLatencies: Map<string, MeetingLatencyRecord[]>;
11
42
  private meetingId?;
12
43
  private MAX_INTEGER;
44
+ private LOCUS_SYNC_SKEW_THRESHOLD_MS;
45
+ private LOCUS_SYNC_PENDING_RECORD_TTL_MS;
46
+ private LOCUS_SYNC_MAX_RECORDS_PER_DATASET;
13
47
  /**
14
48
  * @constructor
15
49
  */
@@ -18,6 +52,164 @@ export default class CallDiagnosticLatencies extends WebexPlugin {
18
52
  * Clear timestamps
19
53
  */
20
54
  clearTimestamps(): void;
55
+ /**
56
+ * Clear tracked Locus sync latency state for a dataset.
57
+ *
58
+ * When a `trackingId` is supplied only the single record matching it is dropped, mirroring the
59
+ * native client which discards the individual in-progress record on a sync error (by syncId).
60
+ * When no `trackingId` is supplied every record for the dataset is dropped (legacy behavior).
61
+ *
62
+ * @param dataSetName dataset name
63
+ * @param meetingId meeting id
64
+ * @param trackingId optional sync tracking id to drop a single record instead of the whole dataset
65
+ */
66
+ clearLocusSyncLatency(dataSetName: string, meetingId: string, trackingId?: string): void;
67
+ /**
68
+ * Calculates Locus sync latency values from stored milestone timestamps.
69
+ * @param meetingId meeting id
70
+ * @param trackingId sync tracking id used to match the record
71
+ * @returns sync latency metrics
72
+ */
73
+ getLocusSyncLatency(meetingId: string, trackingId: string): {
74
+ totalTime: number;
75
+ syncMessageReceiveTime?: number;
76
+ syncResponseTime?: number;
77
+ randomBackoffTime: number;
78
+ hashtreePrepTime: number;
79
+ hashtreeResponseTime: number;
80
+ syncPrepTime: number;
81
+ };
82
+ /**
83
+ * Records the time the LLM state-update message for a Locus sync arrived. This is the milestone
84
+ * that gates the client.locus.sync.complete metric: the metric is emitted only for flows where
85
+ * the update came over LLM (aligned with the agreed requirement that body/http-only syncs do not
86
+ * emit). The record is matched by meeting id + tracking id, regardless of which other milestones
87
+ * are present yet, so the real arrival time is captured even if the /sync response has not landed.
88
+ * @param meetingId meeting id
89
+ * @param trackingId sync tracking id used to match the pending record
90
+ * @returns void
91
+ */
92
+ recordLocusSyncMessageReceived(meetingId: string, trackingId: string): void;
93
+ /**
94
+ * Complete and remove the Locus sync latency record for a meeting + tracking id.
95
+ *
96
+ * Both milestones are required, in any arrival order: the metric is emitted only once BOTH the
97
+ * matching LLM broadcast (messageReceived) AND the /sync response have arrived. The LLM broadcast
98
+ * confirms the client that issued the /sync received the resulting state update for its tracking
99
+ * id (so sync cancel, or a sync storm where the final broadcast echoed another client's tracking
100
+ * id, never emit); the /sync response is always waited for too, since the LLM message can arrive
101
+ * before the HTTP response. If either milestone is missing the record is kept so the other can
102
+ * still arrive; it is only consumed when the metric is actually emitted.
103
+ * @param meetingId meeting id
104
+ * @param trackingId sync tracking id used to match the pending record
105
+ * @returns completed sync latency metric payload, or undefined when not completed
106
+ */
107
+ completeLocusSyncLatency(meetingId: string, trackingId: string): {
108
+ dataSet: string;
109
+ syncLatency: {
110
+ totalTime: number;
111
+ syncMessageReceiveTime?: number;
112
+ syncResponseTime?: number;
113
+ randomBackoffTime: number;
114
+ hashtreePrepTime: number;
115
+ hashtreeResponseTime: number;
116
+ syncPrepTime: number;
117
+ };
118
+ };
119
+ /**
120
+ * Helper to calculate end - start for Locus sync milestones.
121
+ * @param record tracked milestone timestamps
122
+ * @param a start milestone
123
+ * @param b end milestone
124
+ * @returns latency
125
+ */
126
+ private getDiffBetweenLocusSyncTimestamps;
127
+ /**
128
+ * Get the timestamp that starts the sync prep segment.
129
+ * @param record tracked milestone timestamps
130
+ * @returns sync prep start milestone
131
+ */
132
+ private getLocusSyncPrepStart;
133
+ /**
134
+ * Round and clamp Locus sync latency values.
135
+ * @param latency latency value
136
+ * @returns rounded latency
137
+ */
138
+ private getClampedLocusSyncLatency;
139
+ /**
140
+ * Finds a Locus sync latency record for a meeting using a predicate run against each stored
141
+ * locusSync record.
142
+ * @param meetingId meeting id
143
+ * @param predicate matcher run against each locusSync record
144
+ * @param options.searchFromLatest when true, iterate from the most recently added record first
145
+ * @returns matching Locus sync latency record
146
+ */
147
+ private findLocusSyncRecord;
148
+ /**
149
+ * Get the Locus sync latency record for a meeting and tracking id.
150
+ * @param meetingId meeting id
151
+ * @param trackingId /sync response tracking id
152
+ * @returns matching Locus sync latency record
153
+ */
154
+ private getLocusSyncLatencyRecord;
155
+ /**
156
+ * Remove the Locus sync latency record for a meeting and tracking id.
157
+ * @param meetingId meeting id
158
+ * @param trackingId sync tracking id used to match the record
159
+ * @returns void
160
+ */
161
+ private removeLocusSyncLatencyRecord;
162
+ /**
163
+ * Prune stale never-completed Locus sync latency records for the same dataset as the record that
164
+ * just changed. Records are dropped when they have been pending longer than the TTL, or to keep
165
+ * the number of records per dataset under the safety cap (oldest pending candidates first).
166
+ * @param records current records for the meeting
167
+ * @param changedRecord the record that was just updated, used as the reference point
168
+ * @returns the records to keep
169
+ */
170
+ private pruneStaleLocusSyncLatencyRecords;
171
+ /**
172
+ * Get the most recent milestone timestamp stored on a Locus sync latency record, checking
173
+ * milestones from latest to earliest so the newest available one is returned.
174
+ * @param record tracked milestone timestamps
175
+ * @returns latest milestone timestamp, or undefined when none are set
176
+ */
177
+ private getLatestLocusSyncTimestamp;
178
+ /**
179
+ * Persist the Locus sync latency records for a meeting, deleting the meeting entry when no
180
+ * records remain. When pruneOptions is provided, stale records are pruned before saving.
181
+ * @param meetingId meeting id
182
+ * @param records records to save
183
+ * @param pruneOptions when provided, triggers stale record pruning relative to changedRecord
184
+ * @returns void
185
+ */
186
+ private setMeetingLatencyRecords;
187
+ /**
188
+ * Get the latest Locus sync latency record waiting for sync.start.
189
+ * @param meetingId meeting id
190
+ * @param dataSetName dataset name
191
+ * @returns latest pending Locus sync latency record
192
+ */
193
+ private getLatestPendingLocusSyncLatencyRecord;
194
+ /**
195
+ * Store random backoff latency for the current or next Locus sync latency record.
196
+ * @param meetingId meeting id
197
+ * @param dataSetName dataset name
198
+ * @param randomBackoffTime random backoff latency value
199
+ * @returns void
200
+ */
201
+ private saveLocusSyncBackoffLatency;
202
+ /**
203
+ * Checks if metric event name is a Locus sync latency milestone.
204
+ * @param key event name
205
+ * @returns whether event is Locus sync latency milestone
206
+ */
207
+ private isLocusSyncLatencyEvent;
208
+ /**
209
+ * Stores a Locus sync latency milestone timestamp.
210
+ * @param options options
211
+ */
212
+ private saveLocusSyncLatencyTimestamp;
21
213
  /**
22
214
  * Associate current latencies with a meeting id
23
215
  * @param meetingId
@@ -39,19 +231,20 @@ export default class CallDiagnosticLatencies extends WebexPlugin {
39
231
  saveTimestamp({ key, value, options, }: {
40
232
  key: MetricEventNames;
41
233
  value?: number;
42
- options?: {
43
- meetingId?: string;
44
- };
234
+ options?: SaveTimestampOptions;
45
235
  }): void;
46
236
  /**
47
237
  * Store precomputed latency value
48
238
  * @param key - key
49
239
  * @param value - value
50
- * @param accumulate - when it is true, it overwrites existing value with sum of the current value and the new measurement otherwise just store the new measurement
240
+ * @param options - store options (a legacy boolean `accumulate` flag is also accepted)
241
+ * @param options.accumulate - when it is true, it overwrites existing value with sum of the current value and the new measurement otherwise just store the new measurement
242
+ * @param options.meetingId - meeting id, only used for Locus sync latency records
243
+ * @param options.dataSetName - dataset name, only used for Locus sync latency records
51
244
  * @throws
52
245
  * @returns
53
246
  */
54
- saveLatency(key: PreComputedLatencies, value: number, accumulate?: boolean): void;
247
+ saveLatency(key: PreComputedLatencies, value: number, options?: SaveLatencyOptions): void;
55
248
  /**
56
249
  * Measure latency for a request
57
250
  * @param callback - callback for which you would like to measure latency
@@ -267,3 +460,4 @@ export default class CallDiagnosticLatencies extends WebexPlugin {
267
460
  */
268
461
  getOtherAppApiReqResp(): number;
269
462
  }
463
+ export {};
@@ -4,7 +4,7 @@
4
4
  import config from './config';
5
5
  import NewMetrics from './new-metrics';
6
6
  import * as Utils from './utils';
7
- import { ClientEvent, ClientEventLeaveReason, SubmitBehavioralEvent, SubmitClientEvent, SubmitInternalEvent, SubmitOperationalEvent, SubmitBusinessEvent, SubmitMQE, PreComputedLatencies, SubmitFeatureEvent } from './metrics.types';
7
+ import { ClientEvent, ClientEventLeaveReason, SubmitBehavioralEvent, SubmitClientEvent, SubmitInternalEvent, SubmitOperationalEvent, SubmitBusinessEvent, SubmitMQE, PreComputedLatencies, SubmitFeatureEvent, LocusSyncLatencyEventName } from './metrics.types';
8
8
  import * as CALL_DIAGNOSTIC_CONFIG from './call-diagnostic/config';
9
9
  import * as CallDiagnosticUtils from './call-diagnostic/call-diagnostic-metrics.util';
10
10
  import CallDiagnosticMetrics from './call-diagnostic/call-diagnostic-metrics';
@@ -16,4 +16,4 @@ import RtcMetrics from './rtcMetrics';
16
16
  import PreLoginMetrics from './prelogin-metrics';
17
17
  export { default, getOSNameInternal } from './metrics';
18
18
  export { config, CALL_DIAGNOSTIC_CONFIG, NewMetrics, Utils, CallDiagnosticUtils, CallDiagnosticLatencies, CallDiagnosticMetrics, BehavioralMetrics, OperationalMetrics, BusinessMetrics, RtcMetrics, PreLoginMetrics, };
19
- export type { ClientEvent, ClientEventLeaveReason, SubmitBehavioralEvent, SubmitClientEvent, SubmitInternalEvent, SubmitMQE, SubmitOperationalEvent, SubmitBusinessEvent, PreComputedLatencies, SubmitFeatureEvent, };
19
+ export type { ClientEvent, ClientEventLeaveReason, SubmitBehavioralEvent, SubmitClientEvent, SubmitInternalEvent, SubmitMQE, SubmitOperationalEvent, SubmitBusinessEvent, PreComputedLatencies, SubmitFeatureEvent, LocusSyncLatencyEventName, };
@@ -41,8 +41,10 @@ export type SubmitMQEOptions = {
41
41
  webexConferenceIdStr?: string;
42
42
  globalMeetingId?: string;
43
43
  };
44
+ export declare const LOCUS_SYNC_LATENCY_EVENT_NAMES: readonly ["internal.client.locus.sync.start", "internal.client.locus.hashtree.request", "internal.client.locus.hashtree.response", "internal.client.locus.sync.request", "internal.client.locus.sync.response", "internal.client.locus.sync.message.received"];
45
+ export type LocusSyncLatencyEventName = (typeof LOCUS_SYNC_LATENCY_EVENT_NAMES)[number];
44
46
  export type InternalEvent = {
45
- name: 'internal.client.meetinginfo.request' | 'internal.client.meetinginfo.response' | 'internal.register.device.request' | 'internal.register.device.response' | 'internal.reset.join.latencies' | 'internal.host.meeting.participant.admitted' | 'internal.client.meeting.interstitial-window.showed' | 'internal.client.interstitial-window.click.joinbutton' | 'internal.client.add-media.turn-discovery.start' | 'internal.client.add-media.turn-discovery.end' | 'internal.client.share.initiated' | 'internal.client.share.stopped';
47
+ name: 'internal.client.meetinginfo.request' | 'internal.client.meetinginfo.response' | 'internal.register.device.request' | 'internal.register.device.response' | 'internal.reset.join.latencies' | 'internal.host.meeting.participant.admitted' | 'internal.client.meeting.interstitial-window.showed' | 'internal.client.interstitial-window.click.joinbutton' | 'internal.client.add-media.turn-discovery.start' | 'internal.client.add-media.turn-discovery.end' | 'internal.client.share.initiated' | 'internal.client.share.stopped' | LocusSyncLatencyEventName;
46
48
  payload?: never;
47
49
  options?: never;
48
50
  };
@@ -154,7 +156,7 @@ export type BuildClientEventFetchRequestOptions = (args: {
154
156
  payload?: RecursivePartial<ClientEvent['payload']>;
155
157
  options?: SubmitClientEventOptions;
156
158
  }) => Promise<any>;
157
- export type PreComputedLatencies = 'internal.client.pageJMT' | 'internal.download.time' | 'internal.get.cluster.time' | 'internal.click.to.interstitial' | 'internal.click.to.interstitial.with.user.delay' | 'internal.click.to.interstitial.for.client.jmt' | 'internal.refresh.captcha.time' | 'internal.exchange.ci.token.time' | 'internal.get.u2c.time' | 'internal.call.init.join.req' | 'internal.other.app.api.time' | 'internal.api.fetch.intelligence.models';
159
+ export type PreComputedLatencies = 'internal.client.pageJMT' | 'internal.download.time' | 'internal.get.cluster.time' | 'internal.click.to.interstitial' | 'internal.click.to.interstitial.with.user.delay' | 'internal.click.to.interstitial.for.client.jmt' | 'internal.refresh.captcha.time' | 'internal.exchange.ci.token.time' | 'internal.get.u2c.time' | 'internal.call.init.join.req' | 'internal.other.app.api.time' | 'internal.api.fetch.intelligence.models' | 'internal.client.locus.sync.random.backoff';
158
160
  export interface IdType {
159
161
  meetingId?: string;
160
162
  callId?: string;
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "@webex/event-dictionary-ts": "^1.0.2215",
41
41
  "@webex/test-helper-chai": "3.12.0-next.5",
42
42
  "@webex/test-helper-mock-webex": "3.12.0-next.5",
43
- "@webex/webex-core": "3.12.0-next.34",
43
+ "@webex/webex-core": "3.12.0-next.36",
44
44
  "ip-anonymize": "^0.1.0",
45
45
  "lodash": "^4.17.21",
46
46
  "uuid": "^3.3.2"
@@ -53,5 +53,5 @@
53
53
  "test:style": "eslint ./src/**/*.*",
54
54
  "test:unit": "webex-legacy-tools test --unit --runner mocha"
55
55
  },
56
- "version": "3.12.0-next.34"
56
+ "version": "3.12.0-next.36"
57
57
  }