mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki Logs sample: use the selected time range in sample request (#65126)
Logs sample: use the selected time range in sample request There are parts of the query, such as label values, that could only be present during the current selected time interval. If we request using a time range other than the selected one, we are not providing builder suggestions based on the same data that the user is seeing.
This commit is contained in:
parent
ae0f9fc44f
commit
9874a2d48b
@ -1089,8 +1089,30 @@ describe('LokiDatasource', () => {
|
||||
});
|
||||
|
||||
describe('getDataSamples', () => {
|
||||
it('hide request from inspector', () => {
|
||||
const ds = createLokiDatasource(templateSrvStub);
|
||||
let ds: LokiDatasource;
|
||||
beforeEach(() => {
|
||||
ds = createLokiDatasource(templateSrvStub);
|
||||
});
|
||||
it('ignores invalid queries', () => {
|
||||
const spy = jest.spyOn(ds, 'query');
|
||||
ds.getDataSamples({ expr: 'not a query', refId: 'A' });
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
it('ignores metric queries', () => {
|
||||
const spy = jest.spyOn(ds, 'query');
|
||||
ds.getDataSamples({ expr: 'count_over_time({a="b"}[1m])', refId: 'A' });
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
it('uses the current interval in the request', () => {
|
||||
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse));
|
||||
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' });
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
range: ds.getTimeRange(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('hides the request from the inspector', () => {
|
||||
const spy = jest.spyOn(ds, 'query').mockImplementation(() => of({} as DataQueryResponse));
|
||||
ds.getDataSamples({ expr: '{job="bar"}', refId: 'A' });
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
|
@ -22,7 +22,6 @@ import {
|
||||
DateTime,
|
||||
FieldCache,
|
||||
FieldType,
|
||||
getDefaultTimeRange,
|
||||
Labels,
|
||||
LoadingState,
|
||||
LogLevel,
|
||||
@ -548,11 +547,11 @@ export class LokiDatasource
|
||||
expr: query.expr,
|
||||
queryType: LokiQueryType.Range,
|
||||
refId: REF_ID_DATA_SAMPLES,
|
||||
// For samples we limit the request to 10 lines, so queries are small and fast
|
||||
maxLines: 10,
|
||||
};
|
||||
|
||||
// For samples, we use defaultTimeRange (now-6h/now) and limit od 10 lines so queries are small and fast
|
||||
const timeRange = getDefaultTimeRange();
|
||||
const timeRange = this.getTimeRange();
|
||||
const request = makeRequest(lokiLogsQuery, timeRange, CoreApp.Unknown, REF_ID_DATA_SAMPLES, true);
|
||||
return await lastValueFrom(this.query(request).pipe(switchMap((res) => of(res.data))));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user