This rule ensures that all Loki queries in a dashboard use the $__auto
variable for range vector selectors. Using $__auto
allows for dynamic adjustment of the range based on the dashboard's time range and resolution, providing more accurate and performant queries.
Using $__auto
instead of hard-coded time ranges like [5m]
provides several benefits:
- Consistency: It ensures a consistent approach across all Loki queries in the dashboard.
- Query type optimization: It correctly uses
$__interval
for "Range" queries and$__range
for "Instant" queries, optimizing the query for the specific type being used. - Versatility: The
$__auto
variable is automatically substituted with the step value for range queries, and with the selected time range's value (computed from the starting and ending times) for instant queries, making it suitable for various query types.
A detailed explanation can be found in the Grafana Cloud documentation.
sum(count_over_time({job="mysql"} |= "duration" [5m]))
sum(count_over_time({job="mysql"} |= "duration" [$__auto]))
There may be cases where a specific, fixed time range is required for a particular query. In such cases, you may wish to create a lint exclusion for this rule.