mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Use the timerange in languageProvider when it's not provided (#99699)
use the timerange in languageProvider
This commit is contained in:
@@ -1029,6 +1029,23 @@ describe('PrometheusDatasource', () => {
|
||||
expect(interval).toEqual({ text: '15s', value: '15s' });
|
||||
expect(intervalMs).toEqual({ text: 15000, value: 15000 });
|
||||
});
|
||||
|
||||
it('should use the default time range when no range provided in options', () => {
|
||||
const prometheusDatasource = new PrometheusDatasource(
|
||||
{ ...instanceSettings, jsonData: { ...instanceSettings.jsonData, cacheLevel: PrometheusCacheLevel.None } },
|
||||
templateSrvStub
|
||||
);
|
||||
const query = 'query_result(topk(5,rate(http_request_duration_microseconds_count[$__interval])))';
|
||||
prometheusDatasource.metricFindQuery(query);
|
||||
|
||||
// Last 6h
|
||||
const range = replaceMock.mock.calls[1][1].__range;
|
||||
const rangeMs = replaceMock.mock.calls[1][1].__range_ms;
|
||||
const rangeS = replaceMock.mock.calls[1][1].__range_s;
|
||||
expect(range).toEqual({ text: '21600s', value: '21600s' });
|
||||
expect(rangeMs).toEqual({ text: 21600000, value: 21600000 });
|
||||
expect(rangeS).toEqual({ text: 21600, value: 21600 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -456,13 +456,15 @@ export class PrometheusDatasource
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const timeRange = options?.range ?? this.languageProvider.timeRange ?? getDefaultTimeRange();
|
||||
|
||||
const scopedVars = {
|
||||
...this.getIntervalVars(),
|
||||
...this.getRangeScopedVars(options?.range ?? getDefaultTimeRange()),
|
||||
...this.getRangeScopedVars(timeRange),
|
||||
};
|
||||
const interpolated = this.templateSrv.replace(query, scopedVars, this.interpolateQueryExpr);
|
||||
const metricFindQuery = new PrometheusMetricFindQuery(this, interpolated);
|
||||
return metricFindQuery.process(options?.range ?? getDefaultTimeRange());
|
||||
return metricFindQuery.process(timeRange);
|
||||
}
|
||||
|
||||
getIntervalVars() {
|
||||
|
||||
Reference in New Issue
Block a user