How to add label filters for labels extracted using Pattern operation

I have a dashboard panel created with Grafana and Loki as the data source. I use Pattern to extract the log pattern and the Extract Fields transformation to extract the fields from this pattern.

filename="/var/log/extracted.log"} | pattern <time> SERVERID=<serverID> THREADID=<threadID> KEYID=<keyID> TASK=<task> DURATION=<duration>

I am trying to add label filters to the panel so the users can see the results based on a specific serverId, taskId, and keyID separately. Is there a way I can do this?

I have added a screenshot of my current panel

1 Like

Use this

Hi,
If you’re using variables to list the specific serverId, taskId, etc and you have them in fields (toggle Table view and the taskId etc are columns), you can use transformation Filter by Values.
Another way you could probably (I’m not much of Loki user) filter the message on the query like {filename="/var/log/extracted.log", message=~"SERVERID=${serverId} .* TASKID=${taskId}"} just make sure the variables default to .* (although I’m more sure of the transformation approach, this one would be more performant).

1 Like