mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeSeries: Fix leading null-fill for missing intervals (#67570)
This commit is contained in:
parent
8d1c32488b
commit
e5aeb7c322
@ -152,6 +152,34 @@ describe('nullInsertThreshold Transformer', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
// this tests that intervals at 24hr but starting not at 12am UTC are not always snapped to 12am UTC
|
||||
test('should insert leading null at beginning +interval when timeRange.from.valueOf() exceeds threshold 11PM UTC', () => {
|
||||
const df = new MutableDataFrame({
|
||||
refId: 'A',
|
||||
fields: [
|
||||
{
|
||||
name: 'Time',
|
||||
type: FieldType.time,
|
||||
config: { interval: 86400000 },
|
||||
values: [1679439600000, 1679526000000, 1679612400000, 1679698800000, 1679785200000],
|
||||
},
|
||||
{ name: 'One', type: FieldType.number, values: [0, 1, 2, 3, 4] },
|
||||
],
|
||||
});
|
||||
|
||||
const result = applyNullInsertThreshold({
|
||||
frame: df,
|
||||
refFieldName: null,
|
||||
refFieldPseudoMin: 1679320395828,
|
||||
refFieldPseudoMax: 1679815217157,
|
||||
});
|
||||
|
||||
expect(result.fields[0].values).toEqual([
|
||||
1679266800000, 1679353200000, 1679439600000, 1679526000000, 1679612400000, 1679698800000, 1679785200000,
|
||||
]);
|
||||
expect(result.fields[1].values).toEqual([null, null, 0, 1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test('should insert trailing null at end +interval when timeRange.to.valueOf() exceeds threshold', () => {
|
||||
const df = new MutableDataFrame({
|
||||
refId: 'A',
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DataFrame, FieldType, incrRoundDn } from '@grafana/data';
|
||||
import { DataFrame, FieldType } from '@grafana/data';
|
||||
|
||||
type InsertMode = (prev: number, next: number, threshold: number) => number;
|
||||
|
||||
@ -108,11 +108,11 @@ function nullInsertThreshold(
|
||||
const len = refValues.length;
|
||||
const refValuesNew: number[] = [];
|
||||
|
||||
// Continiuously subtract the threshold from the first data
|
||||
// point filling in insert values accordingly
|
||||
// Continuously subtract the threshold from the first data point, filling in insert values accordingly
|
||||
if (refFieldPseudoMin != null && refFieldPseudoMin < refValues[0]) {
|
||||
let preFillCount = Math.ceil((refValues[0] - refFieldPseudoMin) / threshold);
|
||||
// this will be 0 or 1 threshold increment left of visible range
|
||||
let prevSlot = incrRoundDn(refFieldPseudoMin, threshold);
|
||||
let prevSlot = refValues[0] - preFillCount * threshold;
|
||||
|
||||
while (prevSlot < refValues[0]) {
|
||||
// (prevSlot - threshold) is used to simulate the previous 'real' data point, as getInsertValue expects
|
||||
@ -126,8 +126,7 @@ function nullInsertThreshold(
|
||||
|
||||
let prevValue: number = refValues[0];
|
||||
|
||||
// Fill nulls when a value is greater than
|
||||
// the threshold value
|
||||
// Fill nulls when a value is greater than the threshold value
|
||||
for (let i = 1; i < len; i++) {
|
||||
const curValue = refValues[i];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user