Loki: Pass log volume hint as a request header (#42108)

This commit is contained in:
Piotr Jamróz
2021-11-23 11:08:37 +01:00
committed by GitHub
parent f186575693
commit 4db4dc2ce9
3 changed files with 19 additions and 10 deletions

View File

@@ -184,14 +184,26 @@ describe('LokiDatasource', () => {
it('should add volume hint param for log volume queries', () => {
const target = { expr: '{job="grafana"}', refId: 'B', volumeQuery: true };
const req = ds.createRangeQuery(target, options as any, 1000);
expect(req.hint).toBe('logvolhist');
ds.runRangeQuery(target, options);
expect(backendSrv.fetch).toBeCalledWith(
expect.objectContaining({
headers: {
'X-Query-Tag': 'Source=logvolhist',
},
})
);
});
it('should not add volume hint param for regular queries', () => {
const target = { expr: '{job="grafana"}', refId: 'B', volumeQuery: false };
const req = ds.createRangeQuery(target, options as any, 1000);
expect(req.hint).not.toBeDefined();
ds.runRangeQuery(target, options);
expect(backendSrv.fetch).not.toBeCalledWith(
expect.objectContaining({
headers: {
'X-Query-Tag': 'Source=logvolhist',
},
})
);
});
});
});

View File

@@ -248,12 +248,9 @@ export class LokiDatasource
};
}
const hint: { hint?: 'logvolhist' } = target.volumeQuery ? { hint: 'logvolhist' } : {};
return {
...DEFAULT_QUERY_PARAMS,
...range,
...hint,
query,
limit,
};
@@ -284,7 +281,9 @@ export class LokiDatasource
}
const query = this.createRangeQuery(target, options, maxDataPoints);
return this._request(RANGE_QUERY_ENDPOINT, query).pipe(
const headers = target.volumeQuery ? { 'X-Query-Tag': 'Source=logvolhist' } : undefined;
return this._request(RANGE_QUERY_ENDPOINT, query, { headers }).pipe(
catchError((err) => throwError(() => this.processError(err, target))),
switchMap((response) =>
processRangeQueryResponse(

View File

@@ -14,8 +14,6 @@ export interface LokiRangeQueryRequest {
end?: number;
step?: number;
direction?: 'BACKWARD' | 'FORWARD';
// extra info passed to Loki API when a log volume query is run to distinguish it from any other query
hint?: 'logvolhist';
}
export enum LokiResultType {