<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Geohash on Jorge Luis Betancourt</title><link>https://jorgelbg.me/tags/geohash/</link><description>Recent content in Geohash on Jorge Luis Betancourt</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 18 Mar 2020 00:00:00 +0100</lastBuildDate><atom:link href="https://jorgelbg.me/tags/geohash/index.xml" rel="self" type="application/rss+xml"/><item><title>Displaying geohash tags from a Loki datasource in a Grafana Worldmap Panel</title><link>https://jorgelbg.me/2020/03/displaying-geohash-tags-from-a-loki-datasource-in-a-grafana-worldmap-panel/</link><pubDate>Wed, 18 Mar 2020 00:00:00 +0100</pubDate><guid>https://jorgelbg.me/2020/03/displaying-geohash-tags-from-a-loki-datasource-in-a-grafana-worldmap-panel/</guid><description>&lt;blockquote&gt;&#10;&lt;h3 id="-loki-v2x"&gt;🚧 Loki v2.x&lt;/h3&gt;&#10;&lt;p&gt;Loki v2.0 included a new set of features to the query language that allows extraction of labels at&#10;query time, unlocking new possibilities. This means that previously we would need to have the&#10;&lt;code&gt;geohash&lt;/code&gt; information as a label (which is not a great idea). Loki works best when you have a small&#10;set of labels (with &lt;a href="https://grafana.com/blog/2020/04/21/how-labels-in-loki-can-make-log-queries-faster-and-easier/"&gt;no high&#10;cardinality&lt;/a&gt;).&#10;A &lt;code&gt;geohash&lt;/code&gt; field is a very bad candidate for a label 🙃, in our defense before Loki v2.0 this was&#10;the only way of using the &lt;code&gt;geohash&lt;/code&gt; in the worldmap plugin.&lt;/p&gt;&#10;&lt;p&gt;With the new &lt;a href="https://grafana.com/docs/loki/latest/logql/#parser-expression"&gt;Parser expressions&lt;/a&gt; we&#10;can extract labels (at query time) and used them as normal labels in our queries. For instance,&#10;instead of using the old:&lt;/p&gt;&#10;&#10;&lt;div class="code-frame"&gt;&#10; &lt;div class="code-bar" aria-hidden="true"&gt;&#10; &lt;span class="code-dots"&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&#10; &lt;span class="code-lang"&gt;js&lt;/span&gt;&#10; &lt;/div&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count_over_time&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;geohash&lt;/span&gt;&lt;span class="o"&gt;=~&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;.+&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;}[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="nx"&gt;by&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;geohash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;which expects the geo information in a &lt;code&gt;geohash&lt;/code&gt; label. We can instead use the &lt;code&gt;| logfmt&lt;/code&gt; parser&#10;expression to extract the &lt;code&gt;geohash&lt;/code&gt; information from the payload into a label at query time.&lt;/p&gt;&#10;&#10;&lt;div class="code-frame"&gt;&#10; &lt;div class="code-bar" aria-hidden="true"&gt;&#10; &lt;span class="code-dots"&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&#10; &lt;span class="code-lang"&gt;js&lt;/span&gt;&#10; &lt;/div&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count_over_time&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;domain&lt;/span&gt;&lt;span class="o"&gt;=~&lt;/span&gt;&lt;span class="s2"&gt;&amp;#34;jorgelbg.me&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;logfmt&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="nx"&gt;by&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;geohash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10;&lt;/div&gt;&#10;&lt;p&gt;This has the advantage of not polluting our set of identifiable labels and helping to keep Loki&#10;queries as fast as possible.&lt;/p&gt;&#10;&lt;p&gt;Note: Beside the &lt;code&gt;| logfmt&lt;/code&gt; parser it is also possible to use the &lt;code&gt;| json&lt;/code&gt; one if the payload sent&#10;to Loki is in the JSON format.&lt;/p&gt;&#10;&lt;/blockquote&gt;</description></item></channel></rss>