Prometheus: make $__range more precise (#21722)

* Make $__range more precise in Prometheus

It is now always equivalent to `${__range_s}s`, rather than rounding
down to an integer multiple of the biggest possible unit. For example,
a range of 47 hours is now represented as `169200s` rather than `1d`.

Closes #21689.

* Update a unit test to match new __range calc
This commit is contained in:
Bruce Merry
2020-02-11 15:28:06 +02:00
committed by GitHub
parent e612d7a2f9
commit 02c779cfa3
3 changed files with 3 additions and 4 deletions

View File

@@ -1456,7 +1456,7 @@ describe('PrometheusDatasource', () => {
it('should use overridden ranges, not dashboard ranges', async () => {
const expectedRangeSecond = 3600;
const expectedRangeString = '1h';
const expectedRangeString = '3600s';
const query = {
range: {
from: time({}),

View File

@@ -519,11 +519,10 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
getRangeScopedVars(range: TimeRange = getTimeSrv().timeRange()) {
const msRange = range.to.diff(range.from);
const sRange = Math.round(msRange / 1000);
const regularRange = kbn.secondsToHms(msRange / 1000);
return {
__range_ms: { text: msRange, value: msRange },
__range_s: { text: sRange, value: sRange },
__range: { text: regularRange, value: regularRange },
__range: { text: sRange + 's', value: sRange + 's' },
};
}