@webex/internal-plugin-metrics 3.5.0 → 3.6.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.
- package/dist/business-metrics.js +119 -9
- package/dist/business-metrics.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics-latencies.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics.js +26 -7
- package/dist/call-diagnostic/call-diagnostic-metrics.js.map +1 -1
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js +7 -2
- package/dist/call-diagnostic/call-diagnostic-metrics.util.js.map +1 -1
- package/dist/call-diagnostic/config.js +13 -3
- package/dist/call-diagnostic/config.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/metrics.js +1 -1
- package/dist/metrics.types.js.map +1 -1
- package/dist/new-metrics.js +5 -2
- package/dist/new-metrics.js.map +1 -1
- package/dist/rtcMetrics/constants.js +11 -0
- package/dist/rtcMetrics/constants.js.map +1 -0
- package/dist/rtcMetrics/index.js +223 -0
- package/dist/rtcMetrics/index.js.map +1 -0
- package/dist/types/business-metrics.d.ts +36 -4
- package/dist/types/call-diagnostic/call-diagnostic-metrics.d.ts +4 -1
- package/dist/types/call-diagnostic/config.d.ts +3 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/metrics.types.d.ts +19 -2
- package/dist/types/new-metrics.d.ts +5 -3
- package/dist/types/rtcMetrics/constants.d.ts +4 -0
- package/dist/types/rtcMetrics/index.d.ts +80 -0
- package/package.json +12 -12
- package/src/business-metrics.ts +97 -5
- package/src/call-diagnostic/call-diagnostic-metrics-latencies.ts +1 -1
- package/src/call-diagnostic/call-diagnostic-metrics.ts +26 -7
- package/src/call-diagnostic/call-diagnostic-metrics.util.ts +11 -5
- package/src/call-diagnostic/config.ts +12 -0
- package/src/index.ts +2 -0
- package/src/metrics.types.ts +98 -23
- package/src/new-metrics.ts +12 -2
- package/src/rtcMetrics/constants.ts +3 -0
- package/src/rtcMetrics/index.ts +205 -0
- package/test/unit/spec/business/business-metrics.ts +69 -2
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-batcher.ts +2 -1
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics-latencies.ts +4 -6
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.ts +489 -16
- package/test/unit/spec/call-diagnostic/call-diagnostic-metrics.util.ts +7 -3
- package/test/unit/spec/new-metrics.ts +18 -3
- package/test/unit/spec/prelogin-metrics-batcher.ts +3 -1
- package/test/unit/spec/rtcMetrics/index.ts +196 -0
- package/dist/behavioral/behavioral-metrics.js +0 -199
- package/dist/behavioral/behavioral-metrics.js.map +0 -1
- package/dist/behavioral/config.js +0 -11
- package/dist/behavioral/config.js.map +0 -1
- package/dist/types/behavioral/behavioral-metrics.d.ts +0 -63
- package/dist/types/behavioral/config.d.ts +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
import uuid from 'uuid';
|
|
3
|
+
import * as CallDiagnosticUtils from '../call-diagnostic/call-diagnostic-metrics.util';
|
|
4
|
+
import RTC_METRICS from './constants';
|
|
5
|
+
import {IdType, IMetricsAttributes} from '../metrics.types';
|
|
6
|
+
|
|
7
|
+
const parseJsonPayload = (payload: any[]): any | null => {
|
|
8
|
+
try {
|
|
9
|
+
if (payload && payload[0]) {
|
|
10
|
+
return JSON.parse(payload[0]);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return null;
|
|
14
|
+
} catch (_) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Rtc Metrics
|
|
21
|
+
*/
|
|
22
|
+
export default class RtcMetrics {
|
|
23
|
+
/**
|
|
24
|
+
* Array of MetricData items to be sent to the metrics service.
|
|
25
|
+
*/
|
|
26
|
+
metricsQueue = [];
|
|
27
|
+
|
|
28
|
+
intervalId: number;
|
|
29
|
+
|
|
30
|
+
webex: any;
|
|
31
|
+
|
|
32
|
+
meetingId?: string;
|
|
33
|
+
|
|
34
|
+
callId?: string;
|
|
35
|
+
|
|
36
|
+
correlationId: string;
|
|
37
|
+
|
|
38
|
+
connectionId: string;
|
|
39
|
+
|
|
40
|
+
shouldSendMetricsOnNextStatsReport: boolean;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the interval.
|
|
44
|
+
*
|
|
45
|
+
* @param {object} webex - The main `webex` object.
|
|
46
|
+
* @param {IdType} Ids - Meeting or Calling id.
|
|
47
|
+
* @param {string} correlationId - The correlation id.
|
|
48
|
+
*/
|
|
49
|
+
constructor(webex, {meetingId, callId}: IdType, correlationId) {
|
|
50
|
+
// `window` is used to prevent typescript from returning a NodeJS.Timer.
|
|
51
|
+
this.intervalId = window.setInterval(this.sendMetricsInQueue.bind(this), 30 * 1000);
|
|
52
|
+
this.meetingId = meetingId;
|
|
53
|
+
this.callId = callId;
|
|
54
|
+
this.webex = webex;
|
|
55
|
+
this.correlationId = correlationId;
|
|
56
|
+
this.resetConnection();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Updates the call identifier with the provided value.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} callId - The new call identifier to set.
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
public updateCallId(callId: string) {
|
|
66
|
+
this.callId = callId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Check to see if the metrics queue has any items.
|
|
71
|
+
*
|
|
72
|
+
* @returns {void}
|
|
73
|
+
*/
|
|
74
|
+
public sendMetricsInQueue() {
|
|
75
|
+
if (this.metricsQueue.length) {
|
|
76
|
+
this.sendMetrics();
|
|
77
|
+
this.metricsQueue = [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Forces sending metrics when we get the next stats-report
|
|
83
|
+
*
|
|
84
|
+
* This is useful for cases when something important happens that affects the media connection,
|
|
85
|
+
* for example when we move from lobby into the meeting.
|
|
86
|
+
*
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
public sendNextMetrics() {
|
|
90
|
+
this.shouldSendMetricsOnNextStatsReport = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Add metrics items to the metrics queue.
|
|
95
|
+
*
|
|
96
|
+
* @param {object} data - An object with a payload array of metrics items.
|
|
97
|
+
*
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
addMetrics(data) {
|
|
101
|
+
if (data.payload.length) {
|
|
102
|
+
if (data.name === 'stats-report') {
|
|
103
|
+
data.payload = data.payload.map(this.anonymizeIp);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.metricsQueue.push(data);
|
|
107
|
+
|
|
108
|
+
if (this.shouldSendMetricsOnNextStatsReport && data.name === 'stats-report') {
|
|
109
|
+
// this is the first useful set of data (WCME gives it to us after 5s), send it out immediately
|
|
110
|
+
// in case the user is unhappy and closes the browser early
|
|
111
|
+
this.sendMetricsInQueue();
|
|
112
|
+
this.shouldSendMetricsOnNextStatsReport = false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
// If a connection fails, send the rest of the metrics in queue and get a new connection id.
|
|
117
|
+
const parsedPayload = parseJsonPayload(data.payload);
|
|
118
|
+
if (
|
|
119
|
+
data.name === 'onconnectionstatechange' &&
|
|
120
|
+
parsedPayload &&
|
|
121
|
+
parsedPayload.value === 'failed'
|
|
122
|
+
) {
|
|
123
|
+
this.sendMetricsInQueue();
|
|
124
|
+
this.resetConnection();
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.error(e);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Clear the metrics interval.
|
|
134
|
+
*
|
|
135
|
+
* @returns {void}
|
|
136
|
+
*/
|
|
137
|
+
closeMetrics() {
|
|
138
|
+
this.sendMetricsInQueue();
|
|
139
|
+
clearInterval(this.intervalId);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Anonymize IP addresses.
|
|
144
|
+
*
|
|
145
|
+
* @param {array} stats - An RTCStatsReport organized into an array of strings.
|
|
146
|
+
* @returns {string}
|
|
147
|
+
*/
|
|
148
|
+
anonymizeIp(stats: string): string {
|
|
149
|
+
const data = JSON.parse(stats);
|
|
150
|
+
// on local and remote candidates, anonymize the last 4 bits.
|
|
151
|
+
if (data.type === 'local-candidate' || data.type === 'remote-candidate') {
|
|
152
|
+
data.ip = CallDiagnosticUtils.anonymizeIPAddress(data.ip) || undefined;
|
|
153
|
+
data.address = CallDiagnosticUtils.anonymizeIPAddress(data.address) || undefined;
|
|
154
|
+
data.relatedAddress =
|
|
155
|
+
CallDiagnosticUtils.anonymizeIPAddress(data.relatedAddress) || undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return JSON.stringify(data);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Set a new connection id.
|
|
163
|
+
*
|
|
164
|
+
* @returns {void}
|
|
165
|
+
*/
|
|
166
|
+
private resetConnection() {
|
|
167
|
+
this.connectionId = uuid.v4();
|
|
168
|
+
this.shouldSendMetricsOnNextStatsReport = true;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Send metrics to the metrics service.
|
|
173
|
+
*
|
|
174
|
+
* @returns {void}
|
|
175
|
+
*/
|
|
176
|
+
private sendMetrics() {
|
|
177
|
+
const metricsAttributes: IMetricsAttributes = {
|
|
178
|
+
type: 'webrtc',
|
|
179
|
+
version: '1.1.0',
|
|
180
|
+
userId: this.webex.internal.device.userId,
|
|
181
|
+
correlationId: this.correlationId,
|
|
182
|
+
connectionId: this.connectionId,
|
|
183
|
+
data: this.metricsQueue,
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
if (this.meetingId) {
|
|
187
|
+
metricsAttributes.meetingId = this.meetingId;
|
|
188
|
+
} else if (this.callId) {
|
|
189
|
+
metricsAttributes.callId = this.callId;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
this.webex.request({
|
|
193
|
+
method: 'POST',
|
|
194
|
+
service: 'unifiedTelemetry',
|
|
195
|
+
resource: 'metric/v2',
|
|
196
|
+
headers: {
|
|
197
|
+
type: 'webrtcMedia',
|
|
198
|
+
appId: RTC_METRICS.APP_ID,
|
|
199
|
+
},
|
|
200
|
+
body: {
|
|
201
|
+
metrics: [metricsAttributes],
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -20,6 +20,8 @@ describe('internal-plugin-metrics', () => {
|
|
|
20
20
|
|
|
21
21
|
beforeEach(() => {
|
|
22
22
|
now = new Date();
|
|
23
|
+
sinon.createSandbox();
|
|
24
|
+
sinon.useFakeTimers(now.getTime());
|
|
23
25
|
|
|
24
26
|
webex = {
|
|
25
27
|
canAuthorize: true,
|
|
@@ -74,7 +76,7 @@ describe('internal-plugin-metrics', () => {
|
|
|
74
76
|
});
|
|
75
77
|
|
|
76
78
|
describe('#sendEvent', () => {
|
|
77
|
-
it('should send correctly shaped business event (check name building and internal tagged event building)', () => {
|
|
79
|
+
it('should send correctly shaped business event (check name building and internal tagged event building) and default correctly', () => {
|
|
78
80
|
// For some reasons `jest` isn't available when testing form build server - so can't use `jest.fn()` here...
|
|
79
81
|
const requestCalls = [];
|
|
80
82
|
const request = function(arg) { requestCalls.push(arg) }
|
|
@@ -86,6 +88,7 @@ describe('internal-plugin-metrics', () => {
|
|
|
86
88
|
assert.equal(requestCalls.length, 1)
|
|
87
89
|
assert.deepEqual(requestCalls[0], {
|
|
88
90
|
eventPayload: {
|
|
91
|
+
appType: 'Web Client',
|
|
89
92
|
context: {
|
|
90
93
|
app: {version: 'webex-version'},
|
|
91
94
|
device: {id: 'deviceId'},
|
|
@@ -113,8 +116,72 @@ describe('internal-plugin-metrics', () => {
|
|
|
113
116
|
},
|
|
114
117
|
type: ['business'],
|
|
115
118
|
});
|
|
116
|
-
assert.
|
|
119
|
+
assert.isString(requestCalls[0].eventPayload.client_timestamp)
|
|
120
|
+
assert.equal(requestCalls[0].eventPayload.client_timestamp, now.toISOString())
|
|
117
121
|
})
|
|
122
|
+
|
|
123
|
+
describe('when table is provided', () => {
|
|
124
|
+
it('should send correctly shaped business event with table: wbx_app_callend_metrics and ignore the key name', () => {
|
|
125
|
+
// For some reasons `jest` isn't available when testing form build server - so can't use `jest.fn()` here...
|
|
126
|
+
const requestCalls = [];
|
|
127
|
+
const request = function(arg) { requestCalls.push(arg) }
|
|
128
|
+
|
|
129
|
+
businessMetrics.clientMetricsBatcher.request = request;
|
|
130
|
+
|
|
131
|
+
assert.equal(requestCalls.length, 0)
|
|
132
|
+
businessMetrics.submitBusinessEvent({ name: "foobar", payload: {bar:"gee"}, table: 'wbxapp_callend_metrics' })
|
|
133
|
+
assert.equal(requestCalls.length, 1)
|
|
134
|
+
assert.deepEqual(requestCalls[0], {
|
|
135
|
+
eventPayload: {
|
|
136
|
+
key: 'callEnd',
|
|
137
|
+
client_timestamp: requestCalls[0].eventPayload.client_timestamp, // This is to bypass time check, which is checked below.
|
|
138
|
+
appType: 'Web Client',
|
|
139
|
+
value: {
|
|
140
|
+
bar: 'gee'
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
type: ['business'],
|
|
144
|
+
});
|
|
145
|
+
assert.isString(requestCalls[0].eventPayload.client_timestamp)
|
|
146
|
+
assert.equal(requestCalls[0].eventPayload.client_timestamp, now.toISOString())
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should send correctly shaped business event with table: business_metrics', () => {
|
|
150
|
+
// For some reasons `jest` isn't available when testing form build server - so can't use `jest.fn()` here...
|
|
151
|
+
const requestCalls = [];
|
|
152
|
+
const request = function(arg) { requestCalls.push(arg) }
|
|
153
|
+
|
|
154
|
+
businessMetrics.clientMetricsBatcher.request = request;
|
|
155
|
+
|
|
156
|
+
assert.equal(requestCalls.length, 0)
|
|
157
|
+
businessMetrics.submitBusinessEvent({ name: "foobar", payload: {bar:"gee"}, table: 'business_metrics' })
|
|
158
|
+
assert.equal(requestCalls.length, 1)
|
|
159
|
+
assert.deepEqual(requestCalls[0], {
|
|
160
|
+
eventPayload: {
|
|
161
|
+
key: 'foobar',
|
|
162
|
+
appType: 'Web Client',
|
|
163
|
+
client_timestamp: requestCalls[0].eventPayload.client_timestamp, // This is to bypass time check, which is checked below.
|
|
164
|
+
value: {
|
|
165
|
+
bar: "gee",
|
|
166
|
+
browser: getBrowserName(),
|
|
167
|
+
browserHeight: window.innerHeight,
|
|
168
|
+
browserVersion: getBrowserVersion(),
|
|
169
|
+
browserWidth: window.innerWidth,
|
|
170
|
+
domain: window.location.hostname,
|
|
171
|
+
inIframe: false,
|
|
172
|
+
locale: window.navigator.language,
|
|
173
|
+
os: getOSNameInternal(),
|
|
174
|
+
app: {version: 'webex-version'},
|
|
175
|
+
device: {id: 'deviceId'},
|
|
176
|
+
locale: 'language',
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
type: ['business'],
|
|
180
|
+
});
|
|
181
|
+
assert.isString(requestCalls[0].eventPayload.client_timestamp)
|
|
182
|
+
assert.equal(requestCalls[0].eventPayload.client_timestamp, now.toISOString())
|
|
183
|
+
});
|
|
184
|
+
});
|
|
118
185
|
})
|
|
119
186
|
});
|
|
120
187
|
});
|
|
@@ -441,7 +441,7 @@ describe('plugin-metrics', () => {
|
|
|
441
441
|
// item also gets assigned a delay property but the key is a Symbol and haven't been able to test that..
|
|
442
442
|
assert.deepEqual(calls.args[0].eventPayload, {
|
|
443
443
|
event: 'my.event',
|
|
444
|
-
origin: {buildType: 'test', networkType: 'unknown'},
|
|
444
|
+
origin: {buildType: 'test', networkType: 'unknown', upgradeChannel: 'test'},
|
|
445
445
|
});
|
|
446
446
|
|
|
447
447
|
assert.deepEqual(calls.args[0].type, ['diagnostic-event']);
|
|
@@ -455,6 +455,7 @@ describe('plugin-metrics', () => {
|
|
|
455
455
|
origin: {
|
|
456
456
|
buildType: 'test',
|
|
457
457
|
networkType: 'unknown',
|
|
458
|
+
upgradeChannel: 'test',
|
|
458
459
|
},
|
|
459
460
|
});
|
|
460
461
|
assert.deepEqual(prepareDiagnosticMetricItemCalls[0].args[1].type, ['diagnostic-event']);
|
|
@@ -12,12 +12,10 @@ describe('internal-plugin-metrics', () => {
|
|
|
12
12
|
sinon.useFakeTimers(now.getTime());
|
|
13
13
|
const webex = {
|
|
14
14
|
meetings: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
},
|
|
15
|
+
getBasicMeetingInformation: (id: string) => {
|
|
16
|
+
if (id === 'meeting-id') {
|
|
17
|
+
return {id: 'meeting-id', allowMediaInLobby: true};
|
|
18
|
+
}
|
|
21
19
|
},
|
|
22
20
|
},
|
|
23
21
|
};
|