|
|
|
@ -53,11 +53,9 @@ describe('runShardSplitQuery()', () => { |
|
|
|
|
request = createRequest([{ expr: '$SELECTOR', refId: 'A', direction: LokiQueryDirection.Scan }]); |
|
|
|
|
datasource = createLokiDatasource(); |
|
|
|
|
datasource.languageProvider.fetchLabelValues = jest.fn(); |
|
|
|
|
datasource.interpolateVariablesInQueries = jest.fn().mockImplementation((queries: LokiQuery[]) => { |
|
|
|
|
return queries.map((query) => { |
|
|
|
|
query.expr = query.expr.replace('$SELECTOR', '{a="b"}'); |
|
|
|
|
return query; |
|
|
|
|
}); |
|
|
|
|
datasource.applyTemplateVariables = jest.fn().mockImplementation((query: LokiQuery) => { |
|
|
|
|
query.expr = query.expr.replace('$SELECTOR', '{a="b"}'); |
|
|
|
|
return query; |
|
|
|
|
}); |
|
|
|
|
jest.mocked(datasource.languageProvider.fetchLabelValues).mockResolvedValue(['1', '10', '2', '20', '3']); |
|
|
|
|
const { metricFrameA } = getMockFrames(); |
|
|
|
@ -83,6 +81,25 @@ describe('runShardSplitQuery()', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('Interpolates queries before execution', async () => { |
|
|
|
|
const request = createRequest([{ expr: 'count_over_time({a="b"}[$__auto])', refId: 'A', step: '$step' }]); |
|
|
|
|
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(['1', '10', '2', '20', '3']); |
|
|
|
|
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
expect(jest.mocked(datasource.runQuery).mock.calls[0][0].targets[0].expr).toBe( |
|
|
|
|
'count_over_time({a="b", __stream_shard__=~"20|10"} | drop __stream_shard__[5m])' |
|
|
|
|
); |
|
|
|
|
expect(jest.mocked(datasource.runQuery).mock.calls[0][0].targets[0].step).toBe('5m'); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('Users query splitting for querying over a day', async () => { |
|
|
|
|
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
// 5 shards, 3 groups + empty shard group, 4 requests
|
|
|
|
@ -92,7 +109,7 @@ describe('runShardSplitQuery()', () => { |
|
|
|
|
|
|
|
|
|
test('Interpolates queries before running', async () => { |
|
|
|
|
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|
expect(datasource.interpolateVariablesInQueries).toHaveBeenCalledTimes(1); |
|
|
|
|
expect(datasource.applyTemplateVariables).toHaveBeenCalledTimes(5); |
|
|
|
|
|
|
|
|
|
expect(datasource.runQuery).toHaveBeenCalledWith({ |
|
|
|
|
intervalMs: expect.any(Number), |
|
|
|
@ -153,11 +170,9 @@ describe('runShardSplitQuery()', () => { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('Sends the whole stream selector to fetch values', async () => { |
|
|
|
|
datasource.interpolateVariablesInQueries = jest.fn().mockImplementation((queries: LokiQuery[]) => { |
|
|
|
|
return queries.map((query) => { |
|
|
|
|
query.expr = query.expr.replace('$SELECTOR', '{service_name="test", filter="true"}'); |
|
|
|
|
return query; |
|
|
|
|
}); |
|
|
|
|
datasource.applyTemplateVariables = jest.fn().mockImplementation((query: LokiQuery) => { |
|
|
|
|
query.expr = query.expr.replace('$SELECTOR', '{service_name="test", filter="true"}'); |
|
|
|
|
return query; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
await expect(runShardSplitQuery(datasource, request)).toEmitValuesWith(() => { |
|
|
|
|