@@ -7,6 +7,37 @@ description: >
77tags : ["grafana", "loki", "worldmap", "geohash"]
88---
99
10+ > ### 🚧 Loki v2.x
11+ >
12+ > Loki v2.0 included a new set of features to the query language that allows extraction of labels at
13+ > query time, unlocking new possibilities. This means that previously we would need to have the
14+ > ` geohash ` information as a label (which is not a great idea). Loki works best when you have a small
15+ > set of labels (with [ no high
16+ > cardinality] ( https://grafana.com/blog/2020/04/21/how-labels-in-loki-can-make-log-queries-faster-and-easier/ ) ).
17+ > A ` geohash ` field is a very bad candidate for a label 🙃, in our defense before Loki v2.0 this was
18+ > the only way of using the ` geohash ` in the worldmap plugin.
19+ >
20+ > With the new [ Parser expressions] ( https://grafana.com/docs/loki/latest/logql/#parser-expression ) we
21+ > can extract labels (at query time) and used them as normal labels in our queries. For instance,
22+ > instead of using the old:
23+ >
24+ > ``` js
25+ > sum (count_over_time ({geohash= ~ " .+" }[1h ])) by (geohash)
26+ > ` ` `
27+ >
28+ > which expects the geo information in a ` geohash` label. We can instead use the ` | logfmt` parser
29+ > expression to extract the ` geohash` information from the payload into a label at query time.
30+ >
31+ > ` ` ` js
32+ > sum (count_over_time ({domain= ~ " jorgelbg.me" } | logfmt [5m ])) by (geohash)
33+ > ` ` `
34+ >
35+ > This has the advantage of not polluting our set of identifiable labels and helping to keep Loki
36+ > queries as fast as possible.
37+ >
38+ > Note: Beside the ` | logfmt` parser it is also possible to use the ` | json` one if the payload sent
39+ > to Loki is in the JSON format.
40+
1041[Loki](https://grafana.com/oss/loki/) is a new~ish project from [Grafana](https://grafana.com), yes
1142the same company behind the popular open-source observability platform. Loki itself is a
1243horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus.
0 commit comments