mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
Range splitting: remove hardcoded chunk limit (#64625)
* Range splitting: allow splits larger than 30 days while keeping the fail safe * Remove limit * Fix test * Remove unnecessary try/catch * Remove unused export
This commit is contained in:
@@ -26,10 +26,4 @@ describe('querySplit', () => {
|
|||||||
[Date.parse('2022-02-06T14:10:43.567'), Date.parse('2022-02-06T14:11:03.567')],
|
[Date.parse('2022-02-06T14:10:43.567'), Date.parse('2022-02-06T14:11:03.567')],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if too many chunks would be generated', () => {
|
|
||||||
const start = Date.parse('2022-02-06T14:10:03');
|
|
||||||
const end = Date.parse('2022-02-06T14:30:03');
|
|
||||||
expect(getRangeChunks(start, end, 10000)).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
// like returned by `new Date().getTime()`. this is needed because the "math"
|
// like returned by `new Date().getTime()`. this is needed because the "math"
|
||||||
// has to be done on integer numbers.
|
// has to be done on integer numbers.
|
||||||
|
|
||||||
const MAX_CHUNK_COUNT = 50;
|
|
||||||
|
|
||||||
// the way loki handles logs-range-queries is that if you specify start & end,
|
// the way loki handles logs-range-queries is that if you specify start & end,
|
||||||
// one of those will be included, but the other will not. this allows us to
|
// one of those will be included, but the other will not. this allows us to
|
||||||
// make it easy to split ranges.
|
// make it easy to split ranges.
|
||||||
@@ -22,7 +20,7 @@ export function getRangeChunks(
|
|||||||
startTime: number,
|
startTime: number,
|
||||||
endTime: number,
|
endTime: number,
|
||||||
idealRangeDuration: number
|
idealRangeDuration: number
|
||||||
): Array<[number, number]> | null {
|
): Array<[number, number]> {
|
||||||
if (endTime - startTime <= idealRangeDuration) {
|
if (endTime - startTime <= idealRangeDuration) {
|
||||||
return [[startTime, endTime]];
|
return [[startTime, endTime]];
|
||||||
}
|
}
|
||||||
@@ -36,10 +34,6 @@ export function getRangeChunks(
|
|||||||
// to cross over the startTime
|
// to cross over the startTime
|
||||||
const chunkStartTime = Math.max(chunkEndTime - idealRangeDuration, startTime);
|
const chunkStartTime = Math.max(chunkEndTime - idealRangeDuration, startTime);
|
||||||
result.push([chunkStartTime, chunkEndTime]);
|
result.push([chunkStartTime, chunkEndTime]);
|
||||||
|
|
||||||
if (result.length > MAX_CHUNK_COUNT) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// because we walked backwards, we need to reverse the array
|
// because we walked backwards, we need to reverse the array
|
||||||
|
|||||||
@@ -13,17 +13,10 @@ describe('querySplit', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if too many chunks would be generated', () => {
|
it('should return the original interval if requested duration is smaller than step', () => {
|
||||||
const start = Date.parse('2022-02-06T14:10:03');
|
|
||||||
const end = Date.parse('2022-02-06T14:35:01');
|
|
||||||
const step = 10 * 1000;
|
|
||||||
expect(getRangeChunks(start, end, step, 20000)).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return null if requested duration is smaller than step', () => {
|
|
||||||
const start = Date.parse('2022-02-06T14:10:03');
|
const start = Date.parse('2022-02-06T14:10:03');
|
||||||
const end = Date.parse('2022-02-06T14:10:33');
|
const end = Date.parse('2022-02-06T14:10:33');
|
||||||
const step = 10 * 1000;
|
const step = 10 * 1000;
|
||||||
expect(getRangeChunks(start, end, step, 1000)).toBeNull();
|
expect(getRangeChunks(start, end, step, 1000)).toEqual([[start, end]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,17 +19,15 @@ function expandTimeRange(startTime: number, endTime: number, step: number): [num
|
|||||||
return [newStartTime, newEndTime];
|
return [newStartTime, newEndTime];
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_CHUNK_COUNT = 50;
|
|
||||||
|
|
||||||
export function getRangeChunks(
|
export function getRangeChunks(
|
||||||
startTime: number,
|
startTime: number,
|
||||||
endTime: number,
|
endTime: number,
|
||||||
step: number,
|
step: number,
|
||||||
idealRangeDuration: number
|
idealRangeDuration: number
|
||||||
): Array<[number, number]> | null {
|
): Array<[number, number]> {
|
||||||
if (idealRangeDuration < step) {
|
if (idealRangeDuration < step) {
|
||||||
// we cannot create chunks smaller than `step`
|
// we cannot create chunks smaller than `step`
|
||||||
return null;
|
return [[startTime, endTime]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// we make the duration a multiple of `step`, lowering it if necessary
|
// we make the duration a multiple of `step`, lowering it if necessary
|
||||||
@@ -45,10 +43,6 @@ export function getRangeChunks(
|
|||||||
// to cross over the startTime
|
// to cross over the startTime
|
||||||
const chunkStartTime = Math.max(chunkEndTime - alignedDuration, alignedStartTime);
|
const chunkStartTime = Math.max(chunkEndTime - alignedDuration, alignedStartTime);
|
||||||
result.push([chunkStartTime, chunkEndTime]);
|
result.push([chunkStartTime, chunkEndTime]);
|
||||||
|
|
||||||
if (result.length > MAX_CHUNK_COUNT) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// because we walked backwards, we need to reverse the array
|
// because we walked backwards, we need to reverse the array
|
||||||
|
|||||||
@@ -41,11 +41,6 @@ export function partitionTimeRange(
|
|||||||
? getLogsRangeChunks(start, end, duration)
|
? getLogsRangeChunks(start, end, duration)
|
||||||
: getMetricRangeChunks(start, end, step, duration);
|
: getMetricRangeChunks(start, end, step, duration);
|
||||||
|
|
||||||
// if the split was not possible, go with the original range
|
|
||||||
if (ranges == null) {
|
|
||||||
return [originalTimeRange];
|
|
||||||
}
|
|
||||||
|
|
||||||
return ranges.map(([start, end]) => {
|
return ranges.map(([start, end]) => {
|
||||||
const from = dateTime(start);
|
const from = dateTime(start);
|
||||||
const to = dateTime(end);
|
const to = dateTime(end);
|
||||||
@@ -197,5 +192,6 @@ export function runPartitionedQueries(datasource: LokiDatasource, request: DataQ
|
|||||||
partition: [request.range],
|
partition: [request.range],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return runGroupedQueries(datasource, requests);
|
return runGroupedQueries(datasource, requests);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user