The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/elasticsearch/queryDef.ts

58 lines
2.0 KiB

import { metricAggregationConfig, pipelineOptions } from './components/QueryEditor/MetricAggregationsEditor/utils';
import {
ElasticsearchQuery,
ExtendedStat,
MetricAggregation,
MovingAverageModelOption,
MetricAggregationType,
DateHistogram,
} from './types';
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 const highlightTags = {
pre: '@HIGHLIGHT@',
post: '@/HIGHLIGHT@',
};
export function defaultMetricAgg(id = '1'): MetricAggregation {
return { type: 'count', id };
}
export function defaultBucketAgg(id = '1'): DateHistogram {
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: ElasticsearchQuery, type: MetricAggregationType): boolean {
return !!target?.metrics?.some((m) => 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;
}