Commit ade11cfe authored by Miguel Rincon's avatar Miguel Rincon

Keep NaN values in data series

While it is important to maintain average, max, min values, this
should be done at the chart level and not at the data level, as these
values cannot be removed from the dataset arbitrarily.
parent ae46ada0
......@@ -65,18 +65,10 @@ const getSeriesLabel = (queryLabel, metricAttributes) => {
*/
// eslint-disable-next-line import/prefer-default-export
export const makeDataSeries = (queryResults, defaultConfig) =>
queryResults
.map(result => {
// NaN values may disrupt avg., max. & min. calculations in the legend, filter them out
const data = result.values.filter(([, value]) => !Number.isNaN(value));
if (!data.length) {
return null;
}
const series = { data };
queryResults.map(result => {
return {
...defaultConfig,
...series,
data: result.values,
name: getSeriesLabel(defaultConfig.name, result.metric),
};
})
.filter(series => series !== null);
});
---
title: Stop removing NaN values from monitoring data series
merge_request: 35086
author:
type: changed
......@@ -33,15 +33,6 @@ describe('monitor helper', () => {
]);
});
it('excludes NaN values', () => {
expect(
monitorHelper.makeDataSeries(
data({ metric: {}, values: [[1, 1], [2, NaN]] }),
defaultConfig,
),
).toEqual([{ ...expectedDataSeries[0], data: [[1, 1]] }]);
});
it('updates series name from templates', () => {
const config = {
...defaultConfig,
......
......@@ -815,6 +815,50 @@ describe('normalizeQueryResponseData', () => {
},
]);
});
it('processes a scalar result with a NaN result', () => {
// Queries may return "NaN" string values.
// e.g. when Prometheus cannot find a metric the query
// `scalar(does_not_exist)` will return a "NaN" value.
const mockScalar = {
resultType: 'scalar',
result: [1435781451.781, 'NaN'],
};
expect(normalizeQueryResponseData(mockScalar)).toEqual([
{
metric: {},
value: ['2015-07-01T20:10:51.781Z', NaN],
values: [['2015-07-01T20:10:51.781Z', NaN]],
},
]);
});
it('processes a matrix result with a "NaN" value', () => {
// Queries may return "NaN" string values.
const mockMatrix = {
resultType: 'matrix',
result: [
{
metric: {
__name__: 'up',
job: 'prometheus',
instance: 'localhost:9090',
},
values: [[1435781430.781, '1'], [1435781460.781, 'NaN']],
},
],
};
expect(normalizeQueryResponseData(mockMatrix)).toEqual([
{
metric: { __name__: 'up', instance: 'localhost:9090', job: 'prometheus' },
value: ['2015-07-01T20:11:00.781Z', NaN],
values: [['2015-07-01T20:10:30.781Z', 1], ['2015-07-01T20:11:00.781Z', NaN]],
},
]);
});
});
describe('normalizeCustomDashboardPath', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment