mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
loki: handle parsing infinity in loki response (#45097)
This commit is contained in:
parent
d8a56d08ba
commit
59c5f14a59
@ -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],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user