weaveworks / grafanalib

Python library for building Grafana dashboards
Apache License 2.0
1.85k stars 307 forks source link

Add Loki target #657

Closed AndiDog closed 1 week ago

AndiDog commented 3 months ago

What does this do?

Loki targets require the "datasource": {"type": "loki", "uid": "[...]"} field split in order to work in Grafana – as tested in Grafana Cloud which would give me cryptic error messages otherwise.

Why is it a good idea?

Loki is a great way to quickly put together custom dashboards if only (parseable) logs are available for an application, but not metrics. There was no previous example how to use grafanalib for Loki queries.

Questions

I added a basic test. Not sure if I should add an example or more documentation.

Also, I made the LokiTarget a standalone class, not based on Target, since the "base fields" in Target are not desired (e.g. adding the field query or others could lead to errors, I think).