2023-02-03 11:04:12 -06:00
|
|
|
import { metricAggregationConfig, pipelineOptions } from './components/QueryEditor/MetricAggregationsEditor/utils';
|
2020-12-04 08:29:40 -06:00
|
|
|
import {
|
2023-02-03 11:04:12 -06:00
|
|
|
ElasticsearchQuery,
|
2020-12-04 08:29:40 -06:00
|
|
|
ExtendedStat,
|
|
|
|
MetricAggregation,
|
|
|
|
MovingAverageModelOption,
|
|
|
|
MetricAggregationType,
|
2023-02-03 11:04:12 -06:00
|
|
|
DateHistogram,
|
|
|
|
} from './types';
|
2017-09-28 05:52:39 -05:00
|
|
|
|
2020-12-04 08:29:40 -06:00
|
|
|
export const extendedStats: ExtendedStat[] = [
|
|
|
|
{ label: 'Avg', value: 'avg' },
|
|
|
|
{ label: 'Min', value: 'min' },
|
|
|
|
{ label: 'Max', value: 'max' },
|
|
|
|
{ label: 'Sum', value: 'sum' },
|
|
|
|
{ label: 'Count', value: 'count' },
|
|
|
|
{ label: 'Std Dev', value: 'std_deviation' },
|
|
|
|
{ label: 'Std Dev Upper', value: 'std_deviation_bounds_upper' },
|
|
|
|
{ label: 'Std Dev Lower', value: 'std_deviation_bounds_lower' },
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
2020-12-04 08:29:40 -06:00
|
|
|
export const movingAvgModelOptions: MovingAverageModelOption[] = [
|
|
|
|
{ label: 'Simple', value: 'simple' },
|
|
|
|
{ label: 'Linear', value: 'linear' },
|
|
|
|
{ label: 'Exponentially Weighted', value: 'ewma' },
|
|
|
|
{ label: 'Holt Linear', value: 'holt' },
|
|
|
|
{ label: 'Holt Winters', value: 'holt_winters' },
|
2017-09-28 05:52:39 -05:00
|
|
|
];
|
|
|
|
|
2021-02-24 10:31:17 -06:00
|
|
|
export const highlightTags = {
|
|
|
|
pre: '@HIGHLIGHT@',
|
|
|
|
post: '@/HIGHLIGHT@',
|
|
|
|
};
|
|
|
|
|
2020-12-04 08:29:40 -06:00
|
|
|
export function defaultMetricAgg(id = '1'): MetricAggregation {
|
|
|
|
return { type: 'count', id };
|
2017-09-28 05:52:39 -05:00
|
|
|
}
|
|
|
|
|
2021-05-10 08:28:47 -05:00
|
|
|
export function defaultBucketAgg(id = '1'): DateHistogram {
|
2020-12-04 08:29:40 -06:00
|
|
|
return { type: 'date_histogram', id, settings: { interval: 'auto' } };
|
2017-09-28 05:52:39 -05:00
|
|
|
}
|
|
|
|
|
2020-12-04 08:29:40 -06:00
|
|
|
export const findMetricById = (metrics: MetricAggregation[], id: MetricAggregation['id']) =>
|
2021-01-20 00:59:48 -06:00
|
|
|
metrics.find((metric) => metric.id === id);
|
2018-11-07 17:46:13 -06:00
|
|
|
|
2021-03-02 03:10:41 -06:00
|
|
|
export function hasMetricOfType(target: ElasticsearchQuery, type: MetricAggregationType): boolean {
|
|
|
|
return !!target?.metrics?.some((m) => m.type === type);
|
2018-11-07 17:46:13 -06:00
|
|
|
}
|
|
|
|
|
2020-12-04 08:29:40 -06:00
|
|
|
// Even if we have type guards when building a query, we currently have no way of getting this information from the response.
|
|
|
|
// We should try to find a better (type safe) way of doing the following 2.
|
|
|
|
export function isPipelineAgg(metricType: MetricAggregationType) {
|
|
|
|
return metricType in pipelineOptions;
|
2018-11-07 17:46:13 -06:00
|
|
|
}
|
2018-11-15 12:06:47 -06:00
|
|
|
|
2020-12-04 08:29:40 -06:00
|
|
|
export function isPipelineAggWithMultipleBucketPaths(metricType: MetricAggregationType) {
|
|
|
|
return !!metricAggregationConfig[metricType].supportsMultipleBucketPaths;
|
2019-11-07 06:13:24 -06:00
|
|
|
}
|