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
2 changed files with 22 additions and 5 deletions
@@ -246,6 +246,20 @@ describe('runSplitQuery()', () => {
expect(datasource.runQuery).toHaveBeenCalledTimes(3); 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 () => { test('with 1h/30m splitDuration and 1 log and 2 metric target runs 3 queries', async () => {
const request = getQueryOptions<LokiQuery>({ const request = getQueryOptions<LokiQuery>({
targets: [ targets: [
@@ -154,11 +154,14 @@ export function runSplitGroupedQueries(datasource: LokiDatasource, requests: Lok
function getNextRequestPointers(requests: LokiGroupedRequest, requestGroup: number, requestN: number) { function getNextRequestPointers(requests: LokiGroupedRequest, requestGroup: number, requestN: number) {
// There's a pending request from the next group: // There's a pending request from the next group:
if (requests[requestGroup + 1]?.partition[requestN - 1]) { for (let i = requestGroup + 1; i < requests.length; i++) {
return { const group = requests[i];
nextRequestGroup: requestGroup + 1, if (group.partition[requestN - 1]) {
nextRequestN: requestN, return {
}; nextRequestGroup: i,
nextRequestN: requestN,
};
}
} }
return { return {
// Find the first group where `[requestN - 1]` is defined // Find the first group where `[requestN - 1]` is defined