|
|
|
@ -442,90 +442,6 @@ describe('runSplitQuery()', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('Splitting targets based on splitDuration', () => { |
|
|
|
|
const range1h = { |
|
|
|
|
from: dateTime('2023-02-08T05:00:00.000Z'), |
|
|
|
|
to: dateTime('2023-02-08T06:00:00.000Z'), |
|
|
|
|
raw: { |
|
|
|
|
from: dateTime('2023-02-08T05:00:00.000Z'), |
|
|
|
|
to: dateTime('2023-02-08T06:00:00.000Z'), |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
beforeEach(() => { |
|
|
|
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [], refId: 'A' })); |
|
|
|
|
}); |
|
|
|
|
test('with 30m splitDuration runs 2 queries', async () => { |
|
|
|
|
const request = { |
|
|
|
|
targets: [{ expr: '{a="b"}', refId: 'A', splitDuration: '30m' }], |
|
|
|
|
range: range1h, |
|
|
|
|
} as DataQueryRequest<LokiQuery>; |
|
|
|
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
expect(datasource.runQuery).toHaveBeenCalledTimes(2); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
test('with 1h splitDuration runs 1 queries', async () => { |
|
|
|
|
const request = { |
|
|
|
|
targets: [{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' }], |
|
|
|
|
range: range1h, |
|
|
|
|
} as DataQueryRequest<LokiQuery>; |
|
|
|
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
expect(datasource.runQuery).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
test('with 1h splitDuration and 2 targets runs 1 queries', async () => { |
|
|
|
|
const request = { |
|
|
|
|
targets: [ |
|
|
|
|
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' }, |
|
|
|
|
{ expr: '{a="b"}', refId: 'B', splitDuration: '1h' }, |
|
|
|
|
], |
|
|
|
|
range: range1h, |
|
|
|
|
} as DataQueryRequest<LokiQuery>; |
|
|
|
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
expect(datasource.runQuery).toHaveBeenCalledTimes(1); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
test('with 1h/30m splitDuration and 2 targets runs 3 queries', async () => { |
|
|
|
|
const request = { |
|
|
|
|
targets: [ |
|
|
|
|
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' }, |
|
|
|
|
{ expr: '{a="b"}', refId: 'B', splitDuration: '30m' }, |
|
|
|
|
], |
|
|
|
|
range: range1h, |
|
|
|
|
} as DataQueryRequest<LokiQuery>; |
|
|
|
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
// 2 x 30m + 1 x 1h
|
|
|
|
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
test('with mixed splitDuration runs the expected amount of queries', async () => { |
|
|
|
|
const request = createRequest( |
|
|
|
|
[ |
|
|
|
|
{ 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 = createRequest( |
|
|
|
|
[ |
|
|
|
|
{ expr: '{a="b"}', refId: 'A', splitDuration: '1h' }, |
|
|
|
|
{ expr: 'count_over_time({c="d"}[1m])', refId: 'C', splitDuration: '30m' }, |
|
|
|
|
], |
|
|
|
|
{ range: range1h } |
|
|
|
|
); |
|
|
|
|
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
// 2 x 30m + 1 x 1h
|
|
|
|
|
expect(datasource.runQuery).toHaveBeenCalledTimes(3); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('Splitting targets based on resolution', () => { |
|
|
|
|
const range1d = { |
|
|
|
|
from: dateTime('2023-02-08T05:00:00.000Z'), |
|
|
|
|