Grafana Loki
One fix in grafana/loki, maintained by Grafana Labs.
Back to all open-source fixesAbout Grafana Loki
Grafana Loki is a horizontally scalable, multi-tenant log aggregation system inspired by Prometheus. Instead of indexing full log contents it indexes labels, and it is queried with LogQL, which includes parsers like json and logfmt to extract fields from log lines at query time.
My work on it
My contribution to Loki is in the LogQL query engine’s parsers. I fixed a bug where renaming a field with the logfmt parser could give a label the wrong value depending on key order in the log line, and brought logfmt’s behavior in line with the json parser. The wrong values had been flowing silently into filters and aggregations.
Consistent label renaming in the logfmt parser
The problem. When logfmt renamed a key to a label name that also appeared as a key in the log line, the line’s own key could overwrite the renamed value, so the result depended on which key came last. Queries like sum by (status) silently grouped on the wrong values, while the json parser handled the same case correctly.
The fix. The parser now only extracts a key when it is the source of a requested rename. I kept the change deliberately minimal and documented a related edge case as out of scope.
How I tested it. Added test cases for both key orders; the previously failing order now passes, along with the rest of the package tests.