<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>LogQL on Grafana Labs</title><link>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/</link><description>Recent content in LogQL on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/enterprise-logs/v1.9.x/loki/logql/index.xml" rel="self" type="application/rss+xml"/><item><title>Log queries</title><link>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/log_queries/</link><pubDate>Mon, 14 Apr 2025 21:05:47 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/log_queries/</guid><content><![CDATA[&lt;h1 id=&#34;log-queries&#34;&gt;Log queries&lt;/h1&gt;
&lt;p&gt;All LogQL queries contain a &lt;strong&gt;log stream selector&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;../query_components.png&#34;
  alt=&#34;parts of a query&#34;/&gt;&lt;/p&gt;
&lt;p&gt;Optionally, the log stream selector can be followed by a &lt;strong&gt;log pipeline&lt;/strong&gt;. A log pipeline is a set of stage expressions that are chained together and applied to the selected log streams. Each expression can filter out, parse, or mutate log lines and their respective labels.&lt;/p&gt;
&lt;p&gt;The following example shows a full log query in action:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{container=&amp;#34;query-frontend&amp;#34;,namespace=&amp;#34;loki-dev&amp;#34;} |= &amp;#34;metrics.go&amp;#34; | logfmt | duration &amp;gt; 10s and throughput_mb &amp;lt; 500&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The query is composed of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;a log stream selector &lt;code&gt;{container=&amp;quot;query-frontend&amp;quot;,namespace=&amp;quot;loki-dev&amp;quot;}&lt;/code&gt; which targets the &lt;code&gt;query-frontend&lt;/code&gt; container  in the &lt;code&gt;loki-dev&lt;/code&gt; namespace.&lt;/li&gt;
&lt;li&gt;a log pipeline &lt;code&gt;|= &amp;quot;metrics.go&amp;quot; | logfmt | duration &amp;gt; 10s and throughput_mb &amp;lt; 500&lt;/code&gt; which will filter out log that contains the word &lt;code&gt;metrics.go&lt;/code&gt;, then parses each log line to extract more labels and filter with them.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;To avoid escaping special characters you can use the &lt;code&gt;`&lt;/code&gt;(backtick) instead of &lt;code&gt;&amp;quot;&lt;/code&gt; when quoting strings.
For example &lt;code&gt;`\w&#43;`&lt;/code&gt; is the same as &lt;code&gt;&amp;quot;\\w&#43;&amp;quot;&lt;/code&gt;.
This is specially useful when writing a regular expression which contains multiple backslashes that require escaping.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;log-stream-selector&#34;&gt;Log stream selector&lt;/h2&gt;
&lt;p&gt;The stream selector determines which log streams to include in a query&amp;rsquo;s results.
A log stream is a unique source of log content, such as a file.
A more granular log stream selector then reduces the number of searched streams to a manageable volume.
This means that the labels passed to the log stream selector will affect the relative performance of the query&amp;rsquo;s execution.&lt;/p&gt;
&lt;p&gt;The log stream selector is specified by one or more comma-separated key-value pairs. Each key is a log label and each value is that label&amp;rsquo;s value.
Curly braces (&lt;code&gt;{&lt;/code&gt; and &lt;code&gt;}&lt;/code&gt;) delimit the stream selector.&lt;/p&gt;
&lt;p&gt;Consider this stream selector:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{app=&amp;#34;mysql&amp;#34;,name=&amp;#34;mysql-backup&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;All log streams that have both a label of &lt;code&gt;app&lt;/code&gt; whose value is &lt;code&gt;mysql&lt;/code&gt;
and a label of &lt;code&gt;name&lt;/code&gt; whose value is &lt;code&gt;mysql-backup&lt;/code&gt; will be included in
the query results.
A stream may contain other pairs of labels and values,
but only the specified pairs within the stream selector are used to determine
which streams will be included within the query results.&lt;/p&gt;
&lt;p&gt;The same rules that apply for &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/querying/basics/#instant-vector-selectors&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Prometheus Label Selectors&lt;/a&gt; apply for Grafana Loki log stream selectors.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;=&lt;/code&gt; operator after the label name is a &lt;strong&gt;label matching operator&lt;/strong&gt;.
The following label matching operators are supported:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;=&lt;/code&gt;: exactly equal&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt;: not equal&lt;/li&gt;
&lt;li&gt;&lt;code&gt;=~&lt;/code&gt;: regex matches&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!~&lt;/code&gt;: regex does not match&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Regex log stream examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{name =~ &amp;quot;mysql.&#43;&amp;quot;}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{name !~ &amp;quot;mysql.&#43;&amp;quot;}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{name !~ `mysql-\d&#43;`}&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;=~&lt;/code&gt; regex operator is fully anchored, meaning regex must match against the &lt;em&gt;entire&lt;/em&gt; string, including newlines. The regex &lt;code&gt;.&lt;/code&gt; character does not match newlines by default. If you want the regex dot character to match newlines you can use the single-line flag, like so: &lt;code&gt;(?s)search_term.&#43;&lt;/code&gt; matches &lt;code&gt;search_term\n&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;log-pipeline&#34;&gt;Log pipeline&lt;/h2&gt;
&lt;p&gt;A log pipeline can be appended to a log stream selector to further process and filter log streams. It is composed of a set of expressions. Each expression is executed in left to right sequence for each log line. If an expression filters out a log line, the pipeline will stop processing the current log line and start processing the next log line.&lt;/p&gt;
&lt;p&gt;Some expressions can mutate the log content and respective labels,
which will be then be available for further filtering and processing in subsequent expressions.
An example that mutates is the expression&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;| line_format &amp;#34;{{.status_code}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Log pipeline expressions fall into one of three categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Filtering expressions: &lt;a href=&#34;#line-filter-expression&#34;&gt;line filter expressions&lt;/a&gt;
and
&lt;a href=&#34;#label-filter-expression&#34;&gt;label filter expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#parser-expression&#34;&gt;Parsing expressions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Formatting expressions: &lt;a href=&#34;#line-format-expression&#34;&gt;line format expressions&lt;/a&gt;
and
&lt;a href=&#34;#labels-format-expression&#34;&gt;label format expressions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;line-filter-expression&#34;&gt;Line filter expression&lt;/h3&gt;
&lt;p&gt;The line filter expression does a distributed &lt;code&gt;grep&lt;/code&gt;
over the aggregated logs from the matching log streams.
It searches the contents of the log line,
discarding those lines that do not match the case sensitive expression.&lt;/p&gt;
&lt;p&gt;Each line filter expression has a &lt;strong&gt;filter operator&lt;/strong&gt;
followed by text or a regular expression.
These filter operators are supported:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;|=&lt;/code&gt;: Log line contains string&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt;: Log line does not contain string&lt;/li&gt;
&lt;li&gt;&lt;code&gt;|~&lt;/code&gt;: Log line contains a match to the regular expression&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!~&lt;/code&gt;: Log line does not contain a match to the regular expression&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Line filter expression examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Keep log lines that have the substring &amp;ldquo;error&amp;rdquo;:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;|= &amp;#34;error&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A complete query using this example:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{job=&amp;#34;mysql&amp;#34;} |= &amp;#34;error&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Discard log lines that have the substring &amp;ldquo;kafka.server:type=ReplicaManager&amp;rdquo;:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;!= &amp;#34;kafka.server:type=ReplicaManager&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A complete query using this example:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{instance=~&amp;#34;kafka-[23]&amp;#34;,name=&amp;#34;kafka&amp;#34;} != &amp;#34;kafka.server:type=ReplicaManager&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Keep log lines that contain a substring that starts with &lt;code&gt;tsdb-ops&lt;/code&gt; and ends with &lt;code&gt;io:2003&lt;/code&gt;. A complete query with a regular expression:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{name=&amp;#34;kafka&amp;#34;} |~ &amp;#34;tsdb-ops.*io:2003&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Keep log lines that contain a substring that starts with &lt;code&gt;error=&lt;/code&gt;,
and is followed by 1 or more word characters. A complete query with a regular expression:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{name=&amp;#34;cassandra&amp;#34;} |~  `error=\w&amp;#43;`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Filter operators can be chained.
Filters are applied sequentially.
Query results will have satisfied every filter.
This complete query example will give results that include the string &lt;code&gt;error&lt;/code&gt;,
and do not include the string &lt;code&gt;timeout&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;mysql&amp;#34;} |= &amp;#34;error&amp;#34; != &amp;#34;timeout&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When using &lt;code&gt;|~&lt;/code&gt; and &lt;code&gt;!~&lt;/code&gt;, Go (as in &lt;a href=&#34;https://golang.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Golang&lt;/a&gt;) &lt;a href=&#34;https://github.com/google/re2/wiki/Syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;RE2 syntax&lt;/a&gt; regex may be used.
The matching is case-sensitive by default.
Switch to case-insensitive matching by prefixing the regular expression
with &lt;code&gt;(?i)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;While line filter expressions could be placed anywhere within a log pipeline,
it is almost always better to have them at the beginning.
Placing them at the beginning improves the performance of the query,
as it only does further processing when a line matches.
For example,
while the results will be the same,
the query specified with&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{job=&amp;#34;mysql&amp;#34;} |= &amp;#34;error&amp;#34; | json | line_format &amp;#34;{{.err}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;will always run faster than&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{job=&amp;#34;mysql&amp;#34;} | json | line_format &amp;#34;{{.message}}&amp;#34; |= &amp;#34;error&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Line filter expressions are the fastest way to filter logs once the
log stream selectors have been applied.&lt;/p&gt;
&lt;p&gt;Line filter expressions have support matching IP addresses. See &lt;a href=&#34;../ip/&#34;&gt;Matching IP addresses&lt;/a&gt; for details.&lt;/p&gt;
&lt;h3 id=&#34;label-filter-expression&#34;&gt;Label filter expression&lt;/h3&gt;
&lt;p&gt;Label filter expression allows filtering log line using their original and extracted labels. It can contain multiple predicates.&lt;/p&gt;
&lt;p&gt;A predicate contains a &lt;strong&gt;label identifier&lt;/strong&gt;, an &lt;strong&gt;operation&lt;/strong&gt; and a &lt;strong&gt;value&lt;/strong&gt; to compare the label with.&lt;/p&gt;
&lt;p&gt;For example with &lt;code&gt;cluster=&amp;quot;namespace&amp;quot;&lt;/code&gt; the cluster is the label identifier, the operation is &lt;code&gt;=&lt;/code&gt; and the value is &amp;ldquo;namespace&amp;rdquo;. The label identifier is always on the right side of the operation.&lt;/p&gt;
&lt;p&gt;We support multiple &lt;strong&gt;value&lt;/strong&gt; types which are automatically inferred from the query input.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;String&lt;/strong&gt; is double quoted or backticked such as &lt;code&gt;&amp;quot;200&amp;quot;&lt;/code&gt; or `&lt;code&gt;us-central1&lt;/code&gt;`.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;https://golang.org/pkg/time/#ParseDuration&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Duration&lt;/a&gt;&lt;/strong&gt; is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as &amp;ldquo;300ms&amp;rdquo;, &amp;ldquo;1.5h&amp;rdquo; or &amp;ldquo;2h45m&amp;rdquo;. Valid time units are &amp;ldquo;ns&amp;rdquo;, &amp;ldquo;us&amp;rdquo; (or &amp;ldquo;µs&amp;rdquo;), &amp;ldquo;ms&amp;rdquo;, &amp;ldquo;s&amp;rdquo;, &amp;ldquo;m&amp;rdquo;, &amp;ldquo;h&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Number&lt;/strong&gt; are floating-point number (64bits), such as&lt;code&gt;250&lt;/code&gt;, &lt;code&gt;89.923&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bytes&lt;/strong&gt; is a sequence of decimal numbers, each with optional fraction and a unit suffix, such as &amp;ldquo;42MB&amp;rdquo;, &amp;ldquo;1.5Kib&amp;rdquo; or &amp;ldquo;20b&amp;rdquo;. Valid bytes units are &amp;ldquo;b&amp;rdquo;, &amp;ldquo;kib&amp;rdquo;, &amp;ldquo;kb&amp;rdquo;, &amp;ldquo;mib&amp;rdquo;, &amp;ldquo;mb&amp;rdquo;, &amp;ldquo;gib&amp;rdquo;,  &amp;ldquo;gb&amp;rdquo;, &amp;ldquo;tib&amp;rdquo;, &amp;ldquo;tb&amp;rdquo;, &amp;ldquo;pib&amp;rdquo;, &amp;ldquo;pb&amp;rdquo;, &amp;ldquo;eib&amp;rdquo;, &amp;ldquo;eb&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;String type work exactly like Prometheus label matchers use in &lt;a href=&#34;#log-stream-selector&#34;&gt;log stream selector&lt;/a&gt;. This means you can use the same operations (&lt;code&gt;=&lt;/code&gt;,&lt;code&gt;!=&lt;/code&gt;,&lt;code&gt;=~&lt;/code&gt;,&lt;code&gt;!~&lt;/code&gt;).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The string type is the only one that can filter out a log line with a label &lt;code&gt;__error__&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Using Duration, Number and Bytes will convert the label value prior to comparision and support the following comparators:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;==&lt;/code&gt; or &lt;code&gt;=&lt;/code&gt; for equality.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt; for inequality.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;gt;=&lt;/code&gt; for greater than and greater than or equal.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;lt;=&lt;/code&gt; for lesser than and lesser than or equal.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For instance, &lt;code&gt;logfmt | duration &amp;gt; 1m and bytes_consumed &amp;gt; 20MB&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If the conversion of the label value fails, the log line is not filtered and an &lt;code&gt;__error__&lt;/code&gt; label is added. To filters those errors see the &lt;a href=&#34;../#pipeline-errors&#34;&gt;pipeline errors&lt;/a&gt; section.&lt;/p&gt;
&lt;p&gt;You can chain multiple predicates using &lt;code&gt;and&lt;/code&gt; and &lt;code&gt;or&lt;/code&gt; which respectively express the &lt;code&gt;and&lt;/code&gt; and &lt;code&gt;or&lt;/code&gt; binary operations. &lt;code&gt;and&lt;/code&gt; can be equivalently expressed by a comma, a space or another pipe. Label filters can be place anywhere in a log pipeline.&lt;/p&gt;
&lt;p&gt;This means that all the following expressions are equivalent:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;| duration &amp;gt;= 20ms or size == 20kb and method!~&amp;#34;2..&amp;#34;
| duration &amp;gt;= 20ms or size == 20kb | method!~&amp;#34;2..&amp;#34;
| duration &amp;gt;= 20ms or size == 20kb , method!~&amp;#34;2..&amp;#34;
| duration &amp;gt;= 20ms or size == 20kb  method!~&amp;#34;2..&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;By default the precedence of multiple predicates is right to left. You can wrap predicates with parenthesis to force a different precedence left to right.&lt;/p&gt;
&lt;p&gt;For example the following are equivalent.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;| duration &amp;gt;= 20ms or method=&amp;#34;GET&amp;#34; and size &amp;lt;= 20KB
| ((duration &amp;gt;= 20ms or method=&amp;#34;GET&amp;#34;) and size &amp;lt;= 20KB)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;It will evaluate first &lt;code&gt;duration &amp;gt;= 20ms or method=&amp;quot;GET&amp;quot;&lt;/code&gt;. To evaluate first &lt;code&gt;method=&amp;quot;GET&amp;quot; and size &amp;lt;= 20KB&lt;/code&gt;, make sure to use proper parenthesis as shown below.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;| duration &amp;gt;= 20ms or (method=&amp;#34;GET&amp;#34; and size &amp;lt;= 20KB)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Label filter expressions are the only expression allowed after the unwrap expression. This is mainly to allow filtering errors from the metric extraction.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Label filter expressions have support matching IP addresses. See &lt;a href=&#34;../ip/&#34;&gt;Matching IP addresses&lt;/a&gt; for details.&lt;/p&gt;
&lt;h3 id=&#34;parser-expression&#34;&gt;Parser expression&lt;/h3&gt;
&lt;p&gt;Parser expression can parse and extract labels from the log content. Those extracted labels can then be used for filtering using &lt;a href=&#34;#label-filter-expression&#34;&gt;label filter expressions&lt;/a&gt; or for &lt;a href=&#34;../metric_queries&#34;&gt;metric aggregations&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Extracted label keys are automatically sanitized by all parsers, to follow Prometheus metric name convention.(They can only contain ASCII letters and digits, as well as underscores and colons. They cannot start with a digit.)&lt;/p&gt;
&lt;p&gt;For instance, the pipeline &lt;code&gt;| json&lt;/code&gt; will produce the following mapping:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{ &amp;#34;a.b&amp;#34;: {c: &amp;#34;d&amp;#34;}, e: &amp;#34;f&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;-&amp;gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;{a_b_c=&amp;#34;d&amp;#34;, e=&amp;#34;f&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In case of errors, for instance if the line is not in the expected format, the log line won&amp;rsquo;t be filtered but instead will get a new &lt;code&gt;__error__&lt;/code&gt; label added.&lt;/p&gt;
&lt;p&gt;If an extracted label key name already exists in the original log stream, the extracted label key will be suffixed with the &lt;code&gt;_extracted&lt;/code&gt; keyword to make the distinction between the two labels. You can forcefully override the original label using a &lt;a href=&#34;#labels-format-expression&#34;&gt;label formatter expression&lt;/a&gt;. However if an extracted key appears twice, only the latest label value will be kept.&lt;/p&gt;
&lt;p&gt;Loki supports  &lt;a href=&#34;#json&#34;&gt;JSON&lt;/a&gt;, &lt;a href=&#34;#logfmt&#34;&gt;logfmt&lt;/a&gt;, &lt;a href=&#34;#pattern&#34;&gt;pattern&lt;/a&gt;, &lt;a href=&#34;#regular-expression&#34;&gt;regexp&lt;/a&gt; and &lt;a href=&#34;#unpack&#34;&gt;unpack&lt;/a&gt; parsers.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s easier to use the predefined parsers &lt;code&gt;json&lt;/code&gt; and &lt;code&gt;logfmt&lt;/code&gt; when you can. If you can&amp;rsquo;t, the &lt;code&gt;pattern&lt;/code&gt; and &lt;code&gt;regexp&lt;/code&gt; parsers can be used for log lines with an unusual structure. The &lt;code&gt;pattern&lt;/code&gt; parser is easier and faster to write; it also outperforms the &lt;code&gt;regexp&lt;/code&gt; parser.
Multiple parsers can be used by a single log pipeline. This is useful for parsing complex logs. There are examples in &lt;a href=&#34;#multiple-parsers&#34;&gt;Multiple parsers&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;json&#34;&gt;JSON&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;json&lt;/strong&gt; parser operates in two modes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;without&lt;/strong&gt; parameters:&lt;/p&gt;
&lt;p&gt;Adding &lt;code&gt;| json&lt;/code&gt; to your pipeline will extract all json properties as labels if the log line is a valid json document.
Nested properties are flattened into label keys using the &lt;code&gt;_&lt;/code&gt; separator.&lt;/p&gt;
&lt;p&gt;Note: &lt;strong&gt;Arrays are skipped&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example the json parsers will extract from the following document:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{
    &amp;#34;protocol&amp;#34;: &amp;#34;HTTP/2.0&amp;#34;,
    &amp;#34;servers&amp;#34;: [&amp;#34;129.0.1.1&amp;#34;,&amp;#34;10.2.1.3&amp;#34;],
    &amp;#34;request&amp;#34;: {
        &amp;#34;time&amp;#34;: &amp;#34;6.032&amp;#34;,
        &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;,
        &amp;#34;host&amp;#34;: &amp;#34;foo.grafana.net&amp;#34;,
        &amp;#34;size&amp;#34;: &amp;#34;55&amp;#34;,
        &amp;#34;headers&amp;#34;: {
          &amp;#34;Accept&amp;#34;: &amp;#34;*/*&amp;#34;,
          &amp;#34;User-Agent&amp;#34;: &amp;#34;curl/7.68.0&amp;#34;
        }
    },
    &amp;#34;response&amp;#34;: {
        &amp;#34;status&amp;#34;: 401,
        &amp;#34;size&amp;#34;: &amp;#34;228&amp;#34;,
        &amp;#34;latency_seconds&amp;#34;: &amp;#34;6.031&amp;#34;
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following list of labels:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;protocol&amp;#34; =&amp;gt; &amp;#34;HTTP/2.0&amp;#34;
&amp;#34;request_time&amp;#34; =&amp;gt; &amp;#34;6.032&amp;#34;
&amp;#34;request_method&amp;#34; =&amp;gt; &amp;#34;GET&amp;#34;
&amp;#34;request_host&amp;#34; =&amp;gt; &amp;#34;foo.grafana.net&amp;#34;
&amp;#34;request_size&amp;#34; =&amp;gt; &amp;#34;55&amp;#34;
&amp;#34;response_status&amp;#34; =&amp;gt; &amp;#34;401&amp;#34;
&amp;#34;response_size&amp;#34; =&amp;gt; &amp;#34;228&amp;#34;
&amp;#34;response_latency_seconds&amp;#34; =&amp;gt; &amp;#34;6.031&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;with&lt;/strong&gt; parameters:&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;| json label=&amp;quot;expression&amp;quot;, another=&amp;quot;expression&amp;quot;&lt;/code&gt; in your pipeline will extract only the
specified json fields to labels. You can specify one or more expressions in this way, the same
as &lt;a href=&#34;#labels-format-expression&#34;&gt;&lt;code&gt;label_format&lt;/code&gt;&lt;/a&gt;; all expressions must be quoted.&lt;/p&gt;
&lt;p&gt;Currently, we only support field access (&lt;code&gt;my.field&lt;/code&gt;, &lt;code&gt;my[&amp;quot;field&amp;quot;]&lt;/code&gt;) and array access (&lt;code&gt;list[0]&lt;/code&gt;), and any combination
of these in any level of nesting (&lt;code&gt;my.list[0][&amp;quot;field&amp;quot;]&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;| json first_server=&amp;quot;servers[0]&amp;quot;, ua=&amp;quot;request.headers[\&amp;quot;User-Agent\&amp;quot;]&lt;/code&gt; will extract from the following document:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{
    &amp;#34;protocol&amp;#34;: &amp;#34;HTTP/2.0&amp;#34;,
    &amp;#34;servers&amp;#34;: [&amp;#34;129.0.1.1&amp;#34;,&amp;#34;10.2.1.3&amp;#34;],
    &amp;#34;request&amp;#34;: {
        &amp;#34;time&amp;#34;: &amp;#34;6.032&amp;#34;,
        &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;,
        &amp;#34;host&amp;#34;: &amp;#34;foo.grafana.net&amp;#34;,
        &amp;#34;size&amp;#34;: &amp;#34;55&amp;#34;,
        &amp;#34;headers&amp;#34;: {
          &amp;#34;Accept&amp;#34;: &amp;#34;*/*&amp;#34;,
          &amp;#34;User-Agent&amp;#34;: &amp;#34;curl/7.68.0&amp;#34;
        }
    },
    &amp;#34;response&amp;#34;: {
        &amp;#34;status&amp;#34;: 401,
        &amp;#34;size&amp;#34;: &amp;#34;228&amp;#34;,
        &amp;#34;latency_seconds&amp;#34;: &amp;#34;6.031&amp;#34;
    }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The following list of labels:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;first_server&amp;#34; =&amp;gt; &amp;#34;129.0.1.1&amp;#34;
&amp;#34;ua&amp;#34; =&amp;gt; &amp;#34;curl/7.68.0&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If an array or an object returned by an expression, it will be assigned to the label in json format.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;| json server_list=&amp;quot;servers&amp;quot;, headers=&amp;quot;request.headers&amp;quot;&lt;/code&gt; will extract:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;server_list&amp;#34; =&amp;gt; `[&amp;#34;129.0.1.1&amp;#34;,&amp;#34;10.2.1.3&amp;#34;]`
&amp;#34;headers&amp;#34; =&amp;gt; `{&amp;#34;Accept&amp;#34;: &amp;#34;*/*&amp;#34;, &amp;#34;User-Agent&amp;#34;: &amp;#34;curl/7.68.0&amp;#34;}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If the label to be extracted is same as the original JSON field, expression can be written as just &lt;code&gt;| json &amp;lt;label&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;For example, to extract &lt;code&gt;servers&lt;/code&gt; fields as label, expression can be written as following&lt;/p&gt;
&lt;p&gt;&lt;code&gt;| json servers&lt;/code&gt; will extract:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;servers&amp;#34; =&amp;gt; `[&amp;#34;129.0.1.1&amp;#34;,&amp;#34;10.2.1.3&amp;#34;]`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Note that &lt;code&gt;| json servers&lt;/code&gt; is same as &lt;code&gt;| json servers=&amp;quot;servers&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;logfmt&#34;&gt;logfmt&lt;/h4&gt;
&lt;p&gt;The &lt;strong&gt;logfmt&lt;/strong&gt; parser can be added using the &lt;code&gt;| logfmt&lt;/code&gt; and will extract all keys and values from the &lt;a href=&#34;https://brandur.org/logfmt&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;logfmt&lt;/a&gt; formatted log line.&lt;/p&gt;
&lt;p&gt;For example the following log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logfmt&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logfmt&#34;&gt;at=info method=GET path=/ host=grafana.net fwd=&amp;#34;124.133.124.161&amp;#34; service=8ms status=200&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;will get those labels extracted:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;at&amp;#34; =&amp;gt; &amp;#34;info&amp;#34;
&amp;#34;method&amp;#34; =&amp;gt; &amp;#34;GET&amp;#34;
&amp;#34;path&amp;#34; =&amp;gt; &amp;#34;/&amp;#34;
&amp;#34;host&amp;#34; =&amp;gt; &amp;#34;grafana.net&amp;#34;
&amp;#34;fwd&amp;#34; =&amp;gt; &amp;#34;124.133.124.161&amp;#34;
&amp;#34;service&amp;#34; =&amp;gt; &amp;#34;8ms&amp;#34;
&amp;#34;status&amp;#34; =&amp;gt; &amp;#34;200&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;pattern&#34;&gt;Pattern&lt;/h4&gt;
&lt;p&gt;The pattern parser allows the explicit extraction of fields from log lines by defining a pattern expression (&lt;code&gt;| pattern &amp;quot;&amp;lt;pattern-expression&amp;gt;&amp;quot;&lt;/code&gt;). The expression matches the structure of a log line.&lt;/p&gt;
&lt;p&gt;Consider this NGINX log line.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;log&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-log&#34;&gt;0.191.12.2 - - [10/Jun/2021:09:14:29 &amp;#43;0000] &amp;#34;GET /api/plugins/versioncheck HTTP/1.1&amp;#34; 200 2 &amp;#34;-&amp;#34; &amp;#34;Go-http-client/2.0&amp;#34; &amp;#34;13.76.247.102, 34.120.177.193&amp;#34; &amp;#34;TLSv1.2&amp;#34; &amp;#34;US&amp;#34; &amp;#34;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This log line can be parsed with the expression&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;ip&amp;gt; - - &amp;lt;_&amp;gt; &amp;quot;&amp;lt;method&amp;gt; &amp;lt;uri&amp;gt; &amp;lt;_&amp;gt;&amp;quot; &amp;lt;status&amp;gt; &amp;lt;size&amp;gt; &amp;lt;_&amp;gt; &amp;quot;&amp;lt;agent&amp;gt;&amp;quot; &amp;lt;_&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;to extract these fields:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;ip&amp;#34; =&amp;gt; &amp;#34;0.191.12.2&amp;#34;
&amp;#34;method&amp;#34; =&amp;gt; &amp;#34;GET&amp;#34;
&amp;#34;uri&amp;#34; =&amp;gt; &amp;#34;/api/plugins/versioncheck&amp;#34;
&amp;#34;status&amp;#34; =&amp;gt; &amp;#34;200&amp;#34;
&amp;#34;size&amp;#34; =&amp;gt; &amp;#34;2&amp;#34;
&amp;#34;agent&amp;#34; =&amp;gt; &amp;#34;Go-http-client/2.0&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A pattern expression is composed of captures and literals.&lt;/p&gt;
&lt;p&gt;A capture is a field name delimited by the &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt; characters. &lt;code&gt;&amp;lt;example&amp;gt;&lt;/code&gt; defines the field name &lt;code&gt;example&lt;/code&gt;.
An unnamed capture appears as &lt;code&gt;&amp;lt;_&amp;gt;&lt;/code&gt;. The unnamed capture skips matched content.&lt;/p&gt;
&lt;p&gt;Captures are matched from the line beginning or the previous set of literals, to the line end or the next set of literals.
If a capture is not matched, the pattern parser will stop.&lt;/p&gt;
&lt;p&gt;Literals can be any sequence of UTF-8 characters, including whitespace characters.&lt;/p&gt;
&lt;p&gt;By default, a pattern expression is anchored at the start of the log line. If the expression starts with literals, then the log line must also start with the same set of literals. Use &lt;code&gt;&amp;lt;_&amp;gt;&lt;/code&gt; at the beginning of the expression if you don&amp;rsquo;t want to anchor the expression at the start.&lt;/p&gt;
&lt;p&gt;Consider the log line&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;log&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-log&#34;&gt;level=debug ts=2021-06-10T09:24:13.472094048Z caller=logging.go:66 traceID=0568b66ad2d9294c msg=&amp;#34;POST /loki/api/v1/push (204) 16.652862ms&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To match &lt;code&gt;msg=&amp;quot;&lt;/code&gt;, use the expression:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;pattern&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-pattern&#34;&gt;&amp;lt;_&amp;gt; msg=&amp;#34;&amp;lt;method&amp;gt; &amp;lt;path&amp;gt; (&amp;lt;status&amp;gt;) &amp;lt;latency&amp;gt;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A pattern expression is invalid if&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It does not contain any named capture.&lt;/li&gt;
&lt;li&gt;It contains two consecutive captures not separated by whitespace characters.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;regular-expression&#34;&gt;Regular expression&lt;/h4&gt;
&lt;p&gt;Unlike the logfmt and json, which extract implicitly all values and takes no parameters, the regexp parser takes a single parameter &lt;code&gt;| regexp &amp;quot;&amp;lt;re&amp;gt;&amp;quot;&lt;/code&gt; which is the regular expression using the &lt;a href=&#34;https://golang.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Golang&lt;/a&gt; &lt;a href=&#34;https://github.com/google/re2/wiki/Syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;RE2 syntax&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The regular expression must contain a least one named sub-match (e.g &lt;code&gt;(?P&amp;lt;name&amp;gt;re)&lt;/code&gt;), each sub-match will extract a different label.&lt;/p&gt;
&lt;p&gt;For example the parser &lt;code&gt;| regexp &amp;quot;(?P&amp;lt;method&amp;gt;\\w&#43;) (?P&amp;lt;path&amp;gt;[\\w|/]&#43;) \\((?P&amp;lt;status&amp;gt;\\d&#43;?)\\) (?P&amp;lt;duration&amp;gt;.*)&amp;quot;&lt;/code&gt; will extract from the following line:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;log&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-log&#34;&gt;POST /api/prom/api/v1/query_range (200) 1.5s&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;those labels:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;kv&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-kv&#34;&gt;&amp;#34;method&amp;#34; =&amp;gt; &amp;#34;POST&amp;#34;
&amp;#34;path&amp;#34; =&amp;gt; &amp;#34;/api/prom/api/v1/query_range&amp;#34;
&amp;#34;status&amp;#34; =&amp;gt; &amp;#34;200&amp;#34;
&amp;#34;duration&amp;#34; =&amp;gt; &amp;#34;1.5s&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;unpack&#34;&gt;unpack&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;unpack&lt;/code&gt; parser parses a JSON log line, unpacking all embedded labels from Promtail&amp;rsquo;s &lt;a href=&#34;/docs/enterprise-logs/v1.9.x/loki/clients/promtail/stages/pack/&#34;&gt;&lt;code&gt;pack&lt;/code&gt; stage&lt;/a&gt;.
&lt;strong&gt;A special property &lt;code&gt;_entry&lt;/code&gt; will also be used to replace the original log line&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example, using &lt;code&gt;| unpack&lt;/code&gt; with the log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{
  &amp;#34;container&amp;#34;: &amp;#34;myapp&amp;#34;,
  &amp;#34;pod&amp;#34;: &amp;#34;pod-3223f&amp;#34;,
  &amp;#34;_entry&amp;#34;: &amp;#34;original log message&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;extracts the &lt;code&gt;container&lt;/code&gt; and &lt;code&gt;pod&lt;/code&gt; labels; it sets &lt;code&gt;original log message&lt;/code&gt; as the new log line.&lt;/p&gt;
&lt;p&gt;You can combine the &lt;code&gt;unpack&lt;/code&gt; and &lt;code&gt;json&lt;/code&gt; parsers (or any other parsers) if the original embedded log line is of a specific format.&lt;/p&gt;
&lt;h3 id=&#34;line-format-expression&#34;&gt;Line format expression&lt;/h3&gt;
&lt;p&gt;The line format expression can rewrite the log line content by using the &lt;a href=&#34;https://golang.org/pkg/text/template/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;text/template&lt;/a&gt; format.
It takes a single string parameter &lt;code&gt;| line_format &amp;quot;{{.label_name}}&amp;quot;&lt;/code&gt;, which is the template format. All labels are injected variables into the template and are available to use with the &lt;code&gt;{{.label_name}}&lt;/code&gt; notation.&lt;/p&gt;
&lt;p&gt;For example the following expression:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{container=&amp;#34;frontend&amp;#34;} | logfmt | line_format &amp;#34;{{.query}} {{.duration}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Will extract and rewrite the log line to only contains the query and the duration of a request.&lt;/p&gt;
&lt;p&gt;You can use double quoted string for the template or backticks &lt;code&gt;`{{.label_name}}`&lt;/code&gt; to avoid the need to escape special characters.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;line_format&lt;/code&gt; also supports &lt;code&gt;math&lt;/code&gt; functions. Example:&lt;/p&gt;
&lt;p&gt;If we have the following labels &lt;code&gt;ip=1.1.1.1&lt;/code&gt;, &lt;code&gt;status=200&lt;/code&gt; and &lt;code&gt;duration=3000&lt;/code&gt;(ms), we can divide the duration by &lt;code&gt;1000&lt;/code&gt; to get the value in seconds.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{container=&amp;#34;frontend&amp;#34;} | logfmt | line_format &amp;#34;{{.ip}} {{.status}} {{div .duration 1000}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The above query will give us the &lt;code&gt;line&lt;/code&gt; as &lt;code&gt;1.1.1.1 200 3&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;See &lt;a href=&#34;../template_functions/&#34;&gt;template functions&lt;/a&gt; to learn about available functions in the template format.&lt;/p&gt;
&lt;h3 id=&#34;labels-format-expression&#34;&gt;Labels format expression&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;| label_format&lt;/code&gt; expression can rename, modify or add labels. It takes as parameter a comma separated list of equality operations, enabling multiple operations at once.&lt;/p&gt;
&lt;p&gt;When both side are label identifiers, for example &lt;code&gt;dst=src&lt;/code&gt;, the operation will rename the &lt;code&gt;src&lt;/code&gt; label into &lt;code&gt;dst&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The right side can alternatively be a template string (double quoted or backtick), for example &lt;code&gt;dst=&amp;quot;{{.status}} {{.query}}&amp;quot;&lt;/code&gt;, in which case the &lt;code&gt;dst&lt;/code&gt; label value is replaced by the result of the &lt;a href=&#34;https://golang.org/pkg/text/template/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;text/template&lt;/a&gt; evaluation. This is the same template engine as the &lt;code&gt;| line_format&lt;/code&gt; expression, which means labels are available as variables and you can use the same list of functions.&lt;/p&gt;
&lt;p&gt;In both cases, if the destination label doesn&amp;rsquo;t exist, then a new one is created.&lt;/p&gt;
&lt;p&gt;The renaming form &lt;code&gt;dst=src&lt;/code&gt; will &lt;em&gt;drop&lt;/em&gt; the &lt;code&gt;src&lt;/code&gt; label after remapping it to the &lt;code&gt;dst&lt;/code&gt; label. However, the &lt;em&gt;template&lt;/em&gt; form will preserve the referenced labels, such that  &lt;code&gt;dst=&amp;quot;{{.src}}&amp;quot;&lt;/code&gt; results in both &lt;code&gt;dst&lt;/code&gt; and &lt;code&gt;src&lt;/code&gt; having the same value.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A single label name can only appear once per expression. This means &lt;code&gt;| label_format foo=bar,foo=&amp;quot;new&amp;quot;&lt;/code&gt; is not allowed but you can use two expressions for the desired effect: &lt;code&gt;| label_format foo=bar | label_format foo=&amp;quot;new&amp;quot;&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;log-queries-examples&#34;&gt;Log queries examples&lt;/h2&gt;
&lt;h3 id=&#34;multiple-filtering&#34;&gt;Multiple filtering&lt;/h3&gt;
&lt;p&gt;Filtering should be done first using label matchers, then line filters (when possible) and finally using label filters. The following query demonstrate this.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{cluster=&amp;#34;ops-tools1&amp;#34;, namespace=&amp;#34;loki-dev&amp;#34;, job=&amp;#34;loki-dev/query-frontend&amp;#34;} |= &amp;#34;metrics.go&amp;#34; !=&amp;#34;out of order&amp;#34; | logfmt | duration &amp;gt; 30s or status_code!=&amp;#34;200&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;multiple-parsers&#34;&gt;Multiple parsers&lt;/h3&gt;
&lt;p&gt;To extract the method and the path of the following logfmt log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;log&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-log&#34;&gt;level=debug ts=2020-10-02T10:10:42.092268913Z caller=logging.go:66 traceID=a9d4d8a928d8db1 msg=&amp;#34;POST /api/prom/api/v1/query_range (200) 1.5s&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can use multiple parsers (logfmt and regexp) like this.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;loki-ops/query-frontend&amp;#34;} | logfmt | line_format &amp;#34;{{.msg}}&amp;#34; | regexp &amp;#34;(?P&amp;lt;method&amp;gt;\\w&amp;#43;) (?P&amp;lt;path&amp;gt;[\\w|/]&amp;#43;) \\((?P&amp;lt;status&amp;gt;\\d&amp;#43;?)\\) (?P&amp;lt;duration&amp;gt;.*)&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This is possible because the &lt;code&gt;| line_format&lt;/code&gt; reformats the log line to become &lt;code&gt;POST /api/prom/api/v1/query_range (200) 1.5s&lt;/code&gt; which can then be parsed with the &lt;code&gt;| regexp ...&lt;/code&gt; parser.&lt;/p&gt;
&lt;h3 id=&#34;formatting&#34;&gt;Formatting&lt;/h3&gt;
&lt;p&gt;The following query shows how you can reformat a log line to make it easier to read on screen.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{cluster=&amp;#34;ops-tools1&amp;#34;, name=&amp;#34;querier&amp;#34;, namespace=&amp;#34;loki-dev&amp;#34;}
  |= &amp;#34;metrics.go&amp;#34; != &amp;#34;loki-canary&amp;#34;
  | logfmt
  | query != &amp;#34;&amp;#34;
  | label_format query=&amp;#34;{{ Replace .query \&amp;#34;\\n\&amp;#34; \&amp;#34;\&amp;#34; -1 }}&amp;#34;
  | line_format &amp;#34;{{ .ts}}\t{{.duration}}\ttraceID = {{.traceID}}\t{{ printf \&amp;#34;%-100.100s\&amp;#34; .query }} &amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Label formatting is used to sanitize the query while the line format reduce the amount of information and creates a tabular output.&lt;/p&gt;
&lt;p&gt;For these given log lines:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;log&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-log&#34;&gt;level=info ts=2020-10-23T20:32:18.094668233Z caller=metrics.go:81 org_id=29 traceID=1980d41501b57b68 latency=fast query=&amp;#34;{cluster=\&amp;#34;ops-tools1\&amp;#34;, job=\&amp;#34;loki-ops/query-frontend\&amp;#34;} |= \&amp;#34;query_range\&amp;#34;&amp;#34; query_type=filter range_type=range length=15m0s step=7s duration=650.22401ms status=200 throughput_mb=1.529717 total_bytes_mb=0.994659
level=info ts=2020-10-23T20:32:18.068866235Z caller=metrics.go:81 org_id=29 traceID=1980d41501b57b68 latency=fast query=&amp;#34;{cluster=\&amp;#34;ops-tools1\&amp;#34;, job=\&amp;#34;loki-ops/query-frontend\&amp;#34;} |= \&amp;#34;query_range\&amp;#34;&amp;#34; query_type=filter range_type=range length=15m0s step=7s duration=624.008132ms status=200 throughput_mb=0.693449 total_bytes_mb=0.432718&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The result would be:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;log&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-log&#34;&gt;2020-10-23T20:32:18.094668233Z	650.22401ms	    traceID = 1980d41501b57b68	{cluster=&amp;#34;ops-tools1&amp;#34;, job=&amp;#34;loki-ops/query-frontend&amp;#34;} |= &amp;#34;query_range&amp;#34;
2020-10-23T20:32:18.068866235Z	624.008132ms	traceID = 1980d41501b57b68	{cluster=&amp;#34;ops-tools1&amp;#34;, job=&amp;#34;loki-ops/query-frontend&amp;#34;} |= &amp;#34;query_range&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="log-queries">Log queries&lt;/h1>
&lt;p>All LogQL queries contain a &lt;strong>log stream selector&lt;/strong>.&lt;/p>
&lt;p>&lt;img
class="lazyload d-inline-block"
data-src="../query_components.png"
alt="parts of a query"/>&lt;/p>
&lt;p>Optionally, the log stream selector can be followed by a &lt;strong>log pipeline&lt;/strong>. A log pipeline is a set of stage expressions that are chained together and applied to the selected log streams. Each expression can filter out, parse, or mutate log lines and their respective labels.&lt;/p></description></item><item><title>Metric queries</title><link>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/metric_queries/</link><pubDate>Tue, 16 Jul 2024 15:42:20 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/metric_queries/</guid><content><![CDATA[&lt;h1 id=&#34;metric-queries&#34;&gt;Metric queries&lt;/h1&gt;
&lt;p&gt;Metric queries extend log queries by applying a function to log query results.
This powerful feature creates metrics from logs.&lt;/p&gt;
&lt;p&gt;Metric queries can be used to calculate the rate of error messages or the top N log sources with the greatest quantity of logs over the last 3 hours.&lt;/p&gt;
&lt;p&gt;Combined with parsers, metric queries can also be used to calculate metrics from a sample value within the log line, such as latency or request size.
All labels, including extracted ones, will be available for aggregations and generation of new series.&lt;/p&gt;
&lt;h2 id=&#34;range-vector-aggregation&#34;&gt;Range Vector aggregation&lt;/h2&gt;
&lt;p&gt;LogQL shares the &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/querying/basics/#range-vector-selectors&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;range vector&lt;/a&gt; concept of Prometheus.
In Grafana Loki, the selected range of samples is a range of selected log or label values.&lt;/p&gt;
&lt;p&gt;The aggregation is applied over a time duration.
Loki defines &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/querying/basics/#time-durations&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Time Durations&lt;/a&gt; with the same syntax as Prometheus.&lt;/p&gt;
&lt;p&gt;Loki supports two types of range vector aggregations: log range aggregations and unwrapped range aggregations.&lt;/p&gt;
&lt;h3 id=&#34;log-range-aggregations&#34;&gt;Log range aggregations&lt;/h3&gt;
&lt;p&gt;A log range aggregation is a query followed by a duration.
A function is applied to aggregate the query over the duration.
The duration can be placed
after the log stream selector or at end of the log pipeline.&lt;/p&gt;
&lt;p&gt;The functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;rate(log-range)&lt;/code&gt;: calculates the number of entries per second&lt;/li&gt;
&lt;li&gt;&lt;code&gt;count_over_time(log-range)&lt;/code&gt;: counts the entries for each log stream within the given range.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bytes_rate(log-range)&lt;/code&gt;: calculates the number of bytes per second for each stream.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bytes_over_time(log-range)&lt;/code&gt;: counts the amount of bytes used by each log stream for a given range.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;absent_over_time(log-range)&lt;/code&gt;: returns an empty vector if the range vector passed to it has any elements and a 1-element vector with the value 1 if the range vector passed to it has no elements. (&lt;code&gt;absent_over_time&lt;/code&gt; is useful for alerting on when no time series and logs stream exist for label combination for a certain amount of time.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Count all the log lines within the last five minutes for the MySQL job.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;count_over_time({job=&amp;#34;mysql&amp;#34;}[5m])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This aggregation includes filters and parsers.
It returns the per-second rate of all non-timeout errors within the last minutes per host for the MySQL job and only includes errors whose duration is above ten seconds.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum by (host) (rate({job=&amp;#34;mysql&amp;#34;} |= &amp;#34;error&amp;#34; != &amp;#34;timeout&amp;#34; | json | duration &amp;gt; 10s [1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;unwrapped-range-aggregations&#34;&gt;Unwrapped range aggregations&lt;/h3&gt;
&lt;p&gt;Unwrapped ranges uses extracted labels as sample values instead of log lines. However to select which label will be used within the aggregation, the log query must end with an unwrap expression and optionally a label filter expression to discard &lt;a href=&#34;../#pipeline-errors&#34;&gt;errors&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The unwrap expression is noted &lt;code&gt;| unwrap label_identifier&lt;/code&gt; where the label identifier is the label name to use for extracting sample values.&lt;/p&gt;
&lt;p&gt;Since label values are string, by default a conversion into a float (64bits) will be attempted, in case of failure the &lt;code&gt;__error__&lt;/code&gt; label is added to the sample.
Optionally the label identifier can be wrapped by a conversion function &lt;code&gt;| unwrap &amp;lt;function&amp;gt;(label_identifier)&lt;/code&gt;, which will attempt to convert the label value from a specific format.&lt;/p&gt;
&lt;p&gt;We currently support the functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;duration_seconds(label_identifier)&lt;/code&gt; (or its short equivalent &lt;code&gt;duration&lt;/code&gt;) which will convert the label value in seconds from the &lt;a href=&#34;https://golang.org/pkg/time/#ParseDuration&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;go duration format&lt;/a&gt; (e.g &lt;code&gt;5m&lt;/code&gt;, &lt;code&gt;24s30ms&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bytes(label_identifier)&lt;/code&gt; which will convert the label value to raw bytes applying the bytes unit  (e.g. &lt;code&gt;5 MiB&lt;/code&gt;, &lt;code&gt;3k&lt;/code&gt;, &lt;code&gt;1G&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Supported function for operating over unwrapped ranges are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;rate(unwrapped-range)&lt;/code&gt;: calculates per second rate of the sum of all values in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rate_counter(unwrapped-range)&lt;/code&gt;: calculates per second rate of the values in the specified interval and treating them as &amp;ldquo;counter metric&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sum_over_time(unwrapped-range)&lt;/code&gt;: the sum of all values in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avg_over_time(unwrapped-range)&lt;/code&gt;: the average value of all points in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;max_over_time(unwrapped-range)&lt;/code&gt;: the maximum value of all points in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;min_over_time(unwrapped-range)&lt;/code&gt;: the minimum value of all points in the specified interval&lt;/li&gt;
&lt;li&gt;&lt;code&gt;first_over_time(unwrapped-range)&lt;/code&gt;: the first value of all points in the specified interval&lt;/li&gt;
&lt;li&gt;&lt;code&gt;last_over_time(unwrapped-range)&lt;/code&gt;: the last value of all points in the specified interval&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stdvar_over_time(unwrapped-range)&lt;/code&gt;: the population standard variance of the values in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stddev_over_time(unwrapped-range)&lt;/code&gt;: the population standard deviation of the values in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;quantile_over_time(scalar,unwrapped-range)&lt;/code&gt;: the φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;absent_over_time(unwrapped-range)&lt;/code&gt;: returns an empty vector if the range vector passed to it has any elements and a 1-element vector with the value 1 if the range vector passed to it has no elements. (&lt;code&gt;absent_over_time&lt;/code&gt; is useful for alerting on when no time series and logs stream exist for label combination for a certain amount of time.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Except for &lt;code&gt;sum_over_time&lt;/code&gt;,&lt;code&gt;absent_over_time&lt;/code&gt; and &lt;code&gt;rate&lt;/code&gt;, unwrapped range aggregations support grouping.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;&amp;lt;aggr-op&amp;gt;([parameter,] &amp;lt;unwrapped-range&amp;gt;) [without|by (&amp;lt;label list&amp;gt;)]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Which can be used to aggregate over distinct labels dimensions by including a &lt;code&gt;without&lt;/code&gt; or &lt;code&gt;by&lt;/code&gt; clause.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;without&lt;/code&gt; removes the listed labels from the result vector, while all other labels are preserved the output. &lt;code&gt;by&lt;/code&gt; does the opposite and drops labels that are not listed in the &lt;code&gt;by&lt;/code&gt; clause, even if their label values are identical between all elements of the vector.&lt;/p&gt;
&lt;h3 id=&#34;unwrapped-examples&#34;&gt;Unwrapped examples&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;quantile_over_time(0.99,
  {cluster=&amp;#34;ops-tools1&amp;#34;,container=&amp;#34;ingress-nginx&amp;#34;}
    | json
    | __error__ = &amp;#34;&amp;#34;
    | unwrap request_time [1m]) by (path)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example calculates the p99 of the nginx-ingress latency by path.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum by (org_id) (
  sum_over_time(
  {cluster=&amp;#34;ops-tools1&amp;#34;,container=&amp;#34;loki-dev&amp;#34;}
      |= &amp;#34;metrics.go&amp;#34;
      | logfmt
      | unwrap bytes_processed [1m])
  )&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This calculates the amount of bytes processed per organization ID.&lt;/p&gt;
&lt;h2 id=&#34;built-in-aggregation-operators&#34;&gt;Built-in aggregation operators&lt;/h2&gt;
&lt;p&gt;Like &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;PromQL&lt;/a&gt;, LogQL supports a subset of built-in aggregation operators that can be used to aggregate the element of a single vector, resulting in a new vector of fewer elements but with aggregated values:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;sum&lt;/code&gt;: Calculate sum over labels&lt;/li&gt;
&lt;li&gt;&lt;code&gt;avg&lt;/code&gt;: Calculate the average over labels&lt;/li&gt;
&lt;li&gt;&lt;code&gt;min&lt;/code&gt;: Select minimum over labels&lt;/li&gt;
&lt;li&gt;&lt;code&gt;max&lt;/code&gt;: Select maximum over labels&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stddev&lt;/code&gt;: Calculate the population standard deviation over labels&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stdvar&lt;/code&gt;: Calculate the population standard variance over labels&lt;/li&gt;
&lt;li&gt;&lt;code&gt;count&lt;/code&gt;: Count number of elements in the vector&lt;/li&gt;
&lt;li&gt;&lt;code&gt;topk&lt;/code&gt;: Select largest k elements by sample value&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bottomk&lt;/code&gt;: Select smallest k elements by sample value&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The aggregation operators can either be used to aggregate over all label values or a set of distinct label values by including a &lt;code&gt;without&lt;/code&gt; or a &lt;code&gt;by&lt;/code&gt; clause:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;&amp;lt;aggr-op&amp;gt;([parameter,] &amp;lt;vector expression&amp;gt;) [without|by (&amp;lt;label list&amp;gt;)]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;parameter&lt;/code&gt; is required when using &lt;code&gt;topk&lt;/code&gt; and &lt;code&gt;bottomk&lt;/code&gt;.
&lt;code&gt;topk&lt;/code&gt; and &lt;code&gt;bottomk&lt;/code&gt; are different from other aggregators in that a subset of the input samples, including the original labels, are returned in the result vector.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;by&lt;/code&gt; and &lt;code&gt;without&lt;/code&gt; are only used to group the input vector.
The &lt;code&gt;without&lt;/code&gt; clause removes the listed labels from the resulting vector, keeping all others.
The &lt;code&gt;by&lt;/code&gt; clause does the opposite, dropping labels that are not listed in the clause, even if their label values are identical between all elements of the vector.&lt;/p&gt;
&lt;h3 id=&#34;vector-aggregation-examples&#34;&gt;Vector aggregation examples&lt;/h3&gt;
&lt;p&gt;Get the top 10 applications by the highest log throughput:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;topk(10,sum(rate({region=&amp;#34;us-east1&amp;#34;}[5m])) by (name))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Get the count of log lines for the last five minutes for a specified job, grouping
by level:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;sum(count_over_time({job=&amp;#34;mysql&amp;#34;}[5m])) by (level)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Get the rate of HTTP GET requests to the &lt;code&gt;/home&lt;/code&gt; endpoint for NGINX logs by region:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;avg(rate(({job=&amp;#34;nginx&amp;#34;} |= &amp;#34;GET&amp;#34; | json | path=&amp;#34;/home&amp;#34;)[10s])) by (region)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="metric-queries">Metric queries&lt;/h1>
&lt;p>Metric queries extend log queries by applying a function to log query results.
This powerful feature creates metrics from logs.&lt;/p>
&lt;p>Metric queries can be used to calculate the rate of error messages or the top N log sources with the greatest quantity of logs over the last 3 hours.&lt;/p></description></item><item><title>Template functions</title><link>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/template_functions/</link><pubDate>Tue, 16 Jul 2024 15:42:20 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/template_functions/</guid><content><![CDATA[&lt;h1 id=&#34;template-functions&#34;&gt;Template functions&lt;/h1&gt;
&lt;p&gt;The &lt;a href=&#34;https://golang.org/pkg/text/template&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;text template&lt;/a&gt; format used in &lt;code&gt;| line_format&lt;/code&gt; and &lt;code&gt;| label_format&lt;/code&gt; support the usage of functions.&lt;/p&gt;
&lt;p&gt;All labels are added as variables in the template engine. They can be referenced using they label name prefixed by a &lt;code&gt;.&lt;/code&gt;(e.g &lt;code&gt;.label_name&lt;/code&gt;). For example the following template will output the value of the path label:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ .path }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Additionally you can also access the log line using the &lt;a href=&#34;#__line__&#34;&gt;&lt;code&gt;__line__&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;p&gt;You can take advantage of &lt;a href=&#34;https://golang.org/pkg/text/template/#hdr-Pipelines&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;pipeline&lt;/a&gt; to join together multiple functions.
In a chained pipeline, the result of each command is passed as the last argument of the following command.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ .path | replace &amp;#34; &amp;#34; &amp;#34;_&amp;#34; | trunc 5 | upper }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;line&#34;&gt;&lt;strong&gt;line&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;This function returns the current log line.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;line() string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{ __line__ | lower }}&amp;#34;
`{{ __line__ }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;tolower-and-toupper&#34;&gt;ToLower and ToUpper&lt;/h2&gt;
&lt;p&gt;This function converts the entire string to lowercase or uppercase.&lt;/p&gt;
&lt;p&gt;Signatures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ToLower(string) string&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ToUpper(string) string&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{.request_method | ToLower}}&amp;#34;
&amp;#34;{{.request_method | ToUpper}}&amp;#34;
`{{ToUpper &amp;#34;This is a string&amp;#34; | ToLower}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In Grafana Loki 2.1 you can also use respectively &lt;a href=&#34;#lower&#34;&gt;&lt;code&gt;lower&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;#upper&#34;&gt;&lt;code&gt;upper&lt;/code&gt;&lt;/a&gt; shortcut, e.g &lt;code&gt;{{.request_method | lower }}&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;replace-string&#34;&gt;Replace string&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In Loki 2.1 &lt;a href=&#34;#replace&#34;&gt;&lt;code&gt;replace&lt;/code&gt;&lt;/a&gt; (as opposed to &lt;code&gt;Replace&lt;/code&gt;) is available with a different signature but easier to chain within pipeline.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to perform a simple string replacement.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Replace(s, old, new string, n int) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It takes four arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt; source string&lt;/li&gt;
&lt;li&gt;&lt;code&gt;old&lt;/code&gt; string to replace&lt;/li&gt;
&lt;li&gt;&lt;code&gt;new&lt;/code&gt; string to replace with&lt;/li&gt;
&lt;li&gt;&lt;code&gt;n&lt;/code&gt; the maximun amount of replacement (-1 for all)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;`{{ Replace &amp;#34;This is a string&amp;#34; &amp;#34; &amp;#34; &amp;#34;-&amp;#34; -1 }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The results in &lt;code&gt;This-is-a-string&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;trim-trimleft-trimright-and-trimspace&#34;&gt;Trim, TrimLeft, TrimRight, and TrimSpace&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In Loki 2.1 &lt;a href=&#34;#trim&#34;&gt;trim&lt;/a&gt;, &lt;a href=&#34;#trimall&#34;&gt;trimAll&lt;/a&gt;, &lt;a href=&#34;#trimsuffix&#34;&gt;trimSuffix&lt;/a&gt; and &lt;a href=&#34;#trimprefix&#34;&gt;trimPrefix&lt;/a&gt; have been added with a different signature for better pipeline chaining.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;Trim&lt;/code&gt; returns a slice of the string s with all leading and
trailing Unicode code points contained in cutset removed.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;Trim(value, cutset string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;TrimLeft&lt;/code&gt; and &lt;code&gt;TrimRight&lt;/code&gt; are the same as &lt;code&gt;Trim&lt;/code&gt; except that it trims only leading and trailing characters respectively.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;`{{ Trim .query &amp;#34;,. &amp;#34; }}`
`{{ TrimLeft .uri &amp;#34;:&amp;#34; }}`
`{{ TrimRight .path &amp;#34;/&amp;#34; }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;TrimSpace&lt;/code&gt; TrimSpace returns string s with all leading
and trailing white space removed, as defined by Unicode.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;TrimSpace(value string) string&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ TrimSpace .latency }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;TrimPrefix&lt;/code&gt; and &lt;code&gt;TrimSuffix&lt;/code&gt; will trim respectively the prefix or suffix supplied.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TrimPrefix(value string, prefix string) string&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TrimSuffix(value string, suffix string) string&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ TrimPrefix .path &amp;#34;/&amp;#34; }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;regexreplaceall-and-regexreplaceallliteral&#34;&gt;regexReplaceAll and regexReplaceAllLiteral&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;regexReplaceAll&lt;/code&gt; returns a copy of the input string, replacing matches of the Regexp with the replacement string replacement. Inside string replacement, $ signs are interpreted as in Expand, so for instance $1 represents the text of the first sub-match. See the golang &lt;a href=&#34;https://golang.org/pkg/regexp/#Regexp.ReplaceAll&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Regexp.replaceAll documentation&lt;/a&gt; for more examples.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;`{{ regexReplaceAll &amp;#34;(a*)bc&amp;#34; .some_label &amp;#34;${1}a&amp;#34; }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;regexReplaceAllLiteral&lt;/code&gt; function returns a copy of the input string and replaces matches of the Regexp with the replacement string replacement. The replacement string is substituted directly, without using Expand.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;`{{ regexReplaceAllLiteral &amp;#34;(ts=)&amp;#34; .timestamp &amp;#34;timestamp=&amp;#34; }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can combine multiple functions using pipe. For example, to strip out spaces and make the request method in capital, you would write the following template: &lt;code&gt;{{ .request_method | TrimSpace | ToUpper }}&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;lower&#34;&gt;lower&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Added in Loki 2.1&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to convert to lower case.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;lower(string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{ .request_method | lower }}&amp;#34;
`{{ lower  &amp;#34;HELLO&amp;#34;}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The last example will return &lt;code&gt;hello&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;upper&#34;&gt;upper&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Added in Loki 2.1&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to convert to upper case.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;upper(string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{ .request_method | upper }}&amp;#34;
`{{ upper  &amp;#34;hello&amp;#34;}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This results in &lt;code&gt;HELLO&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;title&#34;&gt;title&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Convert to title case.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;title(string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{.request_method | title}}&amp;#34;
`{{ title &amp;#34;hello world&amp;#34;}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The last example will return &lt;code&gt;Hello World&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;trunc&#34;&gt;trunc&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Truncate a string and add no suffix.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;trunc(count int,value string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{ .path | trunc 2 }}&amp;#34;
`{{ trunc 5 &amp;#34;hello world&amp;#34;}}`   // output: hello
`{{ trunc -5 &amp;#34;hello world&amp;#34;}}`  // output: world&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;substr&#34;&gt;substr&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Get a substring from a string.&lt;/p&gt;
&lt;p&gt;Signature:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;substr(start int,end int,value string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If start is &amp;lt; 0, this calls value[:end].
If start is &amp;gt;= 0 and end &amp;lt; 0 or end bigger than s length, this calls value[start:]
Otherwise, this calls value[start, end].&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;&amp;#34;{{ .path | substr 2 5 }}&amp;#34;
`{{ substr 0 5 &amp;#34;hello world&amp;#34;}}`  // output: hello
`{{ substr 6 11 &amp;#34;hello world&amp;#34;}}` // output: world&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;replace&#34;&gt;replace&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;This function performs simple string replacement.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;replace(old string, new string, src string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It takes three arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;old&lt;/code&gt; string to replace&lt;/li&gt;
&lt;li&gt;&lt;code&gt;new&lt;/code&gt; string to replace with&lt;/li&gt;
&lt;li&gt;&lt;code&gt;src&lt;/code&gt; source string&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ .cluster | replace &amp;#34;-cluster&amp;#34; &amp;#34;&amp;#34; }}
{{ replace &amp;#34;hello&amp;#34; &amp;#34;world&amp;#34; &amp;#34;hello world&amp;#34; }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The last example will return &lt;code&gt;world world&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;trim&#34;&gt;trim&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The trim function removes space from either side of a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;trim(string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ .ip | trim }}
{{ trim &amp;#34;   hello    &amp;#34; }} // output: hello&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;trimall&#34;&gt;trimAll&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to remove given characters from the front or back of a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;trimAll(chars string,src string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ .path | trimAll &amp;#34;/&amp;#34; }}
{{ trimAll &amp;#34;$&amp;#34; &amp;#34;$5.00&amp;#34; }} // output: 5.00&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;trimsuffix&#34;&gt;trimSuffix&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to trim just the suffix from a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;trimSuffix(suffix string, src string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{  .path | trimSuffix &amp;#34;/&amp;#34; }}
{{ trimSuffix &amp;#34;-&amp;#34; &amp;#34;hello-&amp;#34; }} // output: hello&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;trimprefix&#34;&gt;trimPrefix&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to trim just the prefix from a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;trimPrefix(suffix string, src string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{  .path | trimPrefix &amp;#34;/&amp;#34; }}
{{ trimPrefix &amp;#34;-&amp;#34; &amp;#34;-hello&amp;#34; }} // output: hello&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;indent&#34;&gt;indent&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The indent function indents every line in a given string to the specified indent width. This is useful when aligning multi-line strings.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;indent(spaces int,src string) string&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ indent 4 .query }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This indents each line contained in the &lt;code&gt;.query&lt;/code&gt; by four (4) spaces.&lt;/p&gt;
&lt;h2 id=&#34;nindent&#34;&gt;nindent&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The nindent function is the same as the indent function, but prepends a new line to the beginning of the string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;nindent(spaces int,src string) string&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ nindent 4 .query }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This will indent every line of text by 4 space characters and add a new line to the beginning.&lt;/p&gt;
&lt;h2 id=&#34;repeat&#34;&gt;repeat&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to repeat a string multiple times.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;repeat(c int,value string) string&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ repeat 3 &amp;#34;hello&amp;#34; }} // output: hellohellohello&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;contains&#34;&gt;contains&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Use this function to test to see if one string is contained inside of another.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;contains(s string, src string) bool&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ if .err contains &amp;#34;ErrTimeout&amp;#34; }} timeout {{end}}
{{ if contains &amp;#34;he&amp;#34; &amp;#34;hello&amp;#34; }} yes {{end}}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;hasprefix-and-hassuffix&#34;&gt;hasPrefix and hasSuffix&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.1.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The &lt;code&gt;hasPrefix&lt;/code&gt; and &lt;code&gt;hasSuffix&lt;/code&gt; functions test whether a string has a given prefix or suffix.&lt;/p&gt;
&lt;p&gt;Signatures:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;hasPrefix(prefix string, src string) bool&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hasSuffix(suffix string, src string) bool&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ if .err hasSuffix &amp;#34;Timeout&amp;#34; }} timeout {{end}}
{{ if hasPrefix &amp;#34;he&amp;#34; &amp;#34;hello&amp;#34; }} yes {{end}}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;add&#34;&gt;add&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Sum numbers. Supports multiple numbers&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(i ...interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ add 3 2 5 }} // output: 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;sub&#34;&gt;sub&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Subtract numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a, b interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ sub 5 2 }} // output: 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;mul&#34;&gt;mul&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Mulitply numbers. Supports multiple numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a interface{}, v ...interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ mul 5 2 3}} // output: 30&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;div&#34;&gt;div&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Integer divide numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a, b interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ div 10 2}} // output: 5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;addf&#34;&gt;addf&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Sum numbers. Supports multiple numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(i ...interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ addf 3.5 2 5 }} // output: 10.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;subf&#34;&gt;subf&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Subtract numbers. Supports multiple numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a interface{}, v ...interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ subf  5.5 2 1.5 }} // output: 2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;mulf&#34;&gt;mulf&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Mulitply numbers. Supports multiple numbers&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a interface{}, v ...interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ mulf 5.5 2 2.5 }} // output: 27.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;divf&#34;&gt;divf&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Divide numbers. Supports multiple numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a interface{}, v ...interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ divf 10 2 4}} // output: 1.25&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;mod&#34;&gt;mod&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Modulo wit mod.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a, b interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ mod 10 3}} // output: 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;max&#34;&gt;max&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Return the largest of a series of integers:&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;max(a interface{}, i ...interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ max 1 2 3 }} //output 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;min&#34;&gt;min&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Return the smallest of a series of integers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;min(a interface{}, i ...interface{}) int64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ max 1 2 3 }} //output 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;maxf&#34;&gt;maxf&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Return the largest of a series of floats:&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;maxf(a interface{}, i ...interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ maxf 1 2.5 3 }} //output 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;minf&#34;&gt;minf&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Return the smallest of a series of floats.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;minf(a interface{}, i ...interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ minf 1 2.5 3 }} //output 1.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;ceil&#34;&gt;ceil&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Returns the greatest float value greater than or equal to input value&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;ceil(a interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ ceil 123.001 }} //output 124.0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;floor&#34;&gt;floor&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Returns the greatest float value less than or equal to input value&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;floor(a interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ floor 123.9999 }} //output 123.0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;round&#34;&gt;round&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Returns a float value with the remainder rounded to the given number of digits after the decimal point.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;round(a interface{}, p int, rOpt ...float64) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ round 123.555555 3 }} //output 123.556&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;We can also provide a &lt;code&gt;roundOn&lt;/code&gt; number as third parameter&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ round 123.88571428571 5 .2 }} //output 123.88572&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With default &lt;code&gt;roundOn&lt;/code&gt; of &lt;code&gt;.5&lt;/code&gt; the above value would be &lt;code&gt;123.88571&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;int&#34;&gt;int&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Convert value to an int.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;toInt(v interface{}) int&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ &amp;#34;3&amp;#34; | int }} //output 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;float64&#34;&gt;float64&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Convert to a float64.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;toFloat64(v interface{}) float64&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ &amp;#34;3.5&amp;#34; | float64 }} //output 3.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;fromjson&#34;&gt;fromJson&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Added in Loki 2.3.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;fromJson decodes a JSON document into a structure. If the input cannot be decoded as JSON the function will return an empty string.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;fromJson &amp;#34;{\&amp;#34;foo\&amp;#34;: 55}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Example of a query to print a newline per queries stored as a json array in the log line:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;loki/querier&amp;#34;} |= &amp;#34;finish in prometheus&amp;#34; | logfmt | line_format &amp;#34;{{ range $q := fromJson .queries }} {{ $q.query }} {{ end }}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;now&#34;&gt;now&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;now&lt;/code&gt; returns the current local time.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ now }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;todate&#34;&gt;toDate&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;toDate&lt;/code&gt; parses a formatted string and returns the time value it represents.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ toDate &amp;#34;2006-01-02&amp;#34; &amp;#34;2021-11-02&amp;#34; }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;date&#34;&gt;date&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;date&lt;/code&gt; returns a textual representation of the time value formatted according to the provided &lt;a href=&#34;https://pkg.go.dev/time#pkg-constants&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;golang datetime layout&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{ date &amp;#34;2006-01-02&amp;#34; now }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;unixepoch&#34;&gt;unixEpoch&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;unixEpoch&lt;/code&gt; returns the number of seconds elapsed since January 1, 1970 UTC.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{ unixEpoch now }}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Example of a query to filter Loki querier jobs which create time is 1 day before:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;loki/querier&amp;#34;} | label_format nowEpoch=`{{(unixEpoch now)}}`,createDateEpoch=`{{unixEpoch (toDate &amp;#34;2006-01-02&amp;#34; .createDate)}}` | label_format dateTimeDiff=&amp;#34;{{sub .nowEpoch .createDateEpoch}}&amp;#34; | dateTimeDiff &amp;gt; 86400&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;default&#34;&gt;default&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;default&lt;/code&gt; checks whether the string(&lt;code&gt;src&lt;/code&gt;) is set, and returns default(&lt;code&gt;d&lt;/code&gt;) if not set.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;default(d string, src string) string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;template&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-template&#34;&gt;{{ default &amp;#34;-&amp;#34; &amp;#34;&amp;#34; }} // output: -
{{ default &amp;#34;-&amp;#34; &amp;#34;foo&amp;#34; }} // output: foo&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Example of a query to print a &lt;code&gt;-&lt;/code&gt; if the &lt;code&gt;http_request_headers_x_forwarded_for&lt;/code&gt; label is empty:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;access_log&amp;#34;} | json | line_format `{{.http_request_headers_x_forwarded_for | default &amp;#34;-&amp;#34;}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="template-functions">Template functions&lt;/h1>
&lt;p>The &lt;a href="https://golang.org/pkg/text/template" target="_blank" rel="noopener noreferrer">text template&lt;/a> format used in &lt;code>| line_format&lt;/code> and &lt;code>| label_format&lt;/code> support the usage of functions.&lt;/p>
&lt;p>All labels are added as variables in the template engine. They can be referenced using they label name prefixed by a &lt;code>.&lt;/code>(e.g &lt;code>.label_name&lt;/code>). For example the following template will output the value of the path label:&lt;/p></description></item><item><title>Matching IP addresses</title><link>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/ip/</link><pubDate>Tue, 16 Jul 2024 15:42:20 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/ip/</guid><content><![CDATA[&lt;h1 id=&#34;matching-ip-addresses&#34;&gt;Matching IP addresses&lt;/h1&gt;
&lt;p&gt;LogQL supports matching IP addresses.&lt;/p&gt;
&lt;p&gt;With logs such as&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;3.180.71.3 - - [17/May/2015:08:05:32 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 304 0 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)&amp;#34;
80.91.33.133 - - [17/May/2015:08:05:14 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 304 0 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.16)&amp;#34;
46.4.66.76 - - [17/May/2015:08:05:45 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 404 318 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (1.0.1ubuntu2)&amp;#34;
93.180.71.3 - - [17/May/2015:08:05:26 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 404 324 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;the LogQL line filter is not sufficient.
A line filter such as&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;} |= &amp;#34;3.180.71.3&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;also matches example IP addresses such as 93.180.71.3. A better choice uses a regexp: &lt;code&gt;|~&amp;quot;^3.180.71.3&amp;quot;&lt;/code&gt;. This regexp does not handle IPv6 addresses, and it does not match a range of IP addresses.&lt;/p&gt;
&lt;p&gt;The LogQL support for matching IP addresses handles both IPv4 and IPv6 single addresses, as well as ranges within IP addresses
and CIDR patterns.&lt;/p&gt;
&lt;p&gt;Match IP addresses with the syntax: &lt;code&gt;ip(&amp;quot;&amp;lt;pattern&amp;gt;&amp;quot;)&lt;/code&gt;.
The &lt;code&gt;&amp;lt;pattern&amp;gt;&lt;/code&gt; can be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A single IP address. Examples: &lt;code&gt;ip(&amp;quot;192.0.2.0&amp;quot;)&lt;/code&gt;, &lt;code&gt;ip(&amp;quot;::1&amp;quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A range within the IP address. Examples: &lt;code&gt;ip(&amp;quot;192.168.0.1-192.189.10.12&amp;quot;)&lt;/code&gt;, &lt;code&gt;ip(&amp;quot;2001:db8::1-2001:db8::8&amp;quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A CIDR specification. Examples: &lt;code&gt;ip(&amp;quot;192.51.100.0/24&amp;quot;)&lt;/code&gt;, &lt;code&gt;ip(&amp;quot;2001:db8::/32&amp;quot;)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The IP matching can be used in both line filter and label filter expressions.
When specifying line filter expressions, only the &lt;code&gt;|=&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; operations are allowed.
When specifying label filter expressions, only the  &lt;code&gt;=&lt;/code&gt; and &lt;code&gt;!=&lt;/code&gt; operations are allowed.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Line filter examples&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;} |= ip(&amp;#34;192.168.4.5/16&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Return log lines that do not match with an IPv4 range:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;} != ip(&amp;#34;192.168.4.5-192.168.4.20&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Label filter examples&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;}
	| logfmt
	| remote_addr = ip(&amp;#34;2001:db8::1-2001:db8::8&amp;#34;)
	| level = &amp;#34;error&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Filters can be chained. This example matches log lines with all IPv4 subnet values &lt;code&gt;192.168.4.5/16&lt;/code&gt; except IP address &lt;code&gt;192.168.4.2&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;}
	| logfmt
	| addr = ip(&amp;#34;192.168.4.5/16&amp;#34;)
	| addr != ip(&amp;#34;192.168.4.2&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="matching-ip-addresses">Matching IP addresses&lt;/h1>
&lt;p>LogQL supports matching IP addresses.&lt;/p>
&lt;p>With logs such as&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">3.180.71.3 - - [17/May/2015:08:05:32 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 304 0 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)&amp;#34;
80.91.33.133 - - [17/May/2015:08:05:14 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 304 0 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.16)&amp;#34;
46.4.66.76 - - [17/May/2015:08:05:45 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 404 318 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (1.0.1ubuntu2)&amp;#34;
93.180.71.3 - - [17/May/2015:08:05:26 &amp;#43;0000] &amp;#34;GET /downloads/product_1 HTTP/1.1&amp;#34; 404 324 &amp;#34;-&amp;#34; &amp;#34;Debian APT-HTTP/1.3 (0.8.16~exp12ubuntu10.21)&amp;#34;&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>the LogQL line filter is not sufficient.
A line filter such as&lt;/p></description></item><item><title>Query examples</title><link>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/query_examples/</link><pubDate>Tue, 16 Jul 2024 15:42:20 +0000</pubDate><guid>https://grafana.com/docs/enterprise-logs/v1.9.x/loki/logql/query_examples/</guid><content><![CDATA[&lt;h1 id=&#34;query-examples&#34;&gt;Query examples&lt;/h1&gt;
&lt;p&gt;Some useful query examples here.&lt;/p&gt;
&lt;h2 id=&#34;log-query-examples&#34;&gt;Log Query examples&lt;/h2&gt;
&lt;h3 id=&#34;examples-that-filter-on-ip-address&#34;&gt;Examples that filter on IP address&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Return log lines that are not within a range of IPv4 addresses:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;} != ip(&amp;#34;192.168.4.5-192.168.4.20&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This example matches log lines with all IPv4 subnet values &lt;code&gt;192.168.4.5/16&lt;/code&gt; except IP address &lt;code&gt;192.168.4.2&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job_name=&amp;#34;myapp&amp;#34;}
	| logfmt
	| addr = ip(&amp;#34;192.168.4.5/16&amp;#34;)
	| addr != ip(&amp;#34;192.168.4.2&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;examples-that-aid-in-security-evaluation&#34;&gt;Examples that aid in security evaluation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Extract the user and IP address of failed logins from Linux &lt;code&gt;/var/log/secure&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;security&amp;#34;} 
    |~ &amp;#34;Invalid user.*&amp;#34;
    | regexp &amp;#34;(^(?P&amp;lt;user&amp;gt;\\S&amp;#43; {1,2}){8})&amp;#34;
    | regexp &amp;#34;(^(?P&amp;lt;ip&amp;gt;\\S&amp;#43; {1,2}){10})&amp;#34;
    | line_format &amp;#34;IP = {{.ip}}\tUSER = {{.user}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Get successful logins from Linux &lt;code&gt;/var/log/secure&lt;/code&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;logql&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-logql&#34;&gt;{job=&amp;#34;security&amp;#34;}
    != &amp;#34;grafana_com&amp;#34;
    |= &amp;#34;session opened&amp;#34;
    != &amp;#34;sudo: &amp;#34;
    |regexp &amp;#34;(^(?P&amp;lt;user&amp;gt;\\S&amp;#43; {1,2}){11})&amp;#34;
    | line_format &amp;#34;USER = {{.user}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;metrics-query-examples&#34;&gt;Metrics Query examples&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Return the per-second rate of all non-timeout errors
within the last minutes per host for the MySQL job,
and only include errors whose duration is above ten seconds.&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;sum by (host) (rate({job=&amp;#34;mysql&amp;#34;}
    |= &amp;#34;error&amp;#34; != &amp;#34;timeout&amp;#34;
    | json
    | duration &amp;gt; 10s [1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="query-examples">Query examples&lt;/h1>
&lt;p>Some useful query examples here.&lt;/p>
&lt;h2 id="log-query-examples">Log Query examples&lt;/h2>
&lt;h3 id="examples-that-filter-on-ip-address">Examples that filter on IP address&lt;/h3>
&lt;ul>
&lt;li>
&lt;p>Return log lines that are not within a range of IPv4 addresses:&lt;/p></description></item></channel></rss>