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:
David
2021-01-07 19:13:40 +01:00
committed by GitHub
parent 71e93e521b
commit bf0d940e6d
2 changed files with 33 additions and 4 deletions

View File

@@ -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],
]);
});
});
});