mirror of https://github.com/grafana/grafana.git
shardQuerySplitting: group has pending requests or no shards to run (#108500)
* shardQuerySplitting: group has pending requests or no shards to run * Comment * Regression test
This commit is contained in:
parent
e3c1e75da5
commit
d3a445409b
|
|
@ -6,7 +6,7 @@ import { LokiDatasource } from './datasource';
|
||||||
import { createLokiDatasource } from './mocks/datasource';
|
import { createLokiDatasource } from './mocks/datasource';
|
||||||
import { getMockFrames } from './mocks/frames';
|
import { getMockFrames } from './mocks/frames';
|
||||||
import { runShardSplitQuery } from './shardQuerySplitting';
|
import { runShardSplitQuery } from './shardQuerySplitting';
|
||||||
import { LokiQuery, LokiQueryDirection } from './types';
|
import { LokiQuery, LokiQueryDirection, LokiQueryType } from './types';
|
||||||
|
|
||||||
jest.mock('uuid', () => ({
|
jest.mock('uuid', () => ({
|
||||||
v4: jest.fn().mockReturnValue('uuid'),
|
v4: jest.fn().mockReturnValue('uuid'),
|
||||||
|
|
@ -100,6 +100,26 @@ describe('runShardSplitQuery()', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Runs multiple non-sharded queries', async () => {
|
||||||
|
const request = createRequest([
|
||||||
|
{ expr: 'count_over_time({a="b"}[$__auto])', refId: 'A' },
|
||||||
|
{ expr: 'count_over_time({a="b"}[$__auto])', refId: 'B', queryType: LokiQueryType.Instant },
|
||||||
|
]);
|
||||||
|
datasource = createLokiDatasource({
|
||||||
|
replace: (input = '') => {
|
||||||
|
return input.replace('$__auto', '5m').replace('$step', '5m');
|
||||||
|
},
|
||||||
|
getVariables: () => [],
|
||||||
|
});
|
||||||
|
jest.spyOn(datasource, 'runQuery').mockReturnValue(of({ data: [] }));
|
||||||
|
datasource.languageProvider.fetchLabelValues = jest.fn();
|
||||||
|
jest.mocked(datasource.languageProvider.fetchLabelValues).mockResolvedValue([]);
|
||||||
|
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
|
// 5 shards, 3 groups + empty shard group, 4 requests
|
||||||
|
expect(datasource.runQuery).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Users query splitting for querying over a day', async () => {
|
test('Users query splitting for querying over a day', async () => {
|
||||||
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||||
// 5 shards, 3 groups + empty shard group, 4 requests
|
// 5 shards, 3 groups + empty shard group, 4 requests
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,9 @@ function splitQueriesByStreamShard(
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextRequest = () => {
|
const nextRequest = () => {
|
||||||
|
// Find the next group to execute, which can be queries with pending shards to execute, or the next query with no shards.
|
||||||
const nextGroup =
|
const nextGroup =
|
||||||
groups[group + 1] && groupHasPendingRequests(groups[group + 1])
|
groups[group + 1] && (groups[group + 1].shards === undefined || groupHasPendingRequests(groups[group + 1]))
|
||||||
? groups[group + 1]
|
? groups[group + 1]
|
||||||
: groups.find((shardGroup) => groupHasPendingRequests(shardGroup));
|
: groups.find((shardGroup) => groupHasPendingRequests(shardGroup));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue