import { MetricConfigMap , CounterMetrics , RatioMetrics } from './metric-config-types' ; import { Arguments } from '@kui-shell/core' ; type MetricConfigData = { configmaps : string ; } | { error : any ; } ; type ErrorData = { error : { message : any [ ] ; response : any ; } ; } ; export const ITER8_METRIC_NAMES = { counter : [ 'iter8_request_count' , 'iter8_total_latency' , 'iter8_error_count' ] , ratio : [ 'iter8_mean_latency' , 'iter8_error_rate' ] } ; export async function getMetricConfig ( args ) { return await args . REPL . qexec ( `kubectl get configmaps -n iter8 iter8config-metrics -o yaml` ) ; } export function removeExtraneousMetaData ( configMap ) { const { name , namespace } = configMap . metadata ; const newConfigMap = { ... configMap } ; newConfigMap . metadata = { name , namespace } ; return newConfigMap ; } export class GetMetricConfig { private output : MetricConfigData ; private cmetrics ; private rmetrics ; public async getmetrics ( args ) { return await args . REPL . qexec < MetricConfigMap > ( `kubectl get configmaps -n iter8 iter8config-metrics -o yaml` ) ; } public async getCounterMetrics ( args ) { const res = ( await args . REPL . qexec < MetricConfigMap > ( `kubectl get configmaps -n iter8 iter8config-metrics -o json` ) ) . data [ 'counter_metrics.yaml' ] ; const { load } = await import ( 'js-yaml' ) ; return load ( res ) as CounterMetrics ; } public async getRatioMetrics ( args ) { const res = ( await args . REPL . qexec < MetricConfigMap > ( `kubectl get configmaps -n iter8 iter8config-metrics -o json` ) ) . data [ 'ratio_metrics.yaml' ] ; const { load } = await import ( 'js-yaml' ) ; return load ( res ) as RatioMetrics ; } }