mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
e612d7a2f9
commit
02c779cfa3
@ -111,7 +111,7 @@ Query: query_result(topk(5, sum(rate(http_requests_total[$__range])) by (instanc
|
|||||||
Regex: /"([^"]+)"/
|
Regex: /"([^"]+)"/
|
||||||
```
|
```
|
||||||
|
|
||||||
Populate a variable with the instances having a certain state over the time range shown in the dashboard, using the more precise `$__range_s`:
|
Populate a variable with the instances having a certain state over the time range shown in the dashboard, using `$__range_s`:
|
||||||
|
|
||||||
```
|
```
|
||||||
Query: query_result(max_over_time(<metric>[${__range_s}s]) != <state>)
|
Query: query_result(max_over_time(<metric>[${__range_s}s]) != <state>)
|
||||||
|
@ -1456,7 +1456,7 @@ describe('PrometheusDatasource', () => {
|
|||||||
|
|
||||||
it('should use overridden ranges, not dashboard ranges', async () => {
|
it('should use overridden ranges, not dashboard ranges', async () => {
|
||||||
const expectedRangeSecond = 3600;
|
const expectedRangeSecond = 3600;
|
||||||
const expectedRangeString = '1h';
|
const expectedRangeString = '3600s';
|
||||||
const query = {
|
const query = {
|
||||||
range: {
|
range: {
|
||||||
from: time({}),
|
from: time({}),
|
||||||
|
@ -519,11 +519,10 @@ export class PrometheusDatasource extends DataSourceApi<PromQuery, PromOptions>
|
|||||||
getRangeScopedVars(range: TimeRange = getTimeSrv().timeRange()) {
|
getRangeScopedVars(range: TimeRange = getTimeSrv().timeRange()) {
|
||||||
const msRange = range.to.diff(range.from);
|
const msRange = range.to.diff(range.from);
|
||||||
const sRange = Math.round(msRange / 1000);
|
const sRange = Math.round(msRange / 1000);
|
||||||
const regularRange = kbn.secondsToHms(msRange / 1000);
|
|
||||||
return {
|
return {
|
||||||
__range_ms: { text: msRange, value: msRange },
|
__range_ms: { text: msRange, value: msRange },
|
||||||
__range_s: { text: sRange, value: sRange },
|
__range_s: { text: sRange, value: sRange },
|
||||||
__range: { text: regularRange, value: regularRange },
|
__range: { text: sRange + 's', value: sRange + 's' },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user