Commit 57db4388 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch '223790-nan-or-null-values-should-not-be-removed' into 'master'

Keep NaN values in data series

Closes #223790

See merge request gitlab-org/gitlab!35086
parents f736c78a ade11cfe
......@@ -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 };
return {
...defaultConfig,
...series,
name: getSeriesLabel(defaultConfig.name, result.metric),
};
})
.filter(series => series !== null);
queryResults.map(result => {
return {
...defaultConfig,
data: result.values,
name: getSeriesLabel(defaultConfig.name, result.metric),
};
});
---
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