import { dump , load } from 'js-yaml' ; import { kubectlApplyRule } from './traffic-split' ; import { MetricTypes } from '../modes/get-metrics' ; import { Arguments } from '@kui-shell/core' ; import { removeExtraneousMetaData } from './metric-config' ; import { CounterMetrics , RatioMetrics } from './metric-config-types' ; export default function deleteMetric ( configMap , metricName , type , args ) { try { const counterMetrics = load ( configMap . data [ 'counter_metrics.yaml' ] ) as CounterMetrics ; const ratioMetrics = load ( configMap . data [ 'ratio_metrics.yaml' ] ) as RatioMetrics ; const newConfigMap = removeExtraneousMetaData ( configMap ) ; console . log ( `Deleting metric: ${ metricName } Type: ${ type }` ) ; newConfigMap . data [ 'counter_metrics.yaml' ] = dump ( counterMetrics . filter ( counterMetric => counterMetric . name !== metricName ) ) ; newConfigMap . data [ 'ratio_metrics.yaml' ] = dump ( ratioMetrics . filter ( ratioMetric => ratioMetric . name !== metricName ) ) ; kubectlApplyRule ( newConfigMap , args ) ; return true ; } catch ( err ) { return false ; } }