Loki Query Splitting: Fix bug for mixed split durations (#65925)

* Query splitting: fix next request group pointer calculation

* Update unit test
This commit is contained in:
Matias Chomicki 2023-04-04 15:51:41 +02:00 committed by GitHub
parent fa36392185
commit 44beef2e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 5 deletions

View File

@ -246,6 +246,20 @@ describe('runSplitQuery()', () => {
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
});
});
test('with mixed splitDuration runs the expected amount of queries', async () => {
const request = getQueryOptions<LokiQuery>({
targets: [
{ expr: 'count_over_time({c="d"}[1m])', refId: 'A', splitDuration: '15m' },
{ expr: '{a="b"}', refId: 'B', splitDuration: '15m' },
{ expr: '{a="b"}', refId: 'C', splitDuration: '1h' },
],
range: range1h,
});
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
// 4 * 15m + 4 * 15m + 1 * 1h
expect(datasource.runQuery).toHaveBeenCalledTimes(9);
});
});
test('with 1h/30m splitDuration and 1 log and 2 metric target runs 3 queries', async () => {
const request = getQueryOptions<LokiQuery>({
targets: [

View File

@ -154,11 +154,14 @@ export function runSplitGroupedQueries(datasource: LokiDatasource, requests: Lok
function getNextRequestPointers(requests: LokiGroupedRequest, requestGroup: number, requestN: number) {
// There's a pending request from the next group:
if (requests[requestGroup + 1]?.partition[requestN - 1]) {
return {
nextRequestGroup: requestGroup + 1,
nextRequestN: requestN,
};
for (let i = requestGroup + 1; i < requests.length; i++) {
const group = requests[i];
if (group.partition[requestN - 1]) {
return {
nextRequestGroup: i,
nextRequestN: requestN,
};
}
}
return {
// Find the first group where `[requestN - 1]` is defined