mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: strip out invalid options for logs/metrics queries (#79409)
* fix bug in split query where metric queries with maxLines of 0 would not execute
This commit is contained in:
parent
db7fa30384
commit
d6eca75bf7
@ -42,6 +42,28 @@ describe('runSplitQuery()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('Metric queries with maxLines of 0 will execute', async () => {
|
||||
const request = getQueryOptions<LokiQuery>({
|
||||
targets: [{ expr: 'count_over_time({a="b"}[1m])', refId: 'A', maxLines: 0 }],
|
||||
range,
|
||||
});
|
||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||
// 3 days, 3 chunks, 3 requests.
|
||||
expect(datasource.runQuery).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
});
|
||||
|
||||
test('Log queries with maxLines of 0 will NOT execute', async () => {
|
||||
const request = getQueryOptions<LokiQuery>({
|
||||
targets: [{ expr: '{a="b"}', refId: 'A', maxLines: 0 }],
|
||||
range,
|
||||
});
|
||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith(() => {
|
||||
// Will not request a log query with maxLines of 0
|
||||
expect(datasource.runQuery).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('Returns a DataQueryResponse with the expected attributes', async () => {
|
||||
await expect(runSplitQuery(datasource, request)).toEmitValuesWith((response) => {
|
||||
expect(response[0].data).toBeDefined();
|
||||
|
@ -246,8 +246,12 @@ export function runSplitQuery(datasource: LokiDatasource, request: DataQueryRequ
|
||||
);
|
||||
|
||||
for (const stepMs in stepMsPartition) {
|
||||
const targets = stepMsPartition[stepMs].map((q) => {
|
||||
const { maxLines, ...query } = q;
|
||||
return query;
|
||||
});
|
||||
requests.push({
|
||||
request: { ...request, targets: stepMsPartition[stepMs] },
|
||||
request: { ...request, targets },
|
||||
partition: partitionTimeRange(false, request.range, Number(stepMs), Number(chunkRangeMs)),
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user