<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Query Loki on Grafana Labs</title><link>https://grafana.com/docs/loki/v3.7.x/query/</link><description>Recent content in Query Loki on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/loki/v3.7.x/query/index.xml" rel="self" type="application/rss+xml"/><item><title>Query best practices</title><link>https://grafana.com/docs/loki/v3.7.x/query/bp-query/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/bp-query/</guid><content><![CDATA[&lt;h1 id=&#34;query-best-practices&#34;&gt;Query best practices&lt;/h1&gt;
&lt;p&gt;The way you write queries in Loki affects how quickly you get results returned from those queries. Understanding the way Loki parses queries can help you write queries that are efficient and performant.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-tip&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Tip&lt;/p&gt;&lt;p&gt;Before you start optimizing queries, read the 
    &lt;a href=&#34;/docs/loki/v3.7.x/get-started/labels/bp-labels/&#34;&gt;labels best practices&lt;/a&gt; page to understand what makes a good label. Choosing the right labels is the first step towards writing efficient queries.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Loki evaluates a LogQL query from left to right, in the order that it is written. To get the best possible query performance, eliminate as many potential results as you can earlier in the query and then continue to progressively narrow your search as you continue writing the query. This page describes the recommended order for writing queries that efficiently filter out unwanted results.&lt;/p&gt;
&lt;h2 id=&#34;narrow-down-your-time-range-first&#34;&gt;Narrow down your time range first&lt;/h2&gt;
&lt;p&gt;Reduce the number of logs Loki needs to look through by specifying a period of time that you&amp;rsquo;d like to search through. Loki creates one index file per day, so queries that span over multiple days fetches multiple index files. The fewer files Loki has to search, the faster the query results are returned.&lt;/p&gt;
&lt;p&gt;Time ranges are typically not part of the query, but you can set a time range through your visualization tool or through 
    &lt;a href=&#34;/docs/loki/v3.7.x/reference/loki-http-api/&#34;&gt;the Loki API&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;in-grafana&#34;&gt;In Grafana&lt;/h3&gt;
&lt;p&gt;If you&amp;rsquo;re using Loki with Grafana, you can use the dropdown menu on the upper right hand corner of a dashboard to select a time range, either relative (last X hours) or absolute (a specific date and time).&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;../grafana-time-range-picker.png&#34;
  alt=&#34;Screenshot of time selector on Grafana&#34;/&gt;&lt;/p&gt;
&lt;h3 id=&#34;through-loki-api&#34;&gt;Through Loki API&lt;/h3&gt;
&lt;p&gt;If you&amp;rsquo;re querying Loki through 
    &lt;a href=&#34;/docs/loki/v3.7.x/reference/loki-http-api/&#34;&gt;the Loki API&lt;/a&gt;, you can use the 
    &lt;a href=&#34;/docs/loki/v3.7.x/reference/loki-http-api/#query-logs-within-a-range-of-time&#34;&gt;&lt;code&gt;query_range&lt;/code&gt; endpoint&lt;/a&gt;
to add &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; timestamps for your query as parameters to the HTTP call rather than as part of the query itself.&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;Bash&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-bash&#34;&gt;http://&amp;lt;loki-instance&amp;gt;/loki/api/v1/query_range?query={job=&amp;#34;app&amp;#34;}&amp;amp;start=1633017600000000000&amp;amp;end=1633104000000000000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-precise-label-selectors&#34;&gt;Use precise label selectors&lt;/h2&gt;
&lt;p&gt;Next, write your label selectors. Identify the most specific label you can use within the log line and search based on that first. For example, if the logs contain the labels &lt;code&gt;namespace&lt;/code&gt; and &lt;code&gt;app_name&lt;/code&gt; and the latter is a smaller subset of data, start your query by selecting based on &lt;code&gt;app_name&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;Bash&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-bash&#34;&gt;{app_name=&amp;#34;carnivorousgreenhouse&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Using the most specific label selector has the added benefit of reducing the length of your query. Since &lt;code&gt;app_name&lt;/code&gt; is more specific than &lt;code&gt;namespace&lt;/code&gt;, you don&amp;rsquo;t need to add a selector for &lt;code&gt;namespace&lt;/code&gt;. Adding more general label selectors has no further effect on the query.&lt;/p&gt;
&lt;h2 id=&#34;use-simple-line-filter-expressions-over-regular-expressions&#34;&gt;Use simple line filter expressions over regular expressions&lt;/h2&gt;
&lt;p&gt;When using 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#line-filter-expression&#34;&gt;line filter expressions&lt;/a&gt;, prefer the simpler filter operators such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;|=&lt;/code&gt; (contains string) and&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt; (does not contain string)
over the regular expression filter operators:&lt;/li&gt;
&lt;li&gt;&lt;code&gt;|~&lt;/code&gt; (matches the regular expression)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!~&lt;/code&gt; (does not match the regular expression)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Loki evaluates the first two filter expressions faster than it can evaluate regular expressions, so always try to rewrite your query in terms of whether a log line contains or does not contain a certain string. Use regular expressions only as a last resort.&lt;/p&gt;
&lt;p&gt;Line filter expressions are more efficient than parser expressions.&lt;/p&gt;
&lt;h2 id=&#34;avoid-using-complex-text-parsers&#34;&gt;Avoid using complex text parsers&lt;/h2&gt;
&lt;p&gt;Use 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#parser-expression&#34;&gt;parser expressions&lt;/a&gt; only after line filter expressions. Parser expressions are ways to look through the log line and extract labels in different formats, which can be useful but are also more intensive for Loki to do than line filter expressions. Using them after line filter expressions means that Loki only needs to evaluate parser expressions for log lines that match the line filter expression, reducing the amount of logs that Loki needs to search through.&lt;/p&gt;
&lt;p&gt;Parser expressions include 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#json&#34;&gt;JSON&lt;/a&gt;, 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#logfmt&#34;&gt;logfmt&lt;/a&gt;, 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#pattern&#34;&gt;pattern&lt;/a&gt;, 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#regular-expression&#34;&gt;regexp&lt;/a&gt;, and 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#unpack&#34;&gt;unpack&lt;/a&gt; parsers.&lt;/p&gt;
&lt;h2 id=&#34;use-recording-rules&#34;&gt;Use recording rules&lt;/h2&gt;
&lt;p&gt;Some queries are sufficiently complex, or some datasets sufficiently large, that there is a limit as to how much query performance can be optimized. If you&amp;rsquo;re following the tips on this page and are still experiencing slow query times, consider creating a 
    &lt;a href=&#34;/docs/loki/v3.7.x/operations/recording-rules/&#34;&gt;recording rule&lt;/a&gt; for them. A recording rule runs a query at a predetermined time and also precomputes the results of that query, saving those results for faster retrieval later.&lt;/p&gt;
&lt;h2 id=&#34;further-resources&#34;&gt;Further resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;/blog/2023/01/10/watch-5-tips-for-improving-grafana-loki-query-performance/&#34;&gt;Watch: 5 tips for improving Grafana Loki query performance&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/live/3uFMJLufgSo?feature=shared&amp;amp;t=3385&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Loki Design Basics with Ed Welch (Grafana Office Hours #27)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/loki/v3.7.x/get-started/labels/bp-labels/&#34;&gt;Labels best practices&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="query-best-practices">Query best practices&lt;/h1>
&lt;p>The way you write queries in Loki affects how quickly you get results returned from those queries. Understanding the way Loki parses queries can help you write queries that are efficient and performant.&lt;/p></description></item><item><title>Simple LogQL simulator</title><link>https://grafana.com/docs/loki/v3.7.x/query/analyzer/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/analyzer/</guid><content><![CDATA[&lt;link rel=&#34;stylesheet&#34; href=&#34;../analyzer/style.css&#34;&gt;
&lt;script src=&#34;../analyzer/handlebars.js&#34;&gt;&lt;/script&gt;
&lt;h1 id=&#34;simple-logql-simulator&#34;&gt;Simple LogQL simulator&lt;/h1&gt;
&lt;p&gt;The LogQL simulator is an online tool that you can use to experiment with writing simple LogQL queries and seeing the results, without needing to run an instance of Loki.&lt;/p&gt;
&lt;p&gt;A set of example log lines are included for each of the primary log parsers supported by Loki:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://brandur.org/logfmt&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Logfmt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.json.org/json-en.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;JSON&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Unstructured text, which can be parsed with the Loki pattern or regex parsers&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#log-stream-selector&#34;&gt;log stream selector&lt;/a&gt; &lt;code&gt;{job=&amp;quot;analyze&amp;quot;}&lt;/code&gt; is shown as an example, and it remains fixed for all possible example queries in the simulator. A log stream is a set of logs which share the same labels. In LogQL, you use a log stream selector to determine which log streams to include in a query&amp;rsquo;s results.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This is a very limited simulator, primarily for evaluating filters and parsers. If you want to practice writing more complex queries, such as metric queries, you can use the 
    &lt;a href=&#34;/docs/grafana/latest/explore/logs-integration/&#34;&gt;Explore&lt;/a&gt; feature in Grafana.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To use the LogQL simulator:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Select a log line format using the radio buttons.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can use the provided example log lines, or copy and paste your own log lines into the example log lines box.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the provided example LogQL query, or enter your own query. The 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#log-stream-selector&#34;&gt;log stream selector&lt;/a&gt; remains fixed for all possible example queries. There are additional sample queries at the end of this topic.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click the &lt;strong&gt;Run query&lt;/strong&gt; button to run the entered query against the example log lines.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The results output simulates how Loki would return results for your query. You can also click each line in the results pane to expand the details, which give an explanation for why the log line is or is not included in the query result set.&lt;/p&gt;
&lt;main class=&#34;logql-analyzer&#34;&gt;
    &lt;section class=&#34;logs-source panel-container&#34;&gt;
        &lt;div class=&#34;logs-source__header&#34;&gt;
            &lt;div class=&#34;examples&#34;&gt;
                &lt;span&gt;Log line format:&lt;/span&gt;
                &lt;span class=&#34;example&#34;&gt;
                    &lt;input type=&#34;radio&#34; class=&#34;example-select&#34; name=&#34;example&#34; id=&#34;logfmt-example&#34; checked&gt;
                    &lt;label for=&#34;logfmt-example&#34;&gt;logfmt&lt;/label&gt;
                &lt;/span&gt;
                &lt;span class=&#34;example&#34;&gt;
                    &lt;input type=&#34;radio&#34; class=&#34;example-select&#34; name=&#34;example&#34; id=&#34;json-parser-example&#34;&gt;
                    &lt;label for=&#34;json-parser-example&#34;&gt;JSON&lt;/label&gt;
                &lt;/span&gt;
                &lt;span class=&#34;example&#34;&gt;
                    &lt;input type=&#34;radio&#34; class=&#34;example-select&#34; name=&#34;example&#34; id=&#34;pattern-parser-example&#34;&gt;
                    &lt;label for=&#34;pattern-parser-example&#34;&gt;Unstructured text&lt;/label&gt;
                &lt;/span&gt;
            &lt;/div&gt;
            &lt;div class=&#34;share-section&#34;&gt;
                &lt;span class=&#34;share-link-copied-notification hide&#34; id=&#34;share-link-copied-notification&#34;&gt;
                    &lt;i class=&#34;fa fa-check&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;
                    Link copied to clipboard.
                &lt;/span&gt;
                &lt;button class=&#34;primary-button&#34; id=&#34;share-button&#34;&gt;
                    &lt;i class=&#34;fa fa-link&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;
                    Share
                &lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&#34;panel-header&#34;&gt;
            {job=&#34;analyze&#34;}
        &lt;/div&gt;
        &lt;textarea id=&#34;logs-source-input&#34; class=&#34;logs-source__input&#34;&gt;&lt;/textarea&gt;
    &lt;/section&gt;
    &lt;section class=&#34;query panel-container&#34;&gt;
        &lt;div class=&#34;panel-header&#34;&gt;
            Query:
        &lt;/div&gt;
        &lt;div class=&#34;query-container&#34;&gt;
            &lt;div class=&#34;input-box&#34;&gt;
                &lt;span class=&#34;prefix&#34;&gt;{job=&#34;analyze&#34;} &lt;/span&gt;
                &lt;input id=&#34;query-input&#34; class=&#34;query_input&#34;&gt;
            &lt;/div&gt;
            &lt;button class=&#34;query_submit primary-button&#34;&gt;Run query&lt;/button&gt;
        &lt;/div&gt;
        &lt;div class=&#34;query-error&#34; id=&#34;query-error&#34;&gt;&lt;/div&gt;
    &lt;/section&gt;
    &lt;section class=&#34;results panel-container hide&#34; id=&#34;results&#34;&gt;
    &lt;/section&gt;
&lt;/main&gt;
&lt;script id=&#34;log-result-template&#34; type=&#34;text/x-handlebars-template&#34;&gt;
    &lt;div class=&#34;panel-header&#34;&gt;
        Results
    &lt;/div&gt;
    {{#each results}}
        &lt;article class=&#34;debug-result-row&#34;&gt;
            &lt;div class=&#34;last-stage-result&#34; data-line-index=&#34;{{@index}}&#34;&gt;
                &lt;div class=&#34;line-index&#34;&gt;
                    &lt;div class=&#34;line-index__wrapper&#34;&gt;
                        &lt;i class=&#34;line-cursor expand-cursor&#34;&gt;&lt;/i&gt;
                        &lt;span&gt;Line {{inc @index}}&lt;/span&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
                {{#if this.log_result}}
                    &lt;span {{#if this.filtered_out}}class=&#34;filtered-out&#34;{{/if}}&gt;
                        {{this.log_result}}
                    &lt;/span&gt;
                {{/if}}
                {{#unless this.log_result}}
                    &lt;span class=&#34;note-text&#34;&gt;(empty line)&lt;/span&gt;
                {{/unless}}
            &lt;/div&gt;

            &lt;div class=&#34;debug-result-row__explain hide&#34;&gt;
                &lt;div class=&#34;explain-section origin-line&#34;&gt;
                    &lt;div class=&#34;explain-section__header&#34;&gt;
                        Original log line
                        &lt;span class=&#34;stage-expression&#34;&gt;{{../stream_selector}}&lt;/span&gt;
                    &lt;/div&gt;
                    &lt;div class=&#34;explain-section__body&#34;&gt;
                        {{this.origin_line}}
                        {{#unless this.log_result}}
                            &lt;span class=&#34;note-text&#34;&gt;(empty line)&lt;/span&gt;
                        {{/unless}}
                    &lt;/div&gt;
                &lt;/div&gt;
                {{#each this.stages}}
                    &lt;div class=&#34;arrow-wrapper&#34;&gt;
                        &lt;i class=&#34;fa fa-arrow-down&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;
                    &lt;/div&gt;
                    &lt;div class=&#34;explain-section stage-line&#34;&gt;
                        &lt;div class=&#34;explain-section__header&#34;&gt;
                            &lt;span&gt;stage #{{inc @index}}:&lt;/span&gt;
                            &lt;span class=&#34;stage-expression&#34;&gt; {{stage_expression}} &lt;/span&gt;
                        &lt;/div&gt;
                        &lt;div class=&#34;explain-section__body&#34;&gt;
                            &lt;div class=&#34;explain-section__row&#34;&gt;
                                &lt;div class=&#34;explain-section__row-title&#34;&gt;
                                    Available labels on this stage:
                                &lt;/div&gt;
                                &lt;div class=&#34;explain-section__row-body&#34;&gt;
                                    {{#unless labels_before}}
                                        &lt;span&gt;none&lt;/span&gt;
                                    {{/unless}}
                                    {{#if labels_before}}
                                        {{#each labels_before}}
                                            &lt;article class=&#34;label-value&#34; style=&#34;background-color: {{background_color}}&#34;&gt;
                                                {{name}}={{value}}
                                            &lt;/article&gt;
                                        {{/each}}
                                    {{/if}}
                                &lt;/div&gt;
                            &lt;/div&gt;
                            &lt;div class=&#34;explain-section__row&#34;&gt;
                                &lt;div class=&#34;explain-section__row-title&#34;&gt;
                                    Line after this stage:
                                &lt;/div&gt;
                                &lt;div class=&#34;explain-section__row-body&#34;&gt;
                                    {{#if line_after}}
                                        &lt;span {{#if this.filtered_out}}class=&#34;filtered-out&#34;{{/if}}&gt;
                                            {{line_after}}
                                        &lt;/span&gt;
                                    {{/if}}
                                    {{#unless line_after}}
                                        &lt;span class=&#34;note-text&#34;&gt;(empty line)&lt;/span&gt;
                                    {{/unless}}
                                    {{#if this.filtered_out}}
                                        &lt;span class=&#34;important-text&#34;&gt;the line has been filtered out on this stage&lt;/span&gt;
                                    {{/if}}
                                &lt;/div&gt;
                            &lt;/div&gt;
                            {{#if added_labels}}
                                &lt;div class=&#34;explain-section__row&#34;&gt;
                                    &lt;div class=&#34;explain-section__row-title&#34;&gt;
                                        Added/Modified labels:
                                    &lt;/div&gt;
                                    &lt;div class=&#34;explain-section__row-body&#34;&gt;
                                        {{#each added_labels}}
                                            &lt;article class=&#34;label-value&#34;  style=&#34;background-color: {{background_color}}&#34;&gt;
                                                {{name}}={{value}}
                                            &lt;/article&gt;
                                        {{/each}}
                                    &lt;/div&gt;
                                &lt;/div&gt;
                            {{/if}}
                        &lt;/div&gt;
                    &lt;/div&gt;
                {{/each}}
            &lt;/div&gt;
        &lt;/article&gt;
    {{/each}}
&lt;/script&gt;
&lt;script type=&#34;text/plain&#34; id=&#34;logfmt-example-logs&#34;&gt;
level=info ts=2022-03-23T11:55:29.846163306Z caller=main.go:112 msg=&#34;Starting Grafana Enterprise Logs&#34;
level=debug ts=2022-03-23T11:55:29.846226372Z caller=main.go:113 version=v1.3.0 branch=HEAD Revision=e071a811 LokiVersion=v2.4.2 LokiRevision=525040a3
level=warn ts=2022-03-23T11:55:45.213901602Z caller=added_modules.go:198 msg=&#34;found valid license&#34; cluster=enterprise-logs-test-fixture
level=info ts=2022-03-23T11:55:45.214611239Z caller=server.go:269 http=[::]:3100 grpc=[::]:9095 msg=&#34;server listening on addresses&#34;
level=debug ts=2022-03-23T11:55:45.219665469Z caller=module_service.go:64 msg=initialising module=license
level=warm ts=2022-03-23T11:55:45.219678992Z caller=module_service.go:64 msg=initialising module=server
level=error ts=2022-03-23T11:55:45.221140583Z caller=manager.go:132 msg=&#34;license manager up and running&#34;
level=info ts=2022-03-23T11:55:45.221254326Z caller=loki.go:355 msg=&#34;Loki started&#34;
&lt;/script&gt;
&lt;script type=&#34;text/plain&#34; id=&#34;logfmt-example-query&#34;&gt;
| logfmt | level = &#34;info&#34;
&lt;/script&gt;
&lt;script type=&#34;text/plain&#34; id=&#34;json-parser-example-logs&#34;&gt;
{&#34;timestamp&#34;:&#34;2022-04-26T08:53:59.61Z&#34;,&#34;level&#34;:&#34;INFO&#34;,&#34;class&#34;:&#34;org.springframework.boot.SpringApplication&#34;,&#34;method&#34;:&#34;logStartupProfileInfo&#34;,&#34;file&#34;:&#34;SpringApplication.java&#34;,&#34;line&#34;:663,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;The following profiles are active: no-schedulers,json-logging&#34;}
{&#34;timestamp&#34;:&#34;2022-04-26T08:53:59.645Z&#34;,&#34;level&#34;:&#34;DEBUG&#34;,&#34;class&#34;:&#34;org.springframework.boot.logging.DeferredLog&#34;,&#34;method&#34;:&#34;logTo&#34;,&#34;file&#34;:&#34;DeferredLog.java&#34;,&#34;line&#34;:255,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;Devtools property defaults active! Set &#39;spring.devtools.add-properties&#39; to &#39;false&#39; to disable&#34;}
{&#34;timestamp&#34;:&#34;2022-04-26T08:53:59.645Z&#34;,&#34;level&#34;:&#34;DEBUG&#34;,&#34;class&#34;:&#34;org.springframework.boot.logging.DeferredLog&#34;,&#34;method&#34;:&#34;logTo&#34;,&#34;file&#34;:&#34;DeferredLog.java&#34;,&#34;line&#34;:255,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;For additional web related logging consider setting the &#39;logging.level.web&#39; property to &#39;DEBUG&#39;&#34;}
{&#34;timestamp&#34;:&#34;2022-04-26T08:54:00.274Z&#34;,&#34;level&#34;:&#34;INFO&#34;,&#34;class&#34;:&#34;org.springframework.data.repository.config.RepositoryConfigurationDelegate&#34;,&#34;method&#34;:&#34;registerRepositoriesIn&#34;,&#34;file&#34;:&#34;RepositoryConfigurationDelegate.java&#34;,&#34;line&#34;:132,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;Bootstrapping Spring Data JPA repositories in DEFAULT mode.&#34;}
{&#34;timestamp&#34;:&#34;2022-04-26T08:54:00.327Z&#34;,&#34;level&#34;:&#34;INFO&#34;,&#34;class&#34;:&#34;org.springframework.data.repository.config.RepositoryConfigurationDelegate&#34;,&#34;method&#34;:&#34;registerRepositoriesIn&#34;,&#34;file&#34;:&#34;RepositoryConfigurationDelegate.java&#34;,&#34;line&#34;:201,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;Finished Spring Data repository scanning in 47 ms. Found 3 JPA repository interfaces.&#34;}
{&#34;timestamp&#34;:&#34;2022-04-26T08:54:00.704Z&#34;,&#34;level&#34;:&#34;INFO&#34;,&#34;class&#34;:&#34;org.springframework.boot.web.embedded.tomcat.TomcatWebServer&#34;,&#34;method&#34;:&#34;initialize&#34;,&#34;file&#34;:&#34;TomcatWebServer.java&#34;,&#34;line&#34;:108,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;Tomcat initialized with port(s): 8080 (http)&#34;}
{&#34;timestamp&#34;:&#34;2022-06-16T10:54:47.466Z&#34;,&#34;level&#34;:&#34;INFO&#34;,&#34;class&#34;:&#34;org.apache.juli.logging.DirectJDKLog&#34;,&#34;method&#34;:&#34;log&#34;,&#34;file&#34;:&#34;DirectJDKLog.java&#34;,&#34;line&#34;:173,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;Starting service [Tomcat]&#34;}
{&#34;timestamp&#34;:&#34;2022-06-16T10:54:47.467Z&#34;,&#34;level&#34;:&#34;INFO&#34;,&#34;class&#34;:&#34;org.apache.juli.logging.DirectJDKLog&#34;,&#34;method&#34;:&#34;log&#34;,&#34;file&#34;:&#34;DirectJDKLog.java&#34;,&#34;line&#34;:173,&#34;thread&#34;:&#34;restartedMain&#34;,&#34;message&#34;:&#34;Starting Servlet engine: [Apache Tomcat/9.0.52]&#34;}
&lt;/script&gt;
&lt;script type=&#34;text/plain&#34; id=&#34;json-parser-example-query&#34;&gt;
| json | level=&#34;INFO&#34; | line_format &#34;{{.message}}&#34;
&lt;/script&gt;
&lt;script type=&#34;text/plain&#34; id=&#34;pattern-parser-example-logs&#34;&gt;
238.46.18.83 - - [09/Jun/2022:14:13:44 -0700] &#34;PUT /target/next-generation HTTP/2.0&#34; 404 19042
16.97.233.22 - - [09/Jun/2022:14:13:44 -0700] &#34;DELETE /extensible/functionalities HTTP/1.0&#34; 200 27913
46.201.144.32 - - [09/Jun/2022:14:13:44 -0700] &#34;PUT /e-enable/enable HTTP/2.0&#34; 504 26885
33.122.3.191 - corkery3759 [09/Jun/2022:14:13:44 -0700] &#34;POST /extensible/dynamic/enable HTTP/2.0&#34; 100 23741
94.115.144.32 - damore5842 [09/Jun/2022:14:13:44 -0700] &#34;PUT /matrix/envisioneer HTTP/1.0&#34; 205 29993
145.250.221.107 - price8727 [09/Jun/2022:14:13:44 -0700] &#34;PUT /iterate/networks/e-business/action-items HTTP/1.0&#34; 302 9718
33.201.165.66 - - [09/Jun/2022:14:13:44 -0700] &#34;GET /web-enabled/bricks-and-clicks HTTP/1.0&#34; 205 2353
33.83.191.176 - kling8903 [09/Jun/2022:14:13:44 -0700] &#34;DELETE /architect HTTP/1.1&#34; 401 13783
&lt;/script&gt;
&lt;script type=&#34;text/plain&#34; id=&#34;pattern-parser-example-query&#34;&gt;
| pattern &#34;&lt;_&gt; - &lt;_&gt; &lt;_&gt; \&#34;&lt;method&gt; &lt;url&gt; &lt;protocol&gt;\&#34; &lt;status&gt; &lt;_&gt; &lt;_&gt; \&#34;&lt;_&gt;\&#34; &lt;_&gt;&#34; | status &gt;= 200 and status &lt; 300
&lt;/script&gt;
&lt;script src=&#34;../analyzer/script.js&#34;&gt; &lt;/script&gt;
&lt;h2 id=&#34;additional-sample-queries&#34;&gt;Additional sample queries&lt;/h2&gt;
&lt;p&gt;These are some additional sample queries that you can use in the LogQL simulator.&lt;/p&gt;
&lt;h3 id=&#34;logfmt&#34;&gt;Logfmt&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;| logfmt | level = &amp;#34;debug&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parses logfmt-formatted logs and returns only log lines where the &amp;ldquo;level&amp;rdquo; field is equal to &amp;ldquo;debug&amp;rdquo;.&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;| logfmt | msg=&amp;#34;server listening on addresses&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parses logfmt-formatted logs and returns only log lines with the message “server listening on address.”&lt;/p&gt;
&lt;h3 id=&#34;json&#34;&gt;JSON&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;| json | level=&amp;#34;INFO&amp;#34; | file=&amp;#34;SpringApplication.java&amp;#34; | line_format `{{.class}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parses JSON-formatted logs, filtering for lines where the &amp;rsquo;level&amp;rsquo; field is &amp;ldquo;INFO&amp;rdquo; and the &amp;lsquo;file field is &amp;ldquo;SpringApplication.java&amp;rdquo;, then formats the line to return only the &amp;lsquo;class&amp;rsquo; field.&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;|~ `(T|t)omcat`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Performs a regular expression filter for the string &amp;rsquo;tomcat&amp;rsquo; or &amp;lsquo;Tomcat&amp;rsquo;, without using a parser.&lt;/p&gt;
&lt;h3 id=&#34;unstructured-text&#34;&gt;Unstructured text&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;| pattern &amp;#34;&amp;lt;_&amp;gt; - &amp;lt;_&amp;gt; &amp;lt;_&amp;gt; \&amp;#34;&amp;lt;method&amp;gt; &amp;lt;url&amp;gt; &amp;lt;protocol&amp;gt;\&amp;#34; &amp;lt;status&amp;gt; &amp;lt;_&amp;gt; &amp;lt;_&amp;gt; \&amp;#34;&amp;lt;_&amp;gt;\&amp;#34; &amp;lt;_&amp;gt;&amp;#34; | method=&amp;#34;GET&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parses unstructured logs with the pattern parser, filtering for lines where the HTTP method is &amp;ldquo;GET&amp;rdquo;.&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;| pattern &amp;#34;&amp;lt;_&amp;gt; - &amp;lt;user&amp;gt; &amp;lt;_&amp;gt; \&amp;#34;&amp;lt;method&amp;gt; &amp;lt;url&amp;gt; &amp;lt;protocol&amp;gt;\&amp;#34; &amp;lt;status&amp;gt; &amp;lt;_&amp;gt; &amp;lt;_&amp;gt; \&amp;#34;&amp;lt;_&amp;gt;\&amp;#34; &amp;lt;_&amp;gt;&amp;#34; | user=~&amp;#34;kling.*&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Parses unstructured logs with the pattern parser, extracting the &amp;lsquo;user&amp;rsquo; field, and filtering for lines where the user field starts with &amp;ldquo;kling&amp;rdquo;.&lt;/p&gt;
]]></content><description>&lt;link rel="stylesheet" href="../analyzer/style.css">
&lt;script src="../analyzer/handlebars.js">&lt;/script>
&lt;h1 id="simple-logql-simulator">Simple LogQL simulator&lt;/h1>
&lt;p>The LogQL simulator is an online tool that you can use to experiment with writing simple LogQL queries and seeing the results, without needing to run an instance of Loki.&lt;/p></description></item><item><title>Log queries</title><link>https://grafana.com/docs/loki/v3.7.x/query/log_queries/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/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; Unlike the &lt;a href=&#34;#line-filter-expression&#34;&gt;line filter regex expressions&lt;/a&gt;, the &lt;code&gt;=~&lt;/code&gt; and &lt;code&gt;!~&lt;/code&gt; regex operators are fully anchored.
This means that the regex expression must match against the &lt;em&gt;entire&lt;/em&gt; string, &lt;strong&gt;including newlines&lt;/strong&gt;.
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;.
Alternatively, you can use the &lt;code&gt;\s&lt;/code&gt; (match whitespaces, including newline) in combination with &lt;code&gt;\S&lt;/code&gt; (match not whitespace characters) to match all characters, including newlines.
Refer to &lt;a href=&#34;https://github.com/google/re2/wiki/Syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Google&amp;rsquo;s RE2 syntax&lt;/a&gt; for more information.&lt;/p&gt;
&lt;p&gt;Regex log stream newlines:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{name =~ &amp;quot;.*mysql.*&amp;quot;}&lt;/code&gt;: does not match log label values with newline character&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{name =~ &amp;quot;(?s).*mysql.*}&lt;/code&gt;: match log label values with newline character&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{name =~ &amp;quot;[\S\s]*mysql[\S\s]*}&lt;/code&gt;: match log label values with newline character&lt;/li&gt;
&lt;/ul&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 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 four 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;li&gt;Labels expressions: &lt;a href=&#34;#drop-labels-expression&#34;&gt;drop labels expression&lt;/a&gt; and &lt;a href=&#34;#keep-labels-expression&#34;&gt;keep labels expression&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;&lt;strong&gt;Note:&lt;/strong&gt; Unlike the &lt;a href=&#34;#log-stream-selector&#34;&gt;label matcher regex operators&lt;/a&gt;, the &lt;code&gt;|~&lt;/code&gt; and &lt;code&gt;!~&lt;/code&gt; regex operators are not fully anchored.
This means that the &lt;code&gt;.&lt;/code&gt; regex character matches all characters, &lt;strong&gt;including newlines&lt;/strong&gt;.&lt;/p&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;removing-color-codes&#34;&gt;Removing color codes&lt;/h3&gt;
&lt;p&gt;Line filter expressions support stripping ANSI sequences (color codes) from
the line:&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;example&amp;#34;} | decolorize&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&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 left 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;. The value of the label identifier used for comparison must be a string with a unit suffix to be parsed correctly, such as &amp;ldquo;0.10ms&amp;rdquo; or &amp;ldquo;1h30m&amp;rdquo;. Optionally, &lt;code&gt;label_format&lt;/code&gt; can be used to modify the value and append the unit before making the comparison.&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;kB&amp;rdquo;, &amp;ldquo;MB&amp;rdquo;, &amp;ldquo;GB&amp;rdquo;, &amp;ldquo;TB&amp;rdquo;, &amp;ldquo;KB&amp;rdquo;, &amp;ldquo;KiB&amp;rdquo;, &amp;ldquo;MiB&amp;rdquo;, &amp;ldquo;GiB&amp;rdquo;, &amp;ldquo;TiB&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 comparison 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;The precedence for evaluation of multiple predicates is left to right. You can wrap predicates with parenthesis to force a different precedence.&lt;/p&gt;
&lt;p&gt;These examples 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;To evaluate the logical &lt;code&gt;and&lt;/code&gt; first, use parenthesis, as in this 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;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 first 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;../query_examples/#examples-that-use-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;request_headers_Accept&amp;#34; =&amp;gt; &amp;#34;*/*&amp;#34;
&amp;#34;request_headers_User_Agent&amp;#34; =&amp;gt; &amp;#34;curl/7.68.0&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 operate 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;The &lt;strong&gt;logfmt&lt;/strong&gt; parser can be added using &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 result in having the following 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;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;with&lt;/strong&gt; parameters:&lt;/p&gt;
&lt;p&gt;Similar to &lt;a href=&#34;#json&#34;&gt;JSON&lt;/a&gt;, using &lt;code&gt;| logfmt label=&amp;quot;expression&amp;quot;, another=&amp;quot;expression&amp;quot;&lt;/code&gt; in the pipeline will result in extracting only the fields specified by the labels.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;| logfmt host, fwd_ip=&amp;quot;fwd&amp;quot;&lt;/code&gt; will extract the labels &lt;code&gt;host&lt;/code&gt; and &lt;code&gt;fwd&lt;/code&gt; from 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;And rename &lt;code&gt;fwd&lt;/code&gt; to &lt;code&gt;fwd_ip&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;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;host&amp;#34; =&amp;gt; &amp;#34;grafana.net&amp;#34;
&amp;#34;fwd_ip&amp;#34; =&amp;gt; &amp;#34;124.133.124.161&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The logfmt parser also supports the following flags:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--strict&lt;/code&gt; to enable strict parsing&lt;/p&gt;
&lt;p&gt;With strict parsing enabled, the logfmt parser immediately stops scanning the log line and returns early with an error when it encounters any poorly formatted key/value pair.&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;// accepted key/value pairs
key=value key=&amp;#34;value in double quotes&amp;#34;

// invalid key/value pairs
=value // no key
foo=bar=buzz
fo&amp;#34;o=bar&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Without the &lt;code&gt;--strict&lt;/code&gt; flag the parser skips invalid key/value pairs and continues parsing the rest of the log line.
Non-strict mode offers the flexibility to parse semi-structed log lines, though note that this is only best-effort.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;--keep-empty&lt;/code&gt; to retain standalone keys with empty value&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;--keep-empty&lt;/code&gt; flag set, the logfmt parser retains standalone keys(keys without a value) as labels with value set to empty string.
If the standalone key is explicitly requested using label extraction parameters, there is no need to add this flag.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note: flags if any should appear right after logfmt and before label extraction parameters&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;| logfmt --strict
| logfmt --strict host, fwd_ip=&amp;#34;fwd&amp;#34;
| logfmt --keep-empty --strict host&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 the &lt;a href=&#34;/docs/alloy/latest/reference/components/loki/loki.process/#stagepack-block&#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;Additionally, you can also access the log line using the 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/template_functions/#__line__&#34;&gt;&lt;code&gt;__line__&lt;/code&gt;&lt;/a&gt; function and the timestamp using the 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/template_functions/#__timestamp__&#34;&gt;&lt;code&gt;__timestamp__&lt;/code&gt;&lt;/a&gt; function. See 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/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;h3 id=&#34;drop-labels-expression&#34;&gt;Drop Labels expression&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;:  &lt;code&gt;|drop name, other_name, some_name=&amp;quot;some_value&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;| drop&lt;/code&gt; expression will drop the given labels in the pipeline. For example, for the query &lt;code&gt;{job=&amp;quot;varlogs&amp;quot;}|json|drop level, method=&amp;quot;GET&amp;quot;&lt;/code&gt;, with below log line&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;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;the result will be&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;{host=&amp;#34;grafana.net&amp;#34;, path=&amp;#34;/&amp;#34;, status=&amp;#34;200&amp;#34;} {&amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, this expression can be used to drop &lt;code&gt;__error__&lt;/code&gt; labels as well. For example, for the query &lt;code&gt;{job=&amp;quot;varlogs&amp;quot;}|json|drop __error__&lt;/code&gt;, with below log line&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;INFO GET / loki.net 200&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;the result will be&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;{} INFO GET / loki.net 200&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Example with regex and multiple names&lt;/p&gt;
&lt;p&gt;For the query &lt;code&gt;{job=&amp;quot;varlogs&amp;quot;}|json|drop level, path, app=~&amp;quot;some-api.*&amp;quot;&lt;/code&gt;, with below log lines&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;app&amp;#34;: &amp;#34;some-api-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}
{&amp;#34;app&amp;#34;: &amp;#34;other-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;the result will be&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;{host=&amp;#34;grafana.net&amp;#34;, job=&amp;#34;varlogs&amp;#34;, method=&amp;#34;GET&amp;#34;, status=&amp;#34;200&amp;#34;} {&amp;#34;app&amp;#34;: &amp;#34;some-api-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}
{app=&amp;#34;other-service&amp;#34;, host=&amp;#34;grafana.net&amp;#34;, job=&amp;#34;varlogs&amp;#34;, method=&amp;#34;GET&amp;#34;, status=&amp;#34;200&amp;#34;} {&amp;#34;app&amp;#34;: &amp;#34;other-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;keep-labels-expression&#34;&gt;Keep Labels expression&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;:  &lt;code&gt;|keep name, other_name, some_name=&amp;quot;some_value&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;| keep&lt;/code&gt; expression will keep only the specified labels in the pipeline and drop all the other labels.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The keep stage will not drop the  &lt;strong&gt;error&lt;/strong&gt; or &lt;strong&gt;error_details&lt;/strong&gt; labels added by Loki at query time. To drop these labels, refer to &lt;a href=&#34;#drop-labels-expression&#34;&gt;drop&lt;/a&gt; stage.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;Query examples:&lt;/p&gt;
&lt;p&gt;For the query &lt;code&gt;{job=&amp;quot;varlogs&amp;quot;}|json|keep level, method=&amp;quot;GET&amp;quot;&lt;/code&gt;, with the following log lines:&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;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}
{&amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;POST&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;the result will be&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;{level=&amp;#34;info&amp;#34;, method=&amp;#34;GET&amp;#34;} {&amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}
{level=&amp;#34;info&amp;#34;} {&amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;POST&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For the query &lt;code&gt;{job=&amp;quot;varlogs&amp;quot;}|json|keep level, tenant, app=~&amp;quot;some-api.*&amp;quot;&lt;/code&gt;, with the following log lines:&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;app&amp;#34;: &amp;#34;some-api-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}
{&amp;#34;app&amp;#34;: &amp;#34;other-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;the result will be&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;{app=&amp;#34;some-api-service&amp;#34;, level=&amp;#34;info&amp;#34;} {&amp;#34;app&amp;#34;: &amp;#34;some-api-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&amp;#34;}
{level=&amp;#34;info&amp;#34;} {&amp;#34;app&amp;#34;: &amp;#34;other-service&amp;#34;, &amp;#34;level&amp;#34;: &amp;#34;info&amp;#34;, &amp;#34;method&amp;#34;: &amp;#34;GET&amp;#34;, &amp;#34;path&amp;#34;: &amp;#34;/&amp;#34;, &amp;#34;host&amp;#34;: &amp;#34;grafana.net&amp;#34;, &amp;#34;status&amp;#34;: &amp;#34;200&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/loki/v3.7.x/query/metric_queries/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/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;h4 id=&#34;offset-modifier&#34;&gt;Offset modifier&lt;/h4&gt;
&lt;p&gt;The offset modifier allows changing the time offset for individual range vectors in a query.&lt;/p&gt;
&lt;p&gt;For example, the following expression counts all the logs within the last ten minutes to five minutes rather than last five minutes for the MySQL job. Note that the &lt;code&gt;offset&lt;/code&gt; modifier always needs to follow the range vector selector immediately.&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] offset 5m) // GOOD
count_over_time({job=&amp;#34;mysql&amp;#34;}[5m]) offset 5m // INVALID&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&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;, &lt;code&gt;rate&lt;/code&gt; and &lt;code&gt;rate_counter&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;p&gt;See &lt;a href=&#34;../query_examples/#unwrap-examples&#34;&gt;Unwrap examples&lt;/a&gt; for query examples that use the unwrap expression.&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;li&gt;&lt;code&gt;sort&lt;/code&gt;: returns vector elements sorted by their sample values, in ascending order.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sort_desc&lt;/code&gt;: Same as sort, but sorts in descending order.&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;p&gt;See &lt;a href=&#34;../query_examples/#vector-aggregation-examples&#34;&gt;vector aggregation examples&lt;/a&gt; for query examples that use vector aggregation expressions.&lt;/p&gt;
&lt;h2 id=&#34;functions&#34;&gt;Functions&lt;/h2&gt;
&lt;p&gt;LogQL supports a set of built-in functions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;vector(s scalar)&lt;/code&gt;: returns the scalar s as a vector with no labels. This behaves identically to the &lt;a href=&#34;https://prometheus.io/docs/prometheus/latest/querying/functions/#vector&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Prometheus &lt;code&gt;vector()&lt;/code&gt; function&lt;/a&gt;.
&lt;code&gt;vector&lt;/code&gt; is mainly used to return a value for a series that would otherwise return nothing; this can be useful when using LogQL to define an alert.&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 traefik namespace.&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({namespace=&amp;#34;traefik&amp;#34;}[5m])) # will return nothing
  or
vector(0) # will return 0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;probabilistic-aggregation&#34;&gt;Probabilistic aggregation&lt;/h2&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Probabilistic aggregation is an experimental feature. Engineering and on-call support is not available. Documentation is either limited or not provided outside of code comments. No SLA is provided. To use this feature, set &lt;code&gt;limits_config.shard_aggregations:approx_topk&lt;/code&gt; in your 
    &lt;a href=&#34;/docs/loki/v3.7.x/configure/#limits_config&#34;&gt;Loki configuration&lt;/a&gt;. To enable this feature in Grafana Cloud, contact Grafana Support.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;LogQL&amp;rsquo;s &lt;code&gt;approx_topk&lt;/code&gt; function provides a probabilistic approximation of &lt;code&gt;topk&lt;/code&gt;. It is a drop-in replacement for &lt;code&gt;topk&lt;/code&gt; that is great for when &lt;code&gt;topk&lt;/code&gt; queries time out or hit the maximum series limit. This tends to happen when the list of values that you&amp;rsquo;re sorting through in order to find the most frequent values is very large. &lt;code&gt;approx_topk&lt;/code&gt; is also great in cases where a faster, approximate answer is preferred to a slower, more accurate one.&lt;/p&gt;
&lt;p&gt;The function is of the form:&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;approx_topk(k, &amp;lt;vector expression&amp;gt;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;approx_topk&lt;/code&gt; is only supported for instant queries. Grouping is also not supported and should be handled by an inner &lt;code&gt;sum by&lt;/code&gt; or &lt;code&gt;sum without&lt;/code&gt; even though this might not be the same behavior as &lt;code&gt;topk by&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Under the hood, &lt;code&gt;approx_topk&lt;/code&gt; is implemented using sharding. The &lt;a href=&#34;https://en.wikipedia.org/wiki/Count%E2%80%93min_sketch&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;count-min sketch&lt;/a&gt; algorithm and a heap are used to approximate the counts for each shard. The accuracy of the approximation depends on the size of the heap, which is defined by Loki&amp;rsquo;s&lt;code&gt;max_count_min_sketch_heap_size&lt;/code&gt; parameter. Accuracy decreases as &lt;code&gt;k&lt;/code&gt; approaches the size of the heap (which has a default size of &lt;code&gt;10,000&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The expression &lt;code&gt;approx_topk(k,inner)&lt;/code&gt; becomes&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;topk(
  k,
  eval_cms(
    __count_min_sketch__(inner, shard=1) &amp;#43;&amp;#43; __count_min_sketch__(inner, shard=2)...
  )
)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;__count_min_sketch__&lt;/code&gt; is calculated for each shard and merged on the frontend. Then &lt;code&gt;eval_cms&lt;/code&gt; iterates through the labels list and determines the count for each. Then &lt;code&gt;topk&lt;/code&gt; selects the top items.&lt;/p&gt;
&lt;h2 id=&#34;further-resources&#34;&gt;Further resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Watch: &lt;a href=&#34;https://youtube.com/live/tKcnQ0Q2E-k&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;How to turn logs into metrics with Grafana Loki&lt;/a&gt; (Loki Community Call July 2025)&lt;/li&gt;
&lt;/ul&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>LogQL template functions</title><link>https://grafana.com/docs/loki/v3.7.x/query/template_functions/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/template_functions/</guid><content><![CDATA[&lt;h1 id=&#34;logql-template-functions&#34;&gt;LogQL template functions&lt;/h1&gt;
&lt;p&gt;The Go templating language is embedded in the Loki query language, LogQL.
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;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;In the examples below we use backticks to quote the template strings. This is because some template strings contain double quotes, and using backticks lets us avoid escaping the double quotes.
If you are using a different quoting style, you may need to escape the double quotes.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;For more information, refer to the &lt;a href=&#34;https://pkg.go.dev/text/template&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Go template documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Additionally you can also access the log line using the &lt;code&gt;__line__&lt;/code&gt; function and the timestamp using the &lt;code&gt;__timestamp__&lt;/code&gt; function.&lt;/p&gt;
&lt;h2 id=&#34;template-pipeline-syntax&#34;&gt;Template pipeline syntax&lt;/h2&gt;
&lt;p&gt;A pipeline is a possibly chained sequence of &amp;ldquo;commands&amp;rdquo;. A command is a simple value (argument) or a function or method call, possibly with multiple arguments. A pipeline may be &amp;ldquo;chained&amp;rdquo; by separating a sequence of commands with pipeline characters &amp;lsquo;|&amp;rsquo;. In a chained pipeline, the result of each command is passed as the last argument of the following command. The output of the final command in the pipeline is the value of the pipeline.&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.&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;p&gt;For function that returns a &lt;code&gt;bool&lt;/code&gt; such as &lt;code&gt;contains&lt;/code&gt;, &lt;code&gt;eq&lt;/code&gt;, &lt;code&gt;hasPrefix&lt;/code&gt; and &lt;code&gt;hasSuffix&lt;/code&gt;, you can apply &lt;code&gt;AND&lt;/code&gt; / &lt;code&gt;OR&lt;/code&gt; and nested &lt;code&gt;if&lt;/code&gt; logic.&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;`{{ if and (contains &amp;#34;he&amp;#34; &amp;#34;hello&amp;#34;) (contains &amp;#34;llo&amp;#34; &amp;#34;hello&amp;#34;) }} yes {{end}}`
`{{ if or (contains &amp;#34;he&amp;#34; &amp;#34;hello&amp;#34;) (contains(&amp;#34;llo&amp;#34; &amp;#34;hello&amp;#34;) }} yes {{end}}`
`{{ if contains &amp;#34;ErrTimeout&amp;#34; .err }} timeout {{else if contains &amp;#34;he&amp;#34; &amp;#34;hello&amp;#34;}} yes {{else}} no {{end}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;built-in-variables-for-log-line-properties&#34;&gt;Built-in variables for log line properties&lt;/h2&gt;
&lt;p&gt;These variables provide a way of referencing something from the log line when writing a template expression.&lt;/p&gt;
&lt;h3 id=&#34;label_name&#34;&gt;.label_name&lt;/h3&gt;
&lt;p&gt;All labels from the Log line are added as variables in the template engine. They can be referenced using the label name prefixed by a &lt;code&gt;.&lt;/code&gt;(for example,&lt;code&gt;.label_name&lt;/code&gt;). For example the following template will output the value of the &lt;code&gt;path&lt;/code&gt; 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;h3 id=&#34;line&#34;&gt;&lt;strong&gt;line&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;__line__&lt;/code&gt; function returns the original log line without any modifications.&lt;/p&gt;
&lt;p&gt;Signature: &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;`{{ __line__ | lower }}`
`{{ __line__ }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;timestamp&#34;&gt;&lt;strong&gt;timestamp&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;__timestamp__&lt;/code&gt; function returns the current log line&amp;rsquo;s timestamp.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;timestamp() time.Time&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;`{{ __timestamp__ }}`
`{{ __timestamp__ | date &amp;#34;2006-01-02T15:04:05.00Z-07:00&amp;#34; }}`
`{{ __timestamp__ | unixEpoch }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For more information, refer to the blog &lt;a href=&#34;https://www.pauladamsmith.com/blog/2011/05/go_time.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Parsing and formatting date/time in Go&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;date-and-time&#34;&gt;Date and time&lt;/h2&gt;
&lt;p&gt;You can use the following functions to manipulate dates and times when building LogQL queries.&lt;/p&gt;
&lt;h3 id=&#34;date&#34;&gt;date&lt;/h3&gt;
&lt;p&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;p&gt;Signature: &lt;code&gt;date(fmt string, date interface{}) string&lt;/code&gt;&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;`{{ date &amp;#34;2006-01-02&amp;#34; now }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;duration&#34;&gt;duration&lt;/h3&gt;
&lt;p&gt;An alias for &lt;code&gt;duration_seconds&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;`{{ .foo | duration }}`
`{{ duration .foo }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;duration_seconds&#34;&gt;duration_seconds&lt;/h3&gt;
&lt;p&gt;Convert a humanized time duration to seconds using &lt;a href=&#34;https://pkg.go.dev/time#ParseDuration&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;time.ParseDuration&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;duration_seconds(string) float64&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;`{{ .foo | duration_seconds }}`
`{{ duration_seconds .foo }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;now&#34;&gt;now&lt;/h3&gt;
&lt;p&gt;Returns the current time in the local timezone of the Loki server.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;Now() time.Time&lt;/code&gt;&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;`{{ now }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;todate&#34;&gt;toDate&lt;/h3&gt;
&lt;p&gt;Parses a formatted string and returns the time value it represents using the local timezone of the server running Loki.&lt;/p&gt;
&lt;p&gt;For more consistency between Loki installations, it&amp;rsquo;s recommended to use &lt;code&gt;toDateInZone&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The format string must use the exact date as defined in the &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;p&gt;Signature: &lt;code&gt;toDate(fmt, str string) time.Time&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;`{{ toDate &amp;#34;2006-01-02&amp;#34; &amp;#34;2021-11-02&amp;#34; }}`
`{{ .foo | toDate &amp;#34;2006-01-02T15:04:05.999999999Z&amp;#34; }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;todateinzone&#34;&gt;toDateInZone&lt;/h3&gt;
&lt;p&gt;Parses a formatted string and returns the time value it represents in the provided timezone.&lt;/p&gt;
&lt;p&gt;The format string must use the exact date as defined in the &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;p&gt;The timezone value can be &lt;code&gt;Local&lt;/code&gt;, &lt;code&gt;UTC&lt;/code&gt;, or any of the IANA Time Zone database values&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;toDateInZone(fmt, zone, str string) time.Time&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;`{{ toDateInZone &amp;#34;2006-01-02&amp;#34; &amp;#34;UTC&amp;#34; &amp;#34;2021-11-02&amp;#34; }}`
`{{ .foo | toDateInZone &amp;#34;2006-01-02T15:04:05.999999999Z&amp;#34; &amp;#34;UTC&amp;#34; }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;unixepoch&#34;&gt;unixEpoch&lt;/h3&gt;
&lt;p&gt;Returns the number of seconds elapsed since January 1, 1970 UTC.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;unixEpoch(date time.Time) 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;`{{ unixEpoch now }}`
`{{ .foo | toDateInZone &amp;#34;2006-01-02T15:04:05.999999999Z&amp;#34; &amp;#34;UTC&amp;#34; | unixEpoch }}`&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=`{{sub .nowEpoch .createDateEpoch}}` | dateTimeDiff &amp;gt; 86400&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;unixepochmillis&#34;&gt;unixEpochMillis&lt;/h3&gt;
&lt;p&gt;Returns the number of milliseconds elapsed since January 1, 1970 UTC.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;unixEpochMillis(date time.Time) 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;`{{ unixEpochMillis now }}`
`{{ .foo | toDateInZone &amp;#34;2006-01-02T15:04:05.999999999Z&amp;#34; &amp;#34;UTC&amp;#34; | unixEpochMillis }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;unixepochnanos&#34;&gt;unixEpochNanos&lt;/h3&gt;
&lt;p&gt;Returns the number of nanoseconds elapsed since January 1, 1970 UTC.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;unixEpochNanos(date time.Time) 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;`{{ unixEpochNanos now }}`
`{{ .foo | toDateInZone &amp;#34;2006-01-02T15:04:05.999999999Z&amp;#34; &amp;#34;UTC&amp;#34; | unixEpochNanos }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;unixtotime&#34;&gt;unixToTime&lt;/h3&gt;
&lt;p&gt;Converts the string epoch to the time value it represents. Epoch times in days, seconds, milliseconds, microseconds and nanoseconds are supported.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;unixToTime(epoch string) time.Time&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Examples:&lt;/p&gt;
&lt;p&gt;Consider the following log line &lt;code&gt;{&amp;quot;from&amp;quot;: &amp;quot;1679577215&amp;quot;,&amp;quot;to&amp;quot;:&amp;quot;1679587215&amp;quot;,&amp;quot;message&amp;quot;:&amp;quot;some message&amp;quot;}&lt;/code&gt;. To print the &lt;code&gt;from&lt;/code&gt; field as human readable add the following at the end of the LogQL query:&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;... | json | line_format `from=&amp;#34;{{date &amp;#34;2006-01-02&amp;#34; (unixToTime .from)}}&amp;#34;`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;string-manipulation&#34;&gt;String manipulation&lt;/h2&gt;
&lt;p&gt;You can use the following templates to manipulate strings when building LogQL Queries.&lt;/p&gt;
&lt;h3 id=&#34;alignleft&#34;&gt;alignLeft&lt;/h3&gt;
&lt;p&gt;Use this function to format a string to a fixed with, aligning the content to the left.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;alignLeft(count int, 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;`{{ alignLeft 5 &amp;#34;hello world&amp;#34;}}` // output: &amp;#34;hello&amp;#34;
`{{ alignLeft 5 &amp;#34;hi&amp;#34;}}`          // output: &amp;#34;hi   &amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;alignright&#34;&gt;alignRight&lt;/h3&gt;
&lt;p&gt;Use this function to format a string to a fixed with, aligning the content to the right.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;alignRight(count int, 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;`{{ alignRight 5 &amp;#34;hello world&amp;#34;}}` // output: &amp;#34;world&amp;#34;
`{{ alignRight 5 &amp;#34;hi&amp;#34;}}`          // output: &amp;#34;   hi&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;b64enc&#34;&gt;b64enc&lt;/h3&gt;
&lt;p&gt;Base64 encode a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;b64enc(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;`{{ .foo | b64enc }}`
`{{ b64enc  .foo }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;b64dec&#34;&gt;b64dec&lt;/h3&gt;
&lt;p&gt;Base64 decode a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;b64dec(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;`{{ .foo | b64dec }}`
`{{ b64dec  .foo }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;bytes&#34;&gt;bytes&lt;/h3&gt;
&lt;p&gt;Convert a humanized byte string to bytes using go-humanize. Durations can be turned into strings such as &amp;ldquo;3 days ago&amp;rdquo;, numbers
representing sizes like 82854982 into useful strings like, &amp;ldquo;83 MB&amp;rdquo; or
&amp;ldquo;79 MiB&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;bytes(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;`{{ .foo | bytes }}`
`{{ bytes .foo }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;default&#34;&gt;default&lt;/h3&gt;
&lt;p&gt;Enables outputting a default value if the source string is otherwise empty. If the &amp;lsquo;src&amp;rsquo; parameter is not empty, this function returns the value of &amp;lsquo;src&amp;rsquo;. Useful for JSON fields that can be missing, like HTTP headers in a log line that aren&amp;rsquo;t required, as in the following 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;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;
&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;
&lt;h3 id=&#34;fromjson&#34;&gt;fromJson&lt;/h3&gt;
&lt;p&gt;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;p&gt;Signature: &lt;code&gt;fromJson(v string) interface{}&lt;/code&gt;&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;`{{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 `{{ range $q := fromJson .queries }} {{ $q.query }} {{ end }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;lower&#34;&gt;lower&lt;/h3&gt;
&lt;p&gt;Use this function to convert to lower case.&lt;/p&gt;
&lt;p&gt;Signature: &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;`{{ .request_method | lower }}`
`{{ 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;h3 id=&#34;indent&#34;&gt;indent&lt;/h3&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;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;`{{ 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;h3 id=&#34;nindent&#34;&gt;nindent&lt;/h3&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;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;`{{ 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;h3 id=&#34;repeat&#34;&gt;repeat&lt;/h3&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;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;`{{ repeat 3 &amp;#34;hello&amp;#34; }}` // output: hellohellohello&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;printf&#34;&gt;printf&lt;/h3&gt;
&lt;p&gt;Use this function to format a string in a custom way. For more information about the syntax, refer to the &lt;a href=&#34;https://pkg.go.dev/fmt&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Go documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;printf(format string, a ...interface{})&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;`{{ printf &amp;#34;The IP address was %s&amp;#34; .remote_addr }}` // output: The IP address was 129.168.1.1

`{{ printf &amp;#34;%-40.40s&amp;#34; .request_uri}} {{printf &amp;#34;%-5.5s&amp;#34; .request_method}}`
// output: 
// /a/509965767/alternative-to-my-mtg.html  GET
// /id/609259548/hpr.html                   GET&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&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;line_format &amp;#34;\&amp;#34;|\&amp;#34; {{printf \&amp;#34;%15.15s\&amp;#34; .ClientHost}} \&amp;#34;|\&amp;#34;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;replace&#34;&gt;replace&lt;/h3&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;h3 id=&#34;substr&#34;&gt;substr&lt;/h3&gt;
&lt;p&gt;Get a substring from a string.&lt;/p&gt;
&lt;p&gt;Signature: &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;`{{ .path | substr 2 5 }}`
`{{ 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;h3 id=&#34;title&#34;&gt;title&lt;/h3&gt;
&lt;p&gt;Convert to title case.&lt;/p&gt;
&lt;p&gt;Signature: &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;`{{.request_method | title}}`
`{{ 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;h3 id=&#34;trim&#34;&gt;trim&lt;/h3&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;h3 id=&#34;trimall&#34;&gt;trimAll&lt;/h3&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;h3 id=&#34;trimprefix&#34;&gt;trimPrefix&lt;/h3&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(prefix 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;h3 id=&#34;trimsuffix&#34;&gt;trimSuffix&lt;/h3&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;h3 id=&#34;trunc&#34;&gt;trunc&lt;/h3&gt;
&lt;p&gt;Truncate a string and add no suffix.&lt;/p&gt;
&lt;p&gt;Signature: &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;`{{ .path | trunc 2 }}`
`{{ 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;h3 id=&#34;upper&#34;&gt;upper&lt;/h3&gt;
&lt;p&gt;Use this function to convert to upper case.&lt;/p&gt;
&lt;p&gt;Signature: &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;`{ .request_method | upper }}`
`{{ 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;h3 id=&#34;urlencode&#34;&gt;urlencode&lt;/h3&gt;
&lt;p&gt;Use this function to &lt;a href=&#34;https://en.wikipedia.org/wiki/URL_encoding&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;urlencode&lt;/a&gt; a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;urlencode(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;`{{ .request_url | urlencode }}`
`{{ urlencode  .request_url}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;urldecode&#34;&gt;urldecode&lt;/h3&gt;
&lt;p&gt;Use this function to &lt;a href=&#34;https://en.wikipedia.org/wiki/URL_encoding&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;urldecode&lt;/a&gt; a string.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;urldecode(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;`{{ .request_url | urldecode }}`
`{{ urldecode  .request_url}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;logical-functions&#34;&gt;Logical functions&lt;/h2&gt;
&lt;p&gt;You can use the following logical functions to compare strings when building a template expression.&lt;/p&gt;
&lt;h3 id=&#34;contains&#34;&gt;contains&lt;/h3&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 contains &amp;#34;ErrTimeout&amp;#34; .err }} 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;h3 id=&#34;eq&#34;&gt;eq&lt;/h3&gt;
&lt;p&gt;Use this function to test to see if one string has exact matching inside of another.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;eq(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 eq &amp;#34;ErrTimeout&amp;#34; .err }} timeout {{end}}`
`{{ if eq &amp;#34;hello&amp;#34; &amp;#34;hello&amp;#34; }} yes {{end}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;hasprefix-and-hassuffix&#34;&gt;hasPrefix and hasSuffix&lt;/h3&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 hasSuffix .err &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;mathematical-functions&#34;&gt;Mathematical functions&lt;/h2&gt;
&lt;p&gt;You can use the following mathematical functions when writing template expressions.&lt;/p&gt;
&lt;h3 id=&#34;add&#34;&gt;add&lt;/h3&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;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;`{{ add 3 2 5 }}` // output: 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;addf&#34;&gt;addf&lt;/h3&gt;
&lt;p&gt;Sum floating point 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;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;`{{ addf 3.5 2 5 }}` // output: 10.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;ceil&#34;&gt;ceil&lt;/h3&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;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;`{{ ceil 123.001 }}` //output 124.0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;div&#34;&gt;div&lt;/h3&gt;
&lt;p&gt;Divide two integers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a, b interface{}) int64&lt;/code&gt;&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;`{{ div 10 2}}` // output: 5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;divf&#34;&gt;divf&lt;/h3&gt;
&lt;p&gt;Divide floating point 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;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;`{{ divf 10 2 4}}` // output: 1.25&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;float64&#34;&gt;float64&lt;/h3&gt;
&lt;p&gt;Convert a string to a float64.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;toFloat64(v interface{}) float64&lt;/code&gt;&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;`{{ &amp;#34;3.5&amp;#34; | float64 }}` //output 3.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;floor&#34;&gt;floor&lt;/h3&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;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;`{{ floor 123.9999 }}` //output 123.0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;int&#34;&gt;int&lt;/h3&gt;
&lt;p&gt;Convert value to an integer.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;toInt(v interface{}) int&lt;/code&gt;&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;`{{ &amp;#34;3&amp;#34; | int }}` //output 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;max&#34;&gt;max&lt;/h3&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;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;`{{ max 1 2 3 }}` //output 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;maxf&#34;&gt;maxf&lt;/h3&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;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;`{{ maxf 1 2.5 3 }}` //output 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;min&#34;&gt;min&lt;/h3&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;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;`{{ min 1 2 3 }}`//output 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;minf&#34;&gt;minf&lt;/h3&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;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;`{{ minf 1 2.5 3 }}` //output 1.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;mul&#34;&gt;mul&lt;/h3&gt;
&lt;p&gt;Multiply numbers. Supports multiple numbers.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;mul(a interface{}, v ...interface{}) int64&lt;/code&gt;&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;`{{ mul 5 2 3}}` // output: 30&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;mulf&#34;&gt;mulf&lt;/h3&gt;
&lt;p&gt;Multiply floating numbers. Supports multiple numbers&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;mulf(a interface{}, v ...interface{}) float64&lt;/code&gt;&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;`{{ mulf 5.5 2 2.5 }}` // output: 27.5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;mod&#34;&gt;mod&lt;/h3&gt;
&lt;p&gt;Returns the remainder when number &amp;lsquo;a&amp;rsquo; is divided by number &amp;lsquo;b&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;mod(a, b interface{}) int64&lt;/code&gt;&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;`{{ mod 10 3}}` // output: 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;round&#34;&gt;round&lt;/h3&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;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;`{{ 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;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;`{{ 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;h3 id=&#34;sub&#34;&gt;sub&lt;/h3&gt;
&lt;p&gt;Subtract one number from another.&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;func(a, b interface{}) int64&lt;/code&gt;&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;`{{ sub 5 2 }}` // output: 3&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;subf&#34;&gt;subf&lt;/h3&gt;
&lt;p&gt;Subtract floating 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;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;`{{ subf  5.5 2 1.5 }}` // output: 2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;regular-expression-functions&#34;&gt;Regular expression functions&lt;/h2&gt;
&lt;p&gt;You can use the following functions to perform regular expressions in a template expression.&lt;/p&gt;
&lt;h3 id=&#34;count&#34;&gt;count&lt;/h3&gt;
&lt;p&gt;Counts occurrences of the regex (&lt;code&gt;regex&lt;/code&gt;) in (&lt;code&gt;src&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Signature: &lt;code&gt;count(regex string, src string) int&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;`{{ count &amp;#34;a|b&amp;#34; &amp;#34;abab&amp;#34; }}` // output: 4
`{{ count &amp;#34;o&amp;#34; &amp;#34;foo&amp;#34; }}`    // output: 2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Example of a query to print how many times XYZ occurs in a 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;xyzlog&amp;#34;} | line_format `{{ __line__ | count &amp;#34;XYZ&amp;#34;}}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;regexreplaceall-and-regexreplaceallliteral&#34;&gt;regexReplaceAll and regexReplaceAllLiteral&lt;/h3&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;p&gt;Signature: regexReplaceAll(regex string, src string, replacement string)
(source)&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;`{{ 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;p&gt;Signature: regexReplaceAllLiteral(regex string, src string, replacement string)&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;`{{ regexReplaceAllLiteral &amp;#34;(ts=)&amp;#34; .timestamp &amp;#34;timestamp=&amp;#34; }}`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="logql-template-functions">LogQL template functions&lt;/h1>
&lt;p>The Go templating language is embedded in the Loki query language, LogQL.
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></description></item><item><title>LogCLI</title><link>https://grafana.com/docs/loki/v3.7.x/query/logcli/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/logcli/</guid><content><![CDATA[&lt;h1 id=&#34;logcli&#34;&gt;LogCLI&lt;/h1&gt;
&lt;p&gt;LogCLI is a command-line tool for querying and exploring logs in Grafana Loki:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Installation and Reference: 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/logcli/getting-started/&#34;&gt;LogCLI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Getting started tutorial: 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/logcli/logcli-tutorial/&#34;&gt;LogCLI Tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="logcli">LogCLI&lt;/h1>
&lt;p>LogCLI is a command-line tool for querying and exploring logs in Grafana Loki:&lt;/p>
&lt;ul>
&lt;li>Installation and Reference:
&lt;a href="/docs/loki/v3.7.x/query/logcli/getting-started/">LogCLI&lt;/a>&lt;/li>
&lt;li>Getting started tutorial:
&lt;a href="/docs/loki/v3.7.x/query/logcli/logcli-tutorial/">LogCLI Tutorial&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Matching IP addresses</title><link>https://grafana.com/docs/loki/v3.7.x/query/ip/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/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 also 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;p&gt;This example use the conditional &lt;code&gt;or&lt;/code&gt; and matches log lines with either, all IPv4 subnet values &lt;code&gt;192.168.4.0/24&lt;/code&gt; OR all IPv4 subnet values &lt;code&gt;10.10.15.0/24&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.0/24&amp;#34;) or addr = ip(&amp;#34;10.10.15.0/24&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/loki/v3.7.x/query/query_examples/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/query_examples/</guid><content><![CDATA[&lt;h1 id=&#34;query-examples&#34;&gt;Query examples&lt;/h1&gt;
&lt;p&gt;These LogQL query examples have explanations of what the queries accomplish.&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;
&lt;h2 id=&#34;multiple-filtering-stages-examples&#34;&gt;Multiple filtering stages examples&lt;/h2&gt;
&lt;p&gt;Query results are gathered by successive evaluation of parts of the query from left to right.
To make querying efficient,
order the filtering stages left to right:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;stream selector&lt;/li&gt;
&lt;li&gt;line filters&lt;/li&gt;
&lt;li&gt;label filters&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Consider the query:&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;p&gt;Within this query, the stream selector is&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;{cluster=&amp;#34;ops-tools1&amp;#34;, namespace=&amp;#34;loki-dev&amp;#34;, job=&amp;#34;loki-dev/query-frontend&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;There are two line filters:
&lt;code&gt;|= &amp;quot;metrics.go&amp;quot;&lt;/code&gt;
and &lt;code&gt;!=&amp;quot;out of order&amp;quot;&lt;/code&gt;.
Of the log lines identified with the stream selector,
the query results
include only those log lines that contain the string &amp;ldquo;metrics.go&amp;rdquo;
and do not contain the string &amp;ldquo;out of order&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;logfmt&lt;/code&gt; parser produces the &lt;code&gt;duration&lt;/code&gt; and &lt;code&gt;status_code&lt;/code&gt; labels,
such that they can be used by a label filter.&lt;/p&gt;
&lt;p&gt;The label filter
&lt;code&gt;| duration &amp;gt; 30s or status_code!=&amp;quot;200&amp;quot;&lt;/code&gt;
further filters out log lines.
It includes those log lines that contain a &lt;code&gt;status_code&lt;/code&gt; label
with any value other than the value 200,
as well as log lines that contain a &lt;code&gt;duration&lt;/code&gt; label
with a value greater than 30 sections,&lt;/p&gt;
&lt;p&gt;While every query will have a stream selector,
not all queries will have line and label filters.&lt;/p&gt;
&lt;h2 id=&#34;examples-that-use-multiple-parsers&#34;&gt;Examples that use multiple parsers&lt;/h2&gt;
&lt;p&gt;Consider this logfmt log line.
To extract the method and the path of this 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;To extract the method and the path,
use multiple parsers (logfmt and regexp):&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;h2 id=&#34;log-line-formatting-examples&#34;&gt;Log line formatting examples&lt;/h2&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;
&lt;p&gt;It&amp;rsquo;s possible to strip ANSI sequences from the log line, making it easier
to parse it further:&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;example&amp;#34;} | decolorize&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This way this log line:&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;[2022-11-04 22:17:57.811] \033[0;32http\033[0m: GET /_health (0 ms) 204&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;turns into:&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;[2022-11-04 22:17:57.811] http: GET /_health (0 ms) 204&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;unwrap-examples&#34;&gt;Unwrap examples&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Calculate 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;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;/li&gt;
&lt;li&gt;
&lt;p&gt;Calculate the quantity of bytes processed per organization ID:&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;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;vector-aggregation-examples&#34;&gt;Vector aggregation examples&lt;/h2&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="query-examples">Query examples&lt;/h1>
&lt;p>These LogQL query examples have explanations of what the queries accomplish.&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><item><title>Query acceleration</title><link>https://grafana.com/docs/loki/v3.7.x/query/query_acceleration/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/query_acceleration/</guid><content><![CDATA[&lt;h1 id=&#34;query-acceleration&#34;&gt;Query acceleration&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;In Loki and Grafana Enterprise Logs (GEL), Query acceleration using blooms is an &lt;a href=&#34;/docs/release-life-cycle/&#34;&gt;experimental feature&lt;/a&gt;. Engineering and on-call support is not available. No SLA is provided.&lt;/p&gt;
&lt;p&gt;In Grafana Cloud, Query acceleration using Bloom filters is enabled as a &lt;a href=&#34;/docs/release-life-cycle/&#34;&gt;public preview&lt;/a&gt; for select large-scale customers that are ingesting more that 75TB of logs a month. Limited support and no SLA are provided.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;If 
    &lt;a href=&#34;/docs/loki/v3.7.x/operations/bloom-filters/&#34;&gt;bloom filters&lt;/a&gt; are enabled, you can write LogQL queries using 
    &lt;a href=&#34;/docs/loki/v3.7.x/get-started/labels/structured-metadata/&#34;&gt;structured metadata&lt;/a&gt; to benefit from query acceleration.&lt;/p&gt;
&lt;h2 id=&#34;prerequisites&#34;&gt;Prerequisites&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/loki/v3.7.x/operations/bloom-filters/&#34;&gt;Bloom filters&lt;/a&gt; must be enabled. OpenSource and Enterprise customers must 
    &lt;a href=&#34;/docs/loki/v3.7.x/operations/bloom-filters/#enable-bloom-filters&#34;&gt;enable bloom filters&lt;/a&gt;. Grafana Support enables Bloom Filters for Cloud Customers who are part of the public preview.&lt;/li&gt;
&lt;li&gt;Logs must be sending 
    &lt;a href=&#34;/docs/loki/v3.7.x/get-started/labels/structured-metadata/&#34;&gt;structured metadata&lt;/a&gt;. OpenSource and Enterprise customers must 
    &lt;a href=&#34;/docs/loki/v3.7.x/get-started/labels/structured-metadata/#enable-or-disable-structured-metadata&#34;&gt;enable structured metadata&lt;/a&gt;. Structured metadata is enabled by default in Grafana Cloud.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;query-blooms&#34;&gt;Query blooms&lt;/h3&gt;
&lt;p&gt;Queries will be accelerated for any 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#label-filter-expression&#34;&gt;label filter expression&lt;/a&gt; that satisfies &lt;em&gt;all&lt;/em&gt; of the following criteria:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The label filter expression using &lt;strong&gt;string equality&lt;/strong&gt;, such as &lt;code&gt;| key=&amp;quot;value&amp;quot;&lt;/code&gt;.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;or&lt;/code&gt; and &lt;code&gt;and&lt;/code&gt; operators can be used to match multiple values, such as &lt;code&gt;| detected_level=&amp;quot;error&amp;quot; or detected_level=&amp;quot;warn&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Basic&lt;/em&gt; regular expressions are automatically simplified into a supported expression:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;| key=~&amp;quot;value&amp;quot;&lt;/code&gt; is converted to &lt;code&gt;| key=&amp;quot;value&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;| key=~&amp;quot;value1|value2&amp;quot;&lt;/code&gt; is converted to &lt;code&gt;| key=&amp;quot;value1&amp;quot; or key=&amp;quot;value2&amp;quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;| key=~&amp;quot;.&#43;&amp;quot;&lt;/code&gt; checks for existence of &lt;code&gt;key&lt;/code&gt;. &lt;code&gt;.*&lt;/code&gt; is not supported.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The label filter expression is querying for structured metadata and not a stream label.&lt;/li&gt;
&lt;li&gt;The label filter expression is placed before any 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#parser-expression&#34;&gt;parser expression&lt;/a&gt;, 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#labels-format-expression&#34;&gt;labels format expression&lt;/a&gt;, 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#drop-labels-expression&#34;&gt;drop labels expression&lt;/a&gt;, or 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/#keep-labels-expression&#34;&gt;keep labels expression&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To take full advantage of query acceleration with blooms, ensure that filtering structured metadata is done before any parser expression:&lt;/p&gt;
&lt;p&gt;In the following example, the query is not accelerated because the structured metadata filter, &lt;code&gt;detected_level=&amp;quot;error&amp;quot;&lt;/code&gt;, is after a parser stage, &lt;code&gt;json&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;{cluster=&amp;#34;prod&amp;#34;} | logfmt | json | detected_level=&amp;#34;error&amp;#34; &lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;In the following example, the query is accelerated because the structured metadata filter is before any parser stage.&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;prod&amp;#34;} | detected_level=&amp;#34;error&amp;#34; | logfmt | json &lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="query-acceleration">Query acceleration&lt;/h1>
&lt;div class="admonition admonition-warning">&lt;blockquote>&lt;p class="title text-uppercase">Warning&lt;/p>&lt;p>In Loki and Grafana Enterprise Logs (GEL), Query acceleration using blooms is an &lt;a href="/docs/release-life-cycle/">experimental feature&lt;/a>. Engineering and on-call support is not available. No SLA is provided.&lt;/p></description></item><item><title>LogQL Reference</title><link>https://grafana.com/docs/loki/v3.7.x/query/query_reference/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/query_reference/</guid><content><![CDATA[&lt;h1 id=&#34;logql-reference&#34;&gt;LogQL Reference&lt;/h1&gt;
&lt;p&gt;Loki accepts a number of operators and functions within a 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/&#34;&gt;LogQL query&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;binary-operators&#34;&gt;Binary operators&lt;/h2&gt;
&lt;h3 id=&#34;arithmetic-operators&#34;&gt;Arithmetic operators&lt;/h3&gt;
&lt;p&gt;The following binary arithmetic operators exist in Loki:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&#43;&lt;/code&gt; (addition)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;-&lt;/code&gt; (subtraction)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;*&lt;/code&gt; (multiplication)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;/&lt;/code&gt; (division)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%&lt;/code&gt; (modulo)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;^&lt;/code&gt; (power/exponentiation)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Binary arithmetic operators are defined between two literals (scalars), a literal and a vector, and two vectors.&lt;/p&gt;
&lt;p&gt;Between two literals, the behavior is obvious:
They evaluate to another literal that is the result of the operator applied to both scalar operands (&lt;code&gt;1 &#43; 1 = 2&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Between a vector and a literal, the operator is applied to the value of every data sample in the vector, e.g. if a time series vector is multiplied by 2, the result is another vector in which every sample value of the original vector is multiplied by 2.&lt;/p&gt;
&lt;p&gt;Between two vectors, a binary arithmetic operator is applied to each entry in the left-hand side vector and its matching element in the right-hand vector.
The result is propagated into the result vector with the grouping labels becoming the output label set. Entries for which no matching entry in the right-hand vector can be found are not part of the result.&lt;/p&gt;
&lt;p&gt;Pay special attention to &lt;a href=&#34;#order-of-operations&#34;&gt;operator order&lt;/a&gt; when chaining arithmetic operators.&lt;/p&gt;
&lt;h4 id=&#34;arithmetic-examples&#34;&gt;Arithmetic Examples&lt;/h4&gt;
&lt;p&gt;Implement a health check with a simple query:&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;1 &amp;#43; 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Double the rate of a log stream&amp;rsquo;s entries:&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(rate({app=&amp;#34;foo&amp;#34;}[1m])) * 2&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Get proportion of warning logs to error logs for the &lt;code&gt;foo&lt;/code&gt; app&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(rate({app=&amp;#34;foo&amp;#34;, level=&amp;#34;warn&amp;#34;}[1m])) / sum(rate({app=&amp;#34;foo&amp;#34;, level=&amp;#34;error&amp;#34;}[1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;logical-and-set-operators&#34;&gt;Logical and set operators&lt;/h3&gt;
&lt;p&gt;These logical/set binary operators are only defined between two vectors:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;and&lt;/code&gt; (intersection)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;or&lt;/code&gt; (union)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;unless&lt;/code&gt; (complement)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;code&gt;vector1 and vector2&lt;/code&gt; results in a vector consisting of the elements of vector1 for which there are elements in vector2 with exactly matching label sets.
Other elements are dropped.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;vector1 or vector2&lt;/code&gt; results in a vector that contains all original elements (label sets &#43; values) of vector1 and additionally all elements of vector2 which do not have matching label sets in vector1.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;vector1 unless vector2&lt;/code&gt; results in a vector consisting of the elements of vector1 for which there are no elements in vector2 with exactly matching label sets.
All matching elements in both vectors are dropped.&lt;/p&gt;
&lt;h5 id=&#34;binary-operators-examples&#34;&gt;Binary operators examples&lt;/h5&gt;
&lt;p&gt;This contrived query will return the intersection of these queries, effectively &lt;code&gt;rate({app=&amp;quot;bar&amp;quot;})&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;rate({app=~&amp;#34;foo|bar&amp;#34;}[1m]) and rate({app=&amp;#34;bar&amp;#34;}[1m])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;comparison-operators&#34;&gt;Comparison operators&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;==&lt;/code&gt; (equality)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!=&lt;/code&gt; (inequality)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;&lt;/code&gt; (greater than)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt; (greater than or equal to)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;&lt;/code&gt; (less than)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt; (less than or equal to)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Comparison operators are defined between scalar/scalar, vector/scalar, and vector/vector value pairs.
By default they filter.
Their behavior can be modified by providing &lt;code&gt;bool&lt;/code&gt; after the operator, which will return 0 or 1 for the value rather than filtering.&lt;/p&gt;
&lt;p&gt;Between two scalars, these operators result in another scalar that is either 0 (false) or 1 (true), depending on the comparison result.
The &lt;code&gt;bool&lt;/code&gt; modifier must &lt;strong&gt;not&lt;/strong&gt; be provided.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;1 &amp;gt;= 1&lt;/code&gt; is equivalent to &lt;code&gt;1&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Between a vector and a scalar, these operators are applied to the value of every data sample in the vector, and vector elements between which the comparison result is false get dropped from the result vector.
If the &lt;code&gt;bool&lt;/code&gt; modifier is provided, vector elements that would be dropped instead have the value 0 and vector elements that would be kept have the value 1.&lt;/p&gt;
&lt;p&gt;Filters the streams which logged at least 10 lines in the last minute:&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({foo=&amp;#34;bar&amp;#34;}[1m]) &amp;gt; 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Attach the value(s) &lt;code&gt;0&lt;/code&gt;/&lt;code&gt;1&lt;/code&gt; to streams that logged less/more than 10 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;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({foo=&amp;#34;bar&amp;#34;}[1m]) &amp;gt; bool 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Between two vectors, these operators behave as a filter by default, applied to matching entries.
Vector elements for which the expression is not true or which do not find a match on the other side of the expression get dropped from the result, while the others are propagated into a result vector.
If the &lt;code&gt;bool&lt;/code&gt; modifier is provided, vector elements that would have been dropped instead have the value 0 and vector elements that would be kept have the value 1, with the grouping labels again becoming the output label set.&lt;/p&gt;
&lt;p&gt;Return the streams matching &lt;code&gt;app=foo&lt;/code&gt; without app labels that have higher counts within the last minute than their counterparts matching &lt;code&gt;app=bar&lt;/code&gt; without app 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;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 without(app) (count_over_time({app=&amp;#34;foo&amp;#34;}[1m])) &amp;gt; sum without(app) (count_over_time({app=&amp;#34;bar&amp;#34;}[1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Same as above, but vectors have their values set to &lt;code&gt;1&lt;/code&gt; if they pass the comparison or &lt;code&gt;0&lt;/code&gt; if they fail/would otherwise have been filtered out:&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 without(app) (count_over_time({app=&amp;#34;foo&amp;#34;}[1m])) &amp;gt; bool sum without(app) (count_over_time({app=&amp;#34;bar&amp;#34;}[1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;pattern-match-filter-operators&#34;&gt;Pattern match filter operators&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;|&amp;gt;&lt;/code&gt; (line match pattern)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!&amp;gt;&lt;/code&gt; (line match not pattern)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Pattern Filter not only enhances efficiency but also simplifies the process of writing LogQL queries. By eliminating the need for complex regex patterns, users can create queries using a more intuitive syntax, reducing the cognitive load and potential for errors.&lt;/p&gt;
&lt;p&gt;Within the pattern syntax the &lt;code&gt;&amp;lt;_&amp;gt;&lt;/code&gt; serves as a wildcard, representing any arbitrary text. This allows the query to match log lines where the specified pattern occurs, such as log lines containing static content, with variable content in between.&lt;/p&gt;
&lt;p&gt;Line match pattern 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;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;{service_name=`distributor`} |&amp;gt; `&amp;lt;_&amp;gt; caller=http.go:194 level=debug &amp;lt;_&amp;gt; msg=&amp;#34;POST /push.v1.PusherService/Push &amp;lt;_&amp;gt;`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Line match not pattern 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;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;{service_name=`distributor`} !&amp;gt; `&amp;lt;_&amp;gt; caller=http.go:194 level=debug &amp;lt;_&amp;gt; msg=&amp;#34;POST /push.v1.PusherService/Push &amp;lt;_&amp;gt;`&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For example, the example queries above will respectively match and not match the following log line from the &lt;code&gt;distributor&lt;/code&gt; service:&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;ts=2024-04-05T08:40:13.585911094Z caller=http.go:194 level=debug traceID=23e54a271db607cc orgID=3648 msg=&amp;#34;POST /push.v1.PusherService/Push (200) 12.684035ms&amp;#34;
ts=2024-04-05T08:41:06.551403339Z caller=http.go:194 level=debug traceID=54325a1a15b42e2d orgID=1218 msg=&amp;#34;POST /push.v1.PusherService/Push (200) 1.664285ms&amp;#34;
ts=2024-04-05T08:41:06.506524777Z caller=http.go:194 level=debug traceID=69d4271da1595bcb orgID=1218 msg=&amp;#34;POST /push.v1.PusherService/Push (200) 1.783818ms&amp;#34;
ts=2024-04-05T08:41:06.473740396Z caller=http.go:194 level=debug traceID=3b8ec973e6397814 orgID=3648 msg=&amp;#34;POST /push.v1.PusherService/Push (200) 1.893987ms&amp;#34;
ts=2024-04-05T08:41:05.88999067Z caller=http.go:194 level=debug traceID=6892d7ef67b4d65c orgID=3648 msg=&amp;#34;POST /push.v1.PusherService/Push (200) 2.314337ms&amp;#34;
ts=2024-04-05T08:41:05.826266414Z caller=http.go:194 level=debug traceID=0bb76e910cfd008d orgID=3648 msg=&amp;#34;POST /push.v1.PusherService/Push (200) 3.625744ms&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;order-of-operations&#34;&gt;Order of operations&lt;/h3&gt;
&lt;p&gt;When chaining or combining operators, you have to consider operator precedence:
Generally, you can assume regular &lt;a href=&#34;https://en.wikipedia.org/wiki/Order_of_operations&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;mathematical convention&lt;/a&gt; with operators on the same precedence level being left-associative.&lt;/p&gt;
&lt;p&gt;More details can be found in the &lt;a href=&#34;https://golang.org/ref/spec#Operator_precedence&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Golang language documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;1 &#43; 2 / 3&lt;/code&gt; is equal to &lt;code&gt;1 &#43; ( 2 / 3 )&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;2 * 3 % 2&lt;/code&gt; is evaluated as &lt;code&gt;(2 * 3) % 2&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;keywords-on-and-ignoring&#34;&gt;Keywords on and ignoring&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;ignoring&lt;/code&gt; keyword causes specified labels to be ignored during matching.
The syntax:&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;vector expr&amp;gt; &amp;lt;bin-op&amp;gt; ignoring(&amp;lt;labels&amp;gt;) &amp;lt;vector expr&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example will return the machines which total count within the last minutes exceed average value for app &lt;code&gt;foo&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;max by(machine) (count_over_time({app=&amp;#34;foo&amp;#34;}[1m])) &amp;gt; bool ignoring(machine) avg(count_over_time({app=&amp;#34;foo&amp;#34;}[1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The on keyword reduces the set of considered labels to a specified list.
The syntax:&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;vector expr&amp;gt; &amp;lt;bin-op&amp;gt; on(&amp;lt;labels&amp;gt;) &amp;lt;vector expr&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This example will return every machine total count within the last minutes ratio in app &lt;code&gt;foo&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;sum by(machine) (count_over_time({app=&amp;#34;foo&amp;#34;}[1m])) / on() sum(count_over_time({app=&amp;#34;foo&amp;#34;}[1m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;many-to-one-and-one-to-many-vector-matches&#34;&gt;Many-to-one and one-to-many vector matches&lt;/h3&gt;
&lt;p&gt;Many-to-one and one-to-many matchings occur when each vector element on the &amp;ldquo;one&amp;rdquo;-side can match with multiple elements on the &amp;ldquo;many&amp;rdquo;-side. You must explicitly request matching by using the group_left or group_right modifier, where left or right determines which vector has the higher cardinality.
The syntax:&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;vector expr&amp;gt; &amp;lt;bin-op&amp;gt; ignoring(&amp;lt;labels&amp;gt;) group_left(&amp;lt;labels&amp;gt;) &amp;lt;vector expr&amp;gt;
&amp;lt;vector expr&amp;gt; &amp;lt;bin-op&amp;gt; ignoring(&amp;lt;labels&amp;gt;) group_right(&amp;lt;labels&amp;gt;) &amp;lt;vector expr&amp;gt;
&amp;lt;vector expr&amp;gt; &amp;lt;bin-op&amp;gt; on(&amp;lt;labels&amp;gt;) group_left(&amp;lt;labels&amp;gt;) &amp;lt;vector expr&amp;gt;
&amp;lt;vector expr&amp;gt; &amp;lt;bin-op&amp;gt; on(&amp;lt;labels&amp;gt;) group_right(&amp;lt;labels&amp;gt;) &amp;lt;vector expr&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The label list provided with the group modifier contains additional labels from the &amp;ldquo;one&amp;rdquo;-side that are included in the result metrics. And a label should only appear in one of the lists specified by &lt;code&gt;on&lt;/code&gt; and &lt;code&gt;group_x&lt;/code&gt;. Every time series of the result vector must be uniquely identifiable.
Grouping modifiers can only be used for comparison and arithmetic. By default, the system matches &lt;code&gt;and&lt;/code&gt;, &lt;code&gt;unless&lt;/code&gt;, and &lt;code&gt;or&lt;/code&gt; operations with all entries in the right vector.&lt;/p&gt;
&lt;p&gt;The following example returns the rates requests partitioned by &lt;code&gt;app&lt;/code&gt; and &lt;code&gt;status&lt;/code&gt; as a percentage of total requests.&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 (app, status) (
  rate(
    {job=&amp;#34;http-server&amp;#34;}
      | json
      [5m]
  )
)
/ on (app) group_left
sum by (app) (
  rate(
    {job=&amp;#34;http-server&amp;#34;}
      | json
      [5m]
  )
)

=&amp;gt;
[
  {app=&amp;#34;foo&amp;#34;, status=&amp;#34;200&amp;#34;} =&amp;gt; 0.8
  {app=&amp;#34;foo&amp;#34;, status=&amp;#34;400&amp;#34;} =&amp;gt; 0.1
  {app=&amp;#34;foo&amp;#34;, status=&amp;#34;500&amp;#34;} =&amp;gt; 0.1
]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This version uses &lt;code&gt;group_left(&amp;lt;labels&amp;gt;)&lt;/code&gt; to include &lt;code&gt;&amp;lt;labels&amp;gt;&lt;/code&gt; from the right hand side in the result and returns the cost of discarded events per user, organization, and namespace:&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 (user, namespace) (
  rate(
    {job=&amp;#34;events&amp;#34;}
      | logfmt
      | discarded=&amp;#34;true&amp;#34;
      [5m]
  )
)
* on (user) group_left(organization)
max_over_time(
  {job=&amp;#34;cost-calculator&amp;#34;}
    | logfmt
    | unwrap cost
    [5m]
) by (user, organization)

=&amp;gt;
[
  {user=&amp;#34;foo&amp;#34;, namespace=&amp;#34;dev&amp;#34;, organization=&amp;#34;little-org&amp;#34;} =&amp;gt; 10
  {user=&amp;#34;foo&amp;#34;, namespace=&amp;#34;prod&amp;#34;, organization=&amp;#34;little-org&amp;#34;} =&amp;gt; 50
  {user=&amp;#34;bar&amp;#34;, namespace=&amp;#34;dev&amp;#34;, organization=&amp;#34;big-org&amp;#34;} =&amp;gt; 70
  {user=&amp;#34;bar&amp;#34;, namespace=&amp;#34;prod&amp;#34;, organization=&amp;#34;big-org&amp;#34;} =&amp;gt; 200
]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;
&lt;p&gt;LogQL queries can be commented using the &lt;code&gt;#&lt;/code&gt; character:&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;foo&amp;#34;} # anything that comes after will not be interpreted in your query&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;With multi-line LogQL queries, the query parser can exclude whole or partial lines using &lt;code&gt;#&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;{app=&amp;#34;foo&amp;#34;}
    | json
    # this line will be ignored
    | bar=&amp;#34;baz&amp;#34; # this checks if bar = &amp;#34;baz&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;pipeline-errors&#34;&gt;Pipeline Errors&lt;/h2&gt;
&lt;p&gt;There are multiple reasons which cause pipeline processing errors, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A numeric label filter may fail to turn a label value into a number&lt;/li&gt;
&lt;li&gt;A metric conversion for a label may fail.&lt;/li&gt;
&lt;li&gt;A log line is not a valid json document.&lt;/li&gt;
&lt;li&gt;etc&amp;hellip;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When those failures happen, Loki won&amp;rsquo;t filter out those log lines. Instead they are passed into the next stage of the pipeline with a new system label named &lt;code&gt;__error__&lt;/code&gt;. The only way to filter out errors is by using a label filter expressions. The &lt;code&gt;__error__&lt;/code&gt; label can&amp;rsquo;t be renamed via the language.&lt;/p&gt;
&lt;p&gt;For example to remove json errors:&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;,container=&amp;#34;ingress-nginx&amp;#34;}
    | json
    | __error__ != &amp;#34;JSONParserErr&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively you can remove all error using a catch all matcher such as &lt;code&gt;__error__ = &amp;quot;&amp;quot;&lt;/code&gt; or even show only errors using &lt;code&gt;__error__ != &amp;quot;&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The filter should be placed after the stage that generated this error. This means if you need to remove errors from an unwrap expression it needs to be placed after the unwrap.&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;quantile_over_time(
	0.99,
	{container=&amp;#34;ingress-nginx&amp;#34;,service=&amp;#34;hosted-grafana&amp;#34;}
	| json
	| unwrap response_latency_seconds
	| __error__=&amp;#34;&amp;#34;[1m]
	) by (cluster)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Metric queries cannot contain errors, in case errors are found during execution, Loki will return an error and appropriate status code.&lt;/p&gt;&lt;/blockquote&gt;
&lt;h2 id=&#34;functions&#34;&gt;Functions&lt;/h2&gt;
&lt;p&gt;Loki supports functions to operate on data.&lt;/p&gt;
&lt;h3 id=&#34;label_replace&#34;&gt;label_replace()&lt;/h3&gt;
&lt;p&gt;For each time series in &lt;code&gt;v&lt;/code&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;label_replace(v instant-vector,
    dst_label string,
    replacement string,
    src_label string,
    regex string)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;matches the regular expression &lt;code&gt;regex&lt;/code&gt; against the label &lt;code&gt;src_label&lt;/code&gt;.
If it matches, then the time series is returned with the label &lt;code&gt;dst_label&lt;/code&gt; replaced by the expansion of &lt;code&gt;replacement&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;$1&lt;/code&gt; is replaced with the first matching subgroup,
&lt;code&gt;$2&lt;/code&gt; with the second etc.
If the regular expression doesn&amp;rsquo;t match,
then the time series is returned unchanged.&lt;/p&gt;
&lt;p&gt;This example will return a vector with each time series having a &lt;code&gt;foo&lt;/code&gt; label with the value &lt;code&gt;a&lt;/code&gt; added to it:&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;label_replace(rate({job=&amp;#34;api-server&amp;#34;,service=&amp;#34;a:c&amp;#34;} |= &amp;#34;err&amp;#34; [1m]), &amp;#34;foo&amp;#34;, &amp;#34;$1&amp;#34;,
  &amp;#34;service&amp;#34;, &amp;#34;(.*):.*&amp;#34;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="logql-reference">LogQL Reference&lt;/h1>
&lt;p>Loki accepts a number of operators and functions within a
&lt;a href="/docs/loki/v3.7.x/query/">LogQL query&lt;/a>.&lt;/p>
&lt;h2 id="binary-operators">Binary operators&lt;/h2>
&lt;h3 id="arithmetic-operators">Arithmetic operators&lt;/h3>
&lt;p>The following binary arithmetic operators exist in Loki:&lt;/p></description></item><item><title>Troubleshoot log queries (READ)</title><link>https://grafana.com/docs/loki/v3.7.x/query/troubleshoot-query/</link><pubDate>Thu, 09 Apr 2026 02:28:18 +0000</pubDate><guid>https://grafana.com/docs/loki/v3.7.x/query/troubleshoot-query/</guid><content><![CDATA[&lt;h1 id=&#34;troubleshoot-log-queries-read&#34;&gt;Troubleshoot log queries (READ)&lt;/h1&gt;


&lt;div data-shared=&#34;troubleshoot-query.md&#34;&gt;
            &lt;p&gt;This guide helps you troubleshoot errors that occur when querying logs from Loki. When Loki rejects or fails query requests, it&amp;rsquo;s typically due to query syntax errors, exceeding limits, timeout issues, or storage access problems.&lt;/p&gt;
&lt;p&gt;Before you begin, ensure you have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Access to Grafana Loki logs and metrics&lt;/li&gt;
&lt;li&gt;Understanding of 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/&#34;&gt;LogQL query language&lt;/a&gt; basics&lt;/li&gt;
&lt;li&gt;Permissions to configure limits and settings if needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;monitoring-query-errors&#34;&gt;Monitoring query errors&lt;/h2&gt;
&lt;p&gt;Query errors can be observed using these Prometheus metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;loki_request_duration_seconds&lt;/code&gt; - Query latency by route and status code&lt;/li&gt;
&lt;li&gt;&lt;code&gt;loki_logql_querystats_bytes_processed_per_seconds&lt;/code&gt; - Bytes processed during queries&lt;/li&gt;
&lt;li&gt;&lt;code&gt;loki_frontend_query_range_duration_seconds_bucket&lt;/code&gt; - Frontend query latency&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can set up alerts on 4xx and 5xx status codes to detect query problems early. This can be helpful when tuning limits configurations.&lt;/p&gt;
&lt;h2 id=&#34;logql-parse-errors&#34;&gt;LogQL parse errors&lt;/h2&gt;
&lt;p&gt;Parse errors occur when the LogQL query syntax is invalid. Loki returns HTTP status code &lt;code&gt;400 Bad Request&lt;/code&gt; for all parse errors.&lt;/p&gt;
&lt;h3 id=&#34;error-failed-to-parse-the-log-query&#34;&gt;Error: Failed to parse the log query&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;failed to parse the log query&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Or with position details:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;parse error at line &amp;lt;line&amp;gt;, col &amp;lt;col&amp;gt;: &amp;lt;message&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The LogQL query contains syntax errors. This could be due to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Missing or mismatched brackets, quotes, or braces&lt;/li&gt;
&lt;li&gt;Invalid characters or operators&lt;/li&gt;
&lt;li&gt;Incorrect function syntax&lt;/li&gt;
&lt;li&gt;Invalid duration format&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Common examples:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Invalid Query&lt;/th&gt;
              &lt;th&gt;Error&lt;/th&gt;
              &lt;th&gt;Fix&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;foo&amp;quot;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Missing closing brace&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;foo&amp;quot;}&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;foo&amp;quot;} |= test&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Unquoted filter string&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;foo&amp;quot;} |= &amp;quot;test&amp;quot;&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;rate({app=&amp;quot;foo&amp;quot;}[5minutes])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Invalid duration unit&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;rate({app=&amp;quot;foo&amp;quot;}[5m])&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;foo&amp;quot;} | json&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Missing pipe symbol before parser&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;{app=&amp;quot;foo&amp;quot;} | json&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Start with a simple stream selector: &lt;code&gt;{job=&amp;quot;app&amp;quot;}&lt;/code&gt;, then add filters and operations incrementally to identify syntax issues.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Check bracket matching&lt;/strong&gt; - Ensure all &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;code&gt;[&lt;/code&gt;, &lt;code&gt;]&lt;/code&gt; are properly closed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Verify string quoting&lt;/strong&gt; - All label values and filter strings must be quoted.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use valid duration units&lt;/strong&gt; - Use &lt;code&gt;ns&lt;/code&gt;, &lt;code&gt;us&lt;/code&gt;, &lt;code&gt;ms&lt;/code&gt;, &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;m&lt;/code&gt;, &lt;code&gt;h&lt;/code&gt;, &lt;code&gt;d&lt;/code&gt;, &lt;code&gt;w&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt; , for example, &lt;code&gt;5m&lt;/code&gt; not &lt;code&gt;5minutes&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review operator syntax&lt;/strong&gt; - Ensure label matchers use proper operators (&lt;code&gt;=&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;, &lt;code&gt;=~&lt;/code&gt;, &lt;code&gt;!~&lt;/code&gt;). Check the 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/&#34;&gt;LogQL documentation&lt;/a&gt; for correct operator usage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Grafana Assistant&lt;/strong&gt; - If you are a Cloud Logs user, you can use Grafana Assistant to write or revise your query using natural language, for example, “What errors occurred for application foo in the last hour?”&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend/Querier&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-at-least-one-equality-matcher-required&#34;&gt;Error: At least one equality matcher required&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;parse error : queries require at least one regexp or equality matcher that does not have an empty-compatible value. For instance, app=~&amp;quot;.*&amp;quot; does not meet this requirement, but app=~&amp;quot;.&#43;&amp;quot; will&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query uses only negative matchers (&lt;code&gt;!=&lt;/code&gt;, &lt;code&gt;!~&lt;/code&gt;) or matchers that match empty strings (&lt;code&gt;=~&amp;quot;.*&amp;quot;&lt;/code&gt;), which would select all streams. This is prevented to protect against accidentally querying the entire database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Invalid examples:&lt;/strong&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;{foo!=&amp;#34;bar&amp;#34;}
{app=~&amp;#34;.*&amp;#34;}
{foo!~&amp;#34;bar|baz&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Valid examples:&lt;/strong&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;{foo=&amp;#34;bar&amp;#34;}
{app=~&amp;#34;.&amp;#43;&amp;#34;}
{app=&amp;#34;baz&amp;#34;, foo!=&amp;#34;bar&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Add at least one positive matcher&lt;/strong&gt; that selects specific streams.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use &lt;code&gt;.&#43;&lt;/code&gt; instead of &lt;code&gt;.*&lt;/code&gt;&lt;/strong&gt; in regex matchers to require at least one character.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Add additional label selectors&lt;/strong&gt; to narrow down the query scope.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use Grafana Assistant&lt;/strong&gt; - If you are a Cloud Logs user, you can use Grafana Assistant to write or revise your query using natural language, for example, “Find logs containing ’foo&amp;rsquo; but not &amp;lsquo;bar&amp;rsquo; or &amp;lsquo;baz&amp;rsquo;.”&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-only-label-matchers-are-supported&#34;&gt;Error: Only label matchers are supported&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;only label matchers are supported&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query was passed to an API that only accepts label matchers (like the series API), but included additional expressions like line filters or parsers.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use only stream selectors&lt;/strong&gt; for APIs that don&amp;rsquo;t support full LogQL:&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;# Valid for series API
{app=&amp;#34;foo&amp;#34;, env=&amp;#34;prod&amp;#34;}

# Invalid for series API
{app=&amp;#34;foo&amp;#34;} |= &amp;#34;error&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: API handler&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-log-queries-not-supported-as-instant-query-type&#34;&gt;Error: Log queries not supported as instant query type&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;log queries are not supported as an instant query type, please change your query to a range query type&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/&#34;&gt;log query&lt;/a&gt; (one that returns log lines rather than metrics) was submitted to the instant query endpoint (&lt;code&gt;/loki/api/v1/query&lt;/code&gt;). Log queries must use the range query endpoint.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Convert to a range query&lt;/strong&gt; Convert log queries to range queries with a time range. Range queries are the default in Grafana Explore.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use the range query endpoint&lt;/strong&gt; &lt;code&gt;/loki/api/v1/query_range&lt;/code&gt; for log queries.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Convert to a metric query&lt;/strong&gt; if you need to use instant queries:&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;# This is a log query (returns logs)
{app=&amp;#34;foo&amp;#34;} |= &amp;#34;error&amp;#34;

# This is a metric query (can be instant)
count_over_time({app=&amp;#34;foo&amp;#34;} |= &amp;#34;error&amp;#34;[5m])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use Grafana Assistant&lt;/strong&gt; - If you are a Cloud Logs user, you can use Grafana Assistant to write or revise your query.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query API&lt;/li&gt;
&lt;li&gt;Retryable: No (use correct endpoint or query type)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-invalid-aggregation-without-unwrap&#34;&gt;Error: Invalid aggregation without unwrap&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;parse error : invalid aggregation sum_over_time without unwrap&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Aggregation functions like &lt;code&gt;sum_over_time&lt;/code&gt;, &lt;code&gt;avg_over_time&lt;/code&gt;, &lt;code&gt;min_over_time&lt;/code&gt;, &lt;code&gt;max_over_time&lt;/code&gt; require an &lt;code&gt;unwrap&lt;/code&gt; expression to extract a numeric value from log lines.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add an unwrap expression&lt;/strong&gt; to extract the numeric 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;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;# Invalid
sum_over_time({app=&amp;#34;foo&amp;#34;} | json [5m])

# Valid - unwrap a numeric label
sum_over_time({app=&amp;#34;foo&amp;#34;} | json | unwrap duration [5m])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Parser&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-invalid-aggregation-with-unwrap&#34;&gt;Error: Invalid aggregation with unwrap&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;parse error : invalid aggregation count_over_time with unwrap&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;count_over_time&lt;/code&gt; function doesn&amp;rsquo;t use unwrapped values - it just counts log lines. Using it with &lt;code&gt;unwrap&lt;/code&gt; is invalid.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remove the unwrap expression&lt;/strong&gt; for count_over_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;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;# Invalid
count_over_time({app=&amp;#34;foo&amp;#34;} | json | unwrap duration [5m])

# Valid
count_over_time({app=&amp;#34;foo&amp;#34;} | json [5m])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use sum_over_time&lt;/strong&gt; if you want to sum unwrapped values.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Parser&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;query-limit-errors&#34;&gt;Query limit errors&lt;/h2&gt;
&lt;p&gt;These errors occur when queries exceed configured resource limits. They return HTTP status code &lt;code&gt;400 Bad Request&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;error-maximum-series-reached&#34;&gt;Error: Maximum series reached&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;maximum number of series (&amp;lt;limit&amp;gt;) reached for a single query; consider reducing query cardinality by adding more specific stream selectors, reducing the time range, or aggregating results with functions like sum(), count() or topk()&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query matches more unique label combinations (series) than the configured limit allows. This protects against queries that would consume excessive memory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_query_series&lt;/code&gt;: 500 (default)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add more specific stream selectors&lt;/strong&gt; to reduce cardinality:&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;# Too broad
{job=&amp;#34;ingress-nginx&amp;#34;}

# More specific
{job=&amp;#34;ingress-nginx&amp;#34;, namespace=&amp;#34;production&amp;#34;, pod=~&amp;#34;ingress-nginx-.*&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;Reduce the time range&lt;/strong&gt; of the query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use label filters&lt;/strong&gt; to narrow down results: &lt;code&gt;{job=&amp;quot;app&amp;quot;} |= &amp;quot;error&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use aggregation functions&lt;/strong&gt; to reduce cardinality:&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 (status) (rate({job=&amp;#34;nginx&amp;#34;} | json [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase the limit&lt;/strong&gt; if resources allow:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_query_series: 1000  #default is 500&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-cardinality-issues&#34;&gt;Error: Cardinality issues&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;cardinality limit exceeded for {}; 100001 entries, more than limit of 100000&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query produces results with too many unique label combinations. This protects against queries that would generate excessive memory usage and slow performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cardinality_limit&lt;/code&gt;: 100000&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use more specific label selectors&lt;/strong&gt; to reduce the number of unique streams.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Apply aggregation functions&lt;/strong&gt; to reduce cardinality:&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 (status) (rate({job=&amp;#34;nginx&amp;#34;}[5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;by()&lt;/code&gt; or &lt;code&gt;without()&lt;/code&gt; clauses&lt;/strong&gt; to group results and reduce dimensions:&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 (status, method) (rate({job=&amp;#34;nginx&amp;#34;} | json [5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Another alternative is using &lt;code&gt;drop&lt;/code&gt; or &lt;code&gt;keep&lt;/code&gt; to reduce the number of labels and hence the cardinality:&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;# Drop high-cardinality labels like request_id or trace_id
{job=&amp;#34;nginx&amp;#34;} | json | drop request_id, trace_id, session_id

# Keep only the labels you need
{job=&amp;#34;nginx&amp;#34;} | json | keep status, method, path&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase the limit&lt;/strong&gt; if needed:&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;YAML&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-yaml&#34;&gt;limits_config:
  cardinality_limit: 200000  #default is 100000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Engine&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-max-entries-limit-per-query-exceeded&#34;&gt;Error: Max entries limit per query exceeded&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;max entries limit per query exceeded, limit &amp;gt; max_entries_limit_per_query (&amp;lt;requested&amp;gt; &amp;gt; &amp;lt;limit&amp;gt;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query requests more log entries than the configured maximum. This applies to log queries (not metric queries).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_entries_limit_per_query&lt;/code&gt;: 5000&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the limit parameter&lt;/strong&gt; in your query request.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add more specific filters&lt;/strong&gt; to return fewer results:&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;foo&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;&lt;strong&gt;Reduce the time range&lt;/strong&gt; of the query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase the limit&lt;/strong&gt; if needed:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_entries_limit_per_query: 10000  #default is 5000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Querier/Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-query-would-read-too-many-bytes&#34;&gt;Error: Query would read too many bytes&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;the query would read too many bytes (query: &amp;lt;size&amp;gt;, limit: &amp;lt;limit&amp;gt;); consider adding more specific stream selectors or reduce the time range of the query&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The estimated data volume for the query exceeds the configured limit. This is determined before query execution using index statistics.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_query_bytes_read&lt;/code&gt;: 0B (disabled by default)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add more specific stream selectors&lt;/strong&gt; to reduce data volume.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the time range&lt;/strong&gt; of the query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase the limit&lt;/strong&gt; if resources allow:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_query_bytes_read: 10GB&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-too-many-chunks-count&#34;&gt;Error: Too many chunks (count)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;the query hit the max number of chunks limit (limit: 2000000 chunks)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The number of chunks that the query would read exceeds the configured limit. This protects against queries that would scan excessive amounts of data and consume too much memory.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_chunks_per_query&lt;/code&gt;: 2000000&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Narrow stream selectors&lt;/strong&gt; to reduce the number of matching chunks:&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;# Too broad
{job=&amp;#34;app&amp;#34;}

# More specific
{job=&amp;#34;app&amp;#34;, environment=&amp;#34;production&amp;#34;, namespace=&amp;#34;api&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;Reduce the query time range&lt;/strong&gt; to scan fewer chunks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase the limit&lt;/strong&gt; if resources allow:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_chunks_per_query: 5000000  #default is 2000000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-stream-matcher-limits&#34;&gt;Error: Stream matcher limits&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;max streams matchers per query exceeded, matchers-count &amp;gt; limit (1500 &amp;gt; 1000)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query contains too many stream matchers. This limit prevents queries with excessive complexity that could impact query performance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_streams_matchers_per_query&lt;/code&gt;: 1000&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simplify your query&lt;/strong&gt; by using fewer label matchers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Combine multiple queries&lt;/strong&gt; instead of using many OR conditions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use regex matchers&lt;/strong&gt; to consolidate multiple values:&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;# Good: 3 matchers using regex patterns
{cluster=&amp;#34;prod&amp;#34;, namespace=~&amp;#34;api|web&amp;#34;, pod=~&amp;#34;nginx-.*&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;Increase the limit&lt;/strong&gt; if needed:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_streams_matchers_per_query: 2000  #default is 1000&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Querier&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-query-too-large-for-single-querier&#34;&gt;Error: Query too large for single querier&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;query too large to execute on a single querier: (query: &amp;lt;size&amp;gt;, limit: &amp;lt;limit&amp;gt;); consider adding more specific stream selectors, reduce the time range of the query, or adjust parallelization settings&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Or for un-shardable queries:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;un-shardable query too large to execute on a single querier: (query: &amp;lt;size&amp;gt;, limit: &amp;lt;limit&amp;gt;); consider adding more specific stream selectors or reduce the time range of the query&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Even after query splitting and sharding, individual query shards exceed the per-querier byte limit.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_querier_bytes_read&lt;/code&gt;: 150GB (per querier)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add more specific stream selectors&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the time range&lt;/strong&gt; or Break large queries into smaller time ranges.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simplify the query&lt;/strong&gt; if possible - some queries cannot be sharded.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase the limit&lt;/strong&gt; (requires more querier resources):&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;YAML&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-yaml&#34;&gt;limits_config:
  max_querier_bytes_read: 200GB  # default is 150GB&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Scale querier resources&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-interval-value-exceeds-limit&#34;&gt;Error: Interval value exceeds limit&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[interval] value exceeds limit&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The range vector interval (in brackets like &lt;code&gt;[5m]&lt;/code&gt;) exceeds configured limits.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the range interval&lt;/strong&gt; in your query:&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;# If [1d] is too large, try smaller intervals
rate({app=&amp;#34;foo&amp;#34;}[1h])&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check your configuration&lt;/strong&gt; for &lt;code&gt;max_query_length&lt;/code&gt; limits. The default is &lt;code&gt;30d1h&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Engine&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;time-range-errors&#34;&gt;Time range errors&lt;/h2&gt;
&lt;p&gt;These errors relate to the time range specified in queries.&lt;/p&gt;
&lt;h3 id=&#34;error-query-time-range-exceeds-limit&#34;&gt;Error: Query time range exceeds limit&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;the query time range exceeds the limit (query length: &amp;lt;duration&amp;gt;, limit: &amp;lt;limit&amp;gt;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The difference between the query&amp;rsquo;s start and end time exceeds the maximum allowed query length.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_query_length&lt;/code&gt;: 721h (30 days &#43; 1 hour)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the query time range&lt;/strong&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;logcli&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-logcli&#34;&gt;# Instead of querying 60 days
logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --from=&amp;#34;60d&amp;#34; --to=&amp;#34;now&amp;#34;

# Query 30 days or less
logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --from=&amp;#34;30d&amp;#34; --to=&amp;#34;now&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;Increase the limit&lt;/strong&gt; if storage retention supports it:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_query_length: 2160h  # 90 days&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend/Querier&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be modified)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-data-is-no-longer-available&#34;&gt;Error: Data is no longer available&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;this data is no longer available, it is past now - max_query_lookback (&amp;lt;duration&amp;gt;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The entire query time range falls before the &lt;code&gt;max_query_lookback&lt;/code&gt; limit. This happens when trying to query data older than the configured lookback period.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_query_lookback&lt;/code&gt;: 0 (The default value of 0 does not set a limit.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Query more recent data&lt;/strong&gt; within the lookback window.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Adjust the lookback limit&lt;/strong&gt; if the data should be queryable:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_query_lookback: 8760h  # 1 year&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;The lookback limit should not exceed your retention period.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend/Querier&lt;/li&gt;
&lt;li&gt;Retryable: No&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-invalid-query-time-range&#34;&gt;Error: Invalid query time range&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;invalid query, through &amp;lt; from (&amp;lt;end&amp;gt; &amp;lt; &amp;lt;start&amp;gt;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query end time is before the start time, which is invalid.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Swap start and end times&lt;/strong&gt; if they were reversed.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check timestamp formats&lt;/strong&gt; to ensure times are correctly specified.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend/Querier&lt;/li&gt;
&lt;li&gt;Retryable: No (query must be fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;required-labels-errors&#34;&gt;Required labels errors&lt;/h2&gt;
&lt;p&gt;These errors occur when queries don&amp;rsquo;t meet configured label requirements.&lt;/p&gt;
&lt;h3 id=&#34;error-missing-required-matchers&#34;&gt;Error: Missing required matchers&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;stream selector is missing required matchers [&amp;lt;required_labels&amp;gt;], labels present in the query were [&amp;lt;present_labels&amp;gt;]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The tenant is configured to require certain label matchers in all queries, but the query doesn&amp;rsquo;t include them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;required_labels&lt;/code&gt;: [] (none required by default)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check with your administrator&lt;/strong&gt; about which labels are required.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add the required labels&lt;/strong&gt; to your query:&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;# If &amp;#39;namespace&amp;#39; is required
{app=&amp;#34;foo&amp;#34;, namespace=&amp;#34;production&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must include required labels)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-not-enough-label-matchers&#34;&gt;Error: Not enough label matchers&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;stream selector has less label matchers than required: (present: [&amp;lt;labels&amp;gt;], number_present: &amp;lt;count&amp;gt;, required_number_label_matchers: &amp;lt;required&amp;gt;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The tenant is configured to require a minimum number of label matchers, but the query has fewer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;minimum_labels_number&lt;/code&gt;: 0 (no minimum by default)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add more label matchers&lt;/strong&gt; to meet the minimum requirement:&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;# If minimum is 2, add another selector
{app=&amp;#34;foo&amp;#34;, namespace=&amp;#34;production&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (query must meet requirements)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;timeout-errors&#34;&gt;Timeout errors&lt;/h2&gt;
&lt;p&gt;Timeout errors occur when queries take too long to execute.&lt;/p&gt;
&lt;h3 id=&#34;error-request-timed-out&#34;&gt;Error: Request timed out&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;request timed out, decrease the duration of the request or add more label matchers (prefer exact match over regex match) to reduce the amount of data processed&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;context deadline exceeded&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query exceeded the configured timeout. This can happen due to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Large time ranges&lt;/li&gt;
&lt;li&gt;High cardinality queries&lt;/li&gt;
&lt;li&gt;Complex query expressions&lt;/li&gt;
&lt;li&gt;Insufficient cluster resources&lt;/li&gt;
&lt;li&gt;Network issues&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;query_timeout&lt;/code&gt;: 1m&lt;/li&gt;
&lt;li&gt;&lt;code&gt;server.http_server_read_timeout&lt;/code&gt;: 30s&lt;/li&gt;
&lt;li&gt;&lt;code&gt;server.http_server_write_timeout&lt;/code&gt;: 30s&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the time range&lt;/strong&gt; of the query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add more specific filters&lt;/strong&gt; to reduce data processing:&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;# Less specific (slower)
{namespace=~&amp;#34;prod.*&amp;#34;}

# More specific (faster)
{namespace=&amp;#34;production&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;Prefer exact matchers over regex&lt;/strong&gt; when possible.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add line filters early&lt;/strong&gt; in the pipeline:&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;foo&amp;#34;} |= &amp;#34;error&amp;#34; | json | level=&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;&lt;strong&gt;Increase timeout limits&lt;/strong&gt; (if resources allow):&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;YAML&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-yaml&#34;&gt;limits_config:
  query_timeout: 5m

server:
  http_server_read_timeout: 5m
  http_server_write_timeout: 5m&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use sampling&lt;/strong&gt; for exploratory queries&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;app&amp;#34;} | line_format &amp;#34;{{__timestamp__}} {{.msg}}&amp;#34; | sample 0.1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check for network issues&lt;/strong&gt; between components.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend/Querier&lt;/li&gt;
&lt;li&gt;Retryable: Yes (with modifications)&lt;/li&gt;
&lt;li&gt;HTTP status: 504 Gateway Timeout&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes (query_timeout)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-request-cancelled-by-client&#34;&gt;Error: Request cancelled by client&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;the request was cancelled by the client&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The client closed the connection before receiving a response. This is typically caused by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Client-side timeout&lt;/li&gt;
&lt;li&gt;User navigating away in Grafana&lt;/li&gt;
&lt;li&gt;Network interruption&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Increase client timeout&lt;/strong&gt; in Grafana or LogCLI.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optimize the query&lt;/strong&gt; to return faster.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check network connectivity&lt;/strong&gt; between client and Loki.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Client&lt;/li&gt;
&lt;li&gt;Retryable: Yes&lt;/li&gt;
&lt;li&gt;HTTP status: 499 Client Closed Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;query-blocked-errors&#34;&gt;Query blocked errors&lt;/h2&gt;
&lt;p&gt;These errors occur when queries are administratively blocked.&lt;/p&gt;
&lt;h3 id=&#34;error-query-blocked-by-policy&#34;&gt;Error: Query blocked by policy&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;query blocked by policy&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query matches a configured block rule. Administrators create tenant policies and rate limiting rules to block specific queries or query patterns to protect the cluster from expensive or problematic queries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Check with your Loki administrator&lt;/strong&gt; about blocked queries and to review policy settings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modify the query&lt;/strong&gt; to avoid the block pattern:
&lt;ul&gt;
&lt;li&gt;Change the stream selectors&lt;/li&gt;
&lt;li&gt;Adjust the time range&lt;/li&gt;
&lt;li&gt;Use different aggregations&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request the block to be removed&lt;/strong&gt; if the query is legitimate.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Configuration reference:&lt;/strong&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;YAML&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-yaml&#34;&gt;limits_config:
  blocked_queries:
    - pattern: &amp;#34;.*&amp;#34;          # Regex pattern to match
      regex: true
      types:                 # Query types to block
        - metric
        - filter
      hash: 0               # Or block specific query hash&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Engine&lt;/li&gt;
&lt;li&gt;Retryable: No (unless block is removed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-querying-is-disabled&#34;&gt;Error: Querying is disabled&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;querying is disabled, please contact your Loki operator&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Query parallelism is set to 0, effectively disabling queries for the tenant.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Contact your Loki administrator&lt;/strong&gt; to enable querying.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check configuration&lt;/strong&gt; for &lt;code&gt;max_query_parallelism&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;YAML&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-yaml&#34;&gt;limits_config:
  max_query_parallelism: 32     #(the default)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Frontend&lt;/li&gt;
&lt;li&gt;Retryable: No (until configuration is fixed)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-multi-variant-queries-disabled&#34;&gt;Error: Multi variant queries disabled&lt;/h3&gt;
&lt;p&gt;Multi variant queries are an experimental feature that enables support for running multiple query variants over the same underlying data. For example, running both a &lt;code&gt;rate()&lt;/code&gt; and &lt;code&gt;count_over_time()&lt;/code&gt; query over the same range selector.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;multi variant queries are disabled for this instance&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query uses the variants feature, but it&amp;rsquo;s disabled for the tenant or instance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remove variant expressions&lt;/strong&gt; from the query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Enable the feature&lt;/strong&gt; if needed:&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;YAML&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-yaml&#34;&gt;limits_config:
  enable_multi_variant_queries: true  #default is false&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Engine&lt;/li&gt;
&lt;li&gt;Retryable: No (until feature is enabled)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;pipeline-processing-errors&#34;&gt;Pipeline processing errors&lt;/h2&gt;
&lt;p&gt;Pipeline errors occur during log line processing but don&amp;rsquo;t cause query failures. Instead, affected log lines are annotated with error labels.&lt;/p&gt;
&lt;h3 id=&#34;understanding-pipeline-errors&#34;&gt;Understanding pipeline errors&lt;/h3&gt;
&lt;p&gt;When a pipeline stage fails (for example, parsing JSON that isn&amp;rsquo;t valid JSON), Loki:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Does NOT filter out the log line&lt;/li&gt;
&lt;li&gt;Adds an &lt;code&gt;__error__&lt;/code&gt; label with the error type&lt;/li&gt;
&lt;li&gt;Optionally adds &lt;code&gt;__error_details__&lt;/code&gt; with more information&lt;/li&gt;
&lt;li&gt;Passes the log line to the next pipeline stage&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;error-types&#34;&gt;Error types&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Error Label Value&lt;/th&gt;
              &lt;th&gt;Cause&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;JSONParserErr&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Log line is not valid JSON&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;LogfmtParserErr&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Log line is not valid logfmt&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;SampleExtractionErr&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Failed to extract numeric value for metrics&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;LabelFilterErr&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Label filter operation failed&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;TemplateFormatErr&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Template formatting failed&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;viewing-pipeline-errors&#34;&gt;Viewing pipeline errors&lt;/h3&gt;
&lt;p&gt;To see logs with errors:&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;foo&amp;#34;} | json | __error__!=&amp;#34;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To see error details:&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;foo&amp;#34;} | json | __error__!=&amp;#34;&amp;#34; | line_format &amp;#34;Error: {{.__error__}} - {{.__error_details__}}&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;filtering-out-errors&#34;&gt;Filtering out errors&lt;/h3&gt;
&lt;p&gt;To exclude logs with parsing errors:&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;foo&amp;#34;} | json | __error__=&amp;#34;&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To exclude specific error types:&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;foo&amp;#34;} | json | __error__!=&amp;#34;JSONParserErr&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;dropping-error-labels&#34;&gt;Dropping error labels&lt;/h3&gt;
&lt;p&gt;To remove error labels from results:&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;foo&amp;#34;} | json | drop __error__, __error_details__&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;authentication-and-connection-errors&#34;&gt;Authentication and connection errors&lt;/h2&gt;
&lt;p&gt;These errors occur when connecting to Loki, often when using LogCLI.&lt;/p&gt;
&lt;h3 id=&#34;error-no-org-id&#34;&gt;Error: No org ID&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;no org id&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Multi-tenancy is enabled but no tenant ID was provided in the request.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add the X-Scope-OrgID header&lt;/strong&gt; in your request.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;For LogCLI&lt;/strong&gt;, use the &lt;code&gt;--org-id&lt;/code&gt; flag:&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;Bash&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-bash&#34;&gt;logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --org-id=&amp;#34;my-tenant&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;In Grafana&lt;/strong&gt;, configure the tenant ID in the data source settings.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Loki API&lt;/li&gt;
&lt;li&gt;Retryable: Yes (with tenant ID)&lt;/li&gt;
&lt;li&gt;HTTP status: 400 Bad Request&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-authentication-configuration-conflict&#34;&gt;Error: Authentication configuration conflict&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;at most one of HTTP basic auth (username/password), bearer-token &amp;amp; bearer-token-file is allowed to be configured&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Or:&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;text&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-text&#34;&gt;at most one of the options bearer-token &amp;amp; bearer-token-file is allowed to be configured&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Multiple authentication methods are configured simultaneously in LogCLI.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use only one authentication method&lt;/strong&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;Bash&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-bash&#34;&gt;# Basic auth
logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --username=&amp;#34;user&amp;#34; --password=&amp;#34;pass&amp;#34;

# OR bearer token
logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --bearer-token=&amp;#34;token&amp;#34;

# OR bearer token file
logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --bearer-token-file=&amp;#34;/path/to/token&amp;#34;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: LogCLI&lt;/li&gt;
&lt;li&gt;Retryable: Yes (with correct configuration)&lt;/li&gt;
&lt;li&gt;HTTP status: N/A (client-side error)&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-run-out-of-attempts-while-querying&#34;&gt;Error: Run out of attempts while querying&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;run out of attempts while querying the server&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;LogCLI exhausted all retry attempts when trying to reach Loki. This usually indicates:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Network connectivity issues&lt;/li&gt;
&lt;li&gt;Server unavailability&lt;/li&gt;
&lt;li&gt;Authentication failures&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check Loki server availability&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verify network connectivity&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check authentication credentials&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Increase retries&lt;/strong&gt; if transient issues are expected:&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;Bash&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-bash&#34;&gt;logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --retries=5&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: LogCLI&lt;/li&gt;
&lt;li&gt;Retryable: Yes (automatic retries exhausted)&lt;/li&gt;
&lt;li&gt;HTTP status: Varies&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-websocket-connection-closed-unexpectedly&#34;&gt;Error: WebSocket connection closed unexpectedly&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;websocket: close 1006 (abnormal closure): unexpected EOF&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When tailing logs, the WebSocket connection was closed unexpectedly. This can happen if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The querier handling the tail request stopped&lt;/li&gt;
&lt;li&gt;Network interruption occurred&lt;/li&gt;
&lt;li&gt;Server-side timeout&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;LogCLI will automatically attempt to reconnect, up to 5 times.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check Loki querier health&lt;/strong&gt; if reconnections fail.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review network stability&lt;/strong&gt; between client and server.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Network/Server&lt;/li&gt;
&lt;li&gt;Retryable: Yes (automatic reconnection)&lt;/li&gt;
&lt;li&gt;HTTP status: N/A (WebSocket error)&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;data-availability-errors&#34;&gt;Data availability errors&lt;/h2&gt;
&lt;p&gt;These errors occur when requested data is not available.&lt;/p&gt;
&lt;h3 id=&#34;error-no-data-found&#34;&gt;Error: No data found&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;no data found&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Or an empty result set with no error message.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The query time range contains no matching log data. This can happen if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No logs match the stream selectors&lt;/li&gt;
&lt;li&gt;The time range is outside the data retention period&lt;/li&gt;
&lt;li&gt;Log ingestion is not working&lt;/li&gt;
&lt;li&gt;Stream labels don&amp;rsquo;t match any existing streams&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verify the time range&lt;/strong&gt; contains data for your streams.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check if log ingestion is working&lt;/strong&gt; correctly:&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;Bash&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-bash&#34;&gt;# Check if any data is being ingested
logcli query &amp;#39;{job=~&amp;#34;.&amp;#43;&amp;#34;}&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verify stream selectors&lt;/strong&gt; match existing log streams:&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;Bash&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-bash&#34;&gt;# List available streams
curl http://loki:3100/loki/api/v1/series&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check data retention&lt;/strong&gt; settings to ensure logs are still available.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use broader selectors&lt;/strong&gt; to test if any data exists:&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;.&amp;#43;&amp;#34;}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Query Engine&lt;/li&gt;
&lt;li&gt;Retryable: Yes (with different parameters)&lt;/li&gt;
&lt;li&gt;HTTP status: 200 OK (with empty result)&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-index-not-ready&#34;&gt;Error: Index not ready&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;index not ready&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Or:&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;text&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-text&#34;&gt;index gateway not ready for time range&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The index for the requested time range is not yet available for querying. This can happen when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Index files are still being synced from storage&lt;/li&gt;
&lt;li&gt;The index gateway is still starting up&lt;/li&gt;
&lt;li&gt;Querying data older than the configured ready index period&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;query_ready_index_num_days&lt;/code&gt;: 0 (all indexes are considered ready)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Wait for the index to become available&lt;/strong&gt; - this is often a temporary issue during startup.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Query more recent data&lt;/strong&gt; that&amp;rsquo;s available in ingesters:&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;foo&amp;#34;} # Query last few hours instead of older data&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check the configuration&lt;/strong&gt; for index readiness:&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;YAML&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-yaml&#34;&gt;query_range:
  query_ready_index_num_days: 7  #default is 0&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verify index synchronization&lt;/strong&gt; is working correctly by checking ingester and index gateway logs.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Index Gateway/Querier&lt;/li&gt;
&lt;li&gt;Retryable: Yes (wait and retry)&lt;/li&gt;
&lt;li&gt;HTTP status: 503 Service Unavailable&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-tenant-limits&#34;&gt;Error: Tenant limits&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;max concurrent tail requests limit exceeded, count &amp;gt; limit (10 &amp;gt; 5)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The tenant has exceeded the maximum number of concurrent streaming (tail) requests. This limit protects the cluster from excessive resource consumption by real-time log streaming.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Default configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;max_concurrent_tail_requests&lt;/code&gt;: 10&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Reduce the number of concurrent tail/streaming queries&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Use batch queries&lt;/strong&gt; instead of real-time streaming where possible:&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;# Instead of tailing in real-time
# Use periodic range queries
{app=&amp;#34;foo&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;&lt;strong&gt;Increase the limit&lt;/strong&gt; if more concurrent tails are needed:&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;YAML&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-yaml&#34;&gt;limits_config:
  max_concurrent_tail_requests: 20  #default is 10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Querier&lt;/li&gt;
&lt;li&gt;Retryable: Yes (when connections are available)&lt;/li&gt;
&lt;li&gt;HTTP status: 429 Too Many Requests&lt;/li&gt;
&lt;li&gt;Configurable per tenant: Yes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;storage-errors&#34;&gt;Storage errors&lt;/h2&gt;
&lt;p&gt;These errors occur when Loki cannot read data from storage.&lt;/p&gt;
&lt;h3 id=&#34;error-failed-to-load-chunk&#34;&gt;Error: Failed to load chunk&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;failed to load chunk &amp;#39;&amp;lt;chunk_key&amp;gt;&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Loki couldn&amp;rsquo;t retrieve a chunk from object storage. Possible causes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Chunk was deleted or moved&lt;/li&gt;
&lt;li&gt;Storage permissions issue&lt;/li&gt;
&lt;li&gt;Network connectivity to storage&lt;/li&gt;
&lt;li&gt;Storage service unavailable&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Check storage connectivity&lt;/strong&gt; from Loki components.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Verify storage credentials and permissions&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check for chunk corruption&lt;/strong&gt; or deletion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review storage service status&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Storage Client&lt;/li&gt;
&lt;li&gt;Retryable: Yes (automatically)&lt;/li&gt;
&lt;li&gt;HTTP status: 500 Internal Server Error&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-object-not-found-in-storage&#34;&gt;Error: Object not found in storage&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;object not found in storage&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The requested chunk or object doesn&amp;rsquo;t exist in storage. This might happen if:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Data was deleted due to retention&lt;/li&gt;
&lt;li&gt;Compaction removed the chunk&lt;/li&gt;
&lt;li&gt;Chunk was never written successfully&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Check if data is within retention period&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Verify data was ingested successfully&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Review compaction jobs&lt;/strong&gt; for issues.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Storage Client&lt;/li&gt;
&lt;li&gt;Retryable: No (data doesn&amp;rsquo;t exist)&lt;/li&gt;
&lt;li&gt;HTTP status: 404 or 500 depending on context&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;error-failed-to-decode-chunk&#34;&gt;Error: Failed to decode chunk&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&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;text&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-text&#34;&gt;failed to decode chunk &amp;#39;&amp;lt;chunk_key&amp;gt;&amp;#39; for tenant &amp;#39;&amp;lt;tenant&amp;gt;&amp;#39;: &amp;lt;error&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A chunk was retrieved from storage but couldn&amp;rsquo;t be decoded. This indicates chunk corruption.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Resolution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Report to Loki administrators&lt;/strong&gt; for investigation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Check for storage data integrity issues&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Note that the corrupted chunk data may be unrecoverable.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Properties:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Enforced by: Storage Client&lt;/li&gt;
&lt;li&gt;Retryable: No (chunk is corrupted)&lt;/li&gt;
&lt;li&gt;HTTP status: 500 Internal Server Error&lt;/li&gt;
&lt;li&gt;Configurable per tenant: No&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;troubleshooting-workflow&#34;&gt;Troubleshooting workflow&lt;/h2&gt;
&lt;p&gt;Follow this workflow when investigating query issues:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check the error message&lt;/strong&gt; - Identify which category of error you&amp;rsquo;re encountering.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Review query syntax&lt;/strong&gt; - Use the LogQL documentation to validate your query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check query statistics&lt;/strong&gt; - In Grafana, enable &amp;ldquo;Query Inspector&amp;rdquo; to see:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bytes processed&lt;/li&gt;
&lt;li&gt;Number of chunks scanned&lt;/li&gt;
&lt;li&gt;Execution time breakdown&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simplify the query&lt;/strong&gt; - Start with a basic selector and add complexity:&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;# Start simple
{app=&amp;#34;foo&amp;#34;}

# Add filters
{app=&amp;#34;foo&amp;#34;} |= &amp;#34;error&amp;#34;

# Add parsing
{app=&amp;#34;foo&amp;#34;} |= &amp;#34;error&amp;#34; | json

# Add label filters
{app=&amp;#34;foo&amp;#34;} |= &amp;#34;error&amp;#34; | json | level=&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;&lt;strong&gt;Check metrics&lt;/strong&gt; for query performance:&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;promql&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-promql&#34;&gt;# Query latency
histogram_quantile(0.99, sum(rate(loki_request_duration_seconds_bucket[5m])) by (le, route))

# Query errors
sum by (status_code) (rate(loki_request_duration_seconds_count[5m]))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Review Loki logs&lt;/strong&gt; for detailed error information:&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;Bash&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-bash&#34;&gt;kubectl logs -l app=loki-read --tail=100 | grep -i error&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Test with LogCLI&lt;/strong&gt; for more detailed output:&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;Bash&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-bash&#34;&gt;logcli query &amp;#39;{app=&amp;#34;foo&amp;#34;}&amp;#39; --stats --limit=10&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;related-resources&#34;&gt;Related resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn more about 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/&#34;&gt;LogQL Query Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Configure appropriate 
    &lt;a href=&#34;/docs/loki/v3.7.x/configure/#limits_config&#34;&gt;query limits&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Learn more about 
    &lt;a href=&#34;/docs/loki/v3.7.x/operations/query-acceleration/&#34;&gt;Query performance tuning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Review the 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/logcli/&#34;&gt;LogCLI documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Learn more about 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/log_queries/&#34;&gt;LogQL query optimization&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Review 
    &lt;a href=&#34;/docs/loki/v3.7.x/best-practices/&#34;&gt;query performance best practices&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Use 
    &lt;a href=&#34;/docs/loki/v3.7.x/query/query_stats/&#34;&gt;query debugging features&lt;/a&gt; to analyze slow queries&lt;/li&gt;
&lt;li&gt;Explore the &lt;a href=&#34;https://github.com/grafana/loki&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Loki GitHub repository&lt;/a&gt; for community support&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

        
]]></content><description>&lt;h1 id="troubleshoot-log-queries-read">Troubleshoot log queries (READ)&lt;/h1>
&lt;div data-shared="troubleshoot-query.md">
&lt;p>This guide helps you troubleshoot errors that occur when querying logs from Loki. When Loki rejects or fails query requests, it&amp;rsquo;s typically due to query syntax errors, exceeding limits, timeout issues, or storage access problems.&lt;/p></description></item></channel></rss>