import { LatencyAggregationType } from '../../../../common/latency_aggregation_types' ; export function getLatencyAggregation ( latencyAggregationType , field ) { return { latency : { ... ( latencyAggregationType === LatencyAggregationType . avg ? { avg : { field } } : { percentiles : { field , percents : [ latencyAggregationType === LatencyAggregationType . p95 ? 95 : 99 , ] , } , } ) , } , } ; } export function getLatencyValue ( { latencyAggregationType , aggregation , } ) { if ( 'value' in aggregation ) { return aggregation . value ; } if ( 'values' in aggregation ) { if ( latencyAggregationType === LatencyAggregationType . p95 ) { return aggregation . values [ '95.0' ] ; } if ( latencyAggregationType === LatencyAggregationType . p99 ) { return aggregation . values [ '99.0' ] ; } } return null ; }