loki: handle parsing infinity in loki response (#45097)

This commit is contained in:
Gábor Farkas 2022-02-11 14:28:11 +01:00 committed by GitHub
parent d8a56d08ba
commit 59c5f14a59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -295,6 +295,9 @@ describe('enhanceDataFrame', () => {
[1, '1'],
[2, '0'],
[4, '1'],
[7, 'NaN'],
[8, '+Inf'],
[9, '-Inf'],
];
it('returns data as is if step, start, and end align', () => {
@ -303,6 +306,9 @@ describe('enhanceDataFrame', () => {
[1, 1000],
[0, 2000],
[1, 4000],
[null, 7000],
[Infinity, 8000],
[-Infinity, 9000],
]);
});
});

View File

@ -192,11 +192,22 @@ function lokiMatrixToTimeSeries(matrixResult: LokiMatrixResult, options: Transfo
};
}
function parsePrometheusFormatSampleValue(value: string): number {
switch (value) {
case '+Inf':
return Number.POSITIVE_INFINITY;
case '-Inf':
return Number.NEGATIVE_INFINITY;
default:
return parseFloat(value);
}
}
export function lokiPointsToTimeseriesPoints(data: Array<[number, string]>): TimeSeriesValue[][] {
const datapoints: TimeSeriesValue[][] = [];
for (const [time, value] of data) {
let datapointValue: TimeSeriesValue = parseFloat(value);
let datapointValue: TimeSeriesValue = parsePrometheusFormatSampleValue(value);
if (isNaN(datapointValue)) {
datapointValue = null;