Elasticsearch: add first version of rate aggregation
This commit is contained in:
+39
-1
@@ -1,4 +1,4 @@
|
||||
import { InlineField, Input, InlineSwitch } from '@grafana/ui';
|
||||
import { InlineField, Input, InlineSwitch, Select } from '@grafana/ui';
|
||||
import React, { FunctionComponent, ComponentProps, useState } from 'react';
|
||||
import { extendedStats } from '../../../../query_def';
|
||||
import { useDispatch } from '../../../../hooks/useStatelessReducer';
|
||||
@@ -33,6 +33,22 @@ export const SettingsEditor: FunctionComponent<Props> = ({ metric, previousMetri
|
||||
const description = useDescription(metric);
|
||||
const query = useQuery();
|
||||
|
||||
const rateAggUnitOptions = [
|
||||
{ value: 'seconds', label: 'Seconds' },
|
||||
{ value: 'minute', label: 'Minute' },
|
||||
{ value: 'hour', label: 'Hour' },
|
||||
{ value: 'day', label: 'Day' },
|
||||
{ value: 'week', label: 'Week' },
|
||||
{ value: 'month', label: 'Month' },
|
||||
{ value: 'quarter', label: 'Quarter' },
|
||||
{ value: 'Year', label: 'Year' },
|
||||
];
|
||||
|
||||
const rateAggModeOptions = [
|
||||
{ value: 'sum', label: 'Sum' },
|
||||
{ value: 'value_count', label: 'Value count' },
|
||||
];
|
||||
|
||||
return (
|
||||
<SettingsEditorContainer label={description} hidden={metric.hide}>
|
||||
{metric.type === 'derivative' && <SettingField label="Unit" metric={metric} settingName="unit" />}
|
||||
@@ -109,6 +125,28 @@ export const SettingsEditor: FunctionComponent<Props> = ({ metric, previousMetri
|
||||
</InlineField>
|
||||
)}
|
||||
|
||||
{metric.type === 'rate' && (
|
||||
<>
|
||||
<InlineField label="Unit" {...inlineFieldProps}>
|
||||
<Select
|
||||
id={`ES-query-${query.refId}_metric-${metric.id}-unit`}
|
||||
onChange={(e) => dispatch(changeMetricSetting(metric, 'unit', e.value))}
|
||||
options={rateAggUnitOptions}
|
||||
value={metric.settings?.unit}
|
||||
/>
|
||||
</InlineField>
|
||||
|
||||
<InlineField label="Mode" {...inlineFieldProps}>
|
||||
<Select
|
||||
id={`ES-query-${query.refId}_metric-${metric.id}-mode`}
|
||||
onChange={(e) => dispatch(changeMetricSetting(metric, 'mode', e.value))}
|
||||
options={rateAggModeOptions}
|
||||
value={metric.settings?.unit}
|
||||
/>
|
||||
</InlineField>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isMetricAggregationWithInlineScript(metric) && (
|
||||
<SettingField label="Script" metric={metric} settingName="script" placeholder="_value * 1" />
|
||||
)}
|
||||
|
||||
+12
-1
@@ -20,6 +20,7 @@ export type MetricAggregationType =
|
||||
| 'raw_document'
|
||||
| 'raw_data'
|
||||
| 'logs'
|
||||
| 'rate'
|
||||
| PipelineMetricAggregationType;
|
||||
|
||||
interface BaseMetricAggregation {
|
||||
@@ -153,6 +154,14 @@ export interface Logs extends BaseMetricAggregation {
|
||||
};
|
||||
}
|
||||
|
||||
export interface Rate extends MetricAggregationWithField {
|
||||
type: 'rate';
|
||||
settings?: {
|
||||
unit?: string;
|
||||
mode?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface BasePipelineMetricAggregation extends MetricAggregationWithField {
|
||||
type: PipelineMetricAggregationType;
|
||||
pipelineAgg?: string;
|
||||
@@ -293,7 +302,8 @@ export type MetricAggregationWithSettings =
|
||||
| Average
|
||||
| MovingAverage
|
||||
| MovingFunction
|
||||
| Logs;
|
||||
| Logs
|
||||
| Rate;
|
||||
|
||||
export type MetricAggregationWithMeta = ExtendedStats;
|
||||
|
||||
@@ -355,6 +365,7 @@ export const METRIC_AGGREGATION_TYPES = [
|
||||
'serial_diff',
|
||||
'cumulative_sum',
|
||||
'bucket_script',
|
||||
'rate',
|
||||
];
|
||||
|
||||
export const isMetricAggregationType = (s: MetricAggregationType | string): s is MetricAggregationType =>
|
||||
|
||||
+11
@@ -236,6 +236,17 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
},
|
||||
},
|
||||
},
|
||||
rate: {
|
||||
label: 'Rate',
|
||||
requiresField: true,
|
||||
isPipelineAgg: false,
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
supportsInlineScript: false,
|
||||
hasMeta: false,
|
||||
defaults: {},
|
||||
},
|
||||
};
|
||||
|
||||
interface PipelineOption {
|
||||
|
||||
Reference in New Issue
Block a user