grafana/dashboard-linter

Variable substitution in promql

rgeyer opened this issue · 0 comments

It is perfectly valid for promql to use global, and dashboard templated variables throughout, including in range vector selectors.

Currently, promql which makes use of this will fail. An example is in the kubernetes mixin, on the network panels, this is used heavily in the form of [$interval:$resolution] and results in errors like the one shown below.

[panel-promql-rule] 'Kubernetes / Networking / Cluster': Dashboard 'Kubernetes / Networking / Cluster', panel 'Rate of TCP Retransmits out of all sent segments' invalid PromQL query 'sort_desc(sum(rate(node_netstat_Tcp_RetransSegs{cluster="$cluster"}[$interval:$resolution]) / rate(node_netstat_Tcp_OutSegs{cluster="$cluster"}[$interval:$resolution])) by (instance))': 1:69: parse error: bad duration syntax: ""

The linter should replace all global variables with a sane/unique value which can be validated against.

The linter should also replace all dashboard templated variables with a sane placeholder value, allowing it to be properly evaluated as promql.

This was solved in the closed-source iteration of this dashboard linter in https://github.com/grafana/cloud-onboarding/pull/412, and something similar should be implemented here.