mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Timeseries should not produce 0-values for missing data (#30116)
- It should produce NULL values instead, to be in line with Prometheus.
This commit is contained in:
parent
71e93e521b
commit
bf0d940e6d
@ -1,7 +1,7 @@
|
||||
import { CircularDataFrame, FieldCache, FieldType, MutableDataFrame } from '@grafana/data';
|
||||
import { LokiStreamResult, LokiTailResponse, LokiStreamResponse, LokiResultType, TransformerOptions } from './types';
|
||||
import * as ResultTransformer from './result_transformer';
|
||||
import { enhanceDataFrame } from './result_transformer';
|
||||
import { enhanceDataFrame, lokiPointsToTimeseriesPoints } from './result_transformer';
|
||||
import { setTemplateSrv } from '@grafana/runtime';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
|
||||
@ -256,4 +256,30 @@ describe('enhanceDataFrame', () => {
|
||||
url: '',
|
||||
});
|
||||
});
|
||||
|
||||
describe('lokiPointsToTimeseriesPoints()', () => {
|
||||
/**
|
||||
* NOTE on time parameters:
|
||||
* - Input time series data has timestamps in sec (like Prometheus)
|
||||
* - Output time series has timestamps in ms (as expected for the chart lib)
|
||||
* - Start/end parameters are in ns (as expected for Loki)
|
||||
* - Step is in sec (like in Prometheus)
|
||||
*/
|
||||
const data: Array<[number, string]> = [
|
||||
[1, '1'],
|
||||
[2, '0'],
|
||||
[4, '1'],
|
||||
];
|
||||
|
||||
it('returns data as is if step, start, and end align', () => {
|
||||
const options: Partial<TransformerOptions> = { start: 1 * 1e9, end: 4 * 1e9, step: 1 };
|
||||
const result = lokiPointsToTimeseriesPoints(data, options as TransformerOptions);
|
||||
expect(result).toEqual([
|
||||
[1, 1000],
|
||||
[0, 2000],
|
||||
[null, 3000],
|
||||
[1, 4000],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -185,7 +185,10 @@ function lokiMatrixToTimeSeries(matrixResult: LokiMatrixResult, options: Transfo
|
||||
};
|
||||
}
|
||||
|
||||
function lokiPointsToTimeseriesPoints(data: Array<[number, string]>, options: TransformerOptions): TimeSeriesValue[][] {
|
||||
export function lokiPointsToTimeseriesPoints(
|
||||
data: Array<[number, string]>,
|
||||
options: TransformerOptions
|
||||
): TimeSeriesValue[][] {
|
||||
const stepMs = options.step * 1000;
|
||||
const datapoints: TimeSeriesValue[][] = [];
|
||||
|
||||
@ -199,7 +202,7 @@ function lokiPointsToTimeseriesPoints(data: Array<[number, string]>, options: Tr
|
||||
|
||||
const timestamp = time * 1000;
|
||||
for (let t = baseTimestampMs; t < timestamp; t += stepMs) {
|
||||
datapoints.push([0, t]);
|
||||
datapoints.push([null, t]);
|
||||
}
|
||||
|
||||
baseTimestampMs = timestamp + stepMs;
|
||||
@ -208,7 +211,7 @@ function lokiPointsToTimeseriesPoints(data: Array<[number, string]>, options: Tr
|
||||
|
||||
const endTimestamp = options.end / 1e6;
|
||||
for (let t = baseTimestampMs; t <= endTimestamp; t += stepMs) {
|
||||
datapoints.push([0, t]);
|
||||
datapoints.push([null, t]);
|
||||
}
|
||||
|
||||
return datapoints;
|
||||
|
Loading…
Reference in New Issue
Block a user