Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit e4bf294

Browse files
do not aggregate empty time slices
1 parent 342b96d commit e4bf294

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

dist/datasource.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ var ApmDatasource = /** @class */ (function () {
149149
var metrics = {};
150150
var legendSeparator = "|";
151151
var aggregations = {
152-
sum: function (metricValues) { return metricValues.reduce(function (sum, metricValue) { return sum += metricValue; }, 0); },
153-
mean: function (metricValues) { return metricValues.reduce(function (sum, metricValue) { return sum += metricValue; }, 0) / metricValues.length; },
152+
sum: function (metricValues) { return metricValues.reduce(function (sum, metricValue) { return sum += metricValue; }); },
153+
mean: function (metricValues) { return metricValues.reduce(function (sum, metricValue) { return sum += metricValue; }) / metricValues.length; },
154154
max: function (metricValues) { return metricValues.reduce(function (a, b) { return Math.max(a, b); }); },
155155
min: function (metricValues) { return metricValues.reduce(function (a, b) { return Math.min(a, b); }); },
156156
median: function (metricValues) { return _this.quickselect_median(metricValues); }
@@ -203,7 +203,7 @@ var ApmDatasource = /** @class */ (function () {
203203
return dataPoints;
204204
}, []);
205205
// post processing: if configured, aggregate all time series
206-
if (/^sum|mean|max|min|median$/.test(options.aggregationMode)) {
206+
if (dataPoints.length > 0 && /^sum|mean|max|min|median$/.test(options.aggregationMode)) {
207207
var aggregate = aggregations[options.aggregationMode](dataPoints.map(function (dataPoint) { return dataPoint.metricValue; }));
208208
dataPoints = [{
209209
metricKey: !options.seriesAlias || /^\s*$/.test(options.seriesAlias) ? options.aggregationMode : options.seriesAlias,

src/datasource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ export class ApmDatasource {
169169
let metrics = {};
170170
const legendSeparator = "|";
171171
const aggregations = {
172-
sum: metricValues => metricValues.reduce((sum, metricValue) => sum += metricValue, 0),
173-
mean: metricValues => metricValues.reduce((sum, metricValue) => sum += metricValue, 0) / metricValues.length,
172+
sum: metricValues => metricValues.reduce((sum, metricValue) => sum += metricValue),
173+
mean: metricValues => metricValues.reduce((sum, metricValue) => sum += metricValue) / metricValues.length,
174174
max: metricValues => metricValues.reduce((a, b) => Math.max(a, b)),
175175
min: metricValues => metricValues.reduce((a, b) => Math.min(a, b)),
176176
median: metricValues => this.quickselect_median(metricValues)
@@ -232,7 +232,7 @@ export class ApmDatasource {
232232
}, [])
233233

234234
// post processing: if configured, aggregate all time series
235-
if (/^sum|mean|max|min|median$/.test(options.aggregationMode)) {
235+
if (dataPoints.length > 0 && /^sum|mean|max|min|median$/.test(options.aggregationMode)) {
236236
const aggregate = aggregations[options.aggregationMode](dataPoints.map((dataPoint: MetricPoint) => dataPoint.metricValue));
237237

238238
dataPoints = [{

0 commit comments

Comments
 (0)