Skip to content

Commit

Permalink
feat(internal-plugin-metrics): add business_metrics_wxcc_desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
lialang-cisco committed Nov 20, 2024
1 parent d5445fe commit ea3c708
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
28 changes: 28 additions & 0 deletions packages/@webex/internal-plugin-metrics/src/business-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,32 @@ export default class BusinessMetrics extends GenericMetrics {
return this.submitEvent({kind: 'buisness-events:business_metrics -> ', name, event});
}

/**
* Submit a buisness metric to our metrics endpoint, going to the business_metrics_wxcc_desktop table
* all event payload keys are converted into a hex string value
* @param {string} name of the metric
* @param {EventPayload} payload payload of the metric
* @returns {Promise<any>}
*/
private submitWxccDesktopEvent({name, payload}: {name: string; payload: EventPayload}) {
const event = {
type: ['business'],
eventPayload: {
key: name,
client_timestamp: new Date().toISOString(),
appType: 'WxCC Desktop',
indexHint: 'wxccdesktop',
value: {
...this.getContext(),
...this.getBrowserDetails(),
...payload,
},
},
};

return this.submitEvent({kind: 'buisness-events:business_metrics -> ', name, event});
}

/**
* Submit a buisness metric to our metrics endpoint, going to the default business_ucf table
* all event payload keys are converted into a hex string value
Expand Down Expand Up @@ -112,6 +138,8 @@ export default class BusinessMetrics extends GenericMetrics {
return this.submitCallEndEvent({payload});
case 'business_metrics':
return this.submitBusinessMetricsEvent({name, payload});
case 'business_metrics_wxcc_desktop':
return this.submitWxccDesktopEvent({name, payload});
case 'business_ucf':
return this.submitDefaultEvent({name, payload});
case 'default':
Expand Down
7 changes: 6 additions & 1 deletion packages/@webex/internal-plugin-metrics/src/metrics.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ export interface DeviceContext {

export type MetricType = 'behavioral' | 'operational' | 'business';

export type Table = 'wbxapp_callend_metrics' | 'business_metrics' | 'business_ucf' | 'default';
export type Table =
| 'wbxapp_callend_metrics'
| 'business_metrics'
| 'business_ucf'
| 'business_metrics_wxcc_desktop'
| 'default';

type InternalEventPayload = string | number | boolean;
export type EventPayload = Record<string, InternalEventPayload>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,42 @@ describe('internal-plugin-metrics', () => {
assert.isString(requestCalls[0].eventPayload.client_timestamp)
assert.equal(requestCalls[0].eventPayload.client_timestamp, now.toISOString())
});

it('should send correctly shaped business event with table: business_metrics_wxcc_desktop', () => {
const requestCalls = [];
const request = function(arg) { requestCalls.push(arg) }

businessMetrics.clientMetricsBatcher.request = request;

assert.equal(requestCalls.length, 0)
businessMetrics.submitBusinessEvent({ name: "foobar", payload: {bar:"gee"}, table: 'business_metrics_wxcc_desktop' })
assert.equal(requestCalls.length, 1)
assert.deepEqual(requestCalls[0], {
eventPayload: {
key: 'foobar',
appType: 'WxCC Desktop',
indexHint: 'wxccdesktop',
client_timestamp: requestCalls[0].eventPayload.client_timestamp, // This is to bypass time check, which is checked below.
value: {
bar: "gee",
browser: getBrowserName(),
browserHeight: window.innerHeight,
browserVersion: getBrowserVersion(),
browserWidth: window.innerWidth,
domain: window.location.hostname,
inIframe: false,
locale: window.navigator.language,
os: getOSNameInternal(),
app: {version: 'webex-version'},
device: {id: 'deviceId'},
locale: 'language',
}
},
type: ['business'],
});
assert.isString(requestCalls[0].eventPayload.client_timestamp)
assert.equal(requestCalls[0].eventPayload.client_timestamp, now.toISOString())
});
});
})
});
Expand Down

0 comments on commit ea3c708

Please sign in to comment.