mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
fa36392185
commit
44beef2e41
@ -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: [
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user