Skip to content

Commit 7a919a2

Browse files
committed
feat(internal-plugin-metrics): add business_metrics_wxcc_desktop
1 parent d5445fe commit 7a919a2

File tree

4 files changed

+71
-77
lines changed

4 files changed

+71
-77
lines changed

packages/@webex/internal-plugin-metrics/src/business-metrics.ts

+64-74
Original file line numberDiff line numberDiff line change
@@ -8,82 +8,22 @@ import {EventPayload, Table} from './metrics.types';
88
*/
99
export default class BusinessMetrics extends GenericMetrics {
1010
/**
11-
* unfortunately, the pinot team does not allow changes to the schema of wbxapp_callend_metrics
12-
* so we have to shim this layer specifically for this
13-
* https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table+wbxapp_callend_metrics
14-
* @param {EventPayload} payload payload of the metric
15-
* @returns {Promise<any>}
16-
*/
17-
private submitCallEndEvent({payload}: {payload: EventPayload}) {
18-
const event = {
19-
type: ['business'],
20-
eventPayload: {
21-
key: 'callEnd',
22-
client_timestamp: new Date().toISOString(),
23-
appType: 'Web Client',
24-
value: {
25-
...payload,
26-
},
27-
},
28-
};
29-
30-
return this.submitEvent({
31-
kind: 'buisness-events:wbxapp_callend_metrics -> ',
32-
name: 'wbxapp_callend_metrics',
33-
event,
34-
});
35-
}
36-
37-
/**
38-
* Submit a buisness metric to our metrics endpoint, going to the default business_ucf table
39-
* all event payload keys are converted into a hex string value
40-
* unfortunately, the pinot team does not allow changes to the schema of business_metrics
41-
* so we have to shim this layer specifically for this
42-
* https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table%3A+business_metrics
11+
* Build the metric event to submit.
4312
* @param {string} name of the metric
44-
* @param {EventPayload} payload payload of the metric
45-
* @returns {Promise<any>}
46-
*/
47-
private submitBusinessMetricsEvent({name, payload}: {name: string; payload: EventPayload}) {
48-
const event = {
49-
type: ['business'],
50-
eventPayload: {
51-
key: name,
52-
client_timestamp: new Date().toISOString(),
53-
appType: 'Web Client',
54-
value: {
55-
...this.getContext(),
56-
...this.getBrowserDetails(),
57-
...payload,
58-
},
59-
},
60-
};
61-
62-
return this.submitEvent({kind: 'buisness-events:business_metrics -> ', name, event});
63-
}
64-
65-
/**
66-
* Submit a buisness metric to our metrics endpoint, going to the default business_ucf table
67-
* all event payload keys are converted into a hex string value
68-
* https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Business+metrics++-%3E+ROMA
69-
* @param {string} name of the metric
70-
* @param {EventPayload} user payload of the metric
71-
* @returns {Promise<any>}
13+
* @param {EventPayload} payload user payload of the metric
14+
* @param {EventPayload} metadata to include outside of eventPayload.value
15+
* @returns {object}
7216
*/
73-
private submitDefaultEvent({name, payload}: {name: string; payload: EventPayload}) {
74-
const event = {
17+
private buildEvent({name, payload, metadata}: {name: string; payload: object; metadata: object}) {
18+
return {
7519
type: ['business'],
7620
eventPayload: {
7721
key: name,
78-
appType: 'Web Client',
7922
client_timestamp: new Date().toISOString(),
80-
context: this.getContext(),
81-
browserDetails: this.getBrowserDetails(),
23+
...metadata,
8224
value: payload,
8325
},
8426
};
85-
86-
return this.submitEvent({kind: 'buisness-events:default -> ', name, event});
8727
}
8828

8929
/**
@@ -93,30 +33,80 @@ export default class BusinessMetrics extends GenericMetrics {
9333
* @param {string} name of the metric, ignored if going to wbxapp_callend_metrics
9434
* @param {EventPayload} payload user payload of the metric
9535
* @param {Table} table optional - to submit the metric to and adapt the sent schema
36+
* @param {EventPayload} metadata optional - to include outside of eventPayload.value
9637
* @returns {Promise<any>}
9738
*/
9839
public submitBusinessEvent({
9940
name,
10041
payload,
10142
table,
43+
metadata,
10244
}: {
10345
name: string;
10446
payload: EventPayload;
10547
table?: Table;
48+
metadata?: EventPayload;
10649
}): Promise<void> {
10750
if (!table) {
10851
table = 'default';
10952
}
53+
if (!metadata) {
54+
metadata = {};
55+
}
56+
if (!metadata.appType) {
57+
metadata.appType = 'Web Client';
58+
}
11059
switch (table) {
111-
case 'wbxapp_callend_metrics':
112-
return this.submitCallEndEvent({payload});
113-
case 'business_metrics':
114-
return this.submitBusinessMetricsEvent({name, payload});
60+
case 'wbxapp_callend_metrics': {
61+
// https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table+wbxapp_callend_metrics
62+
const callEndEvent = this.buildEvent({name: 'callEnd', payload, metadata});
63+
64+
return this.submitEvent({
65+
kind: 'buisness-events:wbxapp_callend_metrics -> ',
66+
name: 'wbxapp_callend_metrics',
67+
event: callEndEvent,
68+
});
69+
}
70+
71+
case 'business_metrics': {
72+
// all event payload keys are converted into a hex string value
73+
// unfortunately, the pinot team does not allow changes to the schema of business_metrics
74+
// so we have to shim this layer specifically for this
75+
// https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Table%3A+business_metrics
76+
const businessEvent = this.buildEvent({
77+
name,
78+
payload: {
79+
...this.getContext(),
80+
...this.getBrowserDetails(),
81+
...payload,
82+
},
83+
metadata,
84+
});
85+
86+
return this.submitEvent({
87+
kind: 'buisness-events:business_metrics -> ',
88+
name,
89+
event: businessEvent,
90+
});
91+
}
92+
11593
case 'business_ucf':
116-
return this.submitDefaultEvent({name, payload});
11794
case 'default':
118-
default:
119-
return this.submitDefaultEvent({name, payload});
95+
default: {
96+
// all event payload keys are converted into a hex string value
97+
// https://confluence-eng-gpk2.cisco.com/conf/display/WAP/Business+metrics++-%3E+ROMA
98+
const defaultEvent = this.buildEvent({
99+
name,
100+
payload,
101+
metadata: {
102+
context: this.getContext(),
103+
browserDetails: this.getBrowserDetails(),
104+
...metadata,
105+
},
106+
});
107+
108+
return this.submitEvent({kind: 'buisness-events:default -> ', name, event: defaultEvent});
109+
}
120110
}
121111
}
122112
}

packages/@webex/internal-plugin-metrics/src/new-metrics.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ class Metrics extends WebexPlugin {
207207
name,
208208
payload,
209209
table,
210+
metadata,
210211
}: {
211212
name: string;
212213
payload: EventPayload;
213214
table?: Table;
215+
metadata?: EventPayload;
214216
}) {
215217
if (!this.isReady) {
216218
// @ts-ignore
@@ -223,7 +225,7 @@ class Metrics extends WebexPlugin {
223225

224226
this.lazyBuildBusinessMetrics();
225227

226-
return this.businessMetrics.submitBusinessEvent({name, payload, table});
228+
return this.businessMetrics.submitBusinessEvent({name, payload, table, metadata});
227229
}
228230

229231
/**

packages/@webex/internal-plugin-metrics/test/unit/spec/business/business-metrics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ describe('internal-plugin-metrics', () => {
154154
businessMetrics.clientMetricsBatcher.request = request;
155155

156156
assert.equal(requestCalls.length, 0)
157-
businessMetrics.submitBusinessEvent({ name: "foobar", payload: {bar:"gee"}, table: 'business_metrics' })
157+
businessMetrics.submitBusinessEvent({ name: "foobar", payload: {bar: "gee"}, table: 'business_metrics', metadata: {asdf: 'hjkl'} })
158158
assert.equal(requestCalls.length, 1)
159159
assert.deepEqual(requestCalls[0], {
160160
eventPayload: {
161161
key: 'foobar',
162+
asdf: 'hjkl',
162163
appType: 'Web Client',
163164
client_timestamp: requestCalls[0].eventPayload.client_timestamp, // This is to bypass time check, which is checked below.
164165
value: {
@@ -173,7 +174,6 @@ describe('internal-plugin-metrics', () => {
173174
os: getOSNameInternal(),
174175
app: {version: 'webex-version'},
175176
device: {id: 'deviceId'},
176-
locale: 'language',
177177
}
178178
},
179179
type: ['business'],

packages/@webex/internal-plugin-metrics/test/unit/spec/new-metrics.ts

+2
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ describe('internal-plugin-metrics', () => {
9393
name: 'foobar',
9494
payload: {},
9595
table: 'test',
96+
metadata: { foo: 'bar' },
9697
});
9798

9899
assert.calledWith(webex.internal.newMetrics.businessMetrics.submitBusinessEvent, {
99100
name: 'foobar',
100101
payload: {},
101102
table: 'test',
103+
metadata: { foo: 'bar' },
102104
});
103105
});
104106

0 commit comments

Comments
 (0)