Use of embedded multi-value variables in regex

Hi, I’m new to Grafana so apologies if I’m missing something obvious.

I’m using a single (Prometheus/Thanos) data source - Grafana is configured to pull data from the Thanos query component. At the moment the Thanos query component has access to 2 Prometheus instances. Each of these Prometheus instances has a number of ‘external_labels’ - one of which is ‘cluster’ which I use as a variable in Grafana to focus the scope of data in my graphs.

I’m using Grafana v5.4.3 (6539180)

I’m running into trouble when I attempt to embed variables in the Regex field of Query Options of other variables - but only when the value of said embedded variables have multiple values. This is probably easier to illustrate:

If I select a single $cluster instance from my graph (e.g. k8s.c0.ap-southeast-1.example.com) and then view the $instance variable, the Preview of values is as I expect - i.e. the k8s API nodes are correctly filtered according to their $cluster:
variable-instance-single-cluster-select

Where I run into problems is if I select multiple clusters - e.g. k8s.c0.ap-southeast-1.example.com + k8s.c0.ap-northeast-1.example.com:
variable-instance-multi-cluster-select

Notice in this case the Preview of values is now erroneously $cluster values, not $instance values. I suspect that in this case, $cluster expands as a capture - e.g.

/.*cluster="$cluster".*instance="([^"]+)".*/

expands to

/.*cluster="(k8s.c0.ap-southeast-1.example.com|k8s.c0.ap-northeast-1.example.com)".*instance="([^"]+)".*/

which results in two capture groups and appears to override my intended capture target for $instance.

If I’m correct, surely the expansion should instead use a non-capturing group?

/.*cluster="(?:k8s.c0.ap-southeast-1.example.com|k8s.c0.ap-northeast-1.example.com)".*instance="([^"]+)".*/

Am I missing something or going about this the wrong way? Thanks if you’ve got this far - I’d appreciate any help solving this.

Cheers

Nick

1 Like

I hit this as well, and filed a feature request.