I recently ran into an issue while trying to use Loki fields as variables on a Grafana dashboard. Specifically, I could only extract Label names
or Label values
, which wasn’t exactly what I needed.
After some experimentation, I found a workaround that I thought might be useful for others facing a similar issue. The solution involved using the yesoreyeram-infinity-datasource plugin to directly query Loki, and then parsing the necessary fields.
Here’s how I did it:
-
In the URL Query Params section, I specified a query that would return a single entry for each field value. In my case, the query was:
count(count_over_time({kind="event", env="live"} | logfmt [1h])) by (view_name)
This query aggregates logs from a specificview_name
over one hour. -
The result was a list of values that I could use as variables for my dashboard:
-
Finally, I was able to parse them using UQL and use these values in my dashboard.
The result was exactly what I needed, and I hope this helps others who might run into the same challenge!