mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Pass log volume hint as a request header (#42108)
This commit is contained in:
@@ -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',
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user