Grafana/Loki: How to use multi-select template variable with LogQL?

Viewed 1186

I have a custom template variable that displays the following comma seperated values: info, error, warning, debug. The name of the variable is $Level with multi-select enabled. I need it to have so when you select more than 1 value the line filter expressions will stack on each other like the following:

ex. Info + error are selected: {job="mylogs"} |="info" |="error"

Currently, I have my query setup like this: {job="mylogs"} |="$Level"

However, with the current way, it doesn't produce any logs back when I select more than 1 option. Is there way to achieve this with Grafana/Loki?

TL;DR Is there a way to format Grafana template variables in LogQL line filter expressions?

2 Answers

This works for me now:

{job="mylogs"} | json | msg_name =~ "${customer}"

I solved my question by using this expression to search for multiple values:

{job="mylogs"} |~ "($Level|$Level|$Level|$Level)"

However, this is not a very neat solution. What if I had a custom list of 25+ values. While this solves my immediate problem does anyone a know a more elegant solution?

UPDATE: solution to above problem is just to use this:

{job="mylogs"} |~ "($Level)"

Query automatically expands.

Related