TP-5555 | metrics integration
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "lerna run build"
|
"build": "lerna run build",
|
||||||
|
"local-publish" : "lerna publish --no-git-tag-version"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^9.13.0",
|
"eslint": "^9.13.0",
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import {
|
|||||||
sipRegister, sipUnmuteCall
|
sipRegister, sipUnmuteCall
|
||||||
} from "./assets/js/sip5ml.service.ts";
|
} from "./assets/js/sip5ml.service.ts";
|
||||||
import registerEventProcessor from "./eventsProcessor.ts";
|
import registerEventProcessor from "./eventsProcessor.ts";
|
||||||
|
import MetricsProcessor from "@universal-call-sdk/common/lib/utils/metricsProcessor.ts";
|
||||||
|
|
||||||
class AmeyoAdapter implements IAdapter {
|
class AmeyoAdapter implements IAdapter {
|
||||||
private callbacks: {
|
private callbacks: {
|
||||||
@@ -53,6 +54,11 @@ class AmeyoAdapter implements IAdapter {
|
|||||||
private currentCallMetadata: GenericObject;
|
private currentCallMetadata: GenericObject;
|
||||||
private sipAccountInfo: GenericObject;
|
private sipAccountInfo: GenericObject;
|
||||||
private isAgentAvailable: boolean;
|
private isAgentAvailable: boolean;
|
||||||
|
private isMetricsEnabled : boolean
|
||||||
|
private metricFlowName: string
|
||||||
|
private metricMetadata: GenericObject
|
||||||
|
private metricProcessor: any
|
||||||
|
private metricUrl: string
|
||||||
|
|
||||||
constructor(options: AmeyoInitializationOptions) {
|
constructor(options: AmeyoInitializationOptions) {
|
||||||
console.log('AmeyoAdapter constructor');
|
console.log('AmeyoAdapter constructor');
|
||||||
@@ -94,6 +100,10 @@ class AmeyoAdapter implements IAdapter {
|
|||||||
this.sipAccountInfo = {};
|
this.sipAccountInfo = {};
|
||||||
this.currentCallMetadata = {};
|
this.currentCallMetadata = {};
|
||||||
this.isAgentAvailable = false;
|
this.isAgentAvailable = false;
|
||||||
|
this.isMetricsEnabled = options?.isMetricEnabled || false;
|
||||||
|
this.metricFlowName = options?.metricFlowName || '';
|
||||||
|
this.metricMetadata = options?.metricMetadata || {}
|
||||||
|
this.metricUrl = options?.metricUrl || ''
|
||||||
window.BASE_AMEYO_URL = this.baseUrl;
|
window.BASE_AMEYO_URL = this.baseUrl;
|
||||||
window.AMEYO_LOGIN_URL = options.loginUrl
|
window.AMEYO_LOGIN_URL = options.loginUrl
|
||||||
|
|
||||||
@@ -103,7 +113,11 @@ class AmeyoAdapter implements IAdapter {
|
|||||||
console.log('initializing ameyo adapter');
|
console.log('initializing ameyo adapter');
|
||||||
window.addEventListener('message', this._registerMessageListener);
|
window.addEventListener('message', this._registerMessageListener);
|
||||||
this._initializeAmeyo();
|
this._initializeAmeyo();
|
||||||
|
if(this.isMetricsEnabled) {
|
||||||
|
this.metricProcessor = new MetricsProcessor(this.metricUrl, this.metricFlowName);
|
||||||
|
|
||||||
|
}
|
||||||
|
this.metricProcessor.pushCounterMetric({metricName: 'initSdk', flow: "", metaData: this.metricMetadata})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,15 +129,25 @@ class AmeyoAdapter implements IAdapter {
|
|||||||
loadCredentials({accountName, userName, domain, password});
|
loadCredentials({accountName, userName, domain, password});
|
||||||
loadCallOptions();
|
loadCallOptions();
|
||||||
sipRegister({domain: domainOnly, port});
|
sipRegister({domain: domainOnly, port});
|
||||||
|
this.metricProcessor.pushCounterMetric({metricName: 'sipStackInitialised',flow: 'ameyo-adapter', metaData: this.metricMetadata})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_initializeAmeyo = () => {
|
_initializeAmeyo = () => {
|
||||||
loginInAmeyo(this.userName?.toLowerCase(), this.password);
|
loginInAmeyo(this.userName?.toLowerCase(), this.password);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onListenForCorsBypassResponse = (payload: GenericObject) => {
|
_onListenForCorsBypassResponse = (payload: GenericObject) => {
|
||||||
console.log('universal sdk', payload);
|
console.log('universal sdk', payload);
|
||||||
|
this.metricProcessor.pushCounterMetric({metricName: `ameyo-api-call-count`, metaData: this.metricMetadata, flow: payload?.data?.requestKey})
|
||||||
|
this.metricProcessor.pushHistogramMetric({metricName: `ameyo-api-latency-${payload?.data?.requestKey}`, metaData: this.metricMetadata, flow:'api-latency', value: payload?.data?.time} )
|
||||||
|
|
||||||
|
if(payload?.data?.err) {
|
||||||
|
this.metricProcessor.pushCounterMetric({metricName: `ameyo-api-err`, metaData: this.metricMetadata, flow: payload?.data?.requestKey})
|
||||||
|
}
|
||||||
|
|
||||||
if (payload?.data?.requestKey === RequestKeys.AMEYO_LOGIN) {
|
if (payload?.data?.requestKey === RequestKeys.AMEYO_LOGIN) {
|
||||||
if(payload?.data?.err) {
|
if(payload?.data?.err) {
|
||||||
console.log('on login failed', payload?.data?.err);
|
console.log('on login failed', payload?.data?.err);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
export type GenericObject = {
|
export type GenericObject = {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
@@ -33,8 +32,12 @@ export type AmeyoInitializationOptions = {
|
|||||||
userName: string,
|
userName: string,
|
||||||
password: string,
|
password: string,
|
||||||
eventListenerUrl: string,
|
eventListenerUrl: string,
|
||||||
baseUrl: string
|
baseUrl: string,
|
||||||
loginUrl: string
|
loginUrl: string,
|
||||||
|
isMetricEnabled ?:boolean,
|
||||||
|
metricFlowName ?:string,
|
||||||
|
metricMetadata ?:GenericObject,
|
||||||
|
metricUrl ?:string
|
||||||
}
|
}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
45
packages/common/lib/types/MetricPayload.ts
Normal file
45
packages/common/lib/types/MetricPayload.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import GenericObject from "./GenericObject.ts";
|
||||||
|
|
||||||
|
export enum MetricType {
|
||||||
|
COUNTER = 'COUNTER',
|
||||||
|
GAUGE = 'GAUGE',
|
||||||
|
HISTOGRAM = 'HISTOGRAM'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type MetricPayload = {
|
||||||
|
metricName: string;
|
||||||
|
metricType: MetricType;
|
||||||
|
value: number | string;
|
||||||
|
group: string;
|
||||||
|
subFlow?: string;
|
||||||
|
metaData?: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CounterMetricPayload = {
|
||||||
|
metricName: string;
|
||||||
|
metaData?: Record<string, any>;
|
||||||
|
flow: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export type HistogramMetricPayload = {
|
||||||
|
metricName: string;
|
||||||
|
value: number | string;
|
||||||
|
subFlow?: string;
|
||||||
|
metaData?: Record<string, any>;
|
||||||
|
flow: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GaugeMetricPayload = {
|
||||||
|
metricName: string;
|
||||||
|
value: number | string;
|
||||||
|
subFlow?: string;
|
||||||
|
metaData?: Record<string, any>;
|
||||||
|
flow: string;
|
||||||
|
metadata: GenericObject
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default MetricPayload;
|
||||||
62
packages/common/lib/utils/metricsProcessor.ts
Normal file
62
packages/common/lib/utils/metricsProcessor.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import {CounterMetricPayload, GaugeMetricPayload, HistogramMetricPayload, MetricType} from "../types/MetricPayload.ts";
|
||||||
|
import GenericObject from "../types/GenericObject.ts";
|
||||||
|
|
||||||
|
class MetricsProcessor {
|
||||||
|
private metricUrl : string
|
||||||
|
private portal : string
|
||||||
|
private isMetricEnabled : boolean
|
||||||
|
|
||||||
|
constructor(metricUrl: string, portal: string) {
|
||||||
|
this.metricUrl = metricUrl;
|
||||||
|
this.portal = portal;
|
||||||
|
this.isMetricEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
_sendMetricToMetricServer(payload: {
|
||||||
|
metricType: MetricType;
|
||||||
|
metadata: any;
|
||||||
|
metricName: string;
|
||||||
|
subflow?: any;
|
||||||
|
value?: number | string
|
||||||
|
flow?: string
|
||||||
|
Metadata?:GenericObject
|
||||||
|
}) {
|
||||||
|
if(!this.isMetricEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fetch(this.metricUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({group: `universal-call-sdk-${this.portal}`,...payload})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pushCounterMetric({metricName, flow, metaData}: CounterMetricPayload ) {
|
||||||
|
this._sendMetricToMetricServer({
|
||||||
|
flow: flow,
|
||||||
|
metadata: metaData,
|
||||||
|
metricType: MetricType.COUNTER,
|
||||||
|
metricName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pushHistogramMetric({metricName, value, flow, metaData}: HistogramMetricPayload) {
|
||||||
|
this._sendMetricToMetricServer({
|
||||||
|
flow: flow,
|
||||||
|
metadata: metaData,
|
||||||
|
metricType: MetricType.HISTOGRAM,
|
||||||
|
metricName,
|
||||||
|
value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pushGaugeMetric({metricName, value, flow, metaData}: GaugeMetricPayload) {
|
||||||
|
this._sendMetricToMetricServer({
|
||||||
|
flow: flow,
|
||||||
|
metadata: metaData,
|
||||||
|
metricType: MetricType.GAUGE,
|
||||||
|
metricName,
|
||||||
|
value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MetricsProcessor;
|
||||||
Reference in New Issue
Block a user