mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Add support for $__range_s (#12883)
Fixes #12882 Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
1f88bfd2bc
commit
48364f0111
@ -78,9 +78,9 @@ For details of *metric names*, *label names* and *label values* are please refer
|
||||
|
||||
#### Using interval and range variables
|
||||
|
||||
> Support for `$__range` and `$__range_ms` only available from Grafana v5.3
|
||||
> Support for `$__range`, `$__range_s` and `$__range_ms` only available from Grafana v5.3
|
||||
|
||||
It's possible to use some global built-in variables in query variables; `$__interval`, `$__interval_ms`, `$__range` and `$__range_ms`, see [Global built-in variables](/reference/templating/#global-built-in-variables) for more information. These can be convenient to use in conjunction with the `query_result` function when you need to filter variable queries since
|
||||
It's possible to use some global built-in variables in query variables; `$__interval`, `$__interval_ms`, `$__range`, `$__range_s` and `$__range_ms`, see [Global built-in variables](/reference/templating/#global-built-in-variables) for more information. These can be convenient to use in conjunction with the `query_result` function when you need to filter variable queries since
|
||||
`label_values` function doesn't support queries.
|
||||
|
||||
Make sure to set the variable's `refresh` trigger to be `On Time Range Change` to get the correct instances when changing the time range on the dashboard.
|
||||
@ -94,10 +94,10 @@ Query: query_result(topk(5, sum(rate(http_requests_total[$__range])) by (instanc
|
||||
Regex: /"([^"]+)"/
|
||||
```
|
||||
|
||||
Populate a variable with the instances having a certain state over the time range shown in the dashboard:
|
||||
Populate a variable with the instances having a certain state over the time range shown in the dashboard, using the more precise `$__range_s`:
|
||||
|
||||
```
|
||||
Query: query_result(max_over_time(<metric>[$__range]) != <state>)
|
||||
Query: query_result(max_over_time(<metric>[${__range_s}s]) != <state>)
|
||||
Regex:
|
||||
```
|
||||
|
||||
|
@ -277,7 +277,7 @@ This variable is only available in the Singlestat panel and can be used in the p
|
||||
|
||||
> Only available in Grafana v5.3+
|
||||
|
||||
Currently only supported for Prometheus data sources. This variable represents the range for the current dashboard. It is calculated by `to - from`. It has a millisecond representation called `$__range_ms`.
|
||||
Currently only supported for Prometheus data sources. This variable represents the range for the current dashboard. It is calculated by `to - from`. It has a millisecond and a second representation called `$__range_ms` and `$__range_s`.
|
||||
|
||||
## Repeating Panels
|
||||
|
||||
|
@ -489,9 +489,11 @@ export class PrometheusDatasource {
|
||||
getRangeScopedVars() {
|
||||
let range = this.timeSrv.timeRange();
|
||||
let msRange = range.to.diff(range.from);
|
||||
let sRange = Math.round(msRange / 1000);
|
||||
let regularRange = kbn.secondsToHms(msRange / 1000);
|
||||
return {
|
||||
__range_ms: { text: msRange, value: msRange },
|
||||
__range_s: { text: sRange, value: sRange },
|
||||
__range: { text: regularRange, value: regularRange },
|
||||
};
|
||||
}
|
||||
|
@ -321,8 +321,10 @@ describe('PrometheusDatasource', () => {
|
||||
it('should have the correct range and range_ms', () => {
|
||||
let range = ctx.templateSrvMock.replace.mock.calls[0][1].__range;
|
||||
let rangeMs = ctx.templateSrvMock.replace.mock.calls[0][1].__range_ms;
|
||||
let rangeS = ctx.templateSrvMock.replace.mock.calls[0][1].__range_s;
|
||||
expect(range).toEqual({ text: '21s', value: '21s' });
|
||||
expect(rangeMs).toEqual({ text: 21031, value: 21031 });
|
||||
expect(rangeS).toEqual({ text: 21, value: 21 });
|
||||
});
|
||||
|
||||
it('should pass the default interval value', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user