mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
import { BucketAggregation } from './components/QueryEditor/BucketAggregationsEditor/aggregations';
|
|
import {
|
|
ExtendedStat,
|
|
MetricAggregation,
|
|
MovingAverageModelOption,
|
|
MetricAggregationType,
|
|
} from './components/QueryEditor/MetricAggregationsEditor/aggregations';
|
|
import { metricAggregationConfig, pipelineOptions } from './components/QueryEditor/MetricAggregationsEditor/utils';
|
|
|
|
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' },
|
|
];
|
|
|
|
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' },
|
|
];
|
|
|
|
export function defaultMetricAgg(id = '1'): MetricAggregation {
|
|
return { type: 'count', id };
|
|
}
|
|
|
|
export function defaultBucketAgg(id = '1'): BucketAggregation {
|
|
return { type: 'date_histogram', id, settings: { interval: 'auto' } };
|
|
}
|
|
|
|
export const findMetricById = (metrics: MetricAggregation[], id: MetricAggregation['id']) =>
|
|
metrics.find(metric => metric.id === id);
|
|
|
|
export function hasMetricOfType(target: any, type: string): boolean {
|
|
return target && target.metrics && target.metrics.some((m: any) => m.type === type);
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
export function isPipelineAggWithMultipleBucketPaths(metricType: MetricAggregationType) {
|
|
return !!metricAggregationConfig[metricType].supportsMultipleBucketPaths;
|
|
}
|