import { StagePropsInfo } from "./app&qu...

21/11/2021  •  37 views
import { StagePropsInfo } from "./app";

import { metaData, MetricTypes, MetricValues, Region, ServiceTypes, Stages, statType, WidgetProperties as CommonWidgetProperties} from "./metricsutil";

export enum widgetTitle {
RUNORCHESTRATIONACTIVITY_SUCCESS = 'AWS.ABS.RunOrchestrationActivity.success',
RUNORCHESTRATIONACTIVITY_FAILURE = 'ABAS-AWS.ABS.RunOrchestrationActivity.failure',
RUNORCHESTRATIONACTIVITY_SUCCESS_FAILURE = 'ABAS-AWS.ABS.GetOrchestrationStatusActivity.failure, AWS.ABS.GetOrchestrationStatusActivity.success',
ORW_HEAPMEMORYAFTERGCUSE = 'HeapMemoryAfterGCUse',
GETORCHESTRATIONACTIVITY_FAILURE = 'ABAS-AWS.ABS.GetOrchestrationStatusActivity.failure',
GETORCHESTRATIONSTATUSACTIVITY_SUCCESS = 'AWS.ABS.GetOrchestrationStatusActivity.success'
};

export interface WidgetConfig {
readonly width?: number;
readonly height?: number;
readonly type?: string;
readonly properties?: WidgetProperties;
}

export type WidgetProperties = CommonWidgetProperties & metricType

export interface metricType {
metrics: (string | metricAccount)[][];
}
export interface metricAccount {
accountId: string;
id: string;
}

export function createTopLevelWidgets(stageProps: StagePropsInfo): WidgetConfig[] {
let widgets: WidgetConfig[] = []

widgets.push(
{
height: metaData.height,
width: metaData.width,
type: metaData.type,
properties: {
metrics: getMetrics(stageProps, widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS_FAILURE, true),
yAxis: {
left: {
label: metaData.label,
max: metaData.max,
min: metaData.min,
showUnits: metaData.showUnits
}
},
stat: statType.P99,
title: widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS_FAILURE,
period: metaData.period,
region: stageProps.region,
stacked: metaData.stacked,
view: metaData.view
}
})

widgets.push(
{
height: metaData.height,
width: metaData.width,
type: metaData.type,
properties: {
metrics: getMetrics(stageProps, widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS_FAILURE, false),
yAxis: {
left: {
label: metaData.label,
max: metaData.max,
min: metaData.min,
showUnits: metaData.showUnits
}
},
stat: statType.P99,
title: widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS_FAILURE,
period: metaData.period,
region: stageProps.region,
stacked: metaData.stacked,
view: metaData.view
}
})

widgets.push(
{
height: metaData.height,
width: metaData.width,
type: metaData.type,
properties: {
metrics: getMetrics(stageProps, widgetTitle.RUNORCHESTRATIONACTIVITY_FAILURE),
yAxis: {
left: {
label: metaData.label,
max: metaData.max,
min: metaData.min,
showUnits: metaData.showUnits
}
},
stat: statType.P99,
title: widgetTitle.RUNORCHESTRATIONACTIVITY_FAILURE,
period: metaData.period,
region: stageProps.region,
stacked: metaData.stacked,
view: metaData.view
}
})

widgets.push(
{
height: metaData.height,
width: metaData.width,
type: metaData.type,
properties: {
metrics: getMetrics(stageProps, widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS),
yAxis: {
left: {
label: metaData.label,
max: metaData.max,
min: metaData.min,
showUnits: metaData.showUnits
}
},
stat: statType.P99,
title: widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS,
period: metaData.period,
region: stageProps.region,
stacked: metaData.stacked,
view: metaData.view
}
})

if (stageProps.stage.toLocaleLowerCase() === 'prod') {
widgets.push(
{
height: metaData.height,
width: metaData.width,
type: metaData.type,
properties: {
metrics: getMetrics(stageProps, widgetTitle.ORW_HEAPMEMORYAFTERGCUSE),
yAxis: {
left: {
label: metaData.label,
max: metaData.max,
min: metaData.min,
showUnits: metaData.showUnits
}
},
stat: statType.P99,
title: `ORW-${widgetTitle.ORW_HEAPMEMORYAFTERGCUSE}`,
period: metaData.period,
region: stageProps.region,
stacked: metaData.stacked,
view: metaData.view
}
})
}

return widgets

}

function getMetrics(stageProps: StagePropsInfo, title: string, isFailure?: boolean): (string | metricAccount)[][] {
let metricsArray: (string | metricAccount)[][] = []
let metrics: (string | metricAccount)[] = []

let widgetMetrics: (string | metricAccount)[] = []
widgetMetrics.push(MetricTypes.HOST_GROUP, MetricValues.ALL)
widgetMetrics.push(MetricTypes.HOST, MetricValues.ALL)
widgetMetrics.push(MetricTypes.METHOD_NAME, MetricValues.ALL)
widgetMetrics.push(MetricTypes.CLIENT, MetricValues.ALL)
widgetMetrics.push(MetricTypes.METRIC_CLASS, MetricValues.NONE)
widgetMetrics.push(MetricTypes.INSTANCE, MetricValues.NONE)
widgetMetrics.push({ "accountId": "igraph", "id": "m1" })


switch (title) {
case widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS_FAILURE:
if (isFailure) metrics.push(MetricTypes.SERVICE, widgetTitle.RUNORCHESTRATIONACTIVITY_FAILURE)
else metrics.push(MetricTypes.SERVICE, widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS)
metrics.push(MetricTypes.DATASET, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `Test:${Stages.GAMMA}` : Stages.PROD)
metrics.push(MetricTypes.MARKET_PLACE, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE}:master:${Region.US_AMAZON}`
: `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE}:prod:${Region.US_AMAZON}`)
metrics.push(MetricTypes.SERVICE_NAME, ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE)
metrics.push(...widgetMetrics)
metricsArray.push(metrics)
if (isFailure) metricsArray.push([".", widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS, ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", { "accountId": "igraph", "id": "m2" }])
else metricsArray.push([".", widgetTitle.RUNORCHESTRATIONACTIVITY_FAILURE, ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", { "accountId": "igraph", "id": "m2" }])
break;
case widgetTitle.RUNORCHESTRATIONACTIVITY_FAILURE:
metrics.push(MetricTypes.SERVICE, widgetTitle.RUNORCHESTRATIONACTIVITY_FAILURE)
metrics.push(MetricTypes.DATASET, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `Test:${Stages.GAMMA}` : Stages.PROD)
metrics.push(MetricTypes.MARKET_PLACE, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE}:master:${Region.US_AMAZON}`
: `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE}:prod:${Region.US_AMAZON}`)
metrics.push(MetricTypes.SERVICE_NAME, ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE)
metrics.push(...widgetMetrics)
metricsArray.push(metrics)
metricsArray.push(["...", "retryFailedOrchestration", ".", ".", ".", ".", ".", ".", { "accountId": "igraph", "id": "m2" }])
break;
case widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS:
metrics.push(MetricTypes.SERVICE, widgetTitle.RUNORCHESTRATIONACTIVITY_SUCCESS)
metrics.push(MetricTypes.DATASET, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `Test:${Stages.GAMMA}` : Stages.PROD)
metrics.push(MetricTypes.MARKET_PLACE, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE}:master:${Region.US_AMAZON}`
: `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE}:prod:${Region.US_AMAZON}`)
metrics.push(MetricTypes.SERVICE_NAME, ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE)
metrics.push(...widgetMetrics)
metricsArray.push(metrics)
metricsArray.push(["...", "retryFailedOrchestration", ".", ".", ".", ".", ".", ".", { "accountId": "igraph", "id": "m2" }])
break;
case widgetTitle.ORW_HEAPMEMORYAFTERGCUSE:
metrics.push(MetricTypes.SERVICE, widgetTitle.ORW_HEAPMEMORYAFTERGCUSE)
metrics.push(MetricTypes.DATASET, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `Test:${Stages.GAMMA}` : Stages.PROD)
metrics.push(MetricTypes.MARKET_PLACE, stageProps.stage.toLocaleLowerCase() == 'gamma' ? `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE_ORCHESTRATION_RUNNER_WORKER}:master:${Region.US_AMAZON}`
: `${ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE_ORCHESTRATION_RUNNER_WORKER}:prod:${Region.US_AMAZON}`)
metrics.push(MetricTypes.SERVICE_NAME, ServiceTypes.AWS_ANNIVERSARY_BILLING_SERVICE_ORCHESTRATION_RUNNER_WORKER)
metrics.push(...widgetMetrics)
metricsArray.push(metrics)
break;
default:
break;
}


return metricsArray

}


const generalWidgetDefaults = {someKey : 'someValue'}

const jmxTitleWithValue = {
'CpuUsage' : 'cpuUsage',
'ActiveHeapUsage' : 'usrHeapActive',
'GarbageCollectionCount' : 'fullGcCount'
}


/*const jmxRegionalVariations = {
StagePropsInfo.GAMMA : {dataSet: 'Test:Gamma', marketplace: 'ABAS:gamma:USAmazon'},
StagePropsInfo.PROD : {dataSet: 'Prod', marketplace: 'ABAS:prod:USAmazon'},
StagePropsInfo.PRODZHY : {dataSet: 'ProdZHY', marketplace: 'ABAS:prodzhy:CNAmazon'}
}*/

const jmxDefaultFields = {
stat: 'Average',
view: 'timeSeries',
yAxis: {left: {
label: metaData.label,
max: metaData.max,
min: metaData.min,
showUnits: metaData.showUnits
}},
...generalWidgetDefaults
}

function createJmxWidgets(stageProps: StagePropsInfo) {
// let widgets: Widget[] = []
let metricsArray: (string | metricAccount)[][] = []

metricsArray.forEach(metricTitle => {
const widget = {
title: metricTitle,
...jmxDefaultFields,
// ...jmxRegionalVariations[stageProps.stage]
}
metricsArray .push(widget)
}
)
return metricsArray
}
https://paste.ac/DzrCsMx