import { i18n } from '@osd/i18n' ; import { Assign } from '@osd/utility-types' ; import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common' ; import { AggExpressionType , AggExpressionFunctionArgs , METRIC_TYPES } from '../' ; import { getParsedValue } from '../utils/get_parsed_value' ; const fnName = 'aggMovingAvg' ; type Input = any ; type AggArgs = AggExpressionFunctionArgs < typeof METRIC_TYPES . MOVING_FN > ; type Arguments = Assign < AggArgs , { customMetric ? : AggExpressionType ; } > ; type Output = AggExpressionType ; type FunctionDefinition = ExpressionFunctionDefinition < typeof fnName , Input , Arguments , Output > ; export const aggMovingAvg = ( ) : FunctionDefinition => ( { name : fnName , help : i18n . translate ( 'data.search.aggs.function.metrics.moving_avg.help' , { defaultMessage : 'Generates a serialized agg config for a Moving Average agg' , } ) , type : 'agg_type' , args : { id : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.id.help' , { defaultMessage : 'ID for this aggregation' , } ) , } , enabled : { types : [ 'boolean' ] , default : true , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.enabled.help' , { defaultMessage : 'Specifies whether this aggregation should be enabled' , } ) , } , schema : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.schema.help' , { defaultMessage : 'Schema to use for this aggregation' , } ) , } , metricAgg : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.metricAgg.help' , { defaultMessage : 'Id for finding agg config to use for building parent pipeline aggregations' , } ) , } , customMetric : { types : [ 'agg_type' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.customMetric.help' , { defaultMessage : 'Agg config to use for building parent pipeline aggregations' , } ) , } , window : { types : [ 'number' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.window.help' , { defaultMessage : 'The size of window to "slide" across the histogram.' , } ) , } , buckets_path : { types : [ 'string' ] , required : true , help : i18n . translate ( 'data.search.aggs.metrics.derivative.buckets_path.help' , { defaultMessage : 'Path to the metric of interest' , } ) , } , script : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.script.help' , { defaultMessage : 'Id for finding agg config to use for building parent pipeline aggregations' , } ) , } , json : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.json.help' , { defaultMessage : 'Advanced json to include when the agg is sent to OpenSearch' , } ) , } , customLabel : { types : [ 'string' ] , help : i18n . translate ( 'data.search.aggs.metrics.moving_avg.customLabel.help' , { defaultMessage : 'Represents a custom label for this aggregation' , } ) , } , } , fn : ( input , args ) => { const { id , enabled , schema , ... rest } = args ; return { type : 'agg_type' , value : { id , enabled , schema , type : METRIC_TYPES . MOVING_FN , params : { ... rest , customMetric : args . customMetric ?. value , json : getParsedValue ( args , 'json' ) , } , } , } ; } , } ) ;