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:
Galen Kistler 2023-12-13 07:08:30 -06:00 committed by GitHub
parent db7fa30384
commit d6eca75bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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();

View File

@ -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)),
});
}