mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Replace deprecated moving_avg by moving_fn aggregation (#34155)
* Replace existing moving avg with moving function * Fix getValue to preserve null values * Keep null y values when generating lines. We have a .defined function on the line generator that will split lines for every null value. I've removed the data filter so we can use that function correctly to correctly draw lines only on defined values
This commit is contained in:
parent
0439b68460
commit
762b42ed92
4 changed files with 28 additions and 11 deletions
|
@ -30,7 +30,7 @@ import StubbedIndexPattern from 'fixtures/stubbed_logstash_index_pattern';
|
|||
const metrics = [
|
||||
{ name: 'derivative', title: 'Derivative', agg: derivativeMetricAgg },
|
||||
{ name: 'cumulative_sum', title: 'Cumulative Sum', agg: cumulativeSumMetricAgg },
|
||||
{ name: 'moving_avg', title: 'Moving Avg', agg: movingAvgMetricAgg },
|
||||
{ name: 'moving_avg', title: 'Moving Avg', agg: movingAvgMetricAgg, dslName: 'moving_fn' },
|
||||
{ name: 'serial_diff', title: 'Serial Diff', agg: serialDiffMetricAgg },
|
||||
];
|
||||
|
||||
|
@ -137,7 +137,7 @@ describe('parent pipeline aggs', function () {
|
|||
schema: 'orderAgg'
|
||||
}
|
||||
});
|
||||
expect(aggDsl[metric.name].buckets_path).to.be('2-metric');
|
||||
expect(aggDsl[metric.dslName || metric.name].buckets_path).to.be('2-metric');
|
||||
expect(aggDsl.parentAggs['2-metric'].max.field).to.be('bytes');
|
||||
});
|
||||
|
||||
|
@ -159,8 +159,8 @@ describe('parent pipeline aggs', function () {
|
|||
schema: 'orderAgg'
|
||||
}
|
||||
});
|
||||
expect(aggDsl[metric.name].buckets_path).to.be('2-metric');
|
||||
expect(aggDsl.parentAggs['2-metric'][metric.name].buckets_path).to.be('2-metric-metric');
|
||||
expect(aggDsl[metric.dslName || metric.name].buckets_path).to.be('2-metric');
|
||||
expect(aggDsl.parentAggs['2-metric'][metric.dslName || metric.name].buckets_path).to.be('2-metric-metric');
|
||||
});
|
||||
|
||||
it('should have correct formatter', function () {
|
||||
|
|
|
@ -28,13 +28,34 @@ const movingAvgLabel = i18n.translate('common.ui.aggTypes.metrics.movingAvgLabel
|
|||
|
||||
export const movingAvgMetricAgg = new MetricAggType({
|
||||
name: 'moving_avg',
|
||||
dslName: 'moving_fn',
|
||||
title: i18n.translate('common.ui.aggTypes.metrics.movingAvgTitle', {
|
||||
defaultMessage: 'Moving Avg'
|
||||
}),
|
||||
subtype: parentPipelineAggHelper.subtype,
|
||||
makeLabel: agg => makeNestedLabel(agg, movingAvgLabel),
|
||||
params: [
|
||||
...parentPipelineAggHelper.params()
|
||||
...parentPipelineAggHelper.params(),
|
||||
{
|
||||
name: 'window',
|
||||
default: 5,
|
||||
},
|
||||
{
|
||||
name: 'script',
|
||||
default: 'MovingFunctions.unweightedAvg(values)'
|
||||
}
|
||||
],
|
||||
getValue(agg, bucket) {
|
||||
/**
|
||||
* The previous implementation using `moving_avg` did not
|
||||
* return any bucket in case there are no documents or empty window.
|
||||
* The `moving_fn` aggregation returns buckets with the value null if the
|
||||
* window is empty or doesn't return any value if the sibiling metric
|
||||
* is null. Since our generic MetricAggType.getValue implementation
|
||||
* would return the value 0 for null buckets, we need a specific
|
||||
* implementation here, that preserves the null value.
|
||||
*/
|
||||
return bucket[agg.id] ? bucket[agg.id].value : null;
|
||||
},
|
||||
getFormat: parentPipelineAggHelper.getFormat
|
||||
});
|
||||
|
|
|
@ -145,9 +145,7 @@ export function VislibVisualizationsAreaChartProvider(Private) {
|
|||
return !_.isNull(d.y);
|
||||
})
|
||||
.interpolate(interpolate);
|
||||
return area(data.values.filter(function (d) {
|
||||
return !_.isNull(d.y);
|
||||
}));
|
||||
return area(data.values);
|
||||
})
|
||||
.style('stroke-width', '1px');
|
||||
|
||||
|
|
|
@ -196,9 +196,7 @@ export function VislibVisualizationsLineChartProvider(Private) {
|
|||
.interpolate(interpolate)
|
||||
.x(isHorizontal ? cx : cy)
|
||||
.y(isHorizontal ? cy : cx);
|
||||
return d3Line(data.values.filter(function (d) {
|
||||
return !_.isNull(d.y);
|
||||
}));
|
||||
return d3Line(data.values);
|
||||
})
|
||||
.attr('fill', 'none')
|
||||
.attr('stroke', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue