mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Elasticsearch: Add Support for Serial Differencing Pipeline Aggregation (#28618)
* Elasticsearch: Add support for serial diff pipeline aggregation * Removing settings transsforms * Removing unused deps * removing unused dep * Fixing type in test * Adding backend support for serial_diff
This commit is contained in:
@@ -35,6 +35,15 @@ export const SettingsEditor: FunctionComponent<Props> = ({ metric, previousMetri
|
||||
<SettingsEditorContainer label={description} hidden={metric.hide}>
|
||||
{metric.type === 'derivative' && <SettingField label="Unit" metric={metric} settingName="unit" />}
|
||||
|
||||
{metric.type === 'serial_diff' && (
|
||||
<InlineField label="Lag">
|
||||
<Input
|
||||
onBlur={e => dispatch(changeMetricSetting(metric, 'lag', parseInt(e.target.value, 10)))}
|
||||
defaultValue={metric.settings?.lag}
|
||||
/>
|
||||
</InlineField>
|
||||
)}
|
||||
|
||||
{metric.type === 'cumulative_sum' && <SettingField label="Format" metric={metric} settingName="format" />}
|
||||
|
||||
{metric.type === 'moving_avg' && <MovingAverageSettingsEditor metric={metric} />}
|
||||
|
||||
@@ -4,6 +4,7 @@ export type PipelineMetricAggregationType =
|
||||
| 'moving_avg'
|
||||
| 'moving_fn'
|
||||
| 'derivative'
|
||||
| 'serial_diff'
|
||||
| 'cumulative_sum'
|
||||
| 'bucket_script';
|
||||
|
||||
@@ -247,6 +248,13 @@ export interface Derivative extends BasePipelineMetricAggregation {
|
||||
};
|
||||
}
|
||||
|
||||
export interface SerialDiff extends BasePipelineMetricAggregation {
|
||||
type: 'serial_diff';
|
||||
settings?: {
|
||||
lag?: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface CumulativeSum extends BasePipelineMetricAggregation {
|
||||
type: 'cumulative_sum';
|
||||
settings?: {
|
||||
@@ -267,6 +275,7 @@ export type MetricAggregationWithSettings =
|
||||
| BucketScript
|
||||
| CumulativeSum
|
||||
| Derivative
|
||||
| SerialDiff
|
||||
| RawData
|
||||
| RawDocument
|
||||
| UniqueCount
|
||||
@@ -336,6 +345,7 @@ export const METRIC_AGGREGATION_TYPES = [
|
||||
'moving_avg',
|
||||
'moving_fn',
|
||||
'derivative',
|
||||
'serial_diff',
|
||||
'cumulative_sum',
|
||||
'bucket_script',
|
||||
];
|
||||
|
||||
@@ -147,6 +147,18 @@ export const metricAggregationConfig: MetricsConfiguration = {
|
||||
hasMeta: false,
|
||||
defaults: {},
|
||||
},
|
||||
serial_diff: {
|
||||
label: 'Serial Difference',
|
||||
requiresField: true,
|
||||
isPipelineAgg: true,
|
||||
minVersion: 2,
|
||||
supportsMissing: false,
|
||||
supportsMultipleBucketPaths: false,
|
||||
hasSettings: true,
|
||||
supportsInlineScript: false,
|
||||
hasMeta: false,
|
||||
defaults: {},
|
||||
},
|
||||
cumulative_sum: {
|
||||
label: 'Cumulative Sum',
|
||||
requiresField: true,
|
||||
@@ -236,6 +248,7 @@ export const pipelineOptions: PipelineOptions = {
|
||||
],
|
||||
moving_fn: [{ label: 'window', default: 5 }, { label: 'script' }],
|
||||
derivative: [{ label: 'unit' }],
|
||||
serial_diff: [{ label: 'lag' }],
|
||||
cumulative_sum: [{ label: 'format' }],
|
||||
bucket_script: [],
|
||||
};
|
||||
|
||||
@@ -387,6 +387,35 @@ describe('ElasticQueryBuilder', () => {
|
||||
expect(firstLevel.aggs['2'].derivative.buckets_path).toBe('_count');
|
||||
});
|
||||
|
||||
it('with serial_diff', () => {
|
||||
const query = builder.build({
|
||||
refId: 'A',
|
||||
metrics: [
|
||||
{
|
||||
id: '3',
|
||||
type: 'max',
|
||||
field: '@value',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
type: 'serial_diff',
|
||||
field: '3',
|
||||
settings: {
|
||||
lag: 5,
|
||||
},
|
||||
},
|
||||
],
|
||||
bucketAggs: [{ type: 'date_histogram', field: '@timestamp', id: '3' }],
|
||||
});
|
||||
|
||||
const firstLevel = query.aggs['3'];
|
||||
|
||||
expect(firstLevel.aggs['2']).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].serial_diff).not.toBe(undefined);
|
||||
expect(firstLevel.aggs['2'].serial_diff.buckets_path).toBe('3');
|
||||
expect(firstLevel.aggs['2'].serial_diff.lag).toBe(5);
|
||||
});
|
||||
|
||||
it('with bucket_script', () => {
|
||||
const query = builder.build({
|
||||
refId: 'A',
|
||||
|
||||
Reference in New Issue
Block a user