<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PromLabs Blog]]></title><description><![CDATA[PromLabs - We teach Prometheus-based monitoring and observability]]></description><link>https://promlabs.com</link><generator>GatsbyJS</generator><lastBuildDate>Thu, 08 Oct 2026 13:38:32 GMT</lastBuildDate><item><title><![CDATA[Filling in Missing Series in Binary Operator Matching]]></title><description><![CDATA[A long-requested PromQL feature has just landed in Prometheus 3.10: the ability to fill in default values for missing series in binary…]]></description><link>https://promlabs.com/blog/2026/03/05/filling-in-missing-series-in-binary-operator-matching</link><guid isPermaLink="false">https://promlabs.com/blog/2026/03/05/filling-in-missing-series-in-binary-operator-matching</guid><pubDate>Thu, 05 Mar 2026 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;A long-requested PromQL feature has just &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/17644&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;landed in Prometheus 3.10&lt;/a&gt;: the ability to fill in default values for missing series in binary operations. In this post, we&apos;ll explore the motivation behind this feature, how the new &lt;code&gt;fill()&lt;/code&gt;, &lt;code&gt;fill_left()&lt;/code&gt;, and &lt;code&gt;fill_right()&lt;/code&gt; modifiers work, and what caveats to watch out for when using them.&lt;/p&gt;
&lt;p&gt;I want to specifically thank &lt;a href=&quot;https://www.dash0.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Dash0&lt;/a&gt;, an OpenTelemetry-native observability platform, for sponsoring the development of this feature.&lt;/p&gt;
&lt;h2 id=&quot;the-challenge-missing-series-in-binary-operations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-challenge-missing-series-in-binary-operations&quot; aria-label=&quot;the challenge missing series in binary operations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The challenge: missing series in binary operations&lt;/h2&gt;
&lt;p&gt;When performing binary operations between two vectors in PromQL, only series that find a matching counterpart on the other side are included in the result vector by default. While this behavior is often exactly what you want, there are some situations where you may want a different behavior.&lt;/p&gt;
&lt;p&gt;For example, you may want to add up the rates of successful and failed requests:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;successful_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; + &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;failed_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If a particular label combination (e.g., &lt;code&gt;{method=&quot;GET&quot;, status=&quot;200&quot;}&lt;/code&gt;) only exists on one side of the operation (perhaps because there haven&apos;t been any failures for that combination yet) it will be completely dropped from the result. This is sometimes not what you want: you might prefer to treat the missing side as &lt;code&gt;0&lt;/code&gt; and still get a result, in this case the total rate of either successful or failed requests for any method and status code combination that is present on either side.&lt;/p&gt;
&lt;p&gt;As another example, you might want to compare a metric against a custom threshold that doesn&apos;t exist for every label set:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;api_error_rates &gt; api_error_rate_thresholds&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If some of the label sets in &lt;code&gt;api_error_rates&lt;/code&gt; do not have a matching threshold value, the filter operator will always drop that combination from the result, even if the error rate is very high. Maybe you would like to provide a default value for the threshold instead.&lt;/p&gt;
&lt;h2 id=&quot;the-old-workaround-using-or&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-old-workaround-using-or&quot; aria-label=&quot;the old workaround using or permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The old workaround: using &lt;code&gt;or&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Until now, the standard workaround (besides &lt;a href=&quot;/blog/2023/09/13/dealing-with-missing-time-series-in-prometheus/&quot;&gt;trying to avoid missing series&lt;/a&gt;) was to use the &lt;code&gt;or&lt;/code&gt; operator to fill in potentially missing series:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;vector1 + vector2 or vector1 or vector2&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For the example query above, this becomes:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;successful_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; + &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;failed_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
or &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;successful_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
or &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;failed_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This works but quickly becomes unwieldy. For default values other than &lt;code&gt;0&lt;/code&gt;, it gets even messier:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Use 23 as the default for the right side, 42 for the left side.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;vector1 + vector2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; or &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;vector1 + &lt;span class=&quot;token number&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; or &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt; + vector2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And if you&apos;re using &lt;code&gt;on()&lt;/code&gt; or &lt;code&gt;ignoring()&lt;/code&gt; clauses, you need to carefully replicate that label matching logic with aggregations:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  vector1
+ &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;label1&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;label2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
  vector2
or
  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;label1&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;label2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;vector1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; + &lt;span class=&quot;token number&quot;&gt;23&lt;/span&gt;
or
  &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt; + &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;label1&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;label2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;vector2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This approach is error-prone, verbose, and inefficient. It also inadvertently reintroduces the metric name on resulting series in some cases, which can lead to unexpected behavior.&lt;/p&gt;
&lt;h2 id=&quot;the-new-solution-fill-modifiers-for-providing-default-values&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-new-solution-fill-modifiers-for-providing-default-values&quot; aria-label=&quot;the new solution fill modifiers for providing default values permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The new solution: Fill modifiers for providing default values&lt;/h2&gt;
&lt;p&gt;Prometheus 3.10 introduces three new experimental modifiers that let you specify default values for missing series in a binary operation:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;fill(&amp;#x3C;value&gt;)&lt;/code&gt;&lt;/strong&gt;: Fill in missing series on &lt;em&gt;both&lt;/em&gt; sides of the operation with the specified value.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;fill_left(&amp;#x3C;value&gt;)&lt;/code&gt;&lt;/strong&gt;: Fill in missing series on the &lt;em&gt;left&lt;/em&gt; side only.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;fill_right(&amp;#x3C;value&gt;)&lt;/code&gt;&lt;/strong&gt;: Fill in missing series on the &lt;em&gt;right&lt;/em&gt; side only.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: These modifiers are still &lt;strong&gt;experimental&lt;/strong&gt; for now, so you need to enable them explicitly using the &lt;code&gt;--enable-feature=promql-binop-fill-modifiers&lt;/code&gt; flag when starting Prometheus.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;basic-usage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#basic-usage&quot; aria-label=&quot;basic usage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Basic usage&lt;/h3&gt;
&lt;p&gt;The simplest form is to use &lt;code&gt;fill()&lt;/code&gt; to provide a default value for missing series on either side:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;successful_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; + fill&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;failed_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now, if a series exists on only one side, a &lt;code&gt;0&lt;/code&gt;-valued sample is filled in on the other side, and you get a result for every label combination that exists on &lt;em&gt;either&lt;/em&gt; side.&lt;/p&gt;
&lt;h3 id=&quot;filling-only-one-side&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#filling-only-one-side&quot; aria-label=&quot;filling only one side permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Filling only one side&lt;/h3&gt;
&lt;p&gt;Often, you&apos;ll want to fill in only one of the two sides. For example, when filtering error rates by custom thresholds that might not exist for every label set:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;api_error_rates &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; fill_right&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; api_error_rate_thresholds&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here, if a series from &lt;code&gt;api_error_rates&lt;/code&gt; doesn&apos;t have a matching threshold in &lt;code&gt;api_error_rate_thresholds&lt;/code&gt;, the default threshold of &lt;code&gt;42&lt;/code&gt; is used instead. The left side (&lt;code&gt;api_error_rates&lt;/code&gt;) is &lt;em&gt;not&lt;/em&gt; filled in, so only series that actually exist on the left are considered.&lt;/p&gt;
&lt;h3 id=&quot;using-different-values-for-each-side&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#using-different-values-for-each-side&quot; aria-label=&quot;using different values for each side permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Using different values for each side&lt;/h3&gt;
&lt;p&gt;You can combine &lt;code&gt;fill_left()&lt;/code&gt; and &lt;code&gt;fill_right()&lt;/code&gt; to specify different default values for each side:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;vector1 + fill_left&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; fill_right&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; vector2&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This fills in missing left-side series with &lt;code&gt;10&lt;/code&gt; and missing right-side series with &lt;code&gt;20&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;visualization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#visualization&quot; aria-label=&quot;visualization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Visualization&lt;/h3&gt;
&lt;p&gt;The following diagram shows how &lt;code&gt;fill()&lt;/code&gt; works. We&apos;re adding two vectors, while using &lt;code&gt;0&lt;/code&gt; as the default for any missing series:&lt;/p&gt;
&lt;p style=&quot;overflow-x: auto&quot;&gt;
  &lt;img src=&quot;/images/fill-modifier-fill.svg&quot; alt=&quot;Diagram showing how fill() works in a binary operation&quot; style=&quot;width: auto&quot;&gt;
&lt;/p&gt;
&lt;p&gt;Using &lt;code&gt;fill_right(0)&lt;/code&gt; instead would only fill in the right side, omitting the last row from the result:&lt;/p&gt;
&lt;p style=&quot;overflow-x: auto&quot;&gt;
  &lt;img src=&quot;/images/fill-modifier-fill-right.svg&quot; alt=&quot;Diagram showing how fill_right() works in a binary operation&quot; style=&quot;width: auto&quot;&gt;
&lt;/p&gt;
&lt;h2 id=&quot;working-with-group_left-and-group_right&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#working-with-group_left-and-group_right&quot; aria-label=&quot;working with group_left and group_right permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Working with &lt;code&gt;group_left&lt;/code&gt; and &lt;code&gt;group_right&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The fill modifiers work together with many-to-one matching via &lt;code&gt;group_left()&lt;/code&gt; and &lt;code&gt;group_right()&lt;/code&gt;, but there are some important caveats to understand.&lt;/p&gt;
&lt;h3 id=&quot;filling-the-one-side&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#filling-the-one-side&quot; aria-label=&quot;filling the one side permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Filling the &quot;one&quot; side&lt;/h3&gt;
&lt;p&gt;When filling the &quot;one&quot; side (the side &lt;em&gt;opposite&lt;/em&gt; to the grouping direction), things work as expected. For example, with &lt;code&gt;group_left(cluster)&lt;/code&gt;, you might want to fill in missing info metrics on the right side:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;some_metric + &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;group_left&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; fill_right&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; info_metric&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If no matching &lt;code&gt;info_metric&lt;/code&gt; exists for a given &lt;code&gt;status&lt;/code&gt;, a &lt;code&gt;0&lt;/code&gt;-valued sample is filled in. However, note that the &lt;code&gt;cluster&lt;/code&gt; label from the &lt;code&gt;group_left(cluster)&lt;/code&gt; clause cannot be filled in – there&apos;s simply no source for that value, and we can&apos;t just invent one. So the result will have an empty &lt;code&gt;cluster&lt;/code&gt; label for those filled-in series:&lt;/p&gt;
&lt;p style=&quot;overflow-x: auto&quot;&gt;
  &lt;img src=&quot;/images/fill-modifier-group-left-fill-right.svg&quot; alt=&quot;Diagram showing how fill_right() works with group_left()&quot; style=&quot;width: auto&quot;&gt;
&lt;/p&gt;
&lt;h3 id=&quot;filling-the-many-side&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#filling-the-many-side&quot; aria-label=&quot;filling the many side permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Filling the &quot;many&quot; side&lt;/h3&gt;
&lt;p&gt;When filling in the &quot;many&quot; side of a match, we face an ambiguity: if multiple series &lt;em&gt;would have&lt;/em&gt; existed on that side (if their data hadn&apos;t gone missing for some reason), we don&apos;t know what their differentiating labels would have been. Therefore, only a &lt;em&gt;single&lt;/em&gt; series can be filled in for each missing match group, using only the matching labels as its identity.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;method_status_metric + &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;group_left&lt;/span&gt; fill_left&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; status_only_metric&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If &lt;code&gt;status_only_metric&lt;/code&gt; has a &lt;code&gt;{status=&quot;404&quot;}&lt;/code&gt; series but &lt;code&gt;method_status_metric&lt;/code&gt; has no series with that status, only a single &lt;code&gt;{status=&quot;404&quot;}&lt;/code&gt; series is filled in (with value &lt;code&gt;0&lt;/code&gt;), not multiple separate series for each possible &lt;code&gt;method&lt;/code&gt; value:&lt;/p&gt;
&lt;p style=&quot;overflow-x: auto&quot;&gt;
  &lt;img src=&quot;/images/fill-modifier-group-left-fill-left.svg&quot; alt=&quot;Diagram showing how fill_left() works with group_left()&quot; style=&quot;width: auto&quot;&gt;
&lt;/p&gt;
&lt;h2 id=&quot;supported-operators&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#supported-operators&quot; aria-label=&quot;supported operators permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Supported operators&lt;/h2&gt;
&lt;p&gt;The fill modifiers work with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Arithmetic operators&lt;/strong&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;^&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Comparison operators&lt;/strong&gt;: &lt;code&gt;==&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;, &lt;code&gt;&gt;&lt;/code&gt;, &lt;code&gt;&amp;#x3C;&lt;/code&gt;, &lt;code&gt;&gt;=&lt;/code&gt;, &lt;code&gt;&amp;#x3C;=&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Trigonometric operators&lt;/strong&gt;: &lt;code&gt;atan2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They are &lt;em&gt;not&lt;/em&gt; supported for set operators (&lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;unless&lt;/code&gt;), since the whole point of those operators is to filter series based on their presence or absence.&lt;/p&gt;
&lt;h2 id=&quot;caveats-and-pitfalls&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#caveats-and-pitfalls&quot; aria-label=&quot;caveats and pitfalls permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Caveats and pitfalls&lt;/h2&gt;
&lt;p&gt;Please be careful and don&apos;t just add fill operators to all of your binary operations without careful thought. While they can make it much easier to handle missing series in some situations, they also come with dangers and caveats that you really should be aware of before deciding to use them:&lt;/p&gt;
&lt;h3 id=&quot;caveat-1-danger-of-masking-incorrect-selectors-or-broken-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#caveat-1-danger-of-masking-incorrect-selectors-or-broken-data&quot; aria-label=&quot;caveat 1 danger of masking incorrect selectors or broken data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Caveat 1:&lt;/strong&gt; Danger of masking incorrect selectors or broken data&lt;/h3&gt;
&lt;p&gt;Since the fill modifiers operate silently to fill in missing series and don&apos;t tell you what they did, they can mask real mistakes in your queries or your monitoring setup. This can happen due to a number of reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Mismatched metric names, label names, or label values between your PromQL selectors and your data (causing empty selectors).&lt;/li&gt;
&lt;li&gt;Incorrect matching modifiers (&lt;code&gt;on&lt;/code&gt;, &lt;code&gt;ignoring&lt;/code&gt;, &lt;code&gt;group_left&lt;/code&gt;, &lt;code&gt;group_right&lt;/code&gt;) on a binary operator.&lt;/li&gt;
&lt;li&gt;Missing data that you expect to always be present, but which is absent for some reason.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With the old default behavior, you would get no results for the affected label combinations, making it clear that something is wrong and needs to be investigated. With &lt;code&gt;fill()&lt;/code&gt;, you will get plausible-looking outputs with incorrect values, and you might never know that something is broken. So be extra careful when using the new fill modifiers, especially in alerting rules.&lt;/p&gt;
&lt;h3 id=&quot;caveat-2-changing-output-series-labels-over-time&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#caveat-2-changing-output-series-labels-over-time&quot; aria-label=&quot;caveat 2 changing output series labels over time permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Caveat 2:&lt;/strong&gt; Changing output series labels over time&lt;/h3&gt;
&lt;p&gt;When a series needs to be filled in, its labels are derived from the match group&apos;s matching labels only. If the original series would have had additional labels (like a metric name), those won&apos;t be present on the filled-in result. This can lead to results with inconsistent label sets across different time steps if a series intermittently appears and disappears.&lt;/p&gt;
&lt;p&gt;For example, in a range query, at timestamps where a series exists, you might see an output like &lt;code&gt;failed_requests_total{method=&quot;GET&quot;}&lt;/code&gt;, but at timestamps where it had to be filled in, you&apos;ll just see &lt;code&gt;{method=&quot;GET&quot;}&lt;/code&gt;. This is expected behavior: PromQL evaluates each timestamp independently and cannot know what the &quot;real&quot; labels would have been, had the series been present.&lt;/p&gt;
&lt;h3 id=&quot;caveat-3-no-native-histogram-support-yet&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#caveat-3-no-native-histogram-support-yet&quot; aria-label=&quot;caveat 3 no native histogram support yet permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Caveat 3:&lt;/strong&gt; No native histogram support (yet)&lt;/h3&gt;
&lt;p&gt;Currently, fill values must be numeric literals. Filling in native histograms with a default value is not supported yet, but could be added in the future if there&apos;s demand.&lt;/p&gt;
&lt;h3 id=&quot;caveat-4-you-cant-create-series-from-nothing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#caveat-4-you-cant-create-series-from-nothing&quot; aria-label=&quot;caveat 4 you cant create series from nothing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Caveat 4:&lt;/strong&gt; You can&apos;t create series from nothing&lt;/h3&gt;
&lt;p&gt;Perhaps this is stating the obvious, but it&apos;s important to note that the fill modifiers can only fill in missing series when a matching series exists on at least &lt;em&gt;one&lt;/em&gt; of the two sides. They do not create series out of thin air when both sides are missing. So you still need at least one series on one side of the operation for any output to be produced.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The new &lt;code&gt;fill()&lt;/code&gt;, &lt;code&gt;fill_left()&lt;/code&gt;, and &lt;code&gt;fill_right()&lt;/code&gt; modifiers provide a clean and efficient way to provide default values for missing series in PromQL binary operations. They address a long-standing PromQL pain point and make some previously awkward queries much simpler to write.&lt;/p&gt;
&lt;p&gt;This feature is available starting in &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v3.10.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 3.10&lt;/a&gt;. I encourage you to try it out and provide feedback on the &lt;a href=&quot;https://github.com/prometheus/prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus GitHub repository&lt;/a&gt; or one of our &lt;a href=&quot;https://prometheus.io/community/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;community channels&lt;/a&gt;. If you run into any edge cases or have suggestions for improvements, I&apos;d love to hear about them!&lt;/p&gt;
&lt;p&gt;And if you want to learn more about PromQL and Prometheus, check out our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL training courses&lt;/a&gt;, especially &lt;a href=&quot;https://training.promlabs.com/training/understanding-promql/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Understanding PromQL&lt;/strong&gt;&lt;/a&gt; for a deep dive into the query language.&lt;/p&gt;
&lt;p&gt;Finally, many thanks go to &lt;a href=&quot;https://www.dash0.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Dash0&lt;/a&gt; for inspiring this feature and sponsoring its development!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Why I recommend native Prometheus instrumentation over OpenTelemetry]]></title><description><![CDATA[With all the hype around OpenTelemetry (OTel), you may be tempted to use OpenTelemetry and its SDKs for all of your application…]]></description><link>https://promlabs.com/blog/2025/07/17/why-i-recommend-native-prometheus-instrumentation-over-opentelemetry</link><guid isPermaLink="false">https://promlabs.com/blog/2025/07/17/why-i-recommend-native-prometheus-instrumentation-over-opentelemetry</guid><pubDate>Thu, 17 Jul 2025 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;With all the hype around &lt;a href=&quot;https://opentelemetry.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenTelemetry&lt;/a&gt; (OTel), you may be tempted to use OpenTelemetry and its SDKs for all of your application instrumentation needs. However, when it comes to generating metrics for usage in Prometheus, you should at least think twice before going all in on OTel. Not only do you risk throwing away some of the core features that define Prometheus as a monitoring system, but you&apos;ll also end up with awkward metrics translation and escaping issues, as well as other inefficiencies and complexities. That&apos;s why I still recommend using Prometheus&apos;s own &lt;a href=&quot;https://prometheus.io/docs/instrumenting/clientlibs/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;native instrumentation client libraries&lt;/a&gt; over the OTel SDKs if you want to get the best possible Prometheus monitoring experience. Let&apos;s have a look at the reasons.&lt;/p&gt;
&lt;blockquote style=&quot;background-color: #f8f9fa; padding: 20px 20px 5px 20px; border-radius: 5px;&quot;&gt;
&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; As a co-founder of Prometheus, I&apos;m clearly biased here. There may still be reasons why you absolutely have to use OpenTelemetry with Prometheus, but advertisements for OpenTelemetry are found everywhere else already, so I won&apos;t repeat them here.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;opentelemetry-vs-prometheus-scopes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#opentelemetry-vs-prometheus-scopes&quot; aria-label=&quot;opentelemetry vs prometheus scopes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;OpenTelemetry vs. Prometheus scopes&lt;/h2&gt;
&lt;p&gt;First, if you&apos;re not super familiar with OpenTelemetry and Prometheus, here&apos;s a quick comparison of the scopes of the two systems:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/otel-vs-prometheus-scope.svg&quot; alt=&quot;OTel vs. Prometheus scopes diagram&quot;&gt;&lt;/p&gt;
&lt;p&gt;In short:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;OpenTelemetry&lt;/strong&gt; handles all three signal types (logs, metrics, and traces), but only cares about the generation (instrumentation) and transfer of the generated signals to some third-party backend system. The transfer usually happens via the &lt;a href=&quot;https://opentelemetry.io/docs/specs/otel/protocol/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenTelemetry Protocol (OTLP)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prometheus&lt;/strong&gt; only handles metrics (no logs or traces to be seen here), but it doesn&apos;t stop at generating them. Prometheus is a full monitoring system, so it also provides solutions for actively collecting and storing the data and making it queryable for dashboarding, alerting, and other use cases. The querying happens via the &lt;a href=&quot;https://training.promlabs.com/training/understanding-promql/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL query language&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both system scopes &lt;strong&gt;overlap in the generation and transfer of metrics&lt;/strong&gt;, but they each come with their own client libraries, transfer protocols, data models, and differing philosophies for that overlapping part.&lt;/p&gt;
&lt;h2 id=&quot;the-basics-of-feeding-opentelemetry-metrics-into-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-basics-of-feeding-opentelemetry-metrics-into-prometheus&quot; aria-label=&quot;the basics of feeding opentelemetry metrics into prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The basics of feeding OpenTelemetry metrics into Prometheus&lt;/h2&gt;
&lt;p&gt;While the two systems evolved separately, there are several ways to send OpenTelemetry metrics to Prometheus these days. While you could send them directly from an application to a Prometheus server, the more common approach in the OTel world is to first send all data to the &lt;a href=&quot;https://opentelemetry.io/docs/collector/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenTelemetry Collector&lt;/a&gt;, a separate service that receives and aggregates telemetry from multiple applications. The Collector can then send the processed data to a backend like Prometheus:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/otel-prometheus-exporters.svg&quot; alt=&quot;OTel-to-Prometheus architecture diagram&quot;&gt;&lt;/p&gt;
&lt;p&gt;From the Collector, the metrics can make it into Prometheus in a few different ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://opentelemetry.io/docs/languages/go/exporters/#prometheus-experimental&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Prometheus Exporter&lt;/strong&gt;&lt;/a&gt; allows a Prometheus server to pull metrics from the Collector in Prometheus&apos;s native metrics format. This is not ideal for larger use cases, as it forces all metrics into a single large Prometheus scrape, introducing scaling and reliability challenges.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/prometheusremotewriteexporter/README.md&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Prometheus Remote Write Exporter&lt;/strong&gt;&lt;/a&gt; pushes metrics to the Prometheus server using Prometheus&apos;s own &lt;a href=&quot;https://prometheus.io/docs/specs/remote_write_spec/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;remote write&lt;/a&gt; format for inter-server metrics transfers. This is more suitable for larger use cases.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Most common:&lt;/strong&gt; The &lt;a href=&quot;https://opentelemetry.io/docs/languages/go/exporters/#otlp&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;OTLP Exporter&lt;/strong&gt;&lt;/a&gt; uses OpenTelemetry&apos;s OTLP to push metrics to Prometheus. This is a good alternative to using Prometheus&apos;s remote write format, and in practice what most people use when sending OTel data to Prometheus.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reasons-against-using-opentelemetry-with-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reasons-against-using-opentelemetry-with-prometheus&quot; aria-label=&quot;reasons against using opentelemetry with prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Reasons against using OpenTelemetry with Prometheus&lt;/h2&gt;
&lt;p&gt;With that out of the way, here are some of the reasons why I recommend using native Prometheus instrumentation over OpenTelemetry, especially if you mostly care about metrics and using them in Prometheus.&lt;/p&gt;
&lt;h3 id=&quot;reason-1-you-throw-away-prometheuss-target-health-monitoring&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reason-1-you-throw-away-prometheuss-target-health-monitoring&quot; aria-label=&quot;reason 1 you throw away prometheuss target health monitoring permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Reason 1:&lt;/strong&gt; You throw away Prometheus&apos;s target health monitoring&lt;/h3&gt;
&lt;p&gt;Prometheus is a full monitoring system, and a monitoring system should not just be a mindless receptacle for random incoming metrics. To do its job, a monitoring system fundamentally needs to know what the world &lt;em&gt;should&lt;/em&gt; look like, what the world &lt;em&gt;actually&lt;/em&gt; currently looks like, and what the discrepancies are between the desired and actual states of the world. To achieve this, it needs to know which application processes, machines, and other monitoring targets should currently exist and be healthy in your infrastructure.&lt;/p&gt;
&lt;p&gt;Prometheus&apos;s native monitoring model solves this challenge by combining two crucial concepts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Service discovery&lt;/strong&gt;: Prometheus integrates with a variety of &lt;a href=&quot;https://training.promlabs.com/training/service-discovery/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;service discovery mechanisms&lt;/a&gt; to figure out which monitoring targets should currently exist. For example, on a Kubernetes cluster the Prometheus server can subscribe to a list of all pods, services, ingresses, and so on, of a given type via the Kubernetes API. This list is then continuously updated. If Prometheus does not support the kind of service discovery that you need, you can even build your own.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pull-based metrics collection with built-in health checks:&lt;/strong&gt; By actively pulling and labeling metrics from each discovered target, Prometheus can automatically detect if a target is down or not responding correctly.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So Prometheus always has an up-to-date view of which targets should exist, and it records a synthetic &lt;code&gt;up&lt;/code&gt; metric every time it scrapes a target, setting the sample value to &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;, depending on the success of the scrape:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-active-health-monitoring.svg&quot; alt=&quot;Prometheus&amp;#x27;s active target health monitoring&quot;&gt;&lt;/p&gt;
&lt;p&gt;This makes it trivial to build basic health monitoring for all of your targets, meaning that you can easily find and alert on any targets that are down or unreachable:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Alert if any target in the &quot;demo&quot; job is down for more than 5 minutes.&lt;/span&gt;
&lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; TargetDown
&lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; up&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;job=&quot;demo&quot;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; == 0
&lt;span class=&quot;token key atrule&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5m&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In contrast, OTLP is a push-based protocol and lacks any integration with Prometheus&apos;s service discovery capabilities. So there is no way for Prometheus to tell you if an expected metrics source is not reporting in (or vice versa). You lose the ability to detect if any of the following things go wrong:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A target that is supposed to be running is up, but is not sending metrics.&lt;/li&gt;
&lt;li&gt;A target that is supposed to be running is down / absent and thus also not sending metrics.&lt;/li&gt;
&lt;li&gt;A network failure or partition prevents one or many targets from being able to send metrics.&lt;/li&gt;
&lt;li&gt;A target that is not supposed to be monitored by this Prometheus server is sending metrics anyway (the pull model avoids this automatically).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even if a target first reports data and then stops, you will have no way of knowing whether the target has been intentionally shut down or whether it is now crashing or its metrics reporting is broken. So you may actually have hundreds of broken service processes that you don&apos;t even know about.&lt;/p&gt;
&lt;p&gt;To achieve a similar level of target health monitoring with OTLP, you will have to generate and ingest a separate set of metrics from some source of truth that tells you the intended state for each monitored target and then manually correlate this set of metrics with the incoming OTLP data, joining both sets of data on compatible identifying labels. This is a lot of extra work, so many people just ignore this problem completely (knowingly or not) and never even notice that they don&apos;t have proper target health monitoring.&lt;/p&gt;
&lt;h3 id=&quot;reason-2-you-get-changed-metric-names-andor-ugly-promql-selectors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reason-2-you-get-changed-metric-names-andor-ugly-promql-selectors&quot; aria-label=&quot;reason 2 you get changed metric names andor ugly promql selectors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Reason 2:&lt;/strong&gt; You get changed metric names and/or ugly PromQL selectors&lt;/h3&gt;
&lt;p&gt;When using OpenTelemetry metrics in Prometheus, you will run into some character set compatibility issues, different metric naming conventions, and escaping woes:&lt;/p&gt;
&lt;h4 id=&quot;character-set-differences&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#character-set-differences&quot; aria-label=&quot;character set differences permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Character set differences&lt;/h4&gt;
&lt;p&gt;In contrast to OpenTelemetry, Prometheus has never just focused on generating and transferring metrics, but also cares about using them after collection. Prometheus&apos;s approach to this is the PromQL query language that allows you to write expressions to power dashboards, alerting rules, ad-hoc debugging, and other use cases. When you design a query language, you naturally have to care about syntactical clashes between identifiers and other language constructs like operators - ideally without requiring any escaping around the identifiers. This is why Prometheus has historically been very conservative about the set of characters that it allowed in metric and label names. This is similar to most programming languages, which also don&apos;t allow characters like &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, or &lt;code&gt;/&lt;/code&gt; in identifiers, as they would clash with operators in the language. So until Prometheus 3.0, Prometheus only allowed alphanumeric characters and underscores in label names, while also allowing colons in metric names (regexes &lt;code&gt;[a-zA-Z_][a-zA-Z0-9_]*&lt;/code&gt; and &lt;code&gt;[a-zA-Z_:][a-zA-Z0-9_:]*&lt;/code&gt;, respectively).&lt;/p&gt;
&lt;p&gt;In contrast, OpenTelemetry allows &lt;a href=&quot;https://opentelemetry.io/docs/specs/otel/metrics/api/#instrument-name-syntax&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;dots, dashes, and other operator-like characters&lt;/a&gt; in metric and attribute (label) names - this makes me question whether using OTel metrics in a query language was ever a major design consideration. This is despite the fact that PromQL was already a widely implemented de facto standard for querying metrics when OpenTelemetry was being standardized. In practice, prior to Prometheus 3.0, this meant that the metric and attribute names coming from OpenTelemetry had to be translated to Prometheus-compatible names by replacing unsupported characters with underscores (so &lt;code&gt;my.metric.name&lt;/code&gt; would become &lt;code&gt;my_metric_name&lt;/code&gt;).&lt;/p&gt;
&lt;h4 id=&quot;unit-and-type-suffixes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#unit-and-type-suffixes&quot; aria-label=&quot;unit and type suffixes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unit and type suffixes&lt;/h4&gt;
&lt;p&gt;At the same time, Prometheus&apos;s &lt;a href=&quot;https://prometheus.io/docs/practices/naming/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;metric naming conventions&lt;/a&gt; require metric names to end with a suffix indicating the metric&apos;s unit, as well as a &lt;code&gt;_total&lt;/code&gt; suffix for counter metrics (to disambiguate them from gauges indicating a current count). Both conventions make a metric more understandable, especially in the context of a larger PromQL expression that may be embedded somewhere in a YAML file that is checked in as code. In contrast, OpenTelemetry&apos;s naming conventions only treat the unit and type of a metric as separate metadata fields that are not supposed to be included in the metric name - this is inconvenient if you are working with PromQL expressions in an environment where you don&apos;t have immediate access to a metric&apos;s metadata. To work around this and still keep metric names understandable, the OTLP-to-Prometheus translation layer adds Prometheus-style unit and type suffixes to OpenTelemetry metric names by default.&lt;/p&gt;
&lt;p&gt;So for example, the OTel metric &lt;code&gt;k8s.pod.cpu.time&lt;/code&gt; would become &lt;code&gt;k8s_pod_cpu_time_seconds_total&lt;/code&gt; after translation, both replacing the dots with underscores, as well as clarifying the unit (seconds) and type (counter) of the metric. Unfortunately, this name change can also be confusing for users.&lt;/p&gt;
&lt;h4 id=&quot;utf-8-support-in-prometheus-30&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#utf-8-support-in-prometheus-30&quot; aria-label=&quot;utf 8 support in prometheus 30 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;UTF-8 support in Prometheus 3.0&lt;/h4&gt;
&lt;p&gt;Starting with version 3.0, Prometheus adds full UTF-8 support for metric and label names, so you can now theoretically store unaltered OTel metric names in Prometheus. However, this comes with some drawbacks when writing PromQL selectors: you have to quote names that use the extended character set, and you have to move any such quoted metric names inside of the curly braces (the label matchers list) of the time series selector. Otherwise PromQL would be unable to tell the metric name from a regular string literal expression.&lt;/p&gt;
&lt;p&gt;So for example, if you had a traditional selector like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;my_metric&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;my_label&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;value&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;...you would need to write it like this to support the extended character set (dots instead of underscores in this example):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my.metric&quot;&lt;/span&gt;, &lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my.label&quot;&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;value&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This selector syntax is less intuitive to read and more cumbersome to write, so keep this in mind before deciding to go beyond the original Prometheus character set for identifiers.&lt;/p&gt;
&lt;p&gt;Starting with the UTF-8 support in Prometheus 3, the &lt;code&gt;otlp.translation_strategy&lt;/code&gt; Prometheus configuration file setting allows you to configure the translation strategy for OTel metrics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;UnderscoreEscapingWithSuffixes&lt;/code&gt;: Flatten names to the traditional character set with underscores, as before. This is still the default.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NoUTF8EscapingWithSuffixes&lt;/code&gt;: Keep all original characters, but still add counter and unit suffixes to enhance clarity.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;NoTranslation&lt;/code&gt;: Keep all original characters and don&apos;t add any suffixes (still experimental, might be removed).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whether you want to keep the original character set and live with noisier selector syntax above is up to you. However, I would heavily recommend against using the &lt;code&gt;NoTranslation&lt;/code&gt; option that even omits the unit and type suffixes. That will just make your metrics harder to understand when you&apos;re working with them later on.&lt;/p&gt;
&lt;p&gt;However, if you use Prometheus&apos;s own instrumentation client libraries and naming conventions, you will never even have to think about these character set or naming differences, and your metric and label names will look identical on the instrumentation and usage sides.&lt;/p&gt;
&lt;h3 id=&quot;reason-3-resource-labels-vs-target-labels---same-same-but-different&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reason-3-resource-labels-vs-target-labels---same-same-but-different&quot; aria-label=&quot;reason 3 resource labels vs target labels   same same but different permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Reason 3:&lt;/strong&gt; Resource labels vs. target labels - same same but different?&lt;/h3&gt;
&lt;p&gt;Both Prometheus and OpenTelemetry like to attach a set of labels (or attributes, in OTel terminology) that give you information about the source of a metric, such as the application or service that generated it. In OpenTelemetry, these are called &lt;strong&gt;resource attributes&lt;/strong&gt;, while Prometheus calls them &lt;strong&gt;target labels&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;However, the two systems have somewhat different ideas about how to use these labels:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Prometheus target labels&lt;/strong&gt; are attached to scraped metrics by the Prometheus server based on the target&apos;s metadata, which usually originates from a dynamic service discovery mechanism. Target labels tend to be relatively few and are &lt;em&gt;mostly&lt;/em&gt; identifying (meaning that they are necessary to identify a target, instead of just adding extra information beyond that).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OpenTelemetry resource attributes&lt;/strong&gt; are chosen by the application that generates the metrics and are usually way more numerous and detailed. They often provide a lot of additional context about the metric source, such as the programming language and version of the OTel SDK and other non-critical metadata.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since Prometheus target labels are relatively few and mostly identifying, Prometheus attaches all of them (by default) to every metric that it scrapes from a target. That&apos;s convenient, but this model breaks down for OpenTelemetry&apos;s resource attributes, since attaching a long list of informational attributes to every ingested series makes the resulting metrics too expensive and harder to use.&lt;/p&gt;
&lt;p&gt;So when receiving metrics via OTLP, Prometheus only attaches a small subset of the OTel resource attributes to all metrics by default:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;service.name&lt;/code&gt;: This becomes the &lt;code&gt;job&lt;/code&gt; label in Prometheus, which is used to identify the job (or service).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;service.instance.id&lt;/code&gt;: This becomes the &lt;code&gt;instance&lt;/code&gt; label in Prometheus, which is used to identify the instance (specific process) within the job.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All other resource attributes are only attached to a single &lt;code&gt;target_info&lt;/code&gt; metric that is generated once for each resource. If you then really need to include one of these additional attributes in a query result, you have to join it in via PromQL. However, this gets a bit unwieldy. Instead of just writing a simple query like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_server_request_duration_seconds_count&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;...you will now have to write the following expression to also include the &lt;code&gt;k8s_cluster_name&lt;/code&gt; resource attribute from the &lt;code&gt;target_info&lt;/code&gt; metric:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;    &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_server_request_duration_seconds_count&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
* &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;group_left&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;k8s_cluster_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
    target_info&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There is also a new &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/functions/#info&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;info()&lt;/code&gt; function&lt;/a&gt; in Prometheus 3.0 that aims to make this a bit easier, but it&apos;s still marked as experimental and is not yet fully fleshed out.&lt;/p&gt;
&lt;p&gt;If you are a Prometheus server operator, you can also &lt;a href=&quot;https://prometheus.io/docs/guides/opentelemetry/#promoting-resource-attributes&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;configure which resource attributes are promoted to labels&lt;/a&gt; on each ingested series from a source.&lt;/p&gt;
&lt;p&gt;In any case, you now have to think about all this - how to either join additional labels into your queries, or how to configure your Prometheus server to promote just the right subset of resource attributes to target labels. In contrast, if you use Prometheus&apos;s native instrumentation client libraries and scraping model, only the Prometheus administrator will usually have to think about a general target labeling configuration (or use the default).&lt;/p&gt;
&lt;h3 id=&quot;reason-4-more-prometheus-settings-required-for-ingestion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reason-4-more-prometheus-settings-required-for-ingestion&quot; aria-label=&quot;reason 4 more prometheus settings required for ingestion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Reason 4:&lt;/strong&gt; More Prometheus settings required for ingestion&lt;/h3&gt;
&lt;p&gt;This is admittedly not a big downside, but more of an FYI: To allow Prometheus to receive metrics via OTLP, you will have to configure two additional settings on the Prometheus server:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You&apos;ll need to set the &lt;code&gt;--web.enable-otlp-receiver&lt;/code&gt; command-line flag so that the Prometheus server starts the OTLP receiver on &lt;code&gt;/api/v1/otlp/v1/metrics&lt;/code&gt;. This is because Prometheus is primarily intended to be a pull-based monitoring system, so allowing external clients to push metrics to it could present a security issue and needs to be enabled explicitly. You will now also have to protect this endpoint against pushes from unauthorized sources, a concern that doesn&apos;t exist when Prometheus is in charge of pulling metrics from targets.&lt;/li&gt;
&lt;li&gt;Since OTLP does not guarantee in-order delivery of data (contrary to Prometheus&apos;s usual model of scraping and timestamping data itself), you will need to configure the Prometheus TSDB to allow out-of-order appends for some period of time (like 30 minutes):
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;storage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;tsdb&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;out_of_order_time_window&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30m&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are also potentially other settings you&apos;ll want to configure when using OTLP with Prometheus. See the &lt;a href=&quot;https://prometheus.io/docs/guides/opentelemetry/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus documentation&lt;/a&gt; for details.&lt;/p&gt;
&lt;h3 id=&quot;reason-5-otel-sdks-are-complex-and-can-be-very-slow&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reason-5-otel-sdks-are-complex-and-can-be-very-slow&quot; aria-label=&quot;reason 5 otel sdks are complex and can be very slow permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Reason 5:&lt;/strong&gt; OTel SDKs are complex and can be very slow&lt;/h3&gt;
&lt;p&gt;Another concern is the overall complexity and implementation inefficiency that you are taking on when using OpenTelemetry SDKs instead of Prometheus&apos;s native client libraries. OTel is a large and complex system that tries to do a lot of things, including logs and traces and complex features around views and aggregations for metrics inside of its instrumentation libraries. This means that its SDKs are also large and complex, and you will have to understand more concepts. In contrast, Prometheus&apos;s native instrumentation libraries are small and focused on just generating Prometheus metrics in an efficient way.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; In this example, I will &lt;strong&gt;mostly look at the Prometheus and OpenTelemetry SDKs for the Go programming language&lt;/strong&gt;. I can&apos;t say for sure how the situation looks in all the other languages, but:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Go is a relevant example, as it&apos;s a popular language in the cloud native world and is used for heavy-duty server applications where performance matters.&lt;/li&gt;
&lt;li&gt;Due to OTel&apos;s &lt;a href=&quot;https://opentelemetry.io/docs/specs/otel/metrics/data-model/#events--data-stream--timeseries&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;larger inherent conceptual complexity&lt;/a&gt; in the path between an event (like a counter increment) and the final OTLP output, I would not be surprised if the results are at least directionally similar in other languages as well.&lt;/li&gt;
&lt;li&gt;I did create a vibe-coded variant of the same benchmarks for the Prometheus and OTel Java SDKs (since I don&apos;t speak Java) as well, and the results were similar. At least for multi-threaded performance, the Prometheus SDK was up to &gt;30x faster.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I will also not go into OTel&apos;s more complex SDK initialization and setup code here, since that is a one-time cost that quickly amortizes itself in a larger codebase. However, I do want to take an exemplary look at the &lt;strong&gt;speed of counter increment operations&lt;/strong&gt; in both the OpenTelemetry and Prometheus Go SDKs, since this is a common operation that may happen up to millions of times a second in a busy multi-core server application. You don&apos;t want your instrumentation framework to make up a noticeable portion of your CPU usage in this case, so the Prometheus Go SDK has been highly optimized for this kind of operation. The same is true for metric value updates in general.&lt;/p&gt;
&lt;h4 id=&quot;comparing-counter-increment-performance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#comparing-counter-increment-performance&quot; aria-label=&quot;comparing counter increment performance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Comparing counter increment performance&lt;/h4&gt;
&lt;p&gt;You can find the &lt;a href=&quot;https://github.com/promlabs/prometheus-otel-benchmarks&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;quick-and-dirty benchmark code on GitHub&lt;/a&gt; and see some &lt;a href=&quot;https://gist.github.com/juliusv/1ec2e7580256b2809cde79afcf6de371&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;raw results in a gist&lt;/a&gt;, but in short, the code creates and then increments a counter metric in a busy loop under different conditions: with and without labels (attributes), with different levels of parallelism, and with different levels of labeled child metric reference caching. In every instance, the Prometheus Go SDK is much faster than the OpenTelemetry one (on an Intel i7-12700KF CPU with 20 cores on Arch Linux):&lt;/p&gt;
&lt;div style=&quot;display: flex&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/prom-otel-bench-no-labels.svg&quot; alt=&quot;Benchmarks for counter increments without labels&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/prom-otel-bench-uncached-labels.svg&quot; alt=&quot;Benchmarks for counter increments with uncached labels&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;In the worst case (no labels and a parallelism of 16), the Prometheus SDK was around &lt;strong&gt;26x faster&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the best case (uncached labels and a parallelism of 2), the Prometheus SDK was still around &lt;strong&gt;4.4x faster&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you look at the &lt;a href=&quot;https://gist.github.com/juliusv/1ec2e7580256b2809cde79afcf6de371&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;raw benchmark results&lt;/a&gt;, you will also see &lt;strong&gt;memory allocations&lt;/strong&gt; happening in the OTel SDK whenever attributes are set on a counter increment, while the Prometheus Go SDK allocates zero new memory for all cases.&lt;/p&gt;
&lt;h4 id=&quot;further-optimizations-with-cached-labels&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#further-optimizations-with-cached-labels&quot; aria-label=&quot;further optimizations with cached labels permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Further optimizations with cached labels&lt;/h4&gt;
&lt;p&gt;Prometheus&apos;s Go SDK also lets you keep a reference to a specific labeled child metric, in case you know that you&apos;ll need to increment the same label set many times in a row. In this case, the comparison is even more extreme (up to a &lt;strong&gt;53x difference&lt;/strong&gt;), since the OTel SDK does not allow for this kind of optimization:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/prom-otel-bench-cached-labels.svg&quot; alt=&quot;Benchmarks for counter increments with cached labels&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;a-more-subjective-impression-of-the-sdk-code-complexity&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#a-more-subjective-impression-of-the-sdk-code-complexity&quot; aria-label=&quot;a more subjective impression of the sdk code complexity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A more subjective impression of the SDK code complexity&lt;/h4&gt;
&lt;p&gt;As another more subjective point of comparison, trying to find the line of code in the SDKs where the actual value increment happens took me about &lt;a href=&quot;https://github.com/prometheus/client_golang/blob/8dfb3558355027a1806ce87370bdad604ca2cef6/prometheus/counter.go#L152&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;5 seconds for the Prometheus Go SDK&lt;/a&gt; (starting at the &lt;a href=&quot;https://github.com/promlabs/prometheus-otel-benchmarks/blob/8200ab3c029e03f655bf050ce6812fcf7812d7ea/prometheus_test.go#L27&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;Inc()&lt;/code&gt; call&lt;/a&gt; in the application code in VS Code), while I gave up trying to find the corresponding line in the OpenTelemetry Go SDK after around 15 minutes of looking for it through various indirections and abstractions. I might have been able to find it eventually, for example by profiling the running code or by looking at things again with a fresher mind. This also goes to show the different levels of complexity going on in the two SDKs.&lt;/p&gt;
&lt;h3 id=&quot;reason-6-if-you-want-open-standards-prometheus-is-open-and-established-as-well&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reason-6-if-you-want-open-standards-prometheus-is-open-and-established-as-well&quot; aria-label=&quot;reason 6 if you want open standards prometheus is open and established as well permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;strong&gt;Reason 6&lt;/strong&gt;: If you want open standards, Prometheus is open and established as well&lt;/h3&gt;
&lt;p&gt;Finally, many people are adopting OpenTelemetry because they want to adopt an open standard for their monitoring and observability needs. However, Prometheus is also open source and has an &lt;a href=&quot;https://prometheus.io/governance/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;open governance model&lt;/a&gt;. It is a mature, battle-tested, and a widely used system that is also backed by a large community of contributors and users. Many cloud vendors have adopted PromQL, Prometheus&apos;s Remote Write format, and other Prometheus interfaces as de facto standards for ingesting and querying metrics. And Prometheus&apos;s &lt;a href=&quot;https://prometheus.io/docs/instrumenting/exposition_formats/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;text-based format&lt;/a&gt; for exposing metrics from a target is so simple that it puts a really low floor on the kinds of situations where you can use it. If you really need to, you can even implement basic forms of the format in a few lines of shell script without having to depend on a library. For example, the following script would serve a simple Prometheus &lt;code&gt;/metrics&lt;/code&gt; endpoint containing a single metric:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token shebang important&quot;&gt;#!/bin/bash&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-p&lt;/span&gt; /tmp/metrics
&lt;span class=&quot;token builtin class-name&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;my_metric{label=&quot;value&quot;} 42&apos;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; /tmp/metrics/metrics
npx serve &lt;span class=&quot;token parameter variable&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8080&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-d&lt;/span&gt; /tmp/metrics&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You could now point a Prometheus server at &lt;code&gt;http://localhost:8080/metrics&lt;/code&gt; to pull metrics from this endpoint. Contrast this with OTLP being a &lt;a href=&quot;https://github.com/open-telemetry/opentelemetry-proto/blob/2dd1a231f91a9d5547816b12d166ac2aa5a8fc0c/opentelemetry/proto/metrics/v1/metrics.proto&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;deeply nested protocol-buffer-based transfer format&lt;/a&gt;, which really makes it much harder to implement without a proper SDK.&lt;/p&gt;
&lt;p&gt;Finally, you still always have the option of bridging Prometheus metrics endpoints into OpenTelemetry / OTLP later on if you really need to. For example, you can use the &lt;a href=&quot;https://pkg.go.dev/go.opentelemetry.io/contrib/bridges/prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus Bridge&lt;/a&gt; to expose native Prometheus metrics via OTLP in Go.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;If you are using Prometheus as your monitoring system, I still strongly recommend using Prometheus&apos;s own native instrumentation client libraries and Prometheus&apos;s pull-based monitoring model for monitoring your services. You end up with more reliable, complete, and efficient monitoring, and you avoid the complexities of metric name translation, escaping issues, and the need to join additional labels into queries. Of course you may still have other reasons to use OpenTelemetry, but now you know the downsides as well.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[A Look at the New Prometheus 3.0 UI]]></title><description><![CDATA[The Prometheus Team has just announced Prometheus version 3.0 at PromCon, with an official blog post detailing all the exciting new changes…]]></description><link>https://promlabs.com/blog/2024/09/11/a-look-at-the-new-prometheus-3-0-ui</link><guid isPermaLink="false">https://promlabs.com/blog/2024/09/11/a-look-at-the-new-prometheus-3-0-ui</guid><pubDate>Wed, 11 Sep 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;The Prometheus Team has just announced Prometheus version 3.0 at PromCon, with an &lt;a href=&quot;https://prometheus.io/blog/2024/09/11/prometheus-3-beta/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;official blog post&lt;/a&gt; detailing all the exciting new changes and features. A very visible highlight of Prometheus 3.0 is its new web UI that is enabled by default.&lt;/p&gt;
&lt;p&gt;I&apos;ve worked on this complete UI rewrite over the last half year or so and am excited to finally see it in the hands of users. In this post, I&apos;ll take a closer look at my motivation for building the new UI and then explain what it brings in terms of features and stability caveats.&lt;/p&gt;
&lt;h2 id=&quot;why-a-new-ui&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-a-new-ui&quot; aria-label=&quot;why a new ui permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why a new UI?&lt;/h2&gt;
&lt;p&gt;I initially started building Prometheus&apos; previous UI in 2019 as my first React app ever. It uses an outdated version of the &lt;a href=&quot;https://getbootstrap.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Bootstrap CSS framework&lt;/a&gt; for styling and has accumulated a lot of uncoordinated cruft, visual clutter, and overpowering colors over the years.&lt;/p&gt;
&lt;p&gt;As a drastic example, take a look at the filters at the top of the old &lt;code&gt;/targets&lt;/code&gt; page:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-old-targets-page.png&quot; alt=&quot;Old UI targets page&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Or at the wild collection of checkboxes at the top of the &lt;code&gt;/graph&lt;/code&gt; page – it&apos;s not pretty:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-old-query-page.png&quot; alt=&quot;Old UI graph page&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Tech-wise, the old UI had also become quite dated under the hood, making maintenance and the addition of significant new features more challenging.&lt;/p&gt;
&lt;p&gt;When the Prometheus Team decided to work towards a Prometheus 3.0 release, I knew I couldn&apos;t let that happen with the existing UI. We needed something more shiny for the occasion!&lt;/p&gt;
&lt;p&gt;So the new UI is a complete rewrite (with some code adapted from the old UI), with the main goals being:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reducing the visual clutter&lt;/strong&gt; that has accumulated over the years by rethinking and cleaning up the layout of each page.&lt;/li&gt;
&lt;li&gt;Creating a &lt;strong&gt;more modern look and feel&lt;/strong&gt; using the React-based &lt;a href=&quot;https://mantine.dev/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Mantine UI component framework&lt;/a&gt; instead of the dated Bootstrap-based styles.&lt;/li&gt;
&lt;li&gt;Adding a few major features, like a &lt;strong&gt;&lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;-style tree view, query explanation tab, and metrics and labels explorer&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enabling &lt;strong&gt;better future development and maintenance&lt;/strong&gt; by using a more modern tech stack and patterns under the hood.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While the new UI adds a few new features, the idea here was not to build anything drastically different, like a full dashboard builder. Prometheus still leaves that area to tools such as &lt;a href=&quot;https://grafana.com/oss/grafana/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana&lt;/a&gt; or &lt;a href=&quot;https://perses.dev/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Perses&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;general-remarks-on-the-new-ui-style&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#general-remarks-on-the-new-ui-style&quot; aria-label=&quot;general remarks on the new ui style permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;General remarks on the new UI style&lt;/h2&gt;
&lt;p&gt;Before jumping into details, let&apos;s have a look at the overall look and feel of the new UI.&lt;/p&gt;
&lt;h3 id=&quot;face-lifted-menu-structure&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#face-lifted-menu-structure&quot; aria-label=&quot;face lifted menu structure permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Face-lifted menu structure&lt;/h3&gt;
&lt;p&gt;Here&apos;s a look at the new menu structure:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-menu.png&quot; alt=&quot;New UI menu layout&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As you can see, most pages still exist as before, with slight renamings and added icons. Most importantly, the &lt;strong&gt;&quot;Graph&quot;&lt;/strong&gt; page has been renamed to &lt;strong&gt;&quot;Query&quot;&lt;/strong&gt;, since that just makes much more sense (not every query is graphed). You&apos;ll also see that the status menu is segmented and its title will show you which page you&apos;re currently on, like in the case of the targets page here:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-menu-title.png&quot; alt=&quot;New UI status page with title in menu&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&quot;less-clutter-and-more-consistency-across-pages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#less-clutter-and-more-consistency-across-pages&quot; aria-label=&quot;less clutter and more consistency across pages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Less clutter and more consistency across pages&lt;/h3&gt;
&lt;p&gt;You&apos;ll also see less overall clutter and more visual consistency when it comes to panels and filters across pages. Styles and layouts still differ slightly between pages, since they do serve different needs and present different types of data. But I&apos;ve tried my best to make the differences less jarring. Some rarely needed settings and toggles have been removed from their respective pages, but can still be found in a global settings menu:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-global-settings.png&quot; alt=&quot;New UI global settings menu&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;promql-highlighting-outside-of-the-query-page&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql-highlighting-outside-of-the-query-page&quot; aria-label=&quot;promql highlighting outside of the query page permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL highlighting outside of the query page&lt;/h2&gt;
&lt;p&gt;If you look at the alerts or rules pages in the new UI, you will now see the rule PromQL expressions rendered in a syntax-highlighted way, and without trying to render the entire rule as YAML (which was never fully correct in the old UI anyway). Here is an example from the new alerts page:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-alertspage.png&quot; alt=&quot;New UI alerts page&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;light-and-dark-modes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#light-and-dark-modes&quot; aria-label=&quot;light and dark modes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Light and dark modes&lt;/h2&gt;
&lt;p&gt;Just as in the old UI, the new UI has light and dark modes that you can switch between with the toggle in the top menu. Hopefully, the new dark mode also looks more appealing now:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-treeview-darkmode.png&quot; alt=&quot;New UI dark mode example&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;prominent-new-features&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#prominent-new-features&quot; aria-label=&quot;prominent new features permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Prominent new features&lt;/h2&gt;
&lt;p&gt;Let&apos;s have a look at a few of the most exciting new features of the new UI!&lt;/p&gt;
&lt;h3 id=&quot;metrics-and-labels-explorer&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#metrics-and-labels-explorer&quot; aria-label=&quot;metrics and labels explorer permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Metrics and labels explorer&lt;/h3&gt;
&lt;p&gt;Prometheus 3.0 comes with a new metrics explorer that allows you to search all available metrics, along with the known metadata for each metric:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-metric-explorer.png&quot; alt=&quot;New UI metrics explorer&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This explorer also allows you to drill down into the label names and values of a specific metric name:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-labels-explorer.png&quot; alt=&quot;New UI labels explorer&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This helps you get a quick idea of the available labels on a metric, their individual cardinality, and the number of series they produce. The labels explorer also allows you to progressively add label matching filters to narrow down the result. Finally, you can then insert the constructed selector into your text input.&lt;/p&gt;
&lt;h3 id=&quot;promlens-style-query-tree-view&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promlens-style-query-tree-view&quot; aria-label=&quot;promlens style query tree view permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromLens-style query tree view&lt;/h3&gt;
&lt;p&gt;Adopted from &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;, the new UI now allows you to show any PromQL query as a tree of sub-expressions:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-treeview.png&quot; alt=&quot;New UI PromQL tree view&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The tree view shows you how many series each node evaluates to and what label data is present in each sub-expression. By hovering over a label name, you can see some of the example label values for it:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-treeview-labels.png&quot; alt=&quot;New UI label values in tree view&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You can also click on any tree node to see its full data as a table or graph.&lt;/p&gt;
&lt;h3 id=&quot;explain-tab-to-explain-and-visualize-query-behavior&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#explain-tab-to-explain-and-visualize-query-behavior&quot; aria-label=&quot;explain tab to explain and visualize query behavior permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&quot;Explain&quot; tab to explain and visualize query behavior&lt;/h3&gt;
&lt;p&gt;In conjunction with the tree view, a new &lt;strong&gt;&quot;Explain&quot;&lt;/strong&gt; tab will now give you useful explanations and behavioral insights for any selected tree node. For example, clicking on a function call will show you the documentation for that function:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-explain-functiondocs.png&quot; alt=&quot;New UI showing function documentation&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;But the &lt;strong&gt;&quot;Explain&quot;&lt;/strong&gt; tab is especially useful for understanding and debugging vector matching behavior in a binary operator between two vectors. For example, here you can see a successful many-to-one vector matching being illustrated between two input vectors:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-explain-binopmatching.png&quot; alt=&quot;New UI explaining successful binop matching&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;And here you see an erroneous vector matching attempt, along with explanations and visualizations of what is going wrong:&lt;/p&gt;
&lt;div class=&quot;new-ui-screenshot&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/new-ui-blogpost-explain-binopmatching-error.png&quot; alt=&quot;New UI explaining erroneous binop matching&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;I hope that these new features reduce the pain and bring more joy into people&apos;s PromQL building experiences.&lt;/p&gt;
&lt;h2 id=&quot;feature-completeness-stability-and-switching-back&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#feature-completeness-stability-and-switching-back&quot; aria-label=&quot;feature completeness stability and switching back permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Feature-completeness, stability, and switching back&lt;/h2&gt;
&lt;p&gt;While the new UI brings many new benefits, there are still a few minor &lt;strong&gt;missing features&lt;/strong&gt; in the new UI that we plan to add over time. The two most prominent ones are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Displaying histograms as &lt;strong&gt;heatmaps&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Displaying &lt;strong&gt;exemplars&lt;/strong&gt; in the graph view.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both of these features are unfortunately more tricky to implement using the new &lt;a href=&quot;https://github.com/leeoniya/uPlot&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;uPlot charting library&lt;/a&gt;, which replaces the outdated and largely unmaintained &lt;a href=&quot;https://www.flotcharts.org/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Flot charting library&lt;/a&gt; of the old UI.&lt;/p&gt;
&lt;p&gt;In case you rely on these specific features or you run into any other issues with the new UI, you can still switch back to the old UI for the time being by using the &lt;code&gt;old-ui&lt;/code&gt; feature flag:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;./prometheus --enable-feature=old-ui [...]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Since the new UI is not battle-tested yet, it is also very possible that you will still run into bugs or performance issues. If you do, please &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/new?assignees=&amp;#x26;labels=&amp;#x26;projects=&amp;#x26;template=bug_report.yml&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;report them on GitHub&lt;/a&gt; so I can take a look.&lt;/p&gt;
&lt;h2 id=&quot;try-it&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#try-it&quot; aria-label=&quot;try it permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Try it!&lt;/h2&gt;
&lt;p&gt;To try out the new UI, you can of course install the &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v3.0.0-beta.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 3.0 beta release&lt;/a&gt; right now, but if you just want to play around with the new UI without having to set anything up, take a look at this &lt;a href=&quot;https://demo-new.promlabs.com/query?g0.expr=%23+The+ratios+of+individual+request+rates+as+compared+to+their+instance%27s+total+traffic.%0Arate%28demo_api_request_duration_seconds_count%7Bjob%3D%22demo%22%7D%5B5m%5D%29+%2F+on%28instance%29+group_left+sum+by%28instance%29+%28rate%28demo_api_request_duration_seconds_count%7Bjob%3D%22demo%22%7D%5B5m%5D%29%29&amp;#x26;g0.show_tree=1&amp;#x26;g0.tab=explain&amp;#x26;g0.range_input=1h&amp;#x26;g0.res_type=auto&amp;#x26;g0.res_density=medium&amp;#x26;g0.display_mode=lines&amp;#x26;g0.show_exemplars=0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;temporary demo Prometheus 3.0 server&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;As explained above, the new UI in Prometheus 3.0 doesn&apos;t only give users a more modern and clean experience, but also adds valuable new features around PromQL query building and understanding. I hope that you enjoy the new interface, and I am looking forward to improving it over time!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Number and Duration Literals Are Now Interchangeable in PromQL]]></title><description><![CDATA[Prometheus' 2.54.0 release added experimental support for using duration literals interchangeably with number literals in PromQL. Here's…]]></description><link>https://promlabs.com/blog/2024/08/19/number-and-duration-literals-are-now-interchangeable-in-promql</link><guid isPermaLink="false">https://promlabs.com/blog/2024/08/19/number-and-duration-literals-are-now-interchangeable-in-promql</guid><pubDate>Mon, 19 Aug 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Prometheus&apos; &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.54.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;2.54.0 release&lt;/a&gt; added experimental support for using duration literals interchangeably with number literals in PromQL. Here&apos;s what this means and why it&apos;s useful.&lt;/p&gt;
&lt;h2 id=&quot;number-and-duration-literals&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#number-and-duration-literals&quot; aria-label=&quot;number and duration literals permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Number and duration literals&lt;/h2&gt;
&lt;p&gt;Number literals in PromQL are simply spelled-out numeric floating point values such as &lt;code&gt;5&lt;/code&gt;, &lt;code&gt;1.23&lt;/code&gt;, &lt;code&gt;0xef&lt;/code&gt;, or &lt;code&gt;Inf&lt;/code&gt;. Number literals are their own PromQL syntax tree node and thus represent a full PromQL (sub)expression. In practice, you usually see them being used in the context of binary operators or as function parameters. Let&apos;s look at a few examples.&lt;/p&gt;
&lt;h3 id=&quot;number-literal-examples&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#number-literal-examples&quot; aria-label=&quot;number literal examples permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Number literal examples&lt;/h3&gt;
&lt;p&gt;You could use a number literal as the first parameter to the &lt;code&gt;topk()&lt;/code&gt; aggregator to show the top 3 request rates:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;topk&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You could also use number literals to convert a set of memory usages in bytes to mebibytes (MiB) and then only return the time series that represent usages greater than 20 MiB:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;memory_usage_bytes / &lt;span class=&quot;token number&quot;&gt;1024&lt;/span&gt;^&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;duration-literal-examples&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#duration-literal-examples&quot; aria-label=&quot;duration literal examples permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Duration literal examples&lt;/h3&gt;
&lt;p&gt;Duration literals are specifiers such as &lt;code&gt;5m&lt;/code&gt; (5 minutes) or &lt;code&gt;1h5m30s&lt;/code&gt; (1 hour, 5 minutes, and 30 seconds) that you allow you to select the desired duration for an operation. Up until now, duration literals couldn&apos;t be used as a standalone PromQL expression and were only allowed in special places of the PromQL syntax.&lt;/p&gt;
&lt;p&gt;For example, as the data selection duration of a range vector selector:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or as the time-shifting duration parameter of an &lt;code&gt;offset&lt;/code&gt; modifier:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;memory_usage_bytes &lt;span class=&quot;token operator&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;token context-range&quot;&gt;&lt;span class=&quot;token range-duration number&quot;&gt;1w&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or as the range and resolution parameters of a subquery:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;max_over_time&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;1d&lt;/span&gt;:&lt;span class=&quot;token range-duration number&quot;&gt;15s&lt;/span&gt;&lt;/span&gt;] &lt;span class=&quot;token comment&quot;&gt;# Run the subquery over a 1-day range with a 15-second resolution.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;usability-problem-some-numbers-are-semantically-durations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#usability-problem-some-numbers-are-semantically-durations&quot; aria-label=&quot;usability problem some numbers are semantically durations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Usability problem: Some numbers are semantically durations&lt;/h2&gt;
&lt;p&gt;However, there are cases in PromQL where number literals are semantically durations (usually in seconds), but where the PromQL syntax didn&apos;t allow you to use a duration literal syntax. Let&apos;s look at two prominent examples:&lt;/p&gt;
&lt;p&gt;The second parameter of the &lt;code&gt;predict_linear()&lt;/code&gt; function is semantically a duration in seconds, telling the function how far into the future it should extrapolate a set of gauge values:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Predict the value in 24 hours, based on the behavior of the last 4 hours.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;predict_linear&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;disk_usage_bytes&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;4h&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You may also want to compare one duration with another. For example, you could query for all hosts that have been running for more than 30 days:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; - node_boot_time_seconds &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see, having to write out durations in seconds like this can become cumbersome and error-prone.&lt;/p&gt;
&lt;h2 id=&quot;the-solution-making-number-and-duration-literals-interchangeable&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-solution-making-number-and-duration-literals-interchangeable&quot; aria-label=&quot;the solution making number and duration literals interchangeable permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The solution: Making number and duration literals interchangeable&lt;/h2&gt;
&lt;p&gt;Starting with Prometheus version 2.54.0, Darshan Chaudhary has &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/9138&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;added experimental support for using duration literals in place of numbers, and vice versa&lt;/a&gt;. The support is enabled by default, but may still change due to its experimental nature. As Prometheus generally advises keeping metrics in base units, and numeric durations also occur most commonly in seconds in PromQL, a given duration literal now translates into an equivalent number of seconds when used as a PromQL expression.&lt;/p&gt;
&lt;p&gt;So the following are now equivalent in PromQL:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1s&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;5m&lt;/code&gt; and &lt;code&gt;300&lt;/code&gt; or &lt;code&gt;5 * 60&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;10ms&lt;/code&gt; and &lt;code&gt;0.01&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This means you can now write the above duration expressions more naturally:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;predict_linear&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;disk_usage_bytes&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;4h&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 24h&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; - node_boot_time_seconds &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; 30d&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As a result, PromQL expressions involving numeric numbers will now be easier to write and understand.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In Prometheus 2.54.0, the UI will still show a linter error for duration literals used as numeric PromQL expressions and not highlight them properly yet:&lt;/p&gt;
&lt;div style=&quot;max-width: 700px; margin: auto;&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/duration-literal-expression-linter-error.png&quot; alt=&quot;Prometheus 2.54.0 linter error for duration literal expressions&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This has already been fixed in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/14417&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;a followup Pull Request&lt;/a&gt; by Augustin Husson and should be working fine in the next Prometheus release.&lt;/p&gt;
&lt;p&gt;Since the two syntactical elements are now interchangeable, you could even use a number as a duration now, like:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[300&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, this is generally not going to be as useful as the reverse case.&lt;/p&gt;
&lt;p&gt;Note also that binary operations such as &lt;code&gt;1d * 30&lt;/code&gt; are still only possible in places where the duration literal represents a full PromQL expression. So you still would not be able to query for something like &lt;code&gt;memory_usage_bytes[1d * 30]&lt;/code&gt;, since the contents of the square brackets are syntactically part of a range vector selector and not a full PromQL expression that can be multiplied with another number.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;As we&apos;ve seen, the new support in Prometheus 2.54.0 for treating number literals and duration literals interchangeably will make PromQL use cases involving numeric durations much more natural to read and write.&lt;/p&gt;
&lt;p&gt;If you want to understand more about Prometheus and PromQL, you may also want to take a look at our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Prometheus training courses&lt;/strong&gt;&lt;/a&gt;, especially our &lt;a href=&quot;https://training.promlabs.com/training/understanding-promql/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Understanding PromQL&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Smaller is Better: Why You Should Avoid Large, Multi-Target Exporters in Prometheus]]></title><description><![CDATA[When monitoring many different services or devices with Prometheus, you may be tempted to build a single large exporter that aggregates…]]></description><link>https://promlabs.com/blog/2024/08/17/smaller-is-better-why-you-should-avoid-large-multi-target-exporters-in-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2024/08/17/smaller-is-better-why-you-should-avoid-large-multi-target-exporters-in-prometheus</guid><pubDate>Sat, 17 Aug 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When monitoring many different services or devices with Prometheus, you may be tempted to build a single large exporter that aggregates metrics from all services on one machine, or even from an entire cluster or other large group of monitoring targets. That way, Prometheus only needs to scrape a single endpoint instead of many individual ones. However, this approach comes with a number of downsides and throws away important benefits of Prometheus&apos; pull-based monitoring model and service discovery integration. Let&apos;s have a look at these problems and why single-target exporters generally give you a better monitoring architecture.&lt;/p&gt;
&lt;h2 id=&quot;using-a-single-exporter-for-multiple-targets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#using-a-single-exporter-for-multiple-targets&quot; aria-label=&quot;using a single exporter for multiple targets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Using a single exporter for multiple targets&lt;/h2&gt;
&lt;p&gt;The advice in this article applies to any exporter that aggregates metrics from different services into a single Prometheus scrape. But as an example scenario, imagine that you have a mix of services running on a single machine, and you want to monitor them with Prometheus. One way of doing this would be to use a single exporter that collects metrics from all services and exposes them on a single Prometheus HTTP endpoint:&lt;/p&gt;
&lt;div style=&quot;max-width: 700px; margin: auto;&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-multi-service-exporter.svg&quot; alt=&quot;Single exporter for multiple targets&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This way, Prometheus only needs to scrape a single target, and you don&apos;t need to configure Prometheus to know about all the individual service processes running on the machine. That may sound convenient at first, but having a single big exporter that aggregates metrics for many different services has several downsides. Let&apos;s have a look at them.&lt;/p&gt;
&lt;h2 id=&quot;downsides-of-multi-target-exporters&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#downsides-of-multi-target-exporters&quot; aria-label=&quot;downsides of multi target exporters permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Downsides of multi-target exporters&lt;/h2&gt;
&lt;p&gt;The downsides of a single large exporter are:&lt;/p&gt;
&lt;h3 id=&quot;it-becomes-an-operational-and-scaling-bottleneck-and-a-single-point-of-failure&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#it-becomes-an-operational-and-scaling-bottleneck-and-a-single-point-of-failure&quot; aria-label=&quot;it becomes an operational and scaling bottleneck and a single point of failure permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;It becomes an operational and scaling bottleneck and a single point of failure&lt;/h3&gt;
&lt;p&gt;When a single exporter is responsible for aggregating and exposing metrics for all services on a machine (or cluster, or organization), it becomes an operational and scaling bottleneck and a single point of failure. If the exporter process crashes or becomes overloaded by a service creating too many metrics, you will now lose metrics for all of your services. You may also run into conflicts between teams or services that want to update the exporter, or you may need to coordinate configuration changes to the exporter across many services. That in turn can make it harder for teams to iterate independently on their monitoring setups.&lt;/p&gt;
&lt;p&gt;The Prometheus server can also scrape many small metrics endpoints much more efficiently than a single large one, as it can scrape them in parallel. A larger single scrape is also more likely to hit scrape timeouts or other limitations that can cause the entire scrape to fail.&lt;/p&gt;
&lt;h3 id=&quot;scraping-metrics-selectively-is-harder&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#scraping-metrics-selectively-is-harder&quot; aria-label=&quot;scraping metrics selectively is harder permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Scraping metrics selectively is harder&lt;/h3&gt;
&lt;p&gt;Having a single large exporter makes it harder to scrape metrics selectively. For example, you may only want to scrape metrics for a subset of services that your team is responsible for (like the MySQL server metrics in the image above), while another team might use a different Prometheus server to pull a different set of metrics for their services. With a single exporter, you would always have to scrape all metrics from the exporter&apos;s endpoint and then rely on inefficient and cumbersome &lt;a href=&quot;https://training.promlabs.com/training/relabeling/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;metrics relabeling rules&lt;/a&gt; during the scrape to filter out the metrics you don&apos;t care about.&lt;/p&gt;
&lt;h3 id=&quot;throwing-away-prometheus-target-health-monitoring-capabilities&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#throwing-away-prometheus-target-health-monitoring-capabilities&quot; aria-label=&quot;throwing away prometheus target health monitoring capabilities permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Throwing away Prometheus&apos; target health monitoring capabilities&lt;/h3&gt;
&lt;p&gt;When Prometheus scrapes a target, it records an &lt;code&gt;up&lt;/code&gt; metric with the labels of the target, setting the value to &lt;code&gt;1&lt;/code&gt; if the scrape succeeded or &lt;code&gt;0&lt;/code&gt; if it failed for any reason:&lt;/p&gt;
&lt;div style=&quot;max-width: 800px; margin: auto;&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-active-health-monitoring.svg&quot; alt=&quot;Prometheus&amp;#x27; target health monitoring&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This &lt;code&gt;up&lt;/code&gt; metric can tell you whether the target is reachable and at least healthy enough to expose working Prometheus metrics. That makes it a great way for creating basic target health alerts for everything you expect to exist in your infrastructure. However, if you squeeze all of your service metrics through a single large exporter scrape, you will only get a single &lt;code&gt;up&lt;/code&gt; metric for the whole exporter, and you will lose all information about the individual service processes, and whether any of them are either down or even completely absent. If you care about this information, you will now need to get it from a different source, which won&apos;t be as integrated with Prometheus&apos; service discovery and the resulting target labels.&lt;/p&gt;
&lt;p&gt;Fundamentally, a monitoring system should know what things (processes, services, devices) should exist and then be able to check whether they are healthy and reporting in. Using a single large exporter makes this task significantly more difficult to achieve.&lt;/p&gt;
&lt;h3 id=&quot;throwing-away-prometheus-service-discovery-and-target-label-metadata-capabilities&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#throwing-away-prometheus-service-discovery-and-target-label-metadata-capabilities&quot; aria-label=&quot;throwing away prometheus service discovery and target label metadata capabilities permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Throwing away Prometheus&apos; service discovery and target label metadata capabilities&lt;/h3&gt;
&lt;p&gt;When using a single large exporter, you give up Prometheus&apos; ability to attach rich metadata labels (originating from service discovery) to all metrics of an individual target. This metadata will now need to be contained in the metrics of the exporter itself and the processes that are pushing metrics to it, replicating functionality that Prometheus already provides in a more integrated way (for example, by providing a labeled &lt;code&gt;up&lt;/code&gt; metric as described above).&lt;/p&gt;
&lt;h2 id=&quot;the-prometheus-way-fine-grained-exporters-for-each-target&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-prometheus-way-fine-grained-exporters-for-each-target&quot; aria-label=&quot;the prometheus way fine grained exporters for each target permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Prometheus way: Fine-grained exporters for each target&lt;/h2&gt;
&lt;p&gt;Instead of using a single large exporter that aggregates metrics from many different services, you will usually want to run a separate exporter for each process or device that you are monitoring:&lt;/p&gt;
&lt;div style=&quot;max-width: 700px; margin: auto;&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-single-process-exporters.svg&quot; alt=&quot;Individual exporters for each target&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In this fine-grained monitoring setup, Prometheus can now scrape each monitored target individually, giving you all the benefits of Prometheus&apos; pull-based monitoring model:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No bottlenecks, operational independence&lt;/strong&gt;: Each service team can run and maintain their own exporters, and they can iterate independently of other teams. If one exporter crashes or malfunctions, only the metrics for that service are affected, not all of them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Selective scraping&lt;/strong&gt;: You can now easily collect just the metrics that your team cares about, by selecting which targets to discover and scrape.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integrated health monitoring&lt;/strong&gt;: Prometheus can now monitor the health of each target individually, giving you a per-process &lt;code&gt;up&lt;/code&gt; metric that tells you whether the service process is reachable and healthy enough to expose metrics. That in turn allows you to set up basic health alerts for all service processes that you expect to exist.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service discovery and target metadata&lt;/strong&gt;: Prometheus can use service discovery to find all exporters and attach metadata labels to the metrics originating from each of them that tell you where they came from.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;notable-exceptions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#notable-exceptions&quot; aria-label=&quot;notable exceptions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Notable exceptions&lt;/h2&gt;
&lt;p&gt;There are two prominent exporters in the Prometheus ecosystem that can expose metrics for multiple targets using a single exporter process:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/prometheus/blackbox_exporter&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Blackbox Exporter&lt;/strong&gt;&lt;/a&gt;, which allows you to synthetically probe targets from the outside.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/prometheus/snmp_exporter&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;SNMP Exporter&lt;/strong&gt;&lt;/a&gt;, which allows you to fetch SNMP metrics from network devices.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;However, these exporters are special: They do not group metrics from a set of targets into a single large scrape, but instead only produce metrics for a single backend target for each scrape. To achieve this, the Prometheus server sends a &lt;code&gt;target&lt;/code&gt; HTTP parameter along with each scrape request to tell the exporter which target to produce metrics for. The &lt;code&gt;target&lt;/code&gt; parameter will usually still be based on information from Prometheus&apos; service discovery, allowing you to make full use of fine-grained scraping, per-target health monitoring, and metadata labeling. So while these exporters can be run as a single process for many backend targets, they still appear as many individual targets and scrapes from Prometheus&apos; point of view, are stateless, and can be horizontally scaled at will. If you want to learn more about this model, take a look at our &lt;a href=&quot;https://training.promlabs.com/training/probing-services-blackbox-exporter/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Probing Services - Blackbox Exporter&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;While it may seem convenient to aggregate metrics from many services into a single exporter, doing so throws away many of the benefits that Prometheus&apos; pull-based monitoring model gives you. Instead, it&apos;s usually better to run a separate exporter for each process or device that you are monitoring. This way, you can avoid operational bottlenecks, scaling issues, and single points of failure, and you can take full advantage of Prometheus&apos; target health monitoring, service discovery, and target label metadata capabilities.&lt;/p&gt;
&lt;p&gt;If you want to understand more about Prometheus exporters and how to build them, take a look at our &lt;a href=&quot;https://training.promlabs.com/training/understanding-and-building-exporters/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Understanding and Building Exporters&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Using Metrics-Based Custom Thresholds in Prometheus Alerting Rules]]></title><description><![CDATA[Often you will want to have different alerting thresholds for different label combinations. For example, you may want to have individual…]]></description><link>https://promlabs.com/blog/2024/04/04/using-metrics-based-custom-thresholds-in-prometheus-alerting-rules</link><guid isPermaLink="false">https://promlabs.com/blog/2024/04/04/using-metrics-based-custom-thresholds-in-prometheus-alerting-rules</guid><pubDate>Thu, 04 Apr 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Often you will want to have different alerting thresholds for different label combinations. For example, you may want to have individual thresholds for the error rates of each HTTP path and method combination, rather than a single hardcoded threshold value for all of them. Luckily, Prometheus allows you to write generic alerting rules that you can parametrize based on a joined-in metric with compatible labels. Let&apos;s have a look at how this works!&lt;/p&gt;
&lt;h2 id=&quot;the-problem-single-fixed-thresholds&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-problem-single-fixed-thresholds&quot; aria-label=&quot;the problem single fixed thresholds permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The problem: Single, fixed thresholds&lt;/h2&gt;
&lt;p&gt;Imagine that you have an &lt;code&gt;http_requests_total&lt;/code&gt; metric that counts the total number of HTTP requests your service handles, broken out by &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;method&lt;/code&gt;, and &lt;code&gt;status&lt;/code&gt; labels:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;200&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;77443&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;65934&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;200&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;123&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;200&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;123&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;200&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;34&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,status&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;28923&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; In reality, your time series will likely also be split up by target labels such as &lt;code&gt;job&lt;/code&gt; and &lt;code&gt;instance&lt;/code&gt;, but for simplicity we&apos;ll pretend that those don&apos;t exist here.&lt;/p&gt;
&lt;p&gt;Now you want to set up an alert that fires when the rate of requests with a response status code of &lt;code&gt;500&lt;/code&gt; exceeds a certain threshold.&lt;/p&gt;
&lt;p&gt;In the simplest case, you could write an alerting rule with a fixed (hard-coded) threshold that determines when the alert should fire. For example, the following expression would produce alerts for any label combination where the &lt;code&gt;500&lt;/code&gt; error rate exceeds 5 requests per second:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This works great as long as &quot;5 per second&quot; is a reasonable threshold for each path and method combination. However, in reality you might want to set different thresholds for each label combination, depending on the individual importance and characteristics of each path and method in question.&lt;/p&gt;
&lt;p&gt;You could write a separate alerting rule for each combination, but that would be cumbersome and hard to maintain.&lt;/p&gt;
&lt;h2 id=&quot;the-solution-custom-thresholds-based-on-time-series&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-solution-custom-thresholds-based-on-time-series&quot; aria-label=&quot;the solution custom thresholds based on time series permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The solution: Custom thresholds based on time series&lt;/h2&gt;
&lt;p&gt;Instead, you can write a single alerting rule and parametrize it for each &lt;code&gt;path&lt;/code&gt; and &lt;code&gt;method&lt;/code&gt; combination. For that, you will first need to have another metric (in this example, &lt;code&gt;http_error_rate_threshold&lt;/code&gt;) that represents an individual custom threshold for each label combination:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;http_error_rate_threshold&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;  &lt;span class=&quot;token comment&quot;&gt;# 10 per second.&lt;/span&gt;
http_error_rate_threshold&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;token comment&quot;&gt;# 2 per second.&lt;/span&gt;
http_error_rate_threshold&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;   &lt;span class=&quot;token comment&quot;&gt;# 3 per second.&lt;/span&gt;
http_error_rate_threshold&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;path&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;,method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;token comment&quot;&gt;# 1 per second.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then you can write a single generic alerting rule that joins in this metric to determine when the alert should fire:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;path&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
  http_error_rate_threshold&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This expression compares the individual error rates to the matching custom threshold for each label combination. If a given rate exceeds its threshold, the alert will fire for that label set.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: The &lt;code&gt;on(path, method)&lt;/code&gt; modifier ensures that the matching only happens based on the &lt;code&gt;path&lt;/code&gt; and &lt;code&gt;method&lt;/code&gt; labels, and not on the additional &lt;code&gt;status&lt;/code&gt; label that is only present on the error rates and not on the threshold series. Depending on your data and alerting expression, you will have to choose the right set of labels to match on, and potentially also add a &lt;code&gt;group_left()&lt;/code&gt; modifier after the &lt;code&gt;on(...)&lt;/code&gt; in case multiple series from the first operand can match a single series from your threshold metric (many-to-one matching).&lt;/p&gt;
&lt;h2 id=&quot;adding-a-default-fallback-threshold-for-missing-label-combinations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#adding-a-default-fallback-threshold-for-missing-label-combinations&quot; aria-label=&quot;adding a default fallback threshold for missing label combinations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Adding a default fallback threshold for missing label combinations&lt;/h2&gt;
&lt;p&gt;In some scenarios you may actually want to fall back to a hardcoded default threshold if no custom value is defined for a specific label combination in the &lt;code&gt;http_error_rate_threshold&lt;/code&gt; metric. You can achieve this by using the &lt;code&gt;or&lt;/code&gt; operator to join in a default threshold value for missing label combinations:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;path&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      http_error_rate_threshold
    or &lt;span class=&quot;token operator&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;path&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# Join in default threshold.&lt;/span&gt;
      http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;500&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; + &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As the second argument to the &lt;code&gt;or&lt;/code&gt; operator, we choose a set of time series that will always contain all desired label combinations (in this case, &lt;code&gt;http_requests_total{status=&quot;500&quot;}&lt;/code&gt; is does the job), and then we force the value for each label combination to the default threshold of &lt;code&gt;5&lt;/code&gt; by multiplying each series with &lt;code&gt;0&lt;/code&gt; and adding &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;generating-the-custom-threshold-time-series&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#generating-the-custom-threshold-time-series&quot; aria-label=&quot;generating the custom threshold time series permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Generating the custom threshold time series&lt;/h2&gt;
&lt;p&gt;One question remains: How do you actually get the &lt;code&gt;http_error_rate_threshold&lt;/code&gt; metric with your custom threshold combinations? There is no magic involved here, and it depends on your needs. You generally have a few options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You could expose the custom thresholds from the same process that exposes the main metric you are alerting on.&lt;/li&gt;
&lt;li&gt;You could write a separate &lt;a href=&quot;https://training.promlabs.com/training/understanding-and-building-exporters&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;exporter&lt;/a&gt; that exposes the custom thresholds (potentially even by consulting a database and changing the thresholds over time).&lt;/li&gt;
&lt;li&gt;You could use a set of &lt;a href=&quot;https://training.promlabs.com/training/recording-rules&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;recording rules&lt;/a&gt; to record your custom thresholds for each desired label combination.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The choice depends on your specific use case and how you want to manage the thresholds.&lt;/p&gt;
&lt;p&gt;As an example, here is how you could generate the &lt;code&gt;http_error_rate_threshold&lt;/code&gt; metric using a set of recording rules:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; HTTP error rate thresholds
  &lt;span class=&quot;token key atrule&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; http_error_rate_threshold
    &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; http_error_rate_threshold
    &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/foo&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; http_error_rate_threshold
    &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/bar&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that the above rule set does not define a threshold for the &lt;code&gt;{path=&quot;/bar&quot;, method=&quot;POST&quot;}&lt;/code&gt; label combination. This will cause the alerting rule to fall back to the default threshold of &lt;code&gt;5&lt;/code&gt; for this combination.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;While hard-coded thresholds may be sufficient for many alerting rules, having the ability to parametrize a single generic alerting rule for many different label combinations can be very useful. You now know how to use a correlated metric to dynamically set individual thresholds for different label combinations, and how you can fall back to a default threshold if no custom threshold is defined for a given label combination.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Monitoring TLS Endpoint Certificate Expiration with Prometheus]]></title><description><![CDATA[If you have HTTPS endpoints in your infrastructure, you will want to make sure that none of their TLS certificates are about to expire…]]></description><link>https://promlabs.com/blog/2024/02/06/monitoring-tls-endpoint-certificate-expiration-with-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2024/02/06/monitoring-tls-endpoint-certificate-expiration-with-prometheus</guid><pubDate>Tue, 06 Feb 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you have HTTPS endpoints in your infrastructure, you will want to make sure that none of their TLS certificates are about to expire without you noticing. Let&apos;s have a look at how you can use Prometheus&apos; Blackbox Exporter to monitor for TLS certificates that are about to expire soon, so you can renew them in time.&lt;/p&gt;
&lt;h2 id=&quot;setting-up-the-blackbox-exporter&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#setting-up-the-blackbox-exporter&quot; aria-label=&quot;setting up the blackbox exporter permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Setting up the Blackbox Exporter&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/prometheus/blackbox_exporter&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Blackbox Exporter&lt;/a&gt; is a Prometheus exporter that allows you to actively probe service endpoints from the outside and then return Prometheus metrics about the executed probe request. If you want to learn more about how this exporter works together with Prometheus and what else it can do, you can find all the details in our our &lt;a href=&quot;https://training.promlabs.com/training/probing-services-blackbox-exporter&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Probing Services - Blackbox Exporter&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;
&lt;p&gt;Let&apos;s download and run the Blackbox Exporter:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Download the Blackbox Exporter.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz

&lt;span class=&quot;token comment&quot;&gt;# Unpack it.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;tar&lt;/span&gt; xvfz blackbox_exporter-0.24.0.linux-amd64.tar.gz

&lt;span class=&quot;token comment&quot;&gt;# Change into the unpacked directory.&lt;/span&gt;
&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; blackbox_exporter-0.24.0.linux-amd64

&lt;span class=&quot;token comment&quot;&gt;# Run the Blackbox Exporter on its default port of 9115.&lt;/span&gt;
./blackbox_exporter&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The included default &lt;code&gt;blackbox.yml&lt;/code&gt; configuration file already includes a &lt;code&gt;http_2xx&lt;/code&gt; prober module configuration that allows us to execute HTTP(S) requests through the Blackbox Exporter from Prometheus and get back various Prometheus metrics about the probe.&lt;/p&gt;
&lt;p&gt;Try heading to &lt;a href=&quot;http://localhost:9115/probe?module=http_2xx&amp;#x26;target=https://promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://localhost:9115/probe?module=http_2xx&amp;#x26;target=https://promlabs.com&lt;/a&gt; in your browser to trigger a manual HTTPS probe request against the URL &lt;a href=&quot;https://promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://promlabs.com&lt;/a&gt;. In the response, you will see the resulting Prometheus metrics about the probe request:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE probe_dns_lookup_time_seconds gauge&lt;/span&gt;
probe_dns_lookup_time_seconds &lt;span class=&quot;token number&quot;&gt;0.006111063&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# HELP probe_duration_seconds Returns how long the probe took to complete in seconds&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE probe_duration_seconds gauge&lt;/span&gt;
probe_duration_seconds &lt;span class=&quot;token number&quot;&gt;0.753497273&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# [...abridged...]&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# HELP probe_ssl_earliest_cert_expiry Returns last SSL chain expiry in unixtime&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE probe_ssl_earliest_cert_expiry gauge&lt;/span&gt;
probe_ssl_earliest_cert_expiry &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;.710767408e+09
&lt;span class=&quot;token comment&quot;&gt;# [...abridged...]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;We will later configure Prometheus to scrape this &lt;code&gt;/probe&lt;/code&gt; endpoint to trigger a probe and collect the same metrics.&lt;/p&gt;
&lt;p&gt;The returned metrics include a &lt;code&gt;probe_ssl_earliest_cert_expiry&lt;/code&gt; metric – the value of this metric is a Unix timestamp that tells us when the TLS certificate is about to expire (hopefully this timestamp is in the future, otherwise the certificate has already expired). We can later use this metric to alert us when the certificate is about to expire.&lt;/p&gt;
&lt;h2 id=&quot;setting-up-prometheus-to-probe-endpoints-through-the-blackbox-exporter&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#setting-up-prometheus-to-probe-endpoints-through-the-blackbox-exporter&quot; aria-label=&quot;setting up prometheus to probe endpoints through the blackbox exporter permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Setting up Prometheus to probe endpoints through the Blackbox Exporter&lt;/h2&gt;
&lt;p&gt;Let&apos;s download and unpack Prometheus:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Download Prometheus.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; https://github.com/prometheus/prometheus/releases/download/v2.49.1/prometheus-2.49.1.linux-amd64.tar.gz

&lt;span class=&quot;token comment&quot;&gt;# Unpack it.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;tar&lt;/span&gt; xvfz prometheus-2.49.1.linux-amd64.tar.gz

&lt;span class=&quot;token comment&quot;&gt;# Change into the unpacked directory.&lt;/span&gt;
&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; prometheus-2.49.1.linux-amd64&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now we need to create a Prometheus configuration file to scrape the Blackbox Exporter&apos;s &lt;code&gt;/probe&lt;/code&gt; endpoint with the correct parameters to select the target to probe and the type of probe to execute. In this example, we will check the certificates of the URLs &lt;a href=&quot;https://promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://promlabs.com&lt;/a&gt; and &lt;a href=&quot;https://prometheus.io&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://prometheus.io&lt;/a&gt;. To get alerted about certificates that are about to expire, we also create a rule file with an alerting rule that compares the TLS certificate expiration timestamp against the current time and alerts when a certificate will expire within 7 days.&lt;/p&gt;
&lt;p&gt;Overwrite the downloaded example &lt;code&gt;prometheus.yml&lt;/code&gt; file with the following contents (explanatory comments inline):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;scrape_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15s
  &lt;span class=&quot;token key atrule&quot;&gt;evaluation_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15s

&lt;span class=&quot;token key atrule&quot;&gt;rule_files&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;tls-cert-rules.yml&quot;&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;scrape_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; blackbox
    &lt;span class=&quot;token key atrule&quot;&gt;metrics_path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; /probe &lt;span class=&quot;token comment&quot;&gt;# Do not scrape /metrics, but /probe.&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;module&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;http_2xx&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# Send a &quot;module&quot; HTTP parameter to the exporter to select the right probe module.&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//promlabs.com
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//prometheus.io
    &lt;span class=&quot;token comment&quot;&gt;# A relabeling config that lets us scrape target through the Blackbox Exporter,&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# while labeling the resulting metrics with the probed target&apos;s URL.&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;relabel_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;# Set the &quot;target&quot; HTTP parameter to the target URL that we want to probe.&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;source_labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;__address__&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;target_label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; __param_target
      &lt;span class=&quot;token comment&quot;&gt;# Set the &quot;instance&quot; label to the target URL that we want to probe.&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;source_labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;__param_target&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;token key atrule&quot;&gt;target_label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; instance
      &lt;span class=&quot;token comment&quot;&gt;# Don&apos;t actually scrape the target itself, but the Blackbox Exporter.&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;target_label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; __address__
        &lt;span class=&quot;token key atrule&quot;&gt;replacement&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; localhost&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;9115&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: We use a set of relabeling rules above to scrape each target through the Blackbox Exporter, while labeling the resulting metrics with the probed target&apos;s URL instead of the Blackbox Exporter&apos;s own address. To learn more about relabeling in general, take a look at our free &lt;a href=&quot;https://training.promlabs.com/training/relabeling&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Relabeling&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;
&lt;p&gt;Create the &lt;code&gt;tls-cert-rules.yml&lt;/code&gt; file with the expiration alerting rule:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; tls&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;cert&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;rules
  &lt;span class=&quot;token key atrule&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; TLSCertificateExpiring
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; probe_ssl_earliest_cert_expiry &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; time() &amp;lt; 7&lt;span class=&quot;token important&quot;&gt;*24*3600&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5m
    &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;severity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; warning
    &lt;span class=&quot;token key atrule&quot;&gt;annotations&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;summary&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Certificate for {{ $labels.instance }} is about to expire&quot;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;The certificate for {{ $labels.instance }} is about to expire in less than 7 days.&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now we can start Prometheus with our new configuration:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;./prometheus&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Give Prometheus a few seconds to scrape the Blackbox Exporter and collect metrics. Then head to &lt;a href=&quot;http://localhost:9090/targets&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://localhost:9090/targets&lt;/a&gt; to check that the two endpoints are being probed correctly:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-scraping-blackbox-targets.png&quot; alt=&quot;Prometheus scraping Blackbox Exporter targets&quot;&gt;&lt;/p&gt;
&lt;p&gt;Head to &lt;a href=&quot;http://localhost:9090/alerts&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://localhost:9090/alerts&lt;/a&gt; to see the alerting rule we just created:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/tls-cert-expiration-alert.png&quot; alt=&quot;TLS certificate expiration alert&quot;&gt;&lt;/p&gt;
&lt;p&gt;You should see an alert called &lt;code&gt;TLSCertificateExpiring&lt;/code&gt; that is currently inactive. If you pointed Prometheus at one of your own endpoints for which a certificate is about to expire, the alert should become active.&lt;/p&gt;
&lt;p&gt;You can also manually query the &lt;code&gt;probe_ssl_earliest_cert_expiry&lt;/code&gt; metric to see the expiration timestamp of each certificate:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/query-tls-certificate-expiry.png&quot; alt=&quot;Querying TLS certificate expiry&quot;&gt;&lt;/p&gt;
&lt;p&gt;And to check how many days are left until the certificate expires, you can use the &lt;code&gt;time()&lt;/code&gt; function to get the current Unix time in seconds and subtract the &lt;code&gt;probe_ssl_earliest_cert_expiry&lt;/code&gt; metric from it:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;probe_ssl_earliest_cert_expiry - &lt;span class=&quot;token function&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; / &lt;span class=&quot;token number&quot;&gt;24&lt;/span&gt; / &lt;span class=&quot;token number&quot;&gt;3600&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/images/query-tls-certificate-expiry-duration.png&quot; alt=&quot;Querying TLS certificate expiry duration&quot;&gt;&lt;/p&gt;
&lt;p&gt;In the example above, the certificate for prometheus.io is about to expire in 50.5 days, while the certificate for promlabs.com is about to expire in 40.8 days.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Now we have set up a Prometheus instance that scrapes the Blackbox Exporter&apos;s &lt;code&gt;/probe&lt;/code&gt; endpoint to trigger a probe against our HTTPS endpoints and to collect the resulting metrics. We also have an alerting rule that will fire an alert when the certificate is about to expire, allowing us to renew it in time.&lt;/p&gt;
&lt;p&gt;If you want to learn more about how to set up alerting rules in Prometheus, take a look at our &lt;a href=&quot;https://training.promlabs.com/training/alerting-with-prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Alerting with Prometheus&lt;/strong&gt;&lt;/a&gt; training. You can also learn more about the Blackbox Exporter in our &lt;a href=&quot;https://training.promlabs.com/training/probing-services-blackbox-exporter&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Probing Services - Blackbox Exporter&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Errors, Successes, Totals: Which Metrics Should I Expose to Prometheus?]]></title><description><![CDATA[If your service is handling operations that can either succeed or fail, you may be wondering how to best expose them as Prometheus metrics…]]></description><link>https://promlabs.com/blog/2023/09/19/errors-successes-totals-which-metrics-should-i-expose-to-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2023/09/19/errors-successes-totals-which-metrics-should-i-expose-to-prometheus</guid><pubDate>Tue, 19 Sep 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If your service is handling operations that can either succeed or fail, you may be wondering how to best expose them as Prometheus metrics. Should you expose &lt;strong&gt;errors and successes&lt;/strong&gt; or &lt;strong&gt;errors and totals&lt;/strong&gt;? Should you have a &lt;strong&gt;single metric&lt;/strong&gt; split up by a label or &lt;strong&gt;multiple separate metrics&lt;/strong&gt;? Let&apos;s have a look at these options and when you would use which.&lt;/p&gt;
&lt;h2 id=&quot;first-consider-the-use-case&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#first-consider-the-use-case&quot; aria-label=&quot;first consider the use case permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;First: Consider the use case!&lt;/h2&gt;
&lt;p&gt;To help answer the introductory question, let&apos;s first consider how these metrics would be used. For service monitoring, you will usually want to know the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;total rate&lt;/strong&gt; of operations.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;error rate&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;error rate ratio&lt;/strong&gt; (compared to all operations).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note that querying &lt;strong&gt;success rates&lt;/strong&gt; individually is not actually a common use case!&lt;/p&gt;
&lt;p&gt;For each of these use cases, how (in)convenient would your PromQL queries become for the different metric designs?&lt;/p&gt;
&lt;h2 id=&quot;not-recommended-exposing-errors-and-successes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#not-recommended-exposing-errors-and-successes&quot; aria-label=&quot;not recommended exposing errors and successes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Not recommended: Exposing errors and successes&lt;/h2&gt;
&lt;p&gt;Let&apos;s see what happens when we expose errors and successes. Consider two counters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;errors_total&lt;/code&gt;: The total number of errors.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;successes_total&lt;/code&gt;: The total number of successes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Looking at the desired use cases above, the PromQL queries would become cumbersome. For example, to get the total rate of operations, you would have to manually add the errors to the successes:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
+
  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;successes_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And to get the error rate ratio, you would have to write:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
/
  &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; + &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;successes_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Only querying the error rate is straightforward:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;recommended-for-binary-outcomes-exposing-errors-and-totals&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#recommended-for-binary-outcomes-exposing-errors-and-totals&quot; aria-label=&quot;recommended for binary outcomes exposing errors and totals permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Recommended for binary outcomes: Exposing errors and totals&lt;/h2&gt;
&lt;p&gt;The PromQL queries become much simpler if we expose errors and totals instead:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;errors_total&lt;/code&gt;: The total number of errors.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;operations_total&lt;/code&gt;: The total number of operations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now, the total rate of operations is simply:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The error rate is:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And the error rate ratio is:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
/
  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Thus if you only have binary outcomes (successes and errors without further differentation), &lt;strong&gt;exposing errors and totals is usually the best choice&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;exposing-a-single-metric-with-a-label&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#exposing-a-single-metric-with-a-label&quot; aria-label=&quot;exposing a single metric with a label permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exposing a single metric with a label&lt;/h2&gt;
&lt;p&gt;But what about exposing a single metric with an &lt;code&gt;outcome&lt;/code&gt; (or similar) label? This depends on whether you only have clear binary results (&quot;success&quot; and &quot;error&quot;) or a wide variety of possible outcomes, like HTTP response status codes.&lt;/p&gt;
&lt;h3 id=&quot;not-recommended-a-single-metric-for-binary-outcomes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#not-recommended-a-single-metric-for-binary-outcomes&quot; aria-label=&quot;not recommended a single metric for binary outcomes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Not recommended: A single metric for binary outcomes&lt;/h3&gt;
&lt;p&gt;For binary outcomes, a single metric with a label might look like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;operations_total{outcome=&quot;error&quot;}&lt;/code&gt;: The total number of errors.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;operations_total{outcome=&quot;success&quot;}&lt;/code&gt;: The total number of successes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Calculating the total rate of operations now requires aggregating over the &lt;code&gt;outcome&lt;/code&gt; label:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;outcome&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Calculating the error rate remains straightforward:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;outcome&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;error&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;But calculating the error rate ratio becomes a bit more involved. You have to aggregate over the &lt;code&gt;outcome&lt;/code&gt; label on both sides of the operation to make the label matching work (alternatively, you could use an &lt;code&gt;ignoring(outcome)&lt;/code&gt; modifier on the binary operator):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;outcome&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;outcome&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;error&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
/
  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;outcome&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is clearly more cumbersome than the same query with two separate metric names. Metrics with labels also introduce the danger of missing time series, which we discussed in our &lt;a href=&quot;/blog/2023/09/13/dealing-with-missing-time-series-in-prometheus&quot;&gt;previous blog post&lt;/a&gt;. In this example, the query above would return an empty result instead of a set of &lt;code&gt;0&lt;/code&gt;-valued series in case no errors have happened yet.&lt;/p&gt;
&lt;h3 id=&quot;recommended-a-single-metric-for-non-binary-outcomes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#recommended-a-single-metric-for-non-binary-outcomes&quot; aria-label=&quot;recommended a single metric for non binary outcomes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Recommended: A single metric for non-binary outcomes&lt;/h3&gt;
&lt;p&gt;However, a single metric becomes the best choice when you don&apos;t just have a binary success vs. error outcome. For example, HTTP requests can have a wide range of response status codes, and you wouldn&apos;t want to have a separate metric for each of them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http_requests_200_total&lt;/code&gt;: The total number of HTTP requests with a &lt;code&gt;200&lt;/code&gt; response status code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http_requests_404_total&lt;/code&gt;: The total number of HTTP requests with a &lt;code&gt;404&lt;/code&gt; response status code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http_requests_503_total&lt;/code&gt;: The total number of HTTP requests with a &lt;code&gt;503&lt;/code&gt; response status code.&lt;/li&gt;
&lt;li&gt;...and so on.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Not only would this create a lot of different metric names that you would have to know about and query individually, but it would also make it really hard to query for the total rate:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_200_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
+
  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_404_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
+
  &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_503_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
+
  &lt;span class=&quot;token comment&quot;&gt;# ...all the other possible status codes&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is clearly not a good idea. Instead, you would want to expose a single metric with a &lt;code&gt;status&lt;/code&gt; label:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http_requests_total{status=&quot;200&quot;}&lt;/code&gt;: The total number of HTTP requests with a &lt;code&gt;200&lt;/code&gt; response status code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http_requests_total{status=&quot;404&quot;}&lt;/code&gt;: The total number of HTTP requests with a &lt;code&gt;404&lt;/code&gt; response status code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http_requests_total{status=&quot;503&quot;}&lt;/code&gt;: The total number of HTTP requests with a &lt;code&gt;503&lt;/code&gt; response status code.&lt;/li&gt;
&lt;li&gt;...and so on.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then you can query for the total rate of HTTP requests like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And the &lt;code&gt;5xx&lt;/code&gt; error rate like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=~&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;5..&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And the total &lt;code&gt;5xx&lt;/code&gt; error rate ratio like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=~&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;5..&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
/
  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;So when you have a wide variety of possible outcomes, &lt;strong&gt;exposing a single metric with a label is usually the best choice&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In most cases, you should expose errors and totals as separate metrics. This makes it easy to query for the total rate of operations, the error rate, and the error rate ratio. But if you have more possible outcomes than just &quot;success&quot; and &quot;error&quot; (like for HTTP requests), you probably want to expose a single metric with a label instead.&lt;/p&gt;
&lt;p&gt;If you found this article useful, you may also like our &lt;a href=&quot;https://training.promlabs.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus training courses&lt;/a&gt;, in which we explore Prometheus fundamentals and best practices in depth and from the ground up.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Dealing with Missing Time Series in Prometheus]]></title><description><![CDATA[Due to Prometheus' dimensional data model and the way it tracks and collects metrics, some of the metrics referenced in your PromQL…]]></description><link>https://promlabs.com/blog/2023/09/13/dealing-with-missing-time-series-in-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2023/09/13/dealing-with-missing-time-series-in-prometheus</guid><pubDate>Wed, 13 Sep 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Due to Prometheus&apos; dimensional data model and the way it tracks and collects metrics, some of the metrics referenced in your PromQL expressions may sometimes be missing. Let&apos;s have a look what causes missing series, how they can cause trouble for your dashboards and alerting rules, and what you can do about it.&lt;/p&gt;
&lt;h2 id=&quot;why-are-time-series-sometimes-missing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-are-time-series-sometimes-missing&quot; aria-label=&quot;why are time series sometimes missing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why are time series sometimes missing?&lt;/h2&gt;
&lt;p&gt;There are two major causes for missing time series:&lt;/p&gt;
&lt;h3 id=&quot;when-nothing-has-happened-yet-for-a-given-label-value&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-nothing-has-happened-yet-for-a-given-label-value&quot; aria-label=&quot;when nothing has happened yet for a given label value permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When nothing has happened yet for a given label value&lt;/h3&gt;
&lt;p&gt;Consider a labeled counter metric that tracks a number of operations, partitioned by the type of operation:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;operations_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;optype&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&amp;lt;type&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Since the instrumentation client library cannot guess the possible values for the &lt;code&gt;optype&lt;/code&gt; label without you telling it, the series for each operation type will only start existing once the first operation of that particular type has occurred. And when the service starts up, it will initially not be able to report &lt;em&gt;any series at all&lt;/em&gt; for the  &lt;code&gt;operations_total&lt;/code&gt; metric until at least &lt;em&gt;some&lt;/em&gt; operation happens.&lt;/p&gt;
&lt;p&gt;This applies to any metric with custom instrumentation labels. Metrics without labels do not have this issue, since the client library can initialize them to &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;NaN&lt;/code&gt; (depending on the metric type) and expose them immediately after startup.&lt;/p&gt;
&lt;h3 id=&quot;when-a-target-is-down-or-absent&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-a-target-is-down-or-absent&quot; aria-label=&quot;when a target is down or absent permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When a target is down or absent&lt;/h3&gt;
&lt;p&gt;Metrics can also be missing because a target is down, or because Prometheus is not even trying to scrape the target at all for some reason (for example, when the service discovery integration is broken). We will look at this in a separate blog post and only focus on the case of missing label dimensions here.&lt;/p&gt;
&lt;h2 id=&quot;problems-caused-by-missing-time-series&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#problems-caused-by-missing-time-series&quot; aria-label=&quot;problems caused by missing time series permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Problems caused by missing time series&lt;/h2&gt;
&lt;p&gt;Imagine a PromQL query for the total operations rate:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;optype&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If &lt;em&gt;no operation has happened at all&lt;/em&gt; yet, the expression will return an &lt;em&gt;empty result&lt;/em&gt; instead of a rate with the value of &lt;code&gt;0&lt;/code&gt;, as you may have expected.&lt;/p&gt;
&lt;p&gt;Or if &lt;em&gt;some&lt;/em&gt; operations have happened already, but you are trying to query for a specific operation type that has not happened yet (&lt;code&gt;create&lt;/code&gt; in this example), you can also run into trouble:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;operations_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;,&lt;span class=&quot;token label-key /attr-name/&quot;&gt;optype&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;create&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This will also give you an empty result where you may have expected a &lt;code&gt;0&lt;/code&gt;-valued rate output for the &lt;code&gt;create&lt;/code&gt; operation type.&lt;/p&gt;
&lt;p&gt;In a Grafana dashboard, this means that you will see a &lt;em&gt;&quot;No data&quot;&lt;/em&gt; warning message instead of a rate with a value of &lt;code&gt;0&lt;/code&gt;. But if you tried to use this expression in an alerting rule, the alert may even &lt;em&gt;silently fail to fire&lt;/em&gt;, since Prometheus interprets an empty alerting rule expression output as &quot;everything is fine&quot;! This is less of a problem when you alert on too-high rates of something (since the label value in question will definitely exist if there is a high rate for it), but it can bite you if you are trying to catch too-low rates.&lt;/p&gt;
&lt;h2 id=&quot;dealing-with-missing-time-series&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dealing-with-missing-time-series&quot; aria-label=&quot;dealing with missing time series permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Dealing with missing time series&lt;/h2&gt;
&lt;p&gt;Depending on the situation, there are a few ways to deal with missing time series:&lt;/p&gt;
&lt;h3 id=&quot;when-feasible-pre-initialize-series&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-feasible-pre-initialize-series&quot; aria-label=&quot;when feasible pre initialize series permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When feasible: pre-initialize series!&lt;/h3&gt;
&lt;p&gt;If you only have a small number of possible values for a label that you know beforehand, the best course of action is to pre-initialize each value to &lt;code&gt;0&lt;/code&gt; right after program startup. For example, if we only had the &lt;code&gt;create&lt;/code&gt;, &lt;code&gt;read&lt;/code&gt;, &lt;code&gt;update&lt;/code&gt;, and &lt;code&gt;delete&lt;/code&gt; operation types, we could initialize series for each of them like this in Go:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; val &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;range&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;create&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;read&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;update&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;delete&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    operationsTotal&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WithLabelValues&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;val&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that we are just referencing the labeled series within the metric here, but we do not call the &lt;code&gt;.Inc()&lt;/code&gt; method on it yet – this just initializes the counter series with an initial value of &lt;code&gt;0&lt;/code&gt; for each operation type, but does not increment it yet.&lt;/p&gt;
&lt;h3 id=&quot;use-or-to-join-in-a-default-value&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#use-or-to-join-in-a-default-value&quot; aria-label=&quot;use or to join in a default value permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Use &lt;code&gt;or&lt;/code&gt; to join in a default value&lt;/h3&gt;
&lt;p&gt;Sometimes you may not know all possible label values beforehand, or there may be too many of them to pre-initialize them all. For example, consider a metric that tracks the number of HTTP requests by status code, and you want to calculate the rate for a specific error code, like &lt;code&gt;503&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;,&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;503&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If no request with a &lt;code&gt;503&lt;/code&gt; response status has happened yet, this will return an empty result. But it probably doesn&apos;t make sense to proactively create series for all possible status codes, since that would create a lot of time series that will usually not be needed.&lt;/p&gt;
&lt;p&gt;In cases like this, you can either just accept the fact that your dashboards will sometimes show &lt;em&gt;&quot;No data&quot;&lt;/em&gt; warnings, avoid writing alerting rules that can silently fail when a series is missing, or you can use the &lt;code&gt;or&lt;/code&gt; set operator to join in a default value for the missing series using the &lt;code&gt;up&lt;/code&gt; metric for the same targets as the series you are querying for:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;,&lt;span class=&quot;token label-key /attr-name/&quot;&gt;status&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;503&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
or
  up&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; * &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;up&lt;/code&gt; metric is convenient for this purpose since it is always present for targets that are currently being scraped, and it has the advantage that it has compatible target labels. This makes label matching easy and gives you the expected result labels. The example above will now either return the actual request rate from the &lt;code&gt;http_requests_total&lt;/code&gt; metric (if any &lt;code&gt;503&lt;/code&gt; requests have already happened), or &lt;code&gt;0&lt;/code&gt; (since we force the &lt;code&gt;up&lt;/code&gt; metric to a value of &lt;code&gt;0&lt;/code&gt; via multiplication).&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In this blog post, we looked at how missing time series can cause trouble in your dashboards and alerting rules, and what you can do about it. Hopefully the tips in this article will help you avoid some of the pitfalls of missing series in your instrumentation code and in your PromQL expressions. To learn more Prometheus fundamentals from the ground up, take a look at our &lt;a href=&quot;https://training.promlabs.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus training courses&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[High Availability for Prometheus and Alertmanager: An Overview]]></title><description><![CDATA[If you use Prometheus for mission-critical monitoring and alerting, you will
want to make sure that your Prometheus stack is just as…]]></description><link>https://promlabs.com/blog/2023/08/31/high-availability-for-prometheus-and-alertmanager-an-overview</link><guid isPermaLink="false">https://promlabs.com/blog/2023/08/31/high-availability-for-prometheus-and-alertmanager-an-overview</guid><pubDate>Thu, 31 Aug 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;If you use Prometheus for mission-critical monitoring and alerting, you will
want to make sure that your Prometheus stack is just as reliable as the systems
and services it is monitoring. Let&apos;s take a look at the main strategies for
achieving high availability for Prometheus-based monitoring setups.&lt;/p&gt;
&lt;h2 id=&quot;ha-for-the-prometheus-server&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ha-for-the-prometheus-server&quot; aria-label=&quot;ha for the prometheus server permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;HA for the Prometheus server&lt;/h2&gt;
&lt;p&gt;Making a Prometheus server highly available for monitoring and alerting is
simple: just run multiple Prometheus server instances with an identical
configuration. Both servers then scrape the same metrics, compute the same
alerting rules, and forward exactly the same alerts to the Alertmanager. The
Alertmanager can then deduplicate alerts based on their label sets and only send
you a single notification.&lt;/p&gt;
&lt;div style=&quot;max-width: 700px; margin: auto&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-ha-architecture.svg&quot; alt=&quot;Prometheus HA architecture&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;If you implement this strategy, just make sure that your Prometheus server
instances run on separate machines, or that they are otherwise separated enough
to satisfy your availability requirements. You can run as many replicas as you
want, but most people are happy with two or three.&lt;/p&gt;
&lt;p&gt;If you need to distinguish the replicas of a set when talking to external
systems (like a remote storage system), you can give them different external
replica label values like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;external_labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;replica&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; A &lt;span class=&quot;token comment&quot;&gt;# B for the second replica.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;However, all alerts sent to the Alertmanager will then also have different
replica labels. Since the Alertmanager dedupes alerts based on identical label
sets, this deduplication will now break and you will get as many notifications
as you have Prometheus server replicas! To avoid this, make sure that you drop
the replica label on the alerting path using alert relabeling:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;alerting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;alert_relabel_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# Drop the &quot;replica&quot; label.&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; labeldrop
      &lt;span class=&quot;token key atrule&quot;&gt;regex&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; replica&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now the same alerts from different replicas in the set will look identical again
and can be deduped.&lt;/p&gt;
&lt;h2 id=&quot;ha-for-the-alertmanager&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#ha-for-the-alertmanager&quot; aria-label=&quot;ha for the alertmanager permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;HA for the Alertmanager&lt;/h2&gt;
&lt;p&gt;Prometheus relies on the Alertmanager for routing, grouping, and throttling
alerts. To ensure high availability for the Alertmanager as well, you can run
multiple identical Alertmanager replicas in a &lt;em&gt;clustered mode&lt;/em&gt;. After
configuring all your Prometheus replicas to each send alerts to &lt;em&gt;all
Alertmanager replicas&lt;/em&gt;, the Alertmanager then uses a gossip-based protocol to
replicate information about already-sent notifications to the other replicas in
the cluster:&lt;/p&gt;
&lt;div style=&quot;max-width: 900px; margin: auto&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/alertmanager-ha-architecture.svg&quot; alt=&quot;Alertmanager HA architecture&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now each replica computes on its own which notifications should be generated for
the incoming alerts. However, when a replica sees that another replica has
already sent out a notification for a given alert grouping, it will not send
another one. This ensures that each notification is only sent once. To account
for non-zero replication latency between the Alertmanager replicas, the replicas
also establish an ordering (replica 1, replica 2, replica 3, ...) among each
other and will wait a corresponding multiple of 15 seconds (0s, 15s, 30s, ...)
before sending out a given notification. This ensures that if one replica is
down or fails to communicate with the other replicas, the next replica will
still send out the notification after 15 seconds.&lt;/p&gt;
&lt;p&gt;Note that in the worst case, all Alertmanager replicas could be up and mostly
working, but not be able to reach each other anymore for some reason (e.g. when
the gossip protocol is misconfigured). You can then get as many duplicate
notifications as you have replicas. This is a &quot;fail-open&quot; tradeoff that is made
to ensure that the Alertmanager can still send out notifications even if the
network between the replicas is down.&lt;/p&gt;
&lt;p&gt;You can configure Alertmanager clustering using the &lt;code&gt;--cluster.listen-address&lt;/code&gt;
and &lt;code&gt;--cluster.peer&lt;/code&gt; flags. If you want to see a hands-on example of how to set
up an Alertmanager cluster, check out the
&lt;a href=&quot;https://training.promlabs.com/training/high-availability-for-monitoring-and-alerting/creating-a-highly-available-setup/deploying-alertmanager&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Deploying Alertmanager&lt;/strong&gt;&lt;/a&gt;
section of our
&lt;a href=&quot;https://training.promlabs.com/training/high-availability-for-monitoring-and-alerting/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;High Availability for Monitoring and Alerting&lt;/strong&gt;&lt;/a&gt;
training.&lt;/p&gt;
&lt;h2 id=&quot;other-considerations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-considerations&quot; aria-label=&quot;other considerations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other Considerations&lt;/h2&gt;
&lt;p&gt;Of course there is much more to say about creating fully redundant and highly
available Prometheus monitoring setups. Here&apos;s some other HA-related topics you
may want to look into:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;External / remote storage systems:&lt;/strong&gt; Using remote storage integrations,
Prometheus can send its collected metrics to a remote storage system such as
&lt;a href=&quot;https://cortexmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt;, &lt;a href=&quot;https://thanos.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Thanos&lt;/a&gt;, or
&lt;a href=&quot;https://m3db.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;M3&lt;/a&gt;. These systems are designed for long-term storage,
horizontal scalability, and high availability. By integrating Prometheus with
remote storage systems, you can ensure the continuous availability of your
monitoring data, even in the case of a Prometheus server outage.&lt;/p&gt;
&lt;p&gt;You can learn more about using external storage systems in our
&lt;a href=&quot;https://training.promlabs.com/training/integrating-with-remote-storage-systems/training-overview/introduction&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Integrating with Remote Storage Systems&lt;/strong&gt;&lt;/a&gt;
training.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Monitoring Prometheus itself:&lt;/strong&gt; In addition to implementing redundancy and
failover strategies, it&apos;s crucial to monitor your Prometheus infrastructure
for any potential issues. By monitoring Prometheus itself, you can detect and
resolve problems before they impact the availability of your monitoring
system. You can achieve this by setting up alerting rules and monitoring
dashboards for key metrics such as instance uptime, query performance, and
resource utilization.&lt;/p&gt;
&lt;p&gt;You can learn more about meta-monitoring in our
&lt;a href=&quot;https://training.promlabs.com/training/monitoring-and-debugging-prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Monitoring and Debugging Prometheus&lt;/strong&gt;&lt;/a&gt;
training.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Ensuring high availability in your Prometheus monitoring infrastructure is
crucial for maintaining reliable monitoring and alerting capabilities. By
implementing redundancy, failover strategies, and monitoring Prometheus itself,
you can minimize the risk of downtime and data loss. This will allow your
organization to react quickly to any issues and maintain the stability and
performance of your infrastructure.&lt;/p&gt;
&lt;p&gt;If you want to learn all Prometheus fundamentals from the ground up, take a look
at our &lt;a href=&quot;https://training.promlabs.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Prometheus training courses&lt;/strong&gt;&lt;/a&gt; to get
going today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Sending Prometheus Alerts to Discord with Alertmanager v0.25.0]]></title><description><![CDATA[Today, the Prometheus Team released Alertmanager v0.25.0 with a large set of changes, new features, and bug fixes. As one of the new…]]></description><link>https://promlabs.com/blog/2022/12/23/sending-prometheus-alerts-to-discord-with-alertmanager-v0-25-0</link><guid isPermaLink="false">https://promlabs.com/blog/2022/12/23/sending-prometheus-alerts-to-discord-with-alertmanager-v0-25-0</guid><pubDate>Fri, 23 Dec 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today, the Prometheus Team released &lt;a href=&quot;https://github.com/prometheus/alertmanager/releases/tag/v0.25.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Alertmanager v0.25.0&lt;/a&gt; with a large set of changes, new features, and bug fixes. As one of the new highlights, Alertmanager can now send alert notifications to &lt;a href=&quot;https://discord.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Discord&lt;/a&gt;! This feature was &lt;a href=&quot;https://github.com/prometheus/alertmanager/pull/2948&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;added by Matthias Loibl&lt;/a&gt; of &lt;a href=&quot;https://www.polarsignals.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Polar Signals&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While the new feature still needs to be properly documented at the time of writing, we&apos;ll already show you how you can send alerts to Discord in a short from-scratch walkthrough here.&lt;/p&gt;
&lt;h2 id=&quot;setting-up-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#setting-up-prometheus&quot; aria-label=&quot;setting up prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Setting up Prometheus&lt;/h2&gt;
&lt;p&gt;First, let&apos;s get a minimal Prometheus server running to generate some test alerts.&lt;/p&gt;
&lt;p&gt;Download and unpack Prometheus (adjust the operating system and platform, if necessary):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; https://github.com/prometheus/prometheus/releases/download/v2.41.0/prometheus-2.41.0.linux-amd64.tar.gz
&lt;span class=&quot;token function&quot;&gt;tar&lt;/span&gt; xvfz prometheus-2.41.0.linux-amd64.tar.gz
&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; prometheus-2.41.0.linux-amd64&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Create an alerting rule file &lt;code&gt;demo-alerts.yml&lt;/code&gt; with the following error rate test alert:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; demo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;service&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;alerts
  &lt;span class=&quot;token key atrule&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; DemoServiceHighErrorRate
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;token scalar string&quot;&gt;
      (
        sum without(status, instance) (
          rate(demo_api_request_duration_seconds_count{status=~&quot;5..&quot;,job=&quot;demo&quot;}[1m])
        )
      /
        sum without(status, instance) (
          rate(demo_api_request_duration_seconds_count{job=&quot;demo&quot;}[1m])
        ) * 100 &gt; 0.5
      )&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1m
    &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;severity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; critical
    &lt;span class=&quot;token key atrule&quot;&gt;annotations&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;High 5xx rate for {{ $labels.method }} on {{ $labels.path }}&apos;&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;The 5xx error rate for path {{$labels.path}} with method {{ $labels.method }} in {{ $labels.job }} is {{ printf &quot;%.2f&quot; $value }}%.&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Create a &lt;code&gt;prometheus.yml&lt;/code&gt; file to scrape three demo targets, load the alerting rule file, and send alerts to the Alertmanager we&apos;re going to run:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;scrape_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15s
  &lt;span class=&quot;token key atrule&quot;&gt;evaluation_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 15s

&lt;span class=&quot;token key atrule&quot;&gt;rule_files&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; demo&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;alerts.yml

&lt;span class=&quot;token key atrule&quot;&gt;alerting&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;alertmanagers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&apos;localhost:9093&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;token key atrule&quot;&gt;scrape_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo&apos;&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo.promlabs.com:10000&apos;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo.promlabs.com:10001&apos;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo.promlabs.com:10002&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Start Prometheus as usual with the configs you just created:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;./prometheus&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;setting-up-a-webhook-on-discord&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#setting-up-a-webhook-on-discord&quot; aria-label=&quot;setting up a webhook on discord permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Setting up a webhook on Discord&lt;/h2&gt;
&lt;p&gt;We assume you&apos;re already using Discord and have a channel that you want to send alerts to (in this example, we&apos;re using &lt;code&gt;#alerts&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Edit the channel settings by clicking the &lt;strong&gt;&quot;Edit Channel&quot;&lt;/strong&gt; cog button:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-edit-channel.png&quot; alt=&quot;Edit Discord channel settings&quot;&gt;&lt;/p&gt;
&lt;p&gt;Next, head to the &lt;strong&gt;&quot;Integrations&quot;&lt;/strong&gt; menu item:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-integrations.png&quot; alt=&quot;Creating a new Discord webhook&quot;&gt;&lt;/p&gt;
&lt;p&gt;Click on &lt;strong&gt;&quot;Create Webhook&quot;&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-add-webhook.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Click on the newly added hook:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-click-on-created-webhook.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Adjust the name, copy the webhook URL, and save the hook:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-configure-webhook.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;configuring-alertmanager&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#configuring-alertmanager&quot; aria-label=&quot;configuring alertmanager permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Configuring Alertmanager&lt;/h2&gt;
&lt;p&gt;Download Alertmanager v0.25.0 (in a separate directory):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;wget https&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;//github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;0.25.0.linux&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;amd64.tar.gz
tar xvfz alertmanager&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;0.25.0.linux&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;amd64.tar.gz
cd alertmanager&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;0.25.0.linux&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;amd64&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Set the &lt;code&gt;alertmanager.yml&lt;/code&gt; config file to:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;group_by&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&apos;alertname&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;job&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;

  &lt;span class=&quot;token key atrule&quot;&gt;group_wait&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 30s
  &lt;span class=&quot;token key atrule&quot;&gt;group_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5m
  &lt;span class=&quot;token key atrule&quot;&gt;repeat_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 3h

  &lt;span class=&quot;token key atrule&quot;&gt;receiver&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; discord

&lt;span class=&quot;token key atrule&quot;&gt;receivers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; discord
  &lt;span class=&quot;token key atrule&quot;&gt;discord_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;webhook_url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &amp;lt;DISCORD_WEBHOOK_URL&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;ATTENTION&lt;/strong&gt;: You&apos;ll need to replace the &lt;code&gt;&amp;#x3C;DISCORD_WEBHOOK_URL&gt;&lt;/code&gt; placeholder with the webhook URL you just copied from Discord. It should look something like this: &lt;code&gt;https://discord.com/api/webhooks/XXX/YYY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The config above just sends all alerts (grouped by job and alertname) to a single Discord receiver.&lt;/p&gt;
&lt;p&gt;Start Alertmanager with the above config:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;./alertmanager&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;receiving-and-viewing-alerts-in-discord&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#receiving-and-viewing-alerts-in-discord&quot; aria-label=&quot;receiving and viewing alerts in discord permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Receiving and viewing alerts in Discord&lt;/h2&gt;
&lt;p&gt;The Prometheus server&apos;s &lt;code&gt;/alerts&lt;/code&gt; page should eventually start showing some firing (red) alerts:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-prometheus-alerts-page.png&quot; alt=&quot;The Prometheus server&amp;#x27;s alerts page with firing alerts&quot;&gt;&lt;/p&gt;
&lt;p&gt;Shortly afterwards, you should also see alert notifications arriving on your Discord channel:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-alert-notification.png&quot; alt=&quot;Alert notification in Discord&quot;&gt;&lt;/p&gt;
&lt;p&gt;When all alerts in a group resolve (you can simulate this by stopping the Prometheus server and waiting 5 minutes for the alerts to expire in Alertmanager), you get a resolve notification as well:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/discord-resolved-notification.png&quot; alt=&quot;Resolve notification in Discord&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you would not like to send notifications for resolved alert groups, you can set the &lt;code&gt;send_resolved: false&lt;/code&gt; option in your Discord config in the &lt;code&gt;alertmanager.yml&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The above notifications are based on the &lt;a href=&quot;https://github.com/prometheus/alertmanager/blob/87ad8437fc1e28280e8c5c5fdcb41e0a8904a855/template/default.tmpl#L116-L126&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;default notification templates&lt;/a&gt; compiled into the Alertmanager (showing the alert name and label values in the title as well as full label and annotation details in the message), but it&apos;s possible to override the contents and style of the Discord notification, if you need to. For example, the Discord config in the Alertmanager can also take &lt;a href=&quot;https://prometheus.io/docs/alerting/latest/notifications/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;templateable&lt;/a&gt; &lt;code&gt;title&lt;/code&gt; and &lt;code&gt;message&lt;/code&gt; fields that allow you to adjust the message contents. There are also already &lt;a href=&quot;https://github.com/prometheus/alertmanager/pull/2948/files#r907388978&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;users asking to add support for setting custom avatars and usernames&lt;/a&gt;, so Discord alerts will likely become even more flexible in the future.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;This was just a quick walkthrough to show you how you can send Prometheus alerts to Discord. This new feature should also be &lt;a href=&quot;https://prometheus.io/docs/alerting/latest/configuration/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;documented in the Alertmanager configuration documentation&lt;/a&gt; soon, but in the meantime, you know how to get started!&lt;/p&gt;
&lt;p&gt;And by the way: If you would like to learn Prometheus in a structured way and from the ground up, be sure to also check out our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;self-paced training courses&lt;/a&gt; that cover the basics of Prometheus, alerting and Alertmanager, as well as advanced use cases and integrations.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Understanding Duplicate Samples and Out-of-order Timestamp Errors in Prometheus]]></title><description><![CDATA[Have you ever encountered any of the following errors in your Prometheus server logs? "Error on ingesting out-of-order samples" "Error on…]]></description><link>https://promlabs.com/blog/2022/12/15/understanding-duplicate-samples-and-out-of-order-timestamp-errors-in-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2022/12/15/understanding-duplicate-samples-and-out-of-order-timestamp-errors-in-prometheus</guid><pubDate>Thu, 15 Dec 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Have you ever encountered any of the following errors in your Prometheus server logs?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&quot;Error on ingesting out-of-order samples&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&quot;Error on ingesting samples with different value but same timestamp&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&quot;duplicate sample for timestamp&quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then you likely have a misconfiguration in your setup that causes multiple series to collide and conflict with each other. In this post, we&apos;re going to explain the background behind these errors, what may cause them, and how to you can debug and fix them.&lt;/p&gt;
&lt;h2 id=&quot;background-the-tsdb-is-normally-append-only&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#background-the-tsdb-is-normally-append-only&quot; aria-label=&quot;background the tsdb is normally append only permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Background: The TSDB is (normally) append-only&lt;/h2&gt;
&lt;p&gt;Prometheus is a live monitoring system that usually only needs to keep track of metrics in a steadily ongoing way over time. The Prometheus TSDB reflects this by (normally) only supporting appends to the end of any existing series. That means that it rejects incoming samples that have an earlier timestamp than the latest one within the same series. It also rejects samples with the same timestamp as the latest one in their series when they have a different sample value (otherwise, they are ignored).&lt;/p&gt;
&lt;div style=&quot;max-width: 550px; margin: auto&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-out-of-order-and-duplicate-samples.svg&quot; alt=&quot;Diagram showing duplicate and out-of-order timestamps being rejected&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;However, it is possible to misconfigure Prometheus in such a way that you get duplicated or out-of-order sample timestamps that Prometheus tries and fails to append to the TSDB. This is usually due to an accidental label set collision between multiple time series that causes the series to look the same (same metric name and label set), but it can have other reasons as well. When that happens, appends to the TSDB for the offending samples will fail, and Prometheus will log corresponding errors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Side note:&lt;/strong&gt; &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.39.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.39&lt;/a&gt; introduced an experimental &lt;code&gt;out_of_order_time_window&lt;/code&gt; configuration setting that allows ingesting out-of-order samples within a limited time period, but this feature is not enabled by default. It can be useful in certain situations where not all data can be gathered live.&lt;/p&gt;
&lt;h2 id=&quot;underlying-causes-of-sample-timestamp-errors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#underlying-causes-of-sample-timestamp-errors&quot; aria-label=&quot;underlying causes of sample timestamp errors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Underlying causes of sample timestamp errors&lt;/h2&gt;
&lt;p&gt;Let&apos;s have a look at the most common causes for these problems, along with the error messages they produce.&lt;/p&gt;
&lt;h3 id=&quot;duplicate-targets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#duplicate-targets&quot; aria-label=&quot;duplicate targets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Duplicate targets&lt;/h3&gt;
&lt;p&gt;In a correctly configured Prometheus setup, every target has its own unique set of target labels. Prometheus attaches these labels to all series pulled from a target to help disambiguate otherwise identical metrics from different targets. But it&apos;s possible to misconfigure Prometheus in such a way that multiple targets share the same label set, which can cause label set collisions between the resulting time series. The TSDB will then see the streams of multiple original series as a single series, but reject invalid appends when their samples conflict with each other with out-of-order or duplicate timestamps.&lt;/p&gt;
&lt;p&gt;Here&apos;s one way to easily provoke this duplication, by explicitly setting the &lt;code&gt;job&lt;/code&gt; label of a target group to the same value as another job with an otherwise identical target in your &lt;code&gt;prometheus.yml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;scrape_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5s

&lt;span class=&quot;token key atrule&quot;&gt;scrape_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; demo
  &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; demo.promlabs.com&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10000&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; demo2
  &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;# Override the &quot;job&quot; label to also be &quot;demo&quot; instead of &quot;demo2&quot;.&lt;/span&gt;
      &lt;span class=&quot;token key atrule&quot;&gt;job&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; demo
    &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; demo.promlabs.com&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;10000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Another variant of the above could be achieved by adding target relabeling rules to the second scrape configuration and overriding the &lt;code&gt;job&lt;/code&gt; label to &lt;code&gt;&quot;demo&quot;&lt;/code&gt; that way.&lt;/p&gt;
&lt;p&gt;When one of these duplicated targets starts scraping before the other one, but finishes the scrape last, you will get an &lt;code&gt;&quot;Error on ingesting out-of-order samples&quot;&lt;/code&gt; error message, as the first target tries to insert its samples into the TSDB with a scrape timestamp before the second one that has already completed. As a full log line, that will look something like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-14T12:21:05.833Z caller=scrape.go:1681 level=warn component=&quot;scrape manager&quot; scrape_pool=demo target=http://demo.promlabs.com:10000/metrics msg=&quot;Error on ingesting out-of-order samples&quot; num_dropped=254&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When two duplicated targets start scraping at exactly the same millisecond (which can and does happen between targets from different scrape pools), they will try storing their resulting samples with the same scrape timestamp. But one of these appends will fail with an &lt;code&gt;&quot;Error on ingesting samples with different value but same timestamp&quot;&lt;/code&gt; error message:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-14T12:18:10.841Z caller=scrape.go:1684 level=warn component=&quot;scrape manager&quot; scrape_pool=demo target=http://demo.promlabs.com:10000/metrics msg=&quot;Error on ingesting samples with different value but same timestamp&quot; num_dropped=58&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Usually the &lt;code&gt;scrape_pool&lt;/code&gt; and &lt;code&gt;target&lt;/code&gt; fields from the error message should be enough to point you at the right place in the configuration file to find and fix the conflicting targets. However, the duplication might not be visible in the configuration file itself, in case a remote service discovery mechanism produces duplicate targets, or there is an interaction between the service discovery source and target relabeling rules that leads to a loss of disambiguating labels. In that case, you may also want to take a look at the &lt;code&gt;/targets&lt;/code&gt; page of your Prometheus server to spot identically labeled targets between multiple scrape pools or scrape configs (it&apos;s not possible to have identical targets in the same scrape pool, as Prometheus automatically deduplicates them into a single one). The &lt;code&gt;/service-discovery&lt;/code&gt; page also shows all discovered targets with their label sets before and after relabeling. To fix the ingestion errors, make sure that all targets are labeled uniquely.&lt;/p&gt;
&lt;h3 id=&quot;buggy-client-side-timestamps&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#buggy-client-side-timestamps&quot; aria-label=&quot;buggy client side timestamps permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Buggy client-side timestamps&lt;/h3&gt;
&lt;p&gt;Usually Prometheus &lt;code&gt;/metrics&lt;/code&gt; endpoints will not include explicit timestamps for the samples they expose. Instead, Prometheus assigns its own scrape start timestamp to all pulled samples. However, it&apos;s also possible to provide explicit client-side timestamps for samples in the &lt;a href=&quot;https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus metrics exposition format&lt;/a&gt;. For example, if you wanted to expose a &lt;code&gt;test_metric&lt;/code&gt; metric with a value of &lt;code&gt;42&lt;/code&gt; and a milliseconds Unix timestamp of &lt;code&gt;1671021749332&lt;/code&gt;, the exposition format would read:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# HELP foo A test metric with an explicit timestamp.&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE foo gauge&lt;/span&gt;
test_metric &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1671021749332&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Given the TSDB restrictions mentioned initially, there is a lot that can go wrong here if that feature is misused or incorrectly implemented: if a client-side timestamp moves backwards between scrapes, you will get an out-of-order error. If it stays the same, but the sample value changes, you will get a duplicate timestamp error.&lt;/p&gt;
&lt;p&gt;The error messages in this case will look similar to the ones for duplicate targets, as they both originate in the scrape layer. However, the simple target information from the error logs may not be enough anymore to find the specific problematic metric within the broken target. Luckily, setting the &lt;code&gt;--log.level=debug&lt;/code&gt; flag on the Prometheus server increases logging verbosity such that you can see each series (in the &lt;code&gt;series&lt;/code&gt; log message field) that is causing trouble.&lt;/p&gt;
&lt;p&gt;For duplicate timestamps, that will look like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-14T10:23:40.297Z caller=scrape.go:1730 level=debug component=&quot;scrape manager&quot; scrape_pool=prometheus_dupe target=http://demo.promlabs.com:10000/metrics msg=&quot;Duplicate sample for timestamp&quot; series=go_goroutines&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And for out-of-order timestamps, like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-14T13:12:45.844Z caller=scrape.go:1725 level=debug component=&quot;scrape manager&quot; scrape_pool=demo target=http://demo.promlabs.com:10000/metrics msg=&quot;Out of order sample&quot; series=go_goroutines&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this case, you will have to fix the metrics exposition in the broken target to resolve the problem.&lt;/p&gt;
&lt;!--
### Metric relabeling causing duplicate series

It is also possible to accidentally use metric relabeling (the kind of relabeling that is applied to each pulled series during a scrape) to remove important disambiguating labels of series within a target. For example, the following configuration removes the `code` label from all pulled metrics, but in the `promhttp_metric_handler_requests_total` metric, this label is required to tell 3 different series apart:

```yml

```

--&gt;
&lt;h3 id=&quot;duplicate-series-from-rules&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#duplicate-series-from-rules&quot; aria-label=&quot;duplicate series from rules permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Duplicate series from rules&lt;/h3&gt;
&lt;p&gt;It is also possible to create colliding series between the outputs of multiple recording rules. Take this rule file example, which records the metric &lt;code&gt;colliding_name&lt;/code&gt; from two rules in the same rule group, but with different sample values:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; dupe
  &lt;span class=&quot;token key atrule&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; colliding_name
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; colliding_name
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Although the evaluation of multiple rules from the same group happens sequentially, Prometheus will run them all with the same query evaluation timestamp. This causes the rule evaluation to fail with a &lt;code&gt;&quot;duplicate sample for timestamp&quot;&lt;/code&gt; error:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-15T10:07:25.976Z caller=manager.go:684 level=warn component=&quot;rule manager&quot; file=dupes-rules.yml group=dupe name=colliding_name index=1 msg=&quot;Rule evaluation result discarded&quot; err=&quot;duplicate sample for timestamp&quot; sample=&quot;{__name__=\&quot;colliding_name\&quot;} =&gt; 1 @[1671098845972]&quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This error also helpfully logs the rule group, the recorded metric name, as well as the offending label set of the sample. That way, you should be able to fix the problem in your rule files.&lt;/p&gt;
&lt;p&gt;As a variation, it is also possible for such a collision to happen between series produced from a recording rule and a target scrape.&lt;/p&gt;
&lt;h3 id=&quot;remote-write-sending-bad-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remote-write-sending-bad-data&quot; aria-label=&quot;remote write sending bad data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remote write sending bad data&lt;/h3&gt;
&lt;p&gt;If you are using the &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/feature_flags/#remote-write-receiver&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus server&apos;s own remote write receiver&lt;/a&gt; to push samples to Prometheus, you can also run into situations where one or multiple push sources can send conflicting metrics and timestamps. In that case, you may get an &lt;code&gt;&quot;Out of order sample from remote write&quot;&lt;/code&gt; or &lt;code&gt;&quot;duplicate sample for timestamp&quot;&lt;/code&gt; request error on the sending side:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-15T10:49:51.792Z caller=dedupe.go:112 component=remote level=error remote_name=45e379 url=http://localhost:9090/api/v1/write msg=&quot;non-recoverable error&quot; count=6 exemplarCount=0 err=&quot;server returned HTTP status 400 Bad Request: out of order sample&quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Or:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-15T10:51:31.437Z caller=dedupe.go:112 component=remote level=error remote_name=45e379 url=http://localhost:9090/api/v1/write msg=&quot;non-recoverable error&quot; count=3 exemplarCount=0 err=&quot;server returned HTTP status 400 Bad Request: duplicate sample for timestamp&quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And in the receiving Prometheus server, you will get a similar error message (once a &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/11727&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;fix for a bug that we discovered&lt;/a&gt; in the course of writing this article has been fixed):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;ts=2022-12-15T11:04:23.006Z caller=write_handler.go:107 level=error component=web msg=&quot;Out of order sample from remote write&quot; err=&quot;out of order sample&quot; series=&quot;{__name__=\&quot;foo\&quot;, instance=\&quot;localhost:8080\&quot;, job=\&quot;remote\&quot;}&quot; timestamp=1671102261810&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This latter message tells you the exact offending series, so you can hopefully track down and fix its source.&lt;/p&gt;
&lt;h3 id=&quot;intentional-ingestion-of-out-of-order-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#intentional-ingestion-of-out-of-order-data&quot; aria-label=&quot;intentional ingestion of out of order data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Intentional ingestion of out-of-order data&lt;/h3&gt;
&lt;p&gt;Now, there &lt;em&gt;are&lt;/em&gt; a few valid use cases when you might actually want to ingest out-of-order data or even data that is normally too old to be ingested into the TSDB at all. You may have some data sources that cannot produce metrics on an ongoing live basis, but only deliver batched or otherwise delayed results. For these cases, as mentioned above, you will want to turn on Prometheus&apos; new experimental &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#tsdb&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;out_of_order_time_window&lt;/code&gt; TSDB configuration setting&lt;/a&gt; that allows ingesting out-of-order samples within a limited time period to get rid of these error messages.&lt;/p&gt;
&lt;h3 id=&quot;caution-not-all-collisions-cause-errors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#caution-not-all-collisions-cause-errors&quot; aria-label=&quot;caution not all collisions cause errors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Caution: Not all collisions cause errors!&lt;/h3&gt;
&lt;p&gt;As we just learned above, there are multiple series collision conditions that Prometheus can notice and tell us about. But in some cases, Prometheus silently ignores series collisions or can&apos;t detect them at all. So not seeing an error is not a guarantee that everything is working right.&lt;/p&gt;
&lt;h4 id=&quot;silent-failure-of-collisions-caused-by-metric-relabeling&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#silent-failure-of-collisions-caused-by-metric-relabeling&quot; aria-label=&quot;silent failure of collisions caused by metric relabeling permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Silent failure of collisions caused by metric relabeling&lt;/h4&gt;
&lt;p&gt;One such case is when accidentally using metric relabeling (which is applied to each pulled series during a scrape) to remove important disambiguating labels of series from a single target. For example, the following configuration removes the &lt;code&gt;quantile&lt;/code&gt; label from all pulled metrics, but in the &lt;code&gt;go_gc_duration_seconds&lt;/code&gt; metric, this label is required to tell 3 different series apart:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;scrape_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5s

&lt;span class=&quot;token key atrule&quot;&gt;scrape_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; prometheus
  &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; localhost&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;9090&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;metric_relabel_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; labeldrop
    &lt;span class=&quot;token key atrule&quot;&gt;target_label&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; quantile&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The current behavior of Prometheus is to store the first of the conflicting samples, but silently discard the subsequent ones without any warning. We filed &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/11725&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;an issue about possibly reviewing and/or fixing that behavior&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;two-rules-or-targets-writing-into-the-same-series-without-timing-conflicts&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#two-rules-or-targets-writing-into-the-same-series-without-timing-conflicts&quot; aria-label=&quot;two rules or targets writing into the same series without timing conflicts permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Two rules or targets writing into the same series without timing conflicts&lt;/h4&gt;
&lt;p&gt;It can easily happen that Prometheus either scrapes two duplicate targets or ingests samples from two rules writing to the same series, but the samples always arrive in perfect lockstep without creating an out-of-order condition or a duplicate timestamp. In that case, the samples from the two sources will be written to the same time series, with the same value altering back and forth between both input series.&lt;/p&gt;
&lt;p&gt;For example, if you created a rule file like this, recording the metric &lt;code&gt;colliding_name&lt;/code&gt; both with a sample value of &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;groups&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; collision
  &lt;span class=&quot;token key atrule&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; colliding_name
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; collision2
  &lt;span class=&quot;token key atrule&quot;&gt;rules&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;record&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; colliding_name
    &lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;...then you will likely not see any logged errors (unless the two rule groups happen to run at the exact same duplicate timestamp). However, you will see the sample value of the series alternating between &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/colliding-series-graph.png&quot; alt=&quot;Graph of two colliding series&quot;&gt;&lt;/p&gt;
&lt;p&gt;There&apos;s usually no valid use case for this kind of behavior, but it&apos;s currently not possible for Prometheus to detect this case automatically.&lt;/p&gt;
&lt;h2 id=&quot;detecting-these-issues-using-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#detecting-these-issues-using-metrics&quot; aria-label=&quot;detecting these issues using metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Detecting these issues using metrics&lt;/h2&gt;
&lt;p&gt;Besides reading logged error messages, you can also detect out of order and duplicate timestamps by monitoring the following metrics that Prometheus exposes about itself:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;prometheus_tsdb_out_of_order_samples_total&lt;/code&gt;: The total number of out of order samples ingestion failed attempts due to out-of-order support being disabled.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;prometheus_target_scrapes_sample_duplicate_timestamp_total&lt;/code&gt;: The total number scraped samples with duplicate timestamps.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;prometheus_target_scrapes_sample_out_of_order_total&lt;/code&gt;: The total number of scraped out-of-order samples.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;prometheus_http_requests_total{code=&quot;400&quot;,handler=&quot;/api/v1/write&quot;}&lt;/code&gt;: The total number of &lt;code&gt;400&lt;/code&gt; status code requests received by the remote write receiver (in the receiving Prometheus server). This can include errors that result in a &lt;code&gt;400&lt;/code&gt; as well.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;prometheus_remote_storage_samples_failed_total&lt;/code&gt;: The total number of samples that failed to be sent over remote write in the sending Prometheus server. This can also include other errors.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Series collision errors from rule evaluations unfortunately do not show up in a metric yet. There is a &lt;code&gt;prometheus_rule_evaluation_failures_total&lt;/code&gt; metric, but that only counts total failures of a rule&apos;s evaluation, not individual series that have been discarded during the evaluation. However, a rule with problematic output series will still be marked as unhealthy, and the &lt;code&gt;/rules&lt;/code&gt; page will show you the corresponding error:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/rules-page-duplicate-timestamp-error.png&quot; alt=&quot;Duplicate timestamp error on rules page&quot;&gt;.&lt;/p&gt;
&lt;h2 id=&quot;other-storage-errors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-storage-errors&quot; aria-label=&quot;other storage errors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other storage errors&lt;/h2&gt;
&lt;p&gt;Besides out-of-order and duplicate sample timestamps, the Prometheus TSDB can also respond with a set of other errors when trying to append samples or even exemplar data. You can &lt;a href=&quot;https://github.com/prometheus/prometheus/blob/9e26adfd20bd5f7868ab871a34ebbdc852910166/storage/interface.go#L29-L49&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;see all possible errors in the Prometheus storage code&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hopefully these explanations were useful for understanding the background behind these out-of-order and duplicate sample ingestion errors and can be helpful in finding and fixing them the next time they occur in your Prometheus setup.&lt;/p&gt;
&lt;p&gt;If you would like to learn Prometheus in a structured way and from the ground up, please also be sure to check out our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;self-paced training courses&lt;/a&gt; that cover the basics of Prometheus, as well as advanced use cases and integrations.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Avoid These 6 Mistakes When Getting Started With Prometheus]]></title><description><![CDATA[Let's talk about 6 common mistakes to avoid when getting started with Prometheus-based monitoring: Mistake 1: Cardinality bombs This is the…]]></description><link>https://promlabs.com/blog/2022/12/11/avoid-these-6-mistakes-when-getting-started-with-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2022/12/11/avoid-these-6-mistakes-when-getting-started-with-prometheus</guid><pubDate>Sun, 11 Dec 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Let&apos;s talk about 6 common mistakes to avoid when getting started with Prometheus-based monitoring:&lt;/p&gt;
&lt;h2 id=&quot;mistake-1-cardinality-bombs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mistake-1-cardinality-bombs&quot; aria-label=&quot;mistake 1 cardinality bombs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mistake 1: Cardinality bombs&lt;/h2&gt;
&lt;p&gt;This is the classic pitfall that everyone hits at least once when they&apos;re starting out with Prometheus. Once you discover the usefulness of Prometheus&apos; label-based data model, you might be tempted to split up metrics by all kinds of useful label dimensions, up to the point where you create way more time series than your Prometheus server can handle.&lt;/p&gt;
&lt;p&gt;For example, you may have an HTTP server exposing a request counter that is split up by the HTTP method:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;PUT&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;DELETE&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is totally fine, as long as you ensure that you only store valid method values in the &lt;code&gt;method&lt;/code&gt; label. However, maybe now you get the idea to helpfully split up the metric by the ID of the requesting user as well:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;2&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;3&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;…many more…&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;POST&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;16434313&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;2&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;3&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;…many more…&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
http_requests_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;method&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;GET&quot;&lt;/span&gt;,user_id&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;16434313&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;…many more…&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Assuming that you have more than a handful of users, you will now suffer a solid cardinality explosion that will blow up your Prometheus server&apos;s memory usage up to the point of an OOM (out-of-memory) crash.&lt;/p&gt;
&lt;p&gt;So always keep in mind: every &lt;strong&gt;unique combination&lt;/strong&gt; of labels on a metric automatically creates one time series that Prometheus will have to ingest, index, store, and process. While there&apos;s no absolute hard limit for the number of values you can put into a single label, you&apos;ll want to stay under the total budget of time series that your Prometheus server can handle. For example, a large Prometheus server might be able to handle up to a few million time series, so you&apos;ll want to choose the combination of your labels, the metrics they are on, and the number of targets exposing those metrics accordingly so you stay within your total budget of time series for that server.&lt;/p&gt;
&lt;p&gt;In particular, you&apos;ll want to avoid storing &lt;strong&gt;unbounded high-cardinality values&lt;/strong&gt;, like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Public IP addresses or email addresses&lt;/li&gt;
&lt;li&gt;Full HTTP paths, if these paths contain IDs or other unbounded cardinality information&lt;/li&gt;
&lt;li&gt;Process IDs (unless well-bounded to a specific set)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can sometimes work around a high-cardinality issue with a label without removing it completely by reducing the cardinality of its values while still preserving the most useful information. For example, for HTTP paths of the form &lt;code&gt;/api/users/739567637385/posts/28388445&lt;/code&gt;, you could at least replace the highest-cardinality components of the path (user and post IDs in this example) with placeholders in the final label value, to yield a more general pattern like &lt;code&gt;/api/users/{user_id}/posts/{post_id}&lt;/code&gt; that generates way fewer different label values and thus time series.&lt;/p&gt;
&lt;h2 id=&quot;mistake-2-aggregating-away-valuable-labels-in-alerting-expressions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mistake-2-aggregating-away-valuable-labels-in-alerting-expressions&quot; aria-label=&quot;mistake 2 aggregating away valuable labels in alerting expressions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mistake 2: Aggregating away valuable labels in alerting expressions&lt;/h2&gt;
&lt;p&gt;A common temptation when writing alerting expressions that aggregate over an entire service is to aggregate away any labels that you don&apos;t immediately need to determine whether there is a problem or not. For example, if you wanted to determine if your service&apos;s overall error rate (across all label dimensions) was too high, you might write a rule like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;By default, the &lt;code&gt;sum()&lt;/code&gt; aggregator produces a single output series without any labels. This removes not only dimensions that you actually want to aggregate away (like the instance, type of error, etc.), but also all &lt;strong&gt;labels that are common across all input series&lt;/strong&gt; and that may later prove useful for the routing or silencing of alerts in the Alertmanager. Especially the &lt;code&gt;job&lt;/code&gt; label (or equivalent service grouping label) is a common routing label, since a &lt;a href=&quot;https://prometheus.io/docs/concepts/jobs_instances/#jobs-and-instances&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;job&lt;/a&gt; is often associated with a team responsible for handling its alerts. Thus I&apos;d recommend preserving this label in aggregations whenever possible:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;An even better option is to &lt;strong&gt;preserve any labels that you don&apos;t want to explicitly get rid of&lt;/strong&gt;, by replacing the &lt;code&gt;by()&lt;/code&gt; aggregation modifier with an exclude-list approach using the &lt;code&gt;without()&lt;/code&gt; aggregation modifier:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;without&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;instance&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way, any labels on the input series that you don&apos;t explicitly aggregate away will still be available in Alertmanager for alert aggregation and routing, as well as for your understanding of the origin of an alert.&lt;/p&gt;
&lt;h2 id=&quot;mistake-3-using-unscoped-naked-selectors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mistake-3-using-unscoped-naked-selectors&quot; aria-label=&quot;mistake 3 using unscoped naked selectors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mistake 3: Using unscoped, &quot;naked&quot; selectors&lt;/h2&gt;
&lt;p&gt;When writing PromQL queries (especially for alerting!), you want to be extra careful about selecting data only from the job or service that you are intending to write the query for. Multiple unrelated services may expose the same metric name, potentially even with totally different semantic meanings. Even if this is not the case when you&apos;re initially writing your query, a new service with conflicting metric names may appear tomorrow that totally breaks your alerting rules or dashboards.&lt;/p&gt;
&lt;p&gt;To avoid a situation where you accidentally pull in data for unrelated jobs, be sure to &lt;strong&gt;scope your selectors with label matchers that clearly namespace the job or service&lt;/strong&gt; you are referring to. Usually, this would be the &lt;code&gt;job&lt;/code&gt; label.&lt;/p&gt;
&lt;p&gt;For example, an &lt;strong&gt;unsafe &quot;naked&quot; selector&lt;/strong&gt; might select data with the same metric name from other jobs that you are not expecting:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A &lt;strong&gt;safer scoped selector&lt;/strong&gt; will limit the selected metrics to the ones coming from the &lt;code&gt;my-job&lt;/code&gt; job:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;errors_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;my-job&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way you can also avoid situations where your alerting rules or dashboards start misbehaving at a later point once another service is scraped that produces a metric name collision.&lt;/p&gt;
&lt;h2 id=&quot;mistake-4-no-for-duration-in-alerting-rules&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mistake-4-no-for-duration-in-alerting-rules&quot; aria-label=&quot;mistake 4 no for duration in alerting rules permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mistake 4: No &lt;code&gt;for&lt;/code&gt; duration in alerting rules&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;for&lt;/code&gt; field in alerting rules allows you to specify for how long an output time series needs to be present across successive rule evaluation cycles for it to turn from a &lt;strong&gt;pending&lt;/strong&gt; alert to a &lt;strong&gt;firing&lt;/strong&gt; alert. This essentially allows you to add a per-series time tolerance to an alerting rule. Now you may wonder which alerts should have a &lt;code&gt;for&lt;/code&gt; duration, and how long it should be. Is it maybe even a good idea to omit the &lt;code&gt;for&lt;/code&gt; duration completely on most alerts?&lt;/p&gt;
&lt;p&gt;Consider an alerting rule that uses the &lt;code&gt;up&lt;/code&gt; metric to find targets that can&apos;t be scraped successfully, with the optional &lt;code&gt;for&lt;/code&gt; modifier omitted:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; InstanceDown
&lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; up == 0&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A &lt;strong&gt;single failed scrape&lt;/strong&gt; (which can happen quite easily) will cause this rule to fire. Usually you will want to make your alerting rules less trigger-happy and wait at least a couple of minutes to see if a problem persists before notifying a human:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; InstanceDown
&lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; up == 0
&lt;span class=&quot;token key atrule&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5m  &lt;span class=&quot;token comment&quot;&gt;# An instance needs to be down / unreachable for 5 minutes before creating an alert for it.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Specifying no &lt;code&gt;for&lt;/code&gt; duration can even be problematic for alerting expressions that already have some time-averaging baked in. Consider this alert on high error rates:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; HighErrorRate
&lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rate(my_errors_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;job=&quot;my&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;job&quot;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;5m&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;) &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt; 10&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This rule will &lt;strong&gt;fire on the first evaluation in which there is a high error rate&lt;/strong&gt;, as averaged over a 5-minute period of available data. While the 5-minute averaging already introduces some robustness, consider what happens when the Prometheus server is &lt;strong&gt;completely fresh or has not collected data for a while&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The 5-minute &lt;code&gt;rate()&lt;/code&gt; window will only consider a few &lt;strong&gt;very recent samples&lt;/strong&gt;, not actually averaging over five minutes worth of data.&lt;/li&gt;
&lt;li&gt;The rule can now produce &lt;strong&gt;immediately firing alerts&lt;/strong&gt; for series that don&apos;t even have five minutes worth of data yet.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Introducing a &lt;code&gt;for&lt;/code&gt; duration fixes this problem:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; HighErrorRate
&lt;span class=&quot;token key atrule&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rate(my_errors_total&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;job=&quot;my&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;job&quot;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;5m&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;) &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt; 10
&lt;span class=&quot;token key atrule&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5m&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Similar arguments could be made about most alerting rules. So to make your alerting rules more robust, you will almost always want to set the &lt;code&gt;for&lt;/code&gt; duration to &lt;strong&gt;at least a couple of minutes&lt;/strong&gt;. Just keep in mind that this also leads to &lt;strong&gt;slower reaction times&lt;/strong&gt; for alerts, so finding a balance for the &lt;code&gt;for&lt;/code&gt; time tolerance is important.&lt;/p&gt;
&lt;h2 id=&quot;mistake-5-too-short-rate-windows&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mistake-5-too-short-rate-windows&quot; aria-label=&quot;mistake 5 too short rate windows permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mistake 5: Too short &lt;code&gt;rate()&lt;/code&gt; windows&lt;/h2&gt;
&lt;p&gt;Have you ever been frustrated by gappy or completely empty graphs when computing rates over too short time windows, like &lt;code&gt;rate(my_counter[1m])&lt;/code&gt;? &lt;code&gt;rate()&lt;/code&gt; and other PromQL functions (like &lt;code&gt;increase()&lt;/code&gt;, &lt;code&gt;irate()&lt;/code&gt;, &lt;code&gt;deriv()&lt;/code&gt;) that tell you how fast a time series is going up or down over a given time window all &lt;strong&gt;need at least two samples under the input time window&lt;/strong&gt; to be able to tell you how the series is developing between those two samples. If you make the time window too small, you risk just having one or zero samples under the window, in which case the output will become empty.&lt;/p&gt;
&lt;p&gt;For example, if you take the 20s-ranged &lt;code&gt;rate()&lt;/code&gt; of a counter metric that is scraped every 15s, there&apos;s a good chance that those 20s will often not cover two samples, so you get a gappy rate:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/gappy-rate.png&quot; alt=&quot;Gappy rate output&quot;&gt;&lt;/p&gt;
&lt;p&gt;Taken to the extreme: if you decrease the rate window to 16s, you only get an output point very occasionally, when two 15s-apart points happen to fall under an arbitrarily aligned 16s window:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/very-gappy-rate.png&quot; alt=&quot;Very gappy rate output&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you decrease the window further, you end up having no chance at all of covering two samples, so you get a completely empty query output:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/empty-rate-output.png&quot; alt=&quot;Empty rate output&quot;&gt;&lt;/p&gt;
&lt;p&gt;So you&apos;ll want to choose your input windows large enough – not just 2x the scrape interval, but you&apos;ll also want to be robust in the face of occasional scrape failures and unlucky window alignments. It&apos;s generally a good practice to choose rate window sizes to be at least 4x the scrape interval:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/rate-window-size.svg&quot; alt=&quot;Sufficient rate window interval&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;: When using &lt;a href=&quot;https://grafana.com/grafana/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana&lt;/a&gt;, you can also use the &lt;code&gt;$__rate_interval&lt;/code&gt; template variable to automatically choose a safe interval for you.&lt;/p&gt;
&lt;h2 id=&quot;mistake-6-using-rate-and-friends-with-the-wrong-metric-type&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mistake-6-using-rate-and-friends-with-the-wrong-metric-type&quot; aria-label=&quot;mistake 6 using rate and friends with the wrong metric type permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mistake 6: Using &lt;code&gt;rate()&lt;/code&gt; and friends with the wrong metric type&lt;/h2&gt;
&lt;p&gt;While PromQL is statically typed in some other ways, it cannot directly tell you if you&apos;re passing in the wrong type of metric into a function that is not designed to deal with it. The most prominent examples of this are:&lt;/p&gt;
&lt;h3 id=&quot;using-rate-with-gauge-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#using-rate-with-gauge-metrics&quot; aria-label=&quot;using rate with gauge metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Using &lt;code&gt;rate()&lt;/code&gt; with gauge metrics&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;rate()&lt;/code&gt;, &lt;code&gt;irate()&lt;/code&gt;, and &lt;code&gt;increase()&lt;/code&gt; functions are designed to &lt;strong&gt;only work with counter metrics&lt;/strong&gt;. Counters are metrics that track cumulative counts that only ever go up (and never down), except for the occasional reset to &lt;code&gt;0&lt;/code&gt; whenever the tracking process restarts. To neutralize away counter resets as much as possible in the rate calculation, these functions try to interpret any decrease in the sample values under the provided time window as a reset and compensate for it (see also our &lt;a href=&quot;https://promlabs.com/blog/2021/01/29/how-exactly-does-promql-calculate-rates&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;detailed article about rate calculations&lt;/a&gt; on this). This counter reset detection and compensation means that you will only ever get positive results (or &lt;code&gt;0&lt;/code&gt;) out of these functions. If you accidentally pass in a gauge metric that can naturally go up &lt;strong&gt;and&lt;/strong&gt; down (like memory usage), PromQL will &lt;strong&gt;not be able to tell this mistake&lt;/strong&gt;, but will simply return an incorrect output value. This is because every time that your gauge metric goes down, &lt;code&gt;rate()&lt;/code&gt; will interpret this as a counter reset and will incorrectly &quot;correct&quot; for it.&lt;/p&gt;
&lt;h3 id=&quot;using-deriv-with-counter-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#using-deriv-with-counter-metrics&quot; aria-label=&quot;using deriv with counter metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Using &lt;code&gt;deriv()&lt;/code&gt; with counter metrics&lt;/h3&gt;
&lt;p&gt;You can think of the &lt;code&gt;deriv()&lt;/code&gt; function as roughly the equivalent of &lt;code&gt;rate()&lt;/code&gt;, but for gauges. &lt;code&gt;deriv()&lt;/code&gt; tells you how fast a gauge metric is going up or down per second, as measured over an input time window. While not as common, the same pitfall as with &lt;code&gt;rate()&lt;/code&gt; can hit you the other way around here: since the &lt;code&gt;deriv()&lt;/code&gt; function does &lt;strong&gt;not&lt;/strong&gt; implement any logic around counter resets (gauges don&apos;t have these!), trying to calculate the &lt;code&gt;deriv()&lt;/code&gt; of a counter metric will give you incorrect and sometimes even negative results whenever there is a counter reset under the provided window.&lt;/p&gt;
&lt;h3 id=&quot;how-can-you-avoid-passing-in-incorrect-metric-types&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-can-you-avoid-passing-in-incorrect-metric-types&quot; aria-label=&quot;how can you avoid passing in incorrect metric types permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How can you avoid passing in incorrect metric types?&lt;/h3&gt;
&lt;p&gt;Since PromQL cannot automatically detect this kind of incorrect usage, unfortunately you just have to be extra careful when using these functions. Education helps here, but tools like the recently open-sourced &lt;a href=&quot;https://github.com/prometheus/promlens&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens query builder&lt;/a&gt; also use heuristics based on the metric name to try and guess whether you&apos;re passing in a wrong metric type:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/rate-noncounter-hint.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hopefully these tips were helpful for you on your journey of starting out with Prometheus! If you would like to learn Prometheus in a structured way and from the ground up, please also be sure to check out our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;self-paced training courses&lt;/a&gt; that cover the basics of Prometheus, as well as advanced use cases and integrations.&lt;/p&gt;
&lt;h2 id=&quot;related-content&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#related-content&quot; aria-label=&quot;related content permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Related Content&lt;/h2&gt;
&lt;p&gt;We also made a video about these 6 mistakes:&lt;/p&gt;
&lt;div style=&quot;max-width: 530px; margin: auto;&quot;&gt;
  &lt;div style=&quot;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden&quot;&gt;
    &lt;iframe style=&quot;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0&quot; style=&quot;margin: auto; display: block&quot; src=&quot;https://www.youtube.com/embed/NEMsO1qeI1s&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen&gt;&lt;/iframe&gt;
  &lt;/div&gt;
&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Prometheus Turns 10]]></title><description><![CDATA[Today, we want to congratulate Prometheus on its tenth birthday! From Google to SoundCloud Ten years ago today, the first public commit was…]]></description><link>https://promlabs.com/blog/2022/11/24/prometheus-turns-10</link><guid isPermaLink="false">https://promlabs.com/blog/2022/11/24/prometheus-turns-10</guid><pubDate>Thu, 24 Nov 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today, we want to congratulate Prometheus on its tenth birthday!&lt;/p&gt;
&lt;h2 id=&quot;from-google-to-soundcloud&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#from-google-to-soundcloud&quot; aria-label=&quot;from google to soundcloud permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;From Google to SoundCloud&lt;/h2&gt;
&lt;p&gt;Ten years ago today, the &lt;a href=&quot;https://github.com/prometheus/prometheus/commit/734d28b515026ca9f429eba0a7d09954bceb6387&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;first public commit&lt;/a&gt; was pushed to the Prometheus repo. Back then, Matt T. Proud and myself had just left Google to join SoundCloud. At SoundCloud, we encountered an environment that was ahead of its time: Hundreds of microservices were running on an container orchestration system that SoundCloud had built in-house, before Kubernetes or even Docker were born. However, SoundCloud was also facing a myriad of reliability and latency issues, and existing monitoring tools had a hard time making sense of such a dynamic and high-cardinality computing environment. We felt unable to pinpoint the sources of problems, and we were really missing a system that combined a dimensional data model with a flexible query language, an efficient TSDB implementation for tracking dynamic high-cardinality time series data, service discovery support, as well as integrated alerting. All these were qualities that we had gotten used to from Borgmon, Google&apos;s own internal monitoring system at the time.&lt;/p&gt;
&lt;h2 id=&quot;starting-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#starting-prometheus&quot; aria-label=&quot;starting prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Starting Prometheus&lt;/h2&gt;
&lt;p&gt;We felt so strongly about the need for a new open-source monitoring system that we decided to take a stab at building it ourselves. Without even asking anyone at the company, we threw some code on GitHub under an open license and started working on it in our free time (with that &quot;free time&quot; gradually turning into more and more time on the job). Matt focussed on building client instrumentation libraries and a TSDB implementation, while I built the initial PromQL query language, the web UI, as well as the configuration handling. Toward the end of 2012, we had a rough prototype that could scrape metrics from an instrumented service target, store them in a TSDB, and then query and graph those metrics using an early form of PromQL. This end-to-end proof of concept gave us the confidence to keep going: Prometheus was born.&lt;/p&gt;
&lt;h2 id=&quot;the-journey-since-then&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-journey-since-then&quot; aria-label=&quot;the journey since then permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The journey since then&lt;/h2&gt;
&lt;p&gt;Over time, and after overcoming a lot of technical and political hurdles, SoundCloud adopted Prometheus as its primary monitoring system, which gave developers unprecedented insight into their service behaviors. We also finally &lt;a href=&quot;https://developers.soundcloud.com/blog/prometheus-monitoring-at-soundcloud&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;announced the project properly to the wider world in 2015&lt;/a&gt;. The rest is history: Prometheus made it to &lt;a href=&quot;https://news.ycombinator.com/item?id=8995696&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;#1 on Hacker News&lt;/a&gt; and hit a nerve in a world where early Kubernetes users were looking for a monitoring system to go along with the shift to more dynamic computing environments. Ex-Googlers also immediately spotted the uncanny resemblance of Prometheus to Borgmon and were happy to find similar technology outside of Google. Adoption skyrocketed, the Prometheus team grew over the years, and the project joined the &lt;a href=&quot;https://www.cncf.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;CNCF&lt;/a&gt; as the second project after Kubernetes. Prometheus released a 1.0 and then a 2.0 version, became mature, efficient, and feature-rich, and has now become the de-facto standard for metrics-based instrumentation in the world. Even the large cloud companies such as Amazon, Google, and Microsoft now offer managed Prometheus-style monitoring services, and Prometheus interfaces for data collection, querying, and more can be found implemented everywhere. Overall, Prometheus has enabled an era of metrics-driven development, monitoring, and alerting, that allows for much better visibility into systems and services than solutions before it.&lt;/p&gt;
&lt;h2 id=&quot;thanks&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#thanks&quot; aria-label=&quot;thanks permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Thanks!&lt;/h2&gt;
&lt;p&gt;This journey would not have been possible without a lot of great people and organizations: A special thank you goes out to the excellent and ever-growing group of &lt;a href=&quot;https://prometheus.io/governance/#team-members&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus Team members&lt;/a&gt; that have turned Prometheus into what it is today, to the wonderful user community who are using, testing, and spreading Prometheus around the world, as well as to the CNCF and a whole ecosystem of companies (of which my company PromLabs is just one) that are pushing Prometheus-based monitoring forward in new ways. Recently, the team at Speakeasy Productions also produced the &lt;a href=&quot;https://www.youtube.com/watch?v=l1QgLtCkqxk&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Inside Prometheus&lt;/a&gt; film, a documentary about the history of Prometheus, which I recommend watching.&lt;/p&gt;
&lt;p&gt;Finally: If you are looking to learn Prometheus from the ground up or train your engineering team, have a look at our &lt;a href=&quot;https://training.promlabs.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;self-paced Prometheus training courses&lt;/a&gt;, authored by myself as the co-founder of Prometheus.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[PromLabs and Chronosphere Open-Source the PromLens Query Builder]]></title><description><![CDATA[At PromLabs we created PromLens, the ultimate power tool for building, understanding, and visualizing PromQL queries, with the goal of…]]></description><link>https://promlabs.com/blog/2022/10/25/promlabs-and-chronosphere-open-source-the-promlens-query-builder</link><guid isPermaLink="false">https://promlabs.com/blog/2022/10/25/promlabs-and-chronosphere-open-source-the-promlens-query-builder</guid><pubDate>Tue, 25 Oct 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;At PromLabs we created &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;, the ultimate power tool for building, understanding, and visualizing PromQL queries, with the goal of helping users get the most out of PromQL-compatible monitoring solutions. A year ago, we partnered with &lt;a href=&quot;https://chronosphere.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&lt;/a&gt;, a SaaS observability solution, to bring &lt;a href=&quot;/blog/2021/11/04/bringing-the-promlens-fire-to-chronosphere-users&quot;&gt;PromLens-powered PromQL query building capabilities&lt;/a&gt; to all Chronosphere users. Today we are excited to announce that Chronosphere and PromLabs are open-sourcing PromLens, donating PromLens in its entirety to the Prometheus project under the project&apos;s existing open governance.&lt;/p&gt;
&lt;h2 id=&quot;promql-and-promlens&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql-and-promlens&quot; aria-label=&quot;promql and promlens permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL and PromLens&lt;/h2&gt;
&lt;p&gt;Across the IT industry, PromQL has evolved to become the de-facto standard query language for time-series-based monitoring and alerting. While PromQL is a powerful language that allows for flexible calculations, it has a steep learning curve, and building complex queries can be a frustrating experience even for experts when the shape of the underlying data is not well understood. Last year we built &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;, a PromQL query builder, analyzer, and explainer tool that helps you learn and understand PromQL and lets you build queries much more effectively and confidently. First, PromLens helps beginners by surfacing language and syntax features in a graphical way (for example, via a form-based editor), by providing explanations of query constructs, and by showing warnings and quick-fix actions for common mistakes. Second, PromLens also assists users from beginner to expert levels in building and analyzing queries rapidly by showing what underlying data you are working with at each expression node within a query:&lt;/p&gt;
&lt;div style=&quot;max-width: 800px; margin: auto;&quot;&gt;
&lt;p&gt;&lt;img src=&quot;/images/promlens-training-screenshot.png&quot; alt=&quot;PromLens query builder screenshot&quot;&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In short, building and debugging queries using PromLens is a much more effective and enjoyable experience than using a plain text editor.&lt;/p&gt;
&lt;h2 id=&quot;donating-promlens-to-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#donating-promlens-to-prometheus&quot; aria-label=&quot;donating promlens to prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Donating PromLens to Prometheus&lt;/h2&gt;
&lt;p&gt;Until now, PromLens has only been available as a commercial product – it was neither open source nor free (when using advanced features). In collaboration with Chronosphere, we are now donating PromLens to the Prometheus project under the project&apos;s existing open governance and Apache 2 license. This means that PromLens will be available as a free, open-source tool for all Prometheus users, and we will continue to develop it as a community project.&lt;/p&gt;
&lt;p&gt;From today on, you can find the &lt;a href=&quot;https://github.com/prometheus/promlens&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;source code of PromLens on GitHub&lt;/a&gt;, and the Prometheus project will be releasing &lt;a href=&quot;https://github.com/prometheus/promlens/releases&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;binaries&lt;/a&gt; and &lt;a href=&quot;https://hub.docker.com/r/prom/promlens&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Docker images&lt;/a&gt; for PromLens on an ongoing basis. In the future we also aim to integrate PromLens&apos; query building features into the Prometheus server&apos;s own web UI, so that they are available without having to deploy and manage a separate tool. However, we still plan on maintaining PromLens as a standalone project as well, as PromLens can not only be used with native Prometheus backends, but also with any other PromQL-compatible monitoring solution. We invite everyone to contribute and help us build a great community project!&lt;/p&gt;
&lt;p&gt;For more details on the significance of the open-sourcing of PromLens, head over to &lt;a href=&quot;https://chronosphere.io/learn/chronosphere-and-promlabs-donate-promlens-to-prometheus-organization/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&apos;s announcement blog post&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-does-this-mean-for-existing-promlens-customers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-does-this-mean-for-existing-promlens-customers&quot; aria-label=&quot;what does this mean for existing promlens customers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What does this mean for existing PromLens customers?&lt;/h2&gt;
&lt;p&gt;While PromLens will be developed as a community project in the future, we will continue to support existing commercial PromLens users throughout the duration of their remaining license periods. Customers will also be able to continue using the existing Docker images during that time. However, we will not be issuing any new commercial licenses from this point on, and the commercial PromLens version will not receive further updates. If you are interested in using PromLens in the future, we highly recommend migrating to the new open source version.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;We are very excited about the open-sourcing of PromLens and are looking forward to working with the Prometheus community to continue building PromLens as a tool for PromQL query building and analysis. We hope that this will help many more people to get the most out of PromQL and Prometheus. We would also like to thank Chronosphere for making this donation possible and for their great ongoing partnership around enabling Prometheus users worldwide!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What's New in Prometheus 2.39?]]></title><description><![CDATA[Today, the Prometheus Team released Prometheus 2.39. The main highlights are a new experimental TSDB feature that allows appending old or…]]></description><link>https://promlabs.com/blog/2022/10/05/whats-new-in-prometheus-2-39</link><guid isPermaLink="false">https://promlabs.com/blog/2022/10/05/whats-new-in-prometheus-2-39</guid><pubDate>Wed, 05 Oct 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today, the Prometheus Team released &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.39.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.39&lt;/a&gt;. The main highlights are a new experimental TSDB feature that allows appending old or out-of-order data, as well as major improvements in resource usage. Besides that, there are a number of small enhancements and bug fixes. Let&apos;s take a look at the most interesting changes:&lt;/p&gt;
&lt;h2 id=&quot;experimental-out-of-order-ingestion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#experimental-out-of-order-ingestion&quot; aria-label=&quot;experimental out of order ingestion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Experimental out-of-order ingestion&lt;/h2&gt;
&lt;p&gt;Prometheus&apos; own time series database (TSDB) normally has two restrictions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Within a given time series, samples can only be appended in timestamp-based order, so an older sample cannot be ingested when there is already a newer sample for the same series.&lt;/li&gt;
&lt;li&gt;Within the TSDB as a whole, samples can only be appended that are at most one hour older than the newest sample in the TSDB.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While this usually works fine for live monitoring use cases, occasionally you might have metric producers which need to ingest out-of-order data or data older than one hour. This may be because the producer is not always connected to the network, needs to aggregate data over a longer period of time before sending it, or similar constraints. On a technical level, such producers can expose custom client-side timestamps in the metrics exposition format or use the remote write receiver in Prometheus to override Prometheus&apos; own scrape timestamp. However, Prometheus&apos; TSDB does not normally accept such samples when they are out of order or too old.&lt;/p&gt;
&lt;p&gt;Prometheus 2.39 now adds an experimental feature to allow these producers to send out-of-order data or data older than one hour. You can enable this by setting the &lt;code&gt;out_of_order_time_window&lt;/code&gt; setting in a new &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#tsdb&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;tsdb&lt;/code&gt; configuration file section&lt;/a&gt; to a non-zero value. For example, to allow out-of-order and late appends for up to one day, you could add the following to your &lt;code&gt;prometheus.yml&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;storage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;tsdb&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;out_of_order_time_window&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 1d&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that this feature is still &lt;strong&gt;EXPERIMENTAL&lt;/strong&gt; (despite not requiring a feature flag), so it may still change or be removed in the future in case there are major issues.&lt;/p&gt;
&lt;p&gt;Under the hood, this feature required implementing functionality in the TSDB to deal with the creation of TSDB blocks containing out-of-order data when needed, as well as enabling the merging of out-of-order data in queries. You can find the full details and the discussion around this feature in the &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/8535&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;GitHub feature request issue&lt;/a&gt;, the &lt;a href=&quot;https://docs.google.com/document/d/1Kppm7qL9C-BJB1j6yb6-9ObG3AbdZnFUBYPNNWwDBYM/edit&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;implementation design document&lt;/a&gt;, and finally the &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/11075&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request to implement it&lt;/a&gt;, which multiple developers worked on collaboratively.&lt;/p&gt;
&lt;h2 id=&quot;resource-usage-improvements&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#resource-usage-improvements&quot; aria-label=&quot;resource usage improvements permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Resource usage improvements&lt;/h2&gt;
&lt;p&gt;In a series of pull requests, &lt;a href=&quot;https://github.com/bboreham&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Bryan Boreham&lt;/a&gt; went on another resource optimization spree through the Prometheus codebase. He improved the memory reuse in relabeling, optimized WAL replay handling, and removed unnecessary memory usage from TSDB head series, and turned off unnecessary transaction isolation for head compaction. While the real-world effect of this may vary a lot depending on your specific Prometheus usage, in one large use case at Grafana Labs it cut the Prometheus memory usage in half, as tweeted by &lt;a href=&quot;https://github.com/codesome&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Ganesh Vernekar&lt;/a&gt;:&lt;/p&gt;
&lt;a href=&quot;&quot;&gt;
&lt;div style=&quot;max-width: 500px; margin: auto;&quot;&gt;
&lt;p&gt;&lt;a href=&quot;https://twitter.com/_codesome/status/1577264183208398848&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;img src=&quot;/images/prometheus-2-39-memory-usage.png&quot; alt=&quot;Tweet by Ganesh showing a graph of improved memory usage&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/a&gt;
&lt;p&gt;It would be interesting to hear from others what impact they are seeing from these optimizations. Feel free to reply to &lt;a href=&quot;https://twitter.com/_codesome/status/1577264183208398848&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Ganesh&apos;s tweet&lt;/a&gt; with your observations after deploying Prometheus 2.39!&lt;/p&gt;
&lt;h2 id=&quot;other-enhancements&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-enhancements&quot; aria-label=&quot;other enhancements permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other enhancements&lt;/h2&gt;
&lt;p&gt;There are a lot of other improvements in Prometheus 2.39, such as new region metadata labels in the AWS EC2 and AWS Lightsail SD mechanisms, a metadata label for the Puppet SD that indicates the used Puppet query, allowing the copying of label matchers in the web UI when clicking on them in the expression browser&apos;s table-based time series output, and some smaller bug fixes. To see the full list of changes, check out the &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.39.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.39.0 release changelog&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Prometheus 2.39 allows ingestion of out-of-order or older data, massively improves memory usage, and adds a few other features and bug fixes. &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.39.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go try it out now&lt;/a&gt;!&lt;/p&gt;
&lt;div class=&quot;container&quot; style=&quot;text-align: center; padding: 18px; font-size: 1.15em; border: 2px solid #e65013; box-shadow: 0 2px 20px rgb(52 73 94 / 10%); border-radius: 4px; margin-top: 45px; max-width: 70%&quot;&gt;
          Want to learn Prometheus concepts from the ground up, &lt;strong&gt;taught by the co-founder of Prometheus&lt;/strong&gt;? Check out our &lt;strong&gt;
            &lt;a
              target=&quot;_blank&quot;
              href=&quot;https://training.promlabs.com/&quot;
              style=&quot;textDecoration: underline&quot;
            &gt;
              self-paced Prometheus training courses
            &lt;/a&gt;
          &lt;/strong&gt;
          .
        &lt;/div&gt;</content:encoded></item><item><title><![CDATA[Testing the PromQL Compatibility of VMware Tanzu Observability by Wavefront]]></title><description><![CDATA[In the past, we have run and reported on multiple rounds of tests to verify the level of PromQL compatibility of various vendors and…]]></description><link>https://promlabs.com/blog/2022/05/19/testing-the-promql-compatibility-of-vmware-tanzu-observability-by-wavefront</link><guid isPermaLink="false">https://promlabs.com/blog/2022/05/19/testing-the-promql-compatibility-of-vmware-tanzu-observability-by-wavefront</guid><pubDate>Thu, 19 May 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In the past, we have run and reported on multiple rounds of tests to verify the level of PromQL compatibility of various vendors and projects:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Our &lt;a href=&quot;/blog/2020/08/06/comparing-promql-correctness-across-vendors&quot;&gt;initial comparison run&lt;/a&gt; from August 2020,&lt;/li&gt;
&lt;li&gt;Our &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors&quot;&gt;update a few months later&lt;/a&gt; from November 2020,&lt;/li&gt;
&lt;li&gt;Our &lt;a href=&quot;/blog/2021/10/14/promql-vendor-compatibility-round-three&quot;&gt;third and latest survey of the field&lt;/a&gt; from October 2021.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In our last post, we hadn&apos;t been able to fully test the &lt;a href=&quot;https://tanzu.vmware.com/observability-trial&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;VMware Tanzu Observability service by Wavefront&lt;/a&gt; yet, since the only Wavefront test account we had access to was being fed test data by an overly outdated reference Prometheus server. Since then, we have worked with engineers at VMware to establish an updated testing setup, with VMware making multiple engineering iterations on their service to improve their PromQL compatibility level along the way. In this post, we&apos;ll present the latest PromQL testing results for VMware&apos;s service.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;strong&gt;Note:&lt;/strong&gt; The testing and reporting of the results in this post are being &lt;strong&gt;sponsored by VMware&lt;/strong&gt;. Despite such support, we aim to provide compatibility testing reporting that is as neutral and fact-based as possible.&lt;/i&gt;&lt;/p&gt;
&lt;h2 id=&quot;general-notes-on-test-scores&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#general-notes-on-test-scores&quot; aria-label=&quot;general notes on test scores permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;General notes on test scores&lt;/h2&gt;
&lt;p&gt;The general notes on &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors#before-we-start-a-note-on-interpreting-test-scores&quot;&gt;interpreting test scores&lt;/a&gt; from the last testing round still apply here. Please note especially that the numeric test scores (while good to have) are &lt;em&gt;not&lt;/em&gt; alone a great indicator of the &lt;em&gt;quality&lt;/em&gt; of test failures. Manual interpretation is needed to understand the actual impact, although full Prometheus compatibility requires a 100% test score without any cross-cutting issues in any case.&lt;/p&gt;
&lt;h2 id=&quot;updates-to-the-test-query-set&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#updates-to-the-test-query-set&quot; aria-label=&quot;updates to the test query set permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Updates to the test query set&lt;/h2&gt;
&lt;p&gt;Since the last testing round, we &lt;a href=&quot;https://github.com/prometheus/compliance/pull/82&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;started allowing queries with negative offsets&lt;/a&gt; (e.g. &lt;code&gt;some_metric offset -10m&lt;/code&gt;), as &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.33.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.33&lt;/a&gt; from January 29, 2022, started allowing these too. Other than this, there have been no further changes to the test query set. Generally, the test query set still needs to be updated at some point to test the new &lt;code&gt;@&lt;/code&gt; modifier for vector selectors, which was also promoted to a stable level in Prometheus 2.33.&lt;/p&gt;
&lt;h2 id=&quot;testing-tanzu-observability-by-wavefront&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#testing-tanzu-observability-by-wavefront&quot; aria-label=&quot;testing tanzu observability by wavefront permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Testing Tanzu Observability by Wavefront&lt;/h2&gt;
&lt;p&gt;Tanzu Observability &lt;a href=&quot;https://docs.wavefront.com/wavefront_prometheus.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertises support for PromQL&lt;/a&gt;: &quot;Wavefront supports both PromQL and WQL (Wavefront Query Language) queries&quot;. This PromQL support is being built on top of Wavefront&apos;s existing query language using a transpilation approach (which is similar to New Relic). To be able to test Wavefront&apos;s compatibility level, engineers at VMware provided us access to a reference Prometheus server (version 2.34) and a Wavefront test environment into which this Prometheus server remote-writes the usual testing reference data. We were then able to run the PromQL compliance tester tool against this setup.&lt;/p&gt;
&lt;p&gt;Since Wavefront is sometimes off by 1ms when parsing floating-point start/end timestamps of queries, we added a query tweak in the tester configuration to only send full-second-aligned queries. With this tweak applied, we still noticed a number of behavioral deviations from standard PromQL:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hexadecimal scalar literals like &lt;code&gt;0x3d&lt;/code&gt; cannot be parsed.&lt;/li&gt;
&lt;li&gt;Special floating point values like &lt;code&gt;Inf&lt;/code&gt;, &lt;code&gt;-Inf&lt;/code&gt;, and &lt;code&gt;NaN&lt;/code&gt; cannot be parsed.&lt;/li&gt;
&lt;li&gt;Prometheus returns an error if a vector selector does not contain at least one matcher that does not also match an empty string (for safety reasons). For example, Prometheus would reject the query &lt;code&gt;{__name__=~&quot;.*&quot;}&lt;/code&gt;, but allow the more explicit query &lt;code&gt;{__name__=~&quot;.+&quot;}&lt;/code&gt;. Wavefront executes both of these selectors successfully, causing a test comparison mismatch. To be fair, this could be interpreted as Wavefront supporting a superset of PromQL.&lt;/li&gt;
&lt;li&gt;Wavefront does not yet support negative offsets in selectors (e.g. &lt;code&gt;my_metric offset -10m&lt;/code&gt;). Prometheus only started officially supporting negative offsets in version 2.33, so perhaps the behavior in Wavefront has not caught up yet with the latest PromQL changes.&lt;/li&gt;
&lt;li&gt;In several examples, the &lt;code&gt;topk()&lt;/code&gt; / &lt;code&gt;bottomk()&lt;/code&gt; functions return significantly different results, both in sample values and timestamps.&lt;/li&gt;
&lt;li&gt;Series staleness handling is not supported yet, so a purposefully intermittently present metric is returned throughout the query range without any gaps in Wavefront.&lt;/li&gt;
&lt;li&gt;Quantile calculations for the nonsensical target quantiles &lt;code&gt;&amp;#x3C;0&lt;/code&gt; or &lt;code&gt;&gt;1&lt;/code&gt; return &lt;code&gt;-Inf&lt;/code&gt; and &lt;code&gt;+Inf&lt;/code&gt; in Prometheus, but return an error in Wavefront.&lt;/li&gt;
&lt;li&gt;The binary operators &lt;code&gt;+&lt;/code&gt; and &lt;code&gt;*&lt;/code&gt; applied between two instant vectors yield sample values that are totally different from the ones in Prometheus.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;group_left()&lt;/code&gt; many-to-one matching modifier on a binary operator allows including a label from the &quot;one&quot; side in the result in Prometheus, but Wavefront&apos;s results don&apos;t include that label.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;==&lt;/code&gt; / &lt;code&gt;&amp;#x3C;=&lt;/code&gt; / &lt;code&gt;&gt;=&lt;/code&gt; binary operators between two vectors do not always work as expected and return empty results in examples where Prometheus produces an output.&lt;/li&gt;
&lt;li&gt;On a &lt;code&gt;/&lt;/code&gt; binary operator query example that causes a clean one-to-one match and returns results in Prometheus, Wavefront returns an error reporting that cross-joins (which should not occur in the example) are not supported.&lt;/li&gt;
&lt;li&gt;On another &lt;code&gt;/&lt;/code&gt; operator query example that causes a many-to-one match and returns valid results in Prometheus, Wavefront returns an error reporting that the output series would not be unique after dropping dimensions.&lt;/li&gt;
&lt;li&gt;Applying the &lt;code&gt;-&lt;/code&gt; unary operator to an instant vector should drop the metric name, but doesn&apos;t in Wavefront.&lt;/li&gt;
&lt;li&gt;The query &lt;code&gt;-1 ^ 2&lt;/code&gt; returns &lt;code&gt;-1&lt;/code&gt; in Prometheus, but &lt;code&gt;1&lt;/code&gt; in Wavefront, likely due to differences in operator precedence.&lt;/li&gt;
&lt;li&gt;When using the &lt;code&gt;time()&lt;/code&gt; function in a binary filtering operation together with an instant vector (e.g. &lt;code&gt;time() &gt; some_timestamp_metric&lt;/code&gt;), the output sample timestamps are off, and not all original output timesteps are returned.&lt;/li&gt;
&lt;li&gt;Range vector selectors for ranges too small to select any samples (e.g. &lt;code&gt;some_metric[1s]&lt;/code&gt;) produce empty results in Prometheus, whereas they still produce a non-empty output in Wavefront.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;last_over_time()&lt;/code&gt; function is not yet supported in Wavefront.&lt;/li&gt;
&lt;li&gt;Many of the test queries produce special float values like &lt;code&gt;Inf&lt;/code&gt; or &lt;code&gt;NaN&lt;/code&gt; as output sample values, but samples with these values are filtered out in Wavefront, yielding empty result sets.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;delta()&lt;/code&gt;, &lt;code&gt;rate()&lt;/code&gt;, and &lt;code&gt;increase()&lt;/code&gt; functions return very similar, but not always identical results as in Prometheus.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;label_replace()&lt;/code&gt; function calls with invalid target label names or invalid regular expressions fail in Prometheus, but are executed successfully in Wavefront.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;clamp()&lt;/code&gt; function is not yet supported in Wavefront, although &lt;code&gt;clamp_min()&lt;/code&gt; and &lt;code&gt;clamp_max()&lt;/code&gt; are.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;changes()&lt;/code&gt; function sometimes reports a value that is too large by &lt;code&gt;1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;histogram_quantile()&lt;/code&gt; function returns similar, but not identical values to Prometheus, and it does not remove the input metric name when it should.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;count_values()&lt;/code&gt; function is not yet supported in Wavefront.&lt;/li&gt;
&lt;li&gt;A test subquery example with an offset applied returns similar, but different results in Wavefront.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Overall, the service passed &lt;strong&gt;78.10%&lt;/strong&gt; of tests after applying the described input timestamp query tweak. The exact test score varies by a few percent on each run, depending on the exact data covered.&lt;/p&gt;
&lt;p&gt;The only other transpilation-based approach to creating a PromQL-like interface is &lt;a href=&quot;https://newrelic.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;New Relic&lt;/a&gt;, which received a 27.18% score in our &lt;a href=&quot;/blog/2021/10/14/promql-vendor-compatibility-round-three&quot;&gt;last test run from October 2021&lt;/a&gt;. This currently places Wavefront (78.10%) first in the transpilation-based implementation category.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In this post, we looked at the PromQL compatibility of the Tanzu Observability by Wavefront service. While Wavefront already passes the majority of tests, the service still has a number of significant behavioral differences to Prometheus. We are looking forward to VMware continually improving their service&apos;s compatibility over time.&lt;/p&gt;
&lt;p&gt;To view all test results, head to our &lt;a href=&quot;/promql-compliance-tests&quot;&gt;PromQL Compliance Tests&lt;/a&gt; page, also available from our &quot;Resources&quot; menu item at the top of the page.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What's New in Prometheus 2.33?]]></title><description><![CDATA[Today, the Prometheus Team released Prometheus 2.33. While there are only a few completely new features, this release promotes multiple…]]></description><link>https://promlabs.com/blog/2022/01/30/whats-new-in-prometheus-2-33</link><guid isPermaLink="false">https://promlabs.com/blog/2022/01/30/whats-new-in-prometheus-2-33</guid><pubDate>Sun, 30 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today, the Prometheus Team released &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.33.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.33&lt;/a&gt;. While there are only a few completely new features, this release promotes multiple important experimental features to a stable state. It also improves on existing functionality in Prometheus. Let&apos;s take a look at the most interesting changes:&lt;/p&gt;
&lt;h2 id=&quot;promql-queries-can-now-officially-look-into-the-future&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql-queries-can-now-officially-look-into-the-future&quot; aria-label=&quot;promql queries can now officially look into the future permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL queries can now officially look into the future&lt;/h2&gt;
&lt;p&gt;For the longest time it was a simple-to-remember truth that PromQL expressions could only look into the past, relative to their overall evaluation timestamp (whether that was a single timestamp such as in an instant query or a set of subsequent timestamps at regular resolution steps of a range query). As covered in &lt;a href=&quot;/blog/2020/07/02/selecting-data-in-promql&quot;&gt;our blog post about data selection behavior in PromQL&lt;/a&gt;, the underlying reason for this was that both instant and range vector selectors were only ever allowed to look backwards from their evaluation timestamp and could never look into the future, and there are no other constructs in PromQL that select data from the TSDB.&lt;/p&gt;
&lt;p&gt;This officially changes now with the release of Prometheus 2.33, which stabilizes two experimental PromQL features that break this law:&lt;/p&gt;
&lt;h3 id=&quot;anchoring-selectors-to-absolute-timestamps-via-the--modifier&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#anchoring-selectors-to-absolute-timestamps-via-the--modifier&quot; aria-label=&quot;anchoring selectors to absolute timestamps via the  modifier permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Anchoring selectors to absolute timestamps via the &lt;code&gt;@&lt;/code&gt; modifier&lt;/h3&gt;
&lt;p&gt;A few years ago already, Prometheus 2.25 had introduced an experimental &lt;code&gt;@&lt;/code&gt; modifier that allows anchoring a selector such as &lt;code&gt;mymetric&lt;/code&gt; or &lt;code&gt;mymetric[5m]&lt;/code&gt; to an absolute timestamp, e.g. &lt;code&gt;mymetric @ &amp;#x3C;mycustomtimestamp&gt;&lt;/code&gt; or &lt;code&gt;mymetric[5m] @ &amp;#x3C;mycustomtimestamp&gt;&lt;/code&gt;. With this modifier added to a selector, the selector looks back relative from the provided &lt;em&gt;absolute timestamp&lt;/em&gt;, rather than from the current resolution time step. A &lt;a href=&quot;https://prometheus.io/blog/2021/02/18/introducing-the-@-modifier/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;post on the Prometheus blog&lt;/a&gt; covered the reasoning for this feature in more detail, with the prime use case being the ability to show a stable &lt;code&gt;topk()&lt;/code&gt; result over an entire graph range. Until now, this experimental feature had to be explicitly enabled via a flag.&lt;/p&gt;
&lt;p&gt;In Prometheus 2.33, the &lt;code&gt;@&lt;/code&gt; modifier was declared stable and is now always enabled. This means that anyone who wants to cache PromQL query results needs to take into account that results for past evaluation timestamps are not necessarily fixed anymore, since queries may select future data, which may still change as data points are actually coming in for that time range.&lt;/p&gt;
&lt;h3 id=&quot;looking-into-the-future-with-negative-offsets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#looking-into-the-future-with-negative-offsets&quot; aria-label=&quot;looking into the future with negative offsets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Looking into the future with negative offsets&lt;/h3&gt;
&lt;p&gt;Back in 2.26, Prometheus added the &lt;a href=&quot;/blog/2021/04/01/whats-new-in-prometheus-2-26#negative-offsets&quot;&gt;experimental ability to add negative offsets to vector selectors&lt;/a&gt;. Up until now, this feature had to be enabled using a flag to allow writing selectors like &lt;code&gt;mymetric offset -10m&lt;/code&gt; that select data from 10 minutes in the future relative to the evaluation timestamp. Without this feature, you were only allowed to write positive offsets that looked backwards.&lt;/p&gt;
&lt;p&gt;Prometheus 2.33 now marks this feature as stable, removing the need for a feature flag and thus introducing a second permanent PromQL feature that allows a query to look into the future.&lt;/p&gt;
&lt;h2 id=&quot;remote-write-receiver-marked-stable&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remote-write-receiver-marked-stable&quot; aria-label=&quot;remote write receiver marked stable permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remote write receiver marked stable&lt;/h2&gt;
&lt;p&gt;While Prometheus is primarily a pull-based monitoring system, there are occasional use cases for pushing data &lt;em&gt;to&lt;/em&gt; a Prometheus server from a remote-write-protocol &lt;em&gt;sender&lt;/em&gt; (often this will be another Prometheus server, as sending data via remote write requires some level of data pre-processing and batching to work as intended). Prometheus 2.25 originally added support for a remote write receiver in the Prometheus server itself, but it was still marked experimental and had to be enabled using the feature flag &lt;code&gt;--enable-feature=remote-write-receiver&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Prometheus 2.33 now promotes this remote write receiver feature to stable as well, guaranteeing that it will not be removed from Prometheus (at least until Prometheus 3.x happens one day). Since the remote write receiver allows changing the Prometheus server&apos;s state over the network, you will still need to explicitly enable it with a command-line flag, which is now called &lt;code&gt;--web.enable-remote-write-receiver&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;better-performance-and-search-ui-for-targets-service-discovery-and-alerts-pages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#better-performance-and-search-ui-for-targets-service-discovery-and-alerts-pages&quot; aria-label=&quot;better performance and search ui for targets service discovery and alerts pages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Better performance and search UI for targets, service discovery, and alerts pages&lt;/h2&gt;
&lt;p&gt;In the React UI that was introduced a few years ago, the rendering performance for the &lt;code&gt;/targets&lt;/code&gt;, &lt;code&gt;/service-discovery&lt;/code&gt;, and &lt;code&gt;/alerts&lt;/code&gt; pages could sometimes get really slow when a Prometheus server had thousands of targets or alerting rules configured that needed to be shown. Prometheus 2.33 makes rendering for these pages much faster by not showing all items upon the initial page load, but introducing infinite scrolling with on-demand rendering when item lists exceed a certain length. With this change, these pages load much faster for large setups now.&lt;/p&gt;
&lt;p&gt;One downside of not rendering all list items at once is that this hurts full-page searchability using &lt;code&gt;&amp;#x3C;Ctrl&gt;+F&lt;/code&gt;. To still make it easy to search in the target and alert lists, &lt;a href=&quot;https://twitter.com/nexucis&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Augustin Husson&lt;/a&gt; also added a search bar to the top of those pages that allows filtering of the shown results:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/filtered-targets.png&quot; alt=&quot;Filtered target list&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;other-enhancements&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-enhancements&quot; aria-label=&quot;other enhancements permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other enhancements&lt;/h2&gt;
&lt;p&gt;There are a lot of other improvements in Prometheus 2.33, such as better cardinality analysis in &lt;code&gt;promtool&lt;/code&gt;, a new template language function, new Kubernetes service discovery features, enhanced efficiency of the remote write and TSDB layers, and plenty of smaller bug fixes. To see the full list of changes, check out the &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.33.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.33.0 release changelog&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Prometheus 2.33 promotes a couple of interesting features to the stable level and adds a lot of enhancements around performance, both on the UI side and the server side. &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.33.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go try it out now&lt;/a&gt;!&lt;/p&gt;
&lt;div class=&quot;container&quot; style=&quot;text-align: center; padding: 18px; font-size: 1.15em; border: 2px solid #e65013; box-shadow: 0 2px 20px rgb(52 73 94 / 10%); border-radius: 4px; margin-top: 45px; max-width: 70%&quot;&gt;
          Want to learn Prometheus concepts from the ground up, &lt;strong&gt;taught by the co-founder of Prometheus&lt;/strong&gt;? Check out our &lt;strong&gt;
            &lt;a
              target=&quot;_blank&quot;
              href=&quot;https://training.promlabs.com/&quot;
              style=&quot;textDecoration: underline&quot;
            &gt;
              self-paced Prometheus training courses
            &lt;/a&gt;
          &lt;/strong&gt;
          .
        &lt;/div&gt;</content:encoded></item><item><title><![CDATA[Bringing the PromLens Fire to Chronosphere Users]]></title><description><![CDATA[At PromLabs we created PromLens, the ultimate power tool for building, understanding, and visualizing PromQL queries, with the goal of…]]></description><link>https://promlabs.com/blog/2021/11/04/bringing-the-promlens-fire-to-chronosphere-users</link><guid isPermaLink="false">https://promlabs.com/blog/2021/11/04/bringing-the-promlens-fire-to-chronosphere-users</guid><pubDate>Thu, 04 Nov 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;At PromLabs we created &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;, the ultimate power tool for building, understanding, and visualizing &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/basics/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL&lt;/a&gt; queries, with the goal of helping users get the most out of PromQL-compatible monitoring solutions. Today we are happy to announce that we partnered with &lt;a href=&quot;https://chronosphere.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&lt;/a&gt;, a SaaS observability solution, to bring PromQL &lt;a href=&quot;https://chronosphere.io/learn/announcing-query-builder-to-supercharge-your-promql/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;query building capabilities&lt;/a&gt;, powered by PromLens, to all Chronosphere users.&lt;/p&gt;
&lt;h2 id=&quot;promql-and-promlens&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql-and-promlens&quot; aria-label=&quot;promql and promlens permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL and PromLens&lt;/h2&gt;
&lt;p&gt;Across the IT industry, PromQL is becoming the standard query language for time-series-based monitoring and alerting. While PromQL is a powerful language that allows for flexible calculations, it has a daunting learning curve and comes with a few sharp edges and pitfalls. Last year we built &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;, a query builder, analyzer, and explainer tool that helps you learn and understand PromQL and lets you build queries much more effectively and confidently. On one hand, PromLens helps beginners by surfacing language and syntax features in a graphical way (for example, via a form-based editor), by providing explanations of query constructs, and by showing warnings and quick-fix actions for common mistakes. On the other hand, PromLens also assists experts in building and analyzing queries rapidly by showing what underlying data is available at each expression node of a query:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/histogram-missing-le.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;So far, the only way to gain access to these query building and analyzing features for PromQL was to purchase PromLens as a stand-alone tool and deploy it on your own infrastructure. This changes today with Chronosphere&apos;s integration of query building and analysis capabilities in their platform.&lt;/p&gt;
&lt;h2 id=&quot;chronosphere-and-promql&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#chronosphere-and-promql&quot; aria-label=&quot;chronosphere and promql permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Chronosphere and PromQL&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://chronosphere.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&lt;/a&gt; is a SaaS observability and monitoring platform that allows users to store Prometheus-compatible data and query it using PromQL. Notably, Chronosphere is also one of the few services that achieved a full &lt;strong&gt;100% compatibility score&lt;/strong&gt; in our &lt;a href=&quot;/blog/2021/10/14/promql-vendor-compatibility-round-three&quot;&gt;recent round of PromQL compatibility tests&lt;/a&gt; and is generally committed to compatibility with the Prometheus ecosystem.&lt;/p&gt;
&lt;p&gt;Today we are happy to announce that we have worked together with Chronosphere to bring advanced PromQL query building features to the platform&apos;s users. The new Chronosphere feature, called Query Builder, is rooted in PromLens technology and will enable users of the platform to enjoy many of the same benefits that PromLens brings: faster analysis of queries, form-based editing, quick explanations of query constructs, and more. This makes Chronosphere the first platform to offer a fully-fledged visual PromQL query builder to their users.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/chronosphere-query-builder.png&quot; alt=&quot;Chronosphere Query Builder screenshot&quot;&gt;&lt;/p&gt;
&lt;p&gt;Head over to &lt;a href=&quot;https://chronosphere.io/learn/announcing-query-builder-to-supercharge-your-promql/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&apos;s announcement blog post&lt;/a&gt; for more details about the new Query Builder feature!&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;PromLens is an immensely useful tool for understanding, building, and analyzing PromQL queries. With Chronosphere&apos;s new Query Builder feature, all users of their service will also gain access to powerful PromQL query editing features, enabling them to work much more effectively with the language. Stay tuned for future enhancements in this space!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[PromQL Vendor Compatibility, Round Three]]></title><description><![CDATA[Time for round three of our PromQL compatibility tests! In two previous blog posts, we compared PromQL correctness across vendors and then…]]></description><link>https://promlabs.com/blog/2021/10/14/promql-vendor-compatibility-round-three</link><guid isPermaLink="false">https://promlabs.com/blog/2021/10/14/promql-vendor-compatibility-round-three</guid><pubDate>Thu, 14 Oct 2021 00:00:00 GMT</pubDate><content:encoded>&lt;div style=&quot;background-color: #f6f6f6; padding: 20px 20px 0 20px; margin-bottom: 25px;&quot;&gt;
&lt;i&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; See the details of all PromQL compliance test results on our &lt;a href=&quot;/promql-compliance-tests&quot;&gt;PromQL Compliance Test Results page&lt;/a&gt; or in the table below:&lt;/i&gt;
&lt;table class=&quot;mt-3 table&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Test target&lt;/th&gt;&lt;th&gt;Passing&lt;/th&gt;&lt;th&gt;Cross-cutting issues&lt;/th&gt;&lt;th&gt;More details&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://aws.amazon.com/prometheus/&quot;&gt;Amazon Managed Service for Prometheus&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;596 / 596 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/amp&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://chronosphere.io/&quot;&gt;Chronosphere&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;596 / 596 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/chronosphere&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://cortexmetrics.io/&quot;&gt;Cortex&lt;/a&gt;&lt;/strong&gt; (v1.10.0)&lt;/td&gt;&lt;td&gt;596 / 596 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/cortex&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://cloud.google.com/stackdriver/docs/managed-prometheus&quot;&gt;Google Cloud Managed Service for Prometheus&lt;/a&gt;&lt;/strong&gt; (hosted preview)&lt;/td&gt;&lt;td&gt;517 / 548 cases (&lt;strong&gt;94.34%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/gmp&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://grafana.com/products/cloud/&quot;&gt;Grafana Cloud&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;548 / 548 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/grafanacloud&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://m3db.io/&quot;&gt;M3&lt;/a&gt;&lt;/strong&gt; (v1.3.0)&lt;/td&gt;&lt;td&gt;596 / 596 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/m3&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://newrelic.com/&quot;&gt;New Relic&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;162 / 596 cases (&lt;strong&gt;27.18%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/newrelic&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/timescale/promscale&quot;&gt;Promscale&lt;/a&gt;&lt;/strong&gt; (0.6.2)&lt;/td&gt;&lt;td&gt;596 / 596 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/promscale&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://sysdig.com/products/monitor/&quot;&gt;Sysdig Monitor&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;594 / 596 cases (&lt;strong&gt;99.66%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/sysdig&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://thanos.io/&quot;&gt;Thanos&lt;/a&gt;&lt;/strong&gt; (v0.23.1)&lt;/td&gt;&lt;td&gt;596 / 596 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/thanos&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://victoriametrics.com/&quot;&gt;VictoriaMetrics&lt;/a&gt;&lt;/strong&gt; (v1.67.0)&lt;/td&gt;&lt;td&gt;442 / 596 cases (&lt;strong&gt;74.16%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2021-10-14/victoriametrics&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Time for round three of our PromQL compatibility tests! In two previous blog posts, we &lt;a href=&quot;/blog/2020/08/06/comparing-promql-correctness-across-vendors&quot;&gt;compared PromQL correctness across vendors&lt;/a&gt; and then provided &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors&quot;&gt;an update a few months later&lt;/a&gt;. Using an &lt;a href=&quot;https://github.com/prometheus/compliance/tree/main/promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;open-source compliance checker tool&lt;/a&gt;, we evaluated each implementation by running a set of test queries against both the native Prometheus server and the vendor implementation. As a result, we found multiple bugs in the tested projects and mapped out in detail how each deviated from the upstream implementation.&lt;/p&gt;
&lt;p&gt;By now, even more vendors have entered the PromQL space and existing projects have evolved. Today, we are presenting an updated set of PromQL test results both for existing projects and a couple of new players. To allow for some leeway, we only tested for features that were available at least two Prometheus minor versions ago (in Prometheus &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.28.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v2.28.0&lt;/a&gt;). This is in line with what the official &lt;a href=&quot;https://prometheus.io/blog/2021/05/03/introducing-prometheus-conformance-program/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus Conformance Program&lt;/a&gt; requires of vendors to be certified as PromQL-compliant. To be clear, the results in this blog post do not represent official Prometheus Conformance Program results, which will be discussed by &lt;a href=&quot;https://kccncna2021.sched.com/speaker/richih&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Richard &quot;RichiH&quot; Hartmann&lt;/a&gt; in his &lt;a href=&quot;https://kccncna2021.sched.com/event/lV2v/the-prometheus-conformance-program-richard-hartmann-grafana-labs&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;KubeCon Talk&lt;/a&gt; later today.&lt;/p&gt;
&lt;h2 id=&quot;general-notes-on-test-scores-and-vendor-inclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#general-notes-on-test-scores-and-vendor-inclusion&quot; aria-label=&quot;general notes on test scores and vendor inclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;General notes on test scores and vendor inclusion&lt;/h2&gt;
&lt;p&gt;The general notes on &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors#before-we-start-a-note-on-interpreting-test-scores&quot;&gt;interpreting test scores&lt;/a&gt; and &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors#criteria-for-including-a-vendor-in-tests&quot;&gt;inclusion of vendors&lt;/a&gt; from the last testing round still apply. Please note especially that the numeric test scores (while good to have) are &lt;em&gt;not&lt;/em&gt; alone a great indicator of the &lt;em&gt;quality&lt;/em&gt; of test failures. Manual interpretation is needed to understand the actual impact, although full Prometheus compatibility requires a 100% test score without any cross-cutting issues in any case.&lt;/p&gt;
&lt;h2 id=&quot;updates-to-the-test-query-set&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#updates-to-the-test-query-set&quot; aria-label=&quot;updates to the test query set permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Updates to the test query set&lt;/h2&gt;
&lt;p&gt;Since the last testing round, we added some test cases to the suite, both for missing old features and for newly added PromQL features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tests for the &lt;code&gt;absent()&lt;/code&gt;, &lt;code&gt;last_over_time()&lt;/code&gt;, &lt;code&gt;absent_over_time()&lt;/code&gt;, &lt;code&gt;clamp()&lt;/code&gt;, and &lt;code&gt;sgn()&lt;/code&gt; functions.&lt;/li&gt;
&lt;li&gt;Tests for the &lt;code&gt;count_values()&lt;/code&gt; aggregator.&lt;/li&gt;
&lt;li&gt;Tests for composite duration literals (e.g. &lt;code&gt;1h5m15s&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We did &lt;em&gt;not&lt;/em&gt; yet add any tests that expect experimental PromQL features that need to be enabled using a feature flag in Prometheus (like negative offsets or the &lt;code&gt;@&lt;/code&gt;-modifier), as we don&apos;t see these features as an official part of the language yet until they become stable and enabled by default.&lt;/p&gt;
&lt;h2 id=&quot;lets-get-started-updated-comparisons&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lets-get-started-updated-comparisons&quot; aria-label=&quot;lets get started updated comparisons permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Let&apos;s get started: Updated comparisons&lt;/h2&gt;
&lt;p&gt;In this round of tests, we took a look at the following projects and vendors, in alphabetical order:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://aws.amazon.com/prometheus/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Amazon Managed Service for Prometheus&lt;/a&gt; - A hosted Prometheus-style service by AWS.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://chronosphere.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&lt;/a&gt; - A hosted monitoring and observability platform.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cortexmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt; - An open-source, horizontally scalable reimplementation of Prometheus.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cloud.google.com/stackdriver/docs/managed-prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Google Cloud Managed Service for Prometheus&lt;/a&gt; - A hosted (preview) Prometheus-style service by Google.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://grafana.com/products/cloud/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana Cloud&lt;/a&gt; - A hosted monitoring and observability service.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://m3db.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;M3&lt;/a&gt; - An open-source metrics engine and time series database.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://newrelic.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;New Relic&lt;/a&gt; - A hosted monitoring and observability service.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/timescale/promscale&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Promscale&lt;/a&gt; (&lt;a href=&quot;https://www.timescale.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;TimescaleDB&lt;/a&gt;) - An open-source project to store Prometheus data in TimescaleDB.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://sysdig.com/products/monitor/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Sysdig Monitor&lt;/a&gt; - A hosted monitoring and observability platform.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://thanos.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Thanos&lt;/a&gt; - An open-source project to provide query aggregation for long-term storage and HA on top of Prometheus.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://victoriametrics.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;VictoriaMetrics&lt;/a&gt; - An open-source time-series database and monitoring system.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.wavefront.com/wavefront_introduction.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Wavefront by VMWare&lt;/a&gt; - A hosted monitoring and observability platform.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For Wavefront, we are only publishing a preliminary look and no full test scores for now, as we didn&apos;t manage to get access to a full and up-to-date test environment in time for this blog post.&lt;/p&gt;
&lt;p&gt;Note that we are no longer including &lt;a href=&quot;https://www.metricfire.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;MetricFire&lt;/a&gt; in our tests, as they have discontinued their Prometheus service offering for the time being.&lt;/p&gt;
&lt;p&gt;Let&apos;s look at the test results for each of these systems:&lt;/p&gt;
&lt;h3 id=&quot;amazon-managed-service-for-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#amazon-managed-service-for-prometheus&quot; aria-label=&quot;amazon managed service for prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Amazon Managed Service for Prometheus&lt;/h3&gt;
&lt;p&gt;As a new entrant to the Prometheus space, AWS launched their Cortex-based &lt;a href=&quot;https://aws.amazon.com/prometheus/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Amazon Managed Service for Prometheus&lt;/a&gt; (AMP) shortly after our last round of tests. While testing, we noticed that AMP modifies incoming query start and end timestamps to align them to a multiple of the resolution step to achieve better cacheability (similar to Grafana Cloud initially). Unfortunately, this slightly modifies the query semantics, requiring a query tweak as a workaround for further comparisons. The AMP team has been made aware of this issue and we are hoping for them to deactivate the timestamp alignment in the future to achieve full compatibility.&lt;/p&gt;
&lt;p&gt;With a query tweak applied to only send step-aligned test queries, AMP achieved a test score of &lt;strong&gt;100%&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;chronosphere&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#chronosphere&quot; aria-label=&quot;chronosphere permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Chronosphere&lt;/h3&gt;
&lt;p&gt;Similar to last time, Chronosphere provided us with a test account to their service and again achieved a test score of &lt;strong&gt;100%&lt;/strong&gt; without requiring any query tweaks for cross-cutting issues.&lt;/p&gt;
&lt;h3 id=&quot;cortex&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cortex&quot; aria-label=&quot;cortex permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cortex&lt;/h3&gt;
&lt;p&gt;This time around we opted to ignore the deprecated chunks storage mode in Cortex and only tested the &lt;a href=&quot;https://cortexmetrics.io/docs/blocks-storage/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;blocks storage mode&lt;/a&gt;. Cortex again received a test score of &lt;strong&gt;100%&lt;/strong&gt; without any cross-cutting issues for this case.&lt;/p&gt;
&lt;h3 id=&quot;google-managed-service-for-prometheus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#google-managed-service-for-prometheus&quot; aria-label=&quot;google managed service for prometheus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Google Managed Service for Prometheus&lt;/h3&gt;
&lt;p&gt;Google just launched a preview of its &lt;a href=&quot;https://cloud.google.com/stackdriver/docs/managed-prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Google Cloud Managed Service for Prometheus&lt;/a&gt; (GMP) a few days ago, and we already managed to get early access. According to contacts at Google, the service is internally backed by Google&apos;s &lt;a href=&quot;https://www.vldb.org/pvldb/vol13/p3181-adams.pdf&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Monarch monitoring system&lt;/a&gt;. It mostly uses Prometheus&apos;s own query engine code to compute PromQL results, but it replaces certain PromQL query subtrees entirely by native Monarch evaluations (such as &lt;code&gt;rate()&lt;/code&gt; and &lt;code&gt;*_over_time()&lt;/code&gt; function computations, as well as dimensional aggregation operators). To ingest predictable test data into the service from a local machine, we used &lt;a href=&quot;https://github.com/GoogleCloudPlatform/prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Google&apos;s Prometheus fork&lt;/a&gt;, as GMP does not support Prometheus&apos;s native &lt;code&gt;remote_write&lt;/code&gt; protocol for ingestion yet.&lt;/p&gt;
&lt;p&gt;When running the tester against Google&apos;s service, we observed a number of issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Staleness handling is not yet supported, so metrics that end mid-air in Prometheus still get returned for a period of 5 minutes in GMP. According to Google, staleness handling support is planned for 2022.&lt;/li&gt;
&lt;li&gt;The calculation of the &lt;code&gt;rate()&lt;/code&gt; function is entirely delegated to Monarch&apos;s own rate calculation implementation, which produces slightly different results.&lt;/li&gt;
&lt;li&gt;Some newer PromQL features (like the &lt;code&gt;group()&lt;/code&gt; aggregator, newer functions like &lt;code&gt;sgn()&lt;/code&gt;, &lt;code&gt;clamp()&lt;/code&gt;, etc., and composite durations) are not supported yet. This should be fixed &quot;automatically&quot; as Google updates its internal PromQL engine dependency.&lt;/li&gt;
&lt;li&gt;The function &lt;code&gt;last_over_time()&lt;/code&gt; drops the metric name in GMP, but doesn&apos;t in Prometheus.&lt;/li&gt;
&lt;li&gt;Initially, some queries failed randomly with the error &lt;code&gt;&quot;parse error: unknown node type: *parser.MatrixSelector&quot;&lt;/code&gt;, but Google remedied this problem by taking some internal infrastructure measures.&lt;/li&gt;
&lt;li&gt;...and a few other minor query differences.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Overall, Google&apos;s GMP achieved a test score of &lt;strong&gt;94.34%&lt;/strong&gt; without any query tweaks.&lt;/p&gt;
&lt;h3 id=&quot;grafana-cloud&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#grafana-cloud&quot; aria-label=&quot;grafana cloud permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Grafana Cloud&lt;/h3&gt;
&lt;p&gt;Similar to last time, the Cortex-based Grafana Cloud service still initially aligned the query start and end timestamps to the resolution step to achieve better cacheability of queries and required a query tweak to work around this behavioral difference. However, Grafana Labs corrected this issue shortly before we published this blog post. After that fix, we got a test score of &lt;strong&gt;100%&lt;/strong&gt; for Grafana Cloud without any cross-cutting issues.&lt;/p&gt;
&lt;h3 id=&quot;m3&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#m3&quot; aria-label=&quot;m3 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;M3&lt;/h3&gt;
&lt;p&gt;For M3, we tested version &lt;a href=&quot;https://github.com/m3db/m3/releases/tag/v1.3.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v1.3.0&lt;/a&gt; this time. Similar to last time, M3 again received a test score of &lt;strong&gt;100%&lt;/strong&gt; without any cross-cutting issues.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For PromQL to work 100% the same as in Prometheus, we had to ensure that our test queries were only hitting raw, non-aggregated data in M3 (vs. data that has been downsampled into a lower resolution). We did this by not configuring any aggregation in our test M3 database.&lt;/p&gt;
&lt;h3 id=&quot;new-relic&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-relic&quot; aria-label=&quot;new relic permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New Relic&lt;/h3&gt;
&lt;p&gt;We tested New Relic at a score of 31.05% last time, and it seems like the &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors#new-relic&quot;&gt;same issues discussed then&lt;/a&gt; are still valid today. Additionally, a few more queries are now failing due to our expansion of the test query set:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Composite duration strings like &lt;code&gt;10m15s&lt;/code&gt; are not yet supported by New Relic.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;group()&lt;/code&gt; aggregator, &lt;code&gt;sgn()&lt;/code&gt; function, &lt;code&gt;clamp()&lt;/code&gt; function, and several other new features are not supported yet.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In our testing, New Relic received an overall score of &lt;strong&gt;27.18%&lt;/strong&gt; this time.&lt;/p&gt;
&lt;h3 id=&quot;promscale-timescaledb&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promscale-timescaledb&quot; aria-label=&quot;promscale timescaledb permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Promscale (TimescaleDB)&lt;/h3&gt;
&lt;p&gt;This time we tested Promscale &lt;a href=&quot;https://github.com/timescale/promscale/releases/tag/0.6.2&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;0.6.2&lt;/a&gt;. Initially the tests uncovered a bug in the metrics caching layer of Promscale 0.6.1 that was &lt;a href=&quot;https://github.com/timescale/promscale/pull/801&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;promptly fixed&lt;/a&gt; by the Timescale team in Promscale 0.6.2. After this fix, Promscale again received a score of &lt;strong&gt;100%&lt;/strong&gt; without any cross-cutting issues.&lt;/p&gt;
&lt;h3 id=&quot;sysdig-monitor&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sysdig-monitor&quot; aria-label=&quot;sysdig monitor permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sysdig Monitor&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.sysdig.com/en/docs/sysdig-monitor/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Sysdig Monitor&lt;/a&gt; is a cloud-based monitoring service that &lt;a href=&quot;https://docs.sysdig.com/en/using-promql.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertises PromQL support&lt;/a&gt;. Since the &lt;a href=&quot;https://promlabs.com/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;last round of PromQL tests&lt;/a&gt;, Sysdig has added support for ingesting data via the Prometheus &lt;code&gt;remote_write&lt;/code&gt; protocol, which now allows us to test Sysdig&apos;s PromQL implementation with comparable reference data and include it in the official results. Note that we have been working with the Sysdig team on the evaluation and improvement of these test results, and they are sponsoring this part of the blog post as well (thanks!).&lt;/p&gt;
&lt;p&gt;The PromQL tests uncovered a few compatibility issues with Sysdig Monitor:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Timestamp alignment&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Sysdig&apos;s time series database currently only supports storing samples in a fixed 10-second grid for external agents like Prometheus, whereas Prometheus itself usually scrapes and stores samples at arbitrary unaligned timestamps with millisecond precision. To deal with this mismatch in expectations, Sysdig aligns all samples coming from Prometheus to this 10-second grid and discards any duplicate samples within an interval. To factor out the cross-cutting query differences resulting from this limitation, we patched the ingesting reference Prometheus server to align ingested samples to the same grid as Sysdig. We also added a query tweak in the tester tool to align query start and end timestamps to their 10-second resolution step. The Sysdig team is aware of this issue and is working towards providing more flexible sample timestamp support in the future.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fixed bug around inequality matching&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The tests originally found a bug in the handling of negative equality label matchers (&lt;code&gt;!=&lt;/code&gt;) that caused missing output series, which the Sysdig team promptly fixed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fixed bug around &lt;code&gt;count_values()&lt;/code&gt; aggregation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The tests originally found a bug in the &lt;code&gt;count_values()&lt;/code&gt; aggregator implementation, which caused the aggregator to act as if all input series had the same sample value of &lt;code&gt;1&lt;/code&gt; (vs. many different ones). This was quickly identified and fixed by the Sysdig team.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Slight modulo operator deviation&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Lastly, and more mysteriously, a few queries that involve the modulo operator (&lt;code&gt;%&lt;/code&gt;) result in miniscule floating-point differences as compared to Prometheus. Neither we nor the Sysdig team have found the reason for this deviation yet, but slight differences in floating-point modulo implementations on different processors could be one possibility. Hopefully the underlying cause can be identified soon, although it is unlikely to affect real-world use cases.&lt;/p&gt;
&lt;p&gt;After applying the above-mentioned workarounds for timestamp handling, Sysdig Monitor achieved a test score of &lt;strong&gt;99.66%&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;thanos&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#thanos&quot; aria-label=&quot;thanos permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Thanos&lt;/h3&gt;
&lt;p&gt;For Thanos, we tested version &lt;a href=&quot;https://github.com/thanos-io/thanos/releases/tag/v0.23.1&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v0.23.1&lt;/a&gt; this time, which again passed &lt;strong&gt;100%&lt;/strong&gt; of all tests without any query tweaks.&lt;/p&gt;
&lt;h3 id=&quot;victoriametrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#victoriametrics&quot; aria-label=&quot;victoriametrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;VictoriaMetrics&lt;/h3&gt;
&lt;p&gt;For VictoriaMetrics, we tested version &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.67.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v1.67.0&lt;/a&gt; this time. With respect to the last round of tests, VictoriaMetrics seems to have fixed several issues in the meantime:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scalar literals in hexadecimal format (e.g. &lt;code&gt;0x3d&lt;/code&gt;) are now parsed correctly.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;quantile()&lt;/code&gt; aggregator now returns exactly the same values for cases where it returned slightly different values before.&lt;/li&gt;
&lt;li&gt;Boolean comparison operators between an instant vector and scalar (like &lt;code&gt;demo_memory_usage_bytes &gt; bool 1.2345&lt;/code&gt;) no longer return samples for resolution steps at which the metric does not exist.&lt;/li&gt;
&lt;li&gt;And possibly more...&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In a &lt;a href=&quot;https://medium.com/@romanhavronenko/victoriametrics-promql-compliance-d4318203f51e&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;recent Medium post by VictoriaMetrics co-founder Roman Khavronenko&lt;/a&gt;, VictoriaMetrics also lists differences in their MetricsQL implementation and announced their intention to never be fully PromQL-compatible (&quot;However, VictoriaMetrics is not 100% compatible with PromQL and never will be.&quot;). The article goes on to argue that the various behaviors in MetricsQL are preferrable to PromQL, a point that would likely not find complete agreement within the Prometheus Team. However, debating language design decisions is besides the point in this case, as we are looking solely at compatibility here - VictoriaMetrics still positions itself as a &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics#prominent-features&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&quot;drop-in replacement for Prometheus&quot;&lt;/a&gt; and the &lt;a href=&quot;https://docs.victoriametrics.com/MetricsQL.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;MetricsQL description&lt;/a&gt; still says &quot;MetricsQL is backwards-compatible with PromQL&quot; before going on to incompatibilities for the more attentive readers.&lt;/p&gt;
&lt;p&gt;In practice, we have repeatedly encountered users who did not read the fine print and had already adopted VictoriaMetrics, only to be surprised later on when certain PromQL functionality would not work as expected. Incompatibility also means that ecosystem resources stop working for affected users: PromQL proxies that parse and validate queries, PromQL editor language support, rule validation tools, and other software that works with and depends on exact language features. We thus encourage VictoriaMetrics to either create a PromQL-compatible language dialect or remove marketing language that causes casual readers to believe that it is both Prometheus- and PromQL-compatible. The same statement holds true for other vendors - VictoriaMetrics has just taken the most aggressive stance on intentional incompatibility so far, while at the same time capitalizing on the success of the Prometheus project, using the project&apos;s channels for (sometimes misleading) marketing, and brushing off any potential concerns relating to language features that work differently in MetricsQL.&lt;/p&gt;
&lt;p&gt;Despite the above thoughts, VictoriaMetrics achieved a &lt;strong&gt;74.16%&lt;/strong&gt; overall score in our tests this time, which is an improvement over the last round.&lt;/p&gt;
&lt;h3 id=&quot;wavefront-by-vmware&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#wavefront-by-vmware&quot; aria-label=&quot;wavefront by vmware permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Wavefront by VMWare&lt;/h3&gt;
&lt;p&gt;VMWare&apos;s Wavefront service &lt;a href=&quot;https://docs.wavefront.com/wavefront_prometheus.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertises support for PromQL&lt;/a&gt;: &quot;Wavefront supports both PromQL and WQL (Wavefront Query Language) queries&quot;. Talking to contacts at VMWare, this PromQL support is being built on top of Wavefront&apos;s existing query language, so it falls into the transpilation category (similar to New Relic&apos;s). At the time of this writing, we were only able to get access to an internal test setup running at VMWare that ingests reference data both into a Prometheus server and into Wavefront. However, the reference Prometheus server was still using Prometheus version v2.12.0 from 2019, so we were unable to run the current set of tests against it for comparisons. For this reason, we only ran an improvised set of old test cases (similar to the test cases from our previous blog posts) against the Wavefront setup and got a preliminary score of 65.22%, with various queries behaving differently (some in minor, others in major ways). We&apos;re in contact with engineers at VMWare and may publish more detailed test results for Wavefront in the future.&lt;/p&gt;
&lt;h2 id=&quot;future-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#future-work&quot; aria-label=&quot;future work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Future work&lt;/h2&gt;
&lt;p&gt;We single-handedly tested 12 different projects and vendors in this round, which frequently required a lot of back and forth to clarify and fix issues around test setups and compatibility quirks. While the results are valuable, we do not believe that this is a sustainable approach to assessing vendor PromQL compatibility in the future. The Prometheus project has recently announced a &lt;a href=&quot;https://prometheus.io/blog/2021/05/03/introducing-prometheus-conformance-program/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus Conformance Program&lt;/a&gt; that will allow projects and vendors to self-certify their solutions according to a set of guidelines. Within the Prometheus Team, we intend to allow (and require) automated testing where possible over time. We hope that the economic incentives around certified compatibility leads to more vendors assigning resources to improving the test suite as well. At PromLabs we plan to support this work and hope to make it as easy as possible for vendors to self-certify themselves soon.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;A &lt;a href=&quot;https://twitter.com/rakyll/status/1448084198418522113&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;tweet by Jaana Dogan&lt;/a&gt; summarizes the current state of PromQL adoption across the industry well:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&quot;PostgreSQL for relational. PromQL for monitoring. Two big alignments across the industry.&quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The monitoring world is largely converging on PromQL as the standard for time-series based monitoring. Even more vendors are offering PromQL-style services now than last time, with even two of the major cloud providers (AWS and Google) throwing their hat into the ring. The more PromQL becomes the &quot;lingua franca&quot; of monitoring, the more important interoperability becomes, and users will come to expect interchangeable services and portability. As we have seen, there is still a lot of variability in the quality of PromQL support between vendors, and often unfortunately a big gap between marketing claims and reality. We hope that our ongoing testing efforts help by shining a light on these differences. We believe that compatibility with the native PromQL API is important for the Prometheus ecosystem, and we thus also encourage vendors to work towards becoming fully compliant when using the term &quot;PromQL&quot; to advertise their systems.&lt;/p&gt;
&lt;p&gt;To view all test results, head to our &lt;a href=&quot;/promql-compliance-tests&quot;&gt;PromQL Compliance Tests&lt;/a&gt; page, also available from our &quot;Resources&quot; menu item at the top of the page.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;At this point, we would like to thank our ongoing sponsors &lt;a href=&quot;https://timescale.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Timescale&lt;/a&gt; and &lt;a href=&quot;https://it.schwarz/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Schwarz IT&lt;/a&gt; for supporting PromLabs&apos; general Prometheus community and open-source work. While Timescale (via Promscale) is also a vendor that is being evaluated in the tests above, we do our best to provide neutral and objective compatibility testing results, independent of any such support.&lt;/em&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What's New in Prometheus 2.30?]]></title><description><![CDATA[Today, the Prometheus Team released Prometheus 2.30. While this release is relatively light on major new features, it brings a number of…]]></description><link>https://promlabs.com/blog/2021/09/14/whats-new-in-prometheus-2-30</link><guid isPermaLink="false">https://promlabs.com/blog/2021/09/14/whats-new-in-prometheus-2-30</guid><pubDate>Tue, 14 Sep 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today, the Prometheus Team released &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.30.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.30&lt;/a&gt;. While this release is relatively light on major new features, it brings a number of enhancements to configurability and resource usage efficiency (in addition to some bug fixes). Let&apos;s take a look at some of the most relevant ones:&lt;/p&gt;
&lt;h2 id=&quot;faster-server-restart-times-via-snapshotting&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#faster-server-restart-times-via-snapshotting&quot; aria-label=&quot;faster server restart times via snapshotting permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Faster server restart times via snapshotting&lt;/h2&gt;
&lt;p&gt;For large Prometheus servers that track many millions of concurrent time series, a server restart can take up to multiple (or even many) minutes. This is because the Prometheus server has to rebuild its latest in-memory state for recent time series data from the write-ahead-log (WAL) on disk. This process can be quite slow because Prometheus needs to effectively replay the entire ingestion process for every sample in the WAL to reconstruct the final time series chunks in memory.&lt;/p&gt;
&lt;p&gt;Prometheus 2.30 introduces an &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/7229&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;experimental snapshotting feature&lt;/a&gt;, implemented by &lt;a href=&quot;https://github.com/codesome&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Ganesh Vernekar&lt;/a&gt; and enabled using the flag &lt;code&gt;--enable-feature=memory-snapshot-on-shutdown&lt;/code&gt;. With this feature enabled, Prometheus writes out a more raw snapshot of its current in-memory state upon shutdown, which can then be re-read into memory more efficiently when the server restarts. In first experiments with this code, it &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/7229#issuecomment-641945976&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;reduced restart times by 50-80%&lt;/a&gt; in one example.&lt;/p&gt;
&lt;p&gt;Note that Prometheus only writes out this snapshot when it completes an orderly shutdown, and not on a periodic basis during normal operation (to reduce overall write load while Prometheus is running). So this new feature only helps speed up restarts after clean shutdowns. In case of crashes or unclean shutdowns, the most recent data is still just replayed more slowly from the WAL as before.&lt;/p&gt;
&lt;h2 id=&quot;controlling-scrape-intervals-and-timeouts-via-relabeling&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#controlling-scrape-intervals-and-timeouts-via-relabeling&quot; aria-label=&quot;controlling scrape intervals and timeouts via relabeling permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Controlling scrape intervals and timeouts via relabeling&lt;/h2&gt;
&lt;p&gt;Special target labels, along with target relabeling, already allowed Prometheus users to control certain scrape behaviors, such as the address, the HTTP path, or the HTTP parameters sent along with the scrape request. In Prometheus 2.30, &lt;a href=&quot;https://github.com/LeviHarrison&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Levi Harrison&lt;/a&gt; now &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8911&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;extended this configurability to two more parameters&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Scrape intervals:&lt;/strong&gt; How frequently a target should be scraped, controlled by a new &lt;code&gt;__scrape_interval__&lt;/code&gt; meta label, e.g. &lt;code&gt;__scrape_interval__=&quot;15s&quot;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scrape timeouts:&lt;/strong&gt; How long a target scrape may take before failing, controlled by a new &lt;code&gt;__scrape_timeout__&lt;/code&gt; meta label, e.g. &lt;code&gt;__scrape_timeout__=&quot;15s&quot;&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Importantly, this now allows setting per-target scrape intervals within the same scrape configuration section, and since the behavior is controlled via target labels, service discovery mechanisms can now control this behavior on a more dynamic basis as well, such as temporarily telling Prometheus to scrape certain targets more frequently (to get higher-resolution data in certain scenarios) or less frequently (to cause less load).&lt;/p&gt;
&lt;h2 id=&quot;improving-storage-efficiency-by-tuning-timestamp-tolerances&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#improving-storage-efficiency-by-tuning-timestamp-tolerances&quot; aria-label=&quot;improving storage efficiency by tuning timestamp tolerances permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Improving storage efficiency by tuning timestamp tolerances&lt;/h2&gt;
&lt;p&gt;Within each time series, Prometheus uses a double delta compression algorithm for storing sample timestamps. This compression algorithm performs better if the intervals between subsequent timestamps are completely regular. Although Prometheus already tries to scrape targets on a regular interval, actual scrape timestamps can deviate slightly (by a few milliseconds) from the intended schedule. This was exacerbated by a &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/7846&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go regression that caused more timer jitter&lt;/a&gt;. In older versions, Prometheus already allowed setting the &lt;code&gt;--scrape.adjust-timestamps&lt;/code&gt; boolean flag to adjust scrape timestamps by up to 2ms to align them to the intended scrape schedule and thus achieve better timestamp compression.&lt;/p&gt;
&lt;p&gt;In Prometheus 2.30, &lt;a href=&quot;https://github.com/roidelapluie&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Julien Pivotto&lt;/a&gt; now added support for &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/9283&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;tuning this scrape timestamp tolerance duration&lt;/a&gt; using the experimental flag &lt;code&gt;--scrape.timestamp-tolerance=&amp;#x3C;duration&gt;&lt;/code&gt;. Setting this flag to &lt;code&gt;10ms&lt;/code&gt; (vs. its default of &lt;code&gt;2ms&lt;/code&gt;), Julien &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/9283#issuecomment-910260410&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;observed a 30% chunk storage size reduction&lt;/a&gt; in one example use case.&lt;/p&gt;
&lt;p&gt;For more background, there is also a &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/8032&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;proposal around timestamp alignment with more context&lt;/a&gt;, and whether such alignment flags should remaing temporary workarounds or not.&lt;/p&gt;
&lt;h2 id=&quot;other-enhancements&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-enhancements&quot; aria-label=&quot;other enhancements permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other enhancements&lt;/h2&gt;
&lt;p&gt;There are a lot of other smaller improvements in Prometheus 2.30, such as &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/9160&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;improving WAL load memory usage by 24% and CPU usage by 19%&lt;/a&gt;, adding &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/9247&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;two&lt;/a&gt; &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/9295&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;more&lt;/a&gt; optional per-scrape metrics (&lt;code&gt;scrape_timeout_seconds&lt;/code&gt; and &lt;code&gt;scrape_sample_limit&lt;/code&gt;) in addition to &lt;code&gt;up&lt;/code&gt; and friends, and more. To see the full list of changes, check out the &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.30.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.30.0 release changelog&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;While Prometheus 2.30 is relatively light on new features, it adds a few great improvements around configurability and efficiency. &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.30.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go try it out now&lt;/a&gt;!&lt;/p&gt;
&lt;div class=&quot;container&quot; style=&quot;text-align: center; padding: 18px; font-size: 1.15em; border: 2px solid #e65013; box-shadow: 0 2px 20px rgb(52 73 94 / 10%); border-radius: 4px; margin-top: 45px; max-width: 70%&quot;&gt;
          Want to learn Prometheus concepts from the ground up, &lt;strong&gt;taught by the co-founder of Prometheus&lt;/strong&gt;? Check out our &lt;strong&gt;
            &lt;a
              target=&quot;_blank&quot;
              href=&quot;https://training.promlabs.com/&quot;
              style=&quot;textDecoration: underline&quot;
            &gt;
              self-paced Prometheus trainings
            &lt;/a&gt;
          &lt;/strong&gt;
          .
        &lt;/div&gt;</content:encoded></item><item><title><![CDATA[What's New in Prometheus 2.28?]]></title><description><![CDATA[Today I had the pleasure of releasing Prometheus 2.28 in my function as a member of the Prometheus Team. While there are many changes in…]]></description><link>https://promlabs.com/blog/2021/06/21/whats-new-in-prometheus-2-28</link><guid isPermaLink="false">https://promlabs.com/blog/2021/06/21/whats-new-in-prometheus-2-28</guid><pubDate>Mon, 21 Jun 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today I had the pleasure of releasing &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.28.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.28&lt;/a&gt; in my function as a member of the Prometheus Team. While there are many changes in this release, let&apos;s take a look at some of the most relevant new features for users:&lt;/p&gt;
&lt;h2 id=&quot;displaying-trace-exemplars-in-the-graphing-interface&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#displaying-trace-exemplars-in-the-graphing-interface&quot; aria-label=&quot;displaying trace exemplars in the graphing interface permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Displaying trace exemplars in the graphing interface&lt;/h2&gt;
&lt;p&gt;In our blog posts about Prometheus 2.26 and 2.27, we already talked about the new support for &lt;a href=&quot;/blog/2021/04/01/whats-new-in-prometheus-2-26#experimental-trace-exemplars-support&quot;&gt;storing and retrieving trace exemplars in Prometheus&lt;/a&gt;, as well as for &lt;a href=&quot;/blog/2021/05/16/whats-new-in-prometheus-2-27#exemplars-support-in-remote_write&quot;&gt;sending exemplar data over Prometheus&apos;s &lt;code&gt;remote_write&lt;/code&gt; interface&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To take this integration of exemplars with metrics one step further, &lt;a href=&quot;https://github.com/LeviHarrison&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Levi Harrison&lt;/a&gt; now added support for displaying trace exemplars in Prometheus&apos;s graphing interface. When a PromQL query accesses series that have exemplar data attached to them, you can now show those exemplars along with the returned PromQL query data by enabling a per-graph &lt;em&gt;&quot;Show Exemplars&quot;&lt;/em&gt; setting:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/prometheus-graph-exemplars.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;For example, in a latency-related graph, this allows you to easily find trace exemplars for requests with high latency, so that you can further investigate those requests in a tracing system. Since you may want to copy part of the exemplar metadata (such as the trace ID) to correlate it with another system, you can click on any exemplar to show its metadata in a more persistent way under the graph.&lt;/p&gt;
&lt;p&gt;As described in the &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8832&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request that added the exemplar display support&lt;/a&gt;, an easy way to get a demo running where you can try out the exemplar display is by running Grafana&apos;s &quot;The New Stack&quot; demo app:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Clone the &quot;The New Stack&quot; demo app.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; clone git@github.com:grafana/tns

&lt;span class=&quot;token comment&quot;&gt;# Check out a predictable version of the repo.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; checkout ec5673d

&lt;span class=&quot;token comment&quot;&gt;# Use Prometheus 2.28 instead of 2.26.&lt;/span&gt;
&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; production/docker-compose
&lt;span class=&quot;token function&quot;&gt;sed&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-i&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;s/prometheus:v2.26/prometheus:v2.28/&apos;&lt;/span&gt; docker-compose.yml

&lt;span class=&quot;token comment&quot;&gt;# Run components necessary to expose and store metrics and trace exemplars.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;docker-compose&lt;/span&gt; up tempo db app loadgen prometheus&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Then head to &lt;a href=&quot;http://localhost:9090/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;http://localhost:9090/&lt;/a&gt; and run the query:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;histogram_quantile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0.99&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;le&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;tns_request_duration_seconds_bucket&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;1m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Click the &lt;em&gt;&quot;Show Exemplars&quot;&lt;/em&gt; button to show trace exemplars.&lt;/p&gt;
&lt;h2 id=&quot;generic-http-based-service-discovery&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#generic-http-based-service-discovery&quot; aria-label=&quot;generic http based service discovery permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Generic HTTP-based service discovery&lt;/h2&gt;
&lt;p&gt;Prometheus has supported generic service discovery integrations for a long time via its &lt;a href=&quot;https://prometheus.io/docs/guides/file-sd/#use-file-based-service-discovery-to-discover-scrape-targets&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;file_sd&lt;/code&gt; discovery mechanism&lt;/a&gt;, which watches and reads a set of target files from disk. The downside of the &lt;code&gt;file_sd&lt;/code&gt; approach is that it requires sharing a filesystem between Prometheus and a sidecar process that generates the target files. This can be problematic in some environments, and users have asked for a network-based alternative for a long time.&lt;/p&gt;
&lt;p&gt;Thus, &lt;a href=&quot;https://twitter.com/roidelapluie&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Julien Pivotto&lt;/a&gt; introduced a new HTTP-based generic discovery mechanism in Prometheus 2.28. This mechanism works almost like &lt;code&gt;file_sd&lt;/code&gt;, but loads target information from a specified URL rather than from a local file:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; http&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;sd
  &lt;span class=&quot;token key atrule&quot;&gt;http_sd_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;https://infra-db/prometheus-sd&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It also only supports JSON as the targets format, whereas &lt;code&gt;file_sd&lt;/code&gt; supports both JSON and YAML.&lt;/p&gt;
&lt;p&gt;We hope that this new HTTP-based discovery mechanism not only encourages people to build remote sidecar processes that can pull target information from various sources of truth, but that developers will add native Prometheus HTTP discovery support directly into their infrastructure and service databases, getting rid of the need to run a separate process.&lt;/p&gt;
&lt;p&gt;You can find more information on the Prometheus website about &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/http_sd&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;writing your own HTTP-based service discovery integration&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;defaulting-to-the-new-expression-editor&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#defaulting-to-the-new-expression-editor&quot; aria-label=&quot;defaulting to the new expression editor permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Defaulting to the new expression editor&lt;/h2&gt;
&lt;p&gt;Prometheus 2.26 introduced an &lt;a href=&quot;https://promlabs.com/blog/2021/04/01/whats-new-in-prometheus-2-26#new-promql-editor&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;shiny new PromQL editor&lt;/a&gt; with advanced autocompletion, inline linting, and syntax highlighting, that you had to explicitly enable as an experimental feature. Since this new editor is so much more usable than the previous bare text input field, and since we have not received any major complaints about it, Prometheus 2.28 now defaults to this new editor:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/new-promql-editor-default.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;Note that this default is stored in the browser&apos;s local storage and is only set to the &lt;em&gt;new&lt;/em&gt; default value if no previously stored value is present for it yet. Thus if you used Prometheus 2.26 or 2.27 in the meantime and now access 2.28 using the same URL, you may still have to explicitly enable the new editor.&lt;/p&gt;
&lt;p&gt;In case you encounter any issues with this new editor, please &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/new/choose&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;file an issue&lt;/a&gt;. For the time being, you can still revert to the old editor by disabling the &quot;Use experimental editor&quot; checkbox.&lt;/p&gt;
&lt;h2 id=&quot;other-features-and-enhancements&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-features-and-enhancements&quot; aria-label=&quot;other features and enhancements permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other features and enhancements&lt;/h2&gt;
&lt;p&gt;There are several other features, enhancements, and bugfixes that made it into Prometheus 2.28. For example, there is now support for &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8846&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Linode service discovery&lt;/a&gt;, &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8811&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;discovering Kubernetes API servers using a kubeconfig file&lt;/a&gt;, and a &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8662&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;new startup screen in the web UI while the TSDB is starting up&lt;/a&gt;. You can find the full list of changes in the &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.28.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;changelog for Prometheus 2.28&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;A lot has happened in Prometheus 2.28 to integrate it with other systems and make it more usable. &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.28.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go try it out now&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Showcasing PromLens 1.0.0]]></title><description><![CDATA[Today we are happy to release version 1.0.0 of PromLens! PromLens is the ultimate power tool for PromQL that helps you build, analyze…]]></description><link>https://promlabs.com/blog/2021/05/26/showcasing-promlens-1.0.0</link><guid isPermaLink="false">https://promlabs.com/blog/2021/05/26/showcasing-promlens-1.0.0</guid><pubDate>Wed, 26 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today we are happy to release version 1.0.0 of &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;! PromLens is the ultimate power tool for PromQL that helps you build, analyze, explain, and visualize your queries. In case you are unfamiliar with it, &lt;a href=&quot;https://demo.promlens.com/?example&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;try a quick demo here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here is a summary of the most important changes since the &lt;a href=&quot;/blog/2020/12/15/showcasing-promlens-0.11.0&quot;&gt;last release&lt;/a&gt; that help you edit your PromQL expressions more confidently and effectively:&lt;/p&gt;
&lt;h2 id=&quot;a-new-labels-explorer&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#a-new-labels-explorer&quot; aria-label=&quot;a new labels explorer permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A new labels explorer&lt;/h2&gt;
&lt;p&gt;PromLens 1.0.0 extends the existing metrics explorer by allowing you to drill down into the label names and values of a specific metric name. This helps you get a quick idea of the available labels on a metric, their individual cardinality, and the number of series they produce. The labels explorer also allows you to progressively add label matching filters to narrow down the result. Finally, you can then insert the constructed selector into your text input:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/promlens-label-explorer.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;h2 id=&quot;new-promql-features&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-promql-features&quot; aria-label=&quot;new promql features permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New PromQL features&lt;/h2&gt;
&lt;p&gt;This version adds support for a number of new PromQL features that were added in Prometheus version 2.25.0 and 2.26.0. This includes support for the new PromQL functions &lt;code&gt;last_over_time()&lt;/code&gt;, &lt;code&gt;sgn()&lt;/code&gt;, and &lt;code&gt;clamp()&lt;/code&gt;, as well as for the new experimental negative offsets in selectors and the &lt;a href=&quot;https://prometheus.io/blog/2021/02/18/introducing-the-@-modifier/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;new &lt;code&gt;@&lt;/code&gt; modifier&lt;/a&gt; that allows setting a non-relative evaluation timestamp for a selector or subquery.&lt;/p&gt;
&lt;p&gt;The editor for the new &lt;code&gt;@&lt;/code&gt; modifier looks like this:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/promlens-at-modifier.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;h2 id=&quot;what-does-100-mean&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-does-100-mean&quot; aria-label=&quot;what does 100 mean permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What does 1.0.0 mean?&lt;/h2&gt;
&lt;p&gt;Since PromLens is fairly mature by now, we just thought that the version number should reflect this. Other than that, nothing much will change. We already avoided most breaking changes in the past, but will be sure to increment the major version whenever a breaking change (affecting command-line flags, supported integrations, stored shared links, or similar) is required.&lt;/p&gt;
&lt;h2 id=&quot;become-more-productive-with-promlens-today&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#become-more-productive-with-promlens-today&quot; aria-label=&quot;become more productive with promlens today permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Become more productive with PromLens today&lt;/h2&gt;
&lt;p&gt;We are continuously improving PromLens and hope that you will enjoy these new features! You can see the &lt;a href=&quot;https://github.com/promlabs/promlens-public/blob/master/CHANGELOG.md#100--2021-05-26&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;full list of changes in the PromLens 1.0.0 changelog&lt;/a&gt;. Check out &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt; today, &lt;a href=&quot;https://promlens.com/pricing&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;get the full on-premise version&lt;/a&gt;, and &lt;a href=&quot;https://github.com/promlabs/promlens-public/issues&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;report any issues or feature requests you may encounter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Trying out the free preview version of PromLens is as simple as:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;docker&lt;/span&gt; run &lt;span class=&quot;token parameter variable&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8080&lt;/span&gt;:8080 promlabs/promlens:latest&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;...and navigating to &lt;a href=&quot;https://localhost:8080/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://localhost:8080/&lt;/a&gt; in your browser.&lt;/p&gt;
&lt;p&gt;Happy PromQL editing!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What's New in Prometheus 2.27?]]></title><description><![CDATA[Last Wednesday, the Prometheus Team released Prometheus 2.27. While there are many changes in this release, let's take a look at some of the…]]></description><link>https://promlabs.com/blog/2021/05/16/whats-new-in-prometheus-2-27</link><guid isPermaLink="false">https://promlabs.com/blog/2021/05/16/whats-new-in-prometheus-2-27</guid><pubDate>Sun, 16 May 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Last Wednesday, the Prometheus Team released &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.27.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.27&lt;/a&gt;. While there are many changes in this release, let&apos;s take a look at some of the most relevant new features for users:&lt;/p&gt;
&lt;h2 id=&quot;dark-mode&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dark-mode&quot; aria-label=&quot;dark mode permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Dark mode&lt;/h2&gt;
&lt;p&gt;Do you prefer darker user interfaces, especially when using Prometheus at night? In &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8604&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8604&lt;/a&gt;, &lt;a href=&quot;https://github.com/prymitive&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Łukasz Mierzwa&lt;/a&gt; now added the ability to switch the web UI from its default light version to a dark mode:&lt;/p&gt;
&lt;video playsinline muted autoplay loop style=&quot;max-width: 800px&quot;&gt;
  &lt;source src=&quot;/images/prometheus-dark-mode.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;It&apos;s also possible to tell Prometheus to use the browser-preferred theme (using the right-most black/white button in the video).&lt;/p&gt;
&lt;p&gt;The dark UI mode is still early in its development and some of its color choices will still be refined over time.&lt;/p&gt;
&lt;h2 id=&quot;retroactive-backfilling-of-rule-results&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#retroactive-backfilling-of-rule-results&quot; aria-label=&quot;retroactive backfilling of rule results permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Retroactive backfilling of rule results&lt;/h2&gt;
&lt;p&gt;Normally, recording rules in Prometheus only start recording results starting from the time at which they are added to Prometheus. There has been a &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/11&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;long-standing issue&lt;/a&gt; to allow evaluating rules retroactively on old data, so that Prometheus users can access rule results directly for those older time ranges. As a first step to address this, &lt;a href=&quot;https://twitter.com/jessicagreben&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Jessica Greben&lt;/a&gt; added a new subcommand to the &lt;code&gt;promtool&lt;/code&gt; CLI tool in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/7675&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 7675&lt;/a&gt; to support manual backfilling of rule results.&lt;/p&gt;
&lt;p&gt;To backfill rule results, you can create files with your desired rules and then point &lt;code&gt;promtool&lt;/code&gt; at the new rule files, your Prometheus server, and a TSDB output directory in which to create new blocks with the rule result time series:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;promtool tsdb create-blocks-from rules &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;token parameter variable&quot;&gt;--start&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;start-timestamp&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;token parameter variable&quot;&gt;--end&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;end-timestamp&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
  --output-dir &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;output-tsdb-dir&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;token parameter variable&quot;&gt;--url&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;prometheus-server-url&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;
  rules1.yml,rules2.yml&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You can then move the newly generated TSDB blocks into the data directory of a Prometheus server to start accessing them.&lt;/p&gt;
&lt;h2 id=&quot;environment-variable-expansion-for-external-labels&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#environment-variable-expansion-for-external-labels&quot; aria-label=&quot;environment variable expansion for external labels permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Environment variable expansion for external labels&lt;/h2&gt;
&lt;p&gt;To achieve high availability for monitoring, it&apos;s common to run multiple Prometheus servers with identical configuration. However, as an exception to their identical configuration, you often want to be able to assign different &lt;code&gt;external_labels&lt;/code&gt; to each Prometheus server, to differentiate replicas (e.g. &lt;code&gt;replica: prometheus-a&lt;/code&gt; and &lt;code&gt;replica: prometheus-b&lt;/code&gt;). To make this use case easier and not require two different configuration files on disk just to have different external labels, Prometheus 2.27 now allows you to expand environment variables in the &lt;code&gt;external_labels&lt;/code&gt; configuration section.&lt;/p&gt;
&lt;p&gt;To enable this experimental feature, you will have to set the flag &lt;code&gt;--enable-feature=expand-external-labels&lt;/code&gt;. You can then use &lt;code&gt;$envvar&lt;/code&gt; or &lt;code&gt;${envvar}&lt;/code&gt; in that configuration section, e.g.:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;external_labels&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token key atrule&quot;&gt;replica&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; prometheus&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;$&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;PROMETHEUS_REPLICA&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;# [... rest of the configuration file ...]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://twitter.com/roidelapluie&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Julien Pivotto&lt;/a&gt; added this feature in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8649&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8649&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;better-support-for-small-use-cases&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#better-support-for-small-use-cases&quot; aria-label=&quot;better support for small use cases permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Better support for small use cases&lt;/h2&gt;
&lt;p&gt;Prometheus normally requires pre-allocating 512MiB of disk space for new TSDB chunk segment files. This can make it hard to use Prometheus in small environments, where the actual data to be stored in each chunk segment is only a few MiB and the available disk space is low. To make Prometheus work better for those use cases, &lt;a href=&quot;https://github.com/nberkley&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Nathan Berkley&lt;/a&gt; added a flag &lt;code&gt;--storage.tsdb.max-block-chunk-segment-size=&amp;#x3C;size&gt;&lt;/code&gt; in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8478&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8478&lt;/a&gt; to allow configuring the maximum chunk segment file size.&lt;/p&gt;
&lt;p&gt;For example, you could start Prometheus with a maximum chunk segment size of &lt;code&gt;64MiB&lt;/code&gt; like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;./prometheus --storage.tsdb.max-block-chunk-segment-size&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;64MB&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;new-service-discoveries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-service-discoveries&quot; aria-label=&quot;new service discoveries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New service discoveries&lt;/h2&gt;
&lt;p&gt;In an ongoing effort to make Prometheus work better in more environments, the new release furthermore adds two new service discovery mechanisms:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/xperimental&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Robert Jacob&lt;/a&gt; added support for discovering &lt;a href=&quot;https://docs.docker.com/engine/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Docker engine&lt;/a&gt; containers as scrape targets in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8629&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8629&lt;/a&gt;. You can check out the &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#docker_sd_config&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus documentation&lt;/a&gt; for all configuration details.&lt;/p&gt;
&lt;p&gt;A contributor going by the name of &lt;a href=&quot;https://github.com/n888&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;N888&lt;/a&gt; added support for discovering &lt;a href=&quot;https://aws.amazon.com/lightsail/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;AWS Lightsail&lt;/a&gt; compute instances in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8693&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8693&lt;/a&gt;. Again, you can find exact configuration details for this in the &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#lightsail_sd_config&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;oauth-2-support-everywhere&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#oauth-2-support-everywhere&quot; aria-label=&quot;oauth 2 support everywhere permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;OAuth 2 support everywhere&lt;/h2&gt;
&lt;p&gt;When talking to other systems (scrape targets, Alertmanager, remote-write endpoints, and so on), Prometheus already supported multiple authentication schemes: bearer tokens, basic authentication, TLS client certificates, and more (depending on the situation). In addition to those, in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8761&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8761&lt;/a&gt; &lt;a href=&quot;https://github.com/LeviHarrison&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Levi Harrison&lt;/a&gt; now added support for configuring OAuth 2 in all relevant places. This just makes it easier to use Prometheus in environments that already use OAuth 2 for authentication purposes.&lt;/p&gt;
&lt;p&gt;You can find details on configuring OAuth 2 in the &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#oauth2&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus configuration documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;exemplars-support-in-remote_write&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#exemplars-support-in-remote_write&quot; aria-label=&quot;exemplars support in remote_write permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exemplars support in &lt;code&gt;remote_write&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;In our &lt;a href=&quot;/blog/2021/04/01/whats-new-in-prometheus-2-26#experimental-trace-exemplars-support&quot;&gt;blog post about Prometheus 2.26&lt;/a&gt;, we already mentioned the importance of trace exemplars and how Prometheus 2.26 added support for storing them in memory and retrieving them via an HTTP API. This required setting the &lt;code&gt;--enable-feature=exemplar-storage&lt;/code&gt; flag.&lt;/p&gt;
&lt;p&gt;In Prometheus 2.27, &lt;a href=&quot;https://twitter.com/CallumStyan&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Callum Styan&lt;/a&gt; now went one step further and added support for sending exemplars over Prometheus&apos;s &lt;code&gt;remote_write&lt;/code&gt; protocol in &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8296&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request 8296&lt;/a&gt;. A &lt;code&gt;TimeSeries&lt;/code&gt; protobuf message may now contain &lt;a href=&quot;https://github.com/prometheus/prometheus/blob/11bcb9310064ef166b582a82aa8fd07e1cec6545/prompb/types.proto#L48-L55&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;Exemplar&lt;/code&gt;&lt;/a&gt; fields to convey exemplar information. To enable this feature, you need to set the &lt;code&gt;send_exemplars: true&lt;/code&gt; option in your &lt;code&gt;remote_write&lt;/code&gt; configuration section. Remote storage implementors can now start making use of this to allow for better integration of metrics and trace data in their services.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;A lot has happened in Prometheus 2.27 to make it work better for more use cases and to integrate it more with other systems. &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.27.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go try it out now&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[What's New in Prometheus 2.26?]]></title><description><![CDATA[Yesterday, the Prometheus Team released Prometheus 2.26. While there are many changes in this release, let's take a look at some of the most…]]></description><link>https://promlabs.com/blog/2021/04/01/whats-new-in-prometheus-2-26</link><guid isPermaLink="false">https://promlabs.com/blog/2021/04/01/whats-new-in-prometheus-2-26</guid><pubDate>Thu, 01 Apr 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Yesterday, the Prometheus Team released &lt;a href=&quot;https://twitter.com/bwplotka/status/1377280222958092293&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus 2.26&lt;/a&gt;. While there are many changes in this release, let&apos;s take a look at some of the most relevant new features for users:&lt;/p&gt;
&lt;h2 id=&quot;new-promql-editor&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-promql-editor&quot; aria-label=&quot;new promql editor permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New PromQL editor&lt;/h2&gt;
&lt;p&gt;Since the creation of Prometheus in 2012, the built-in PromQL expression editor has just been a simple text input field with no syntax highlighting and almost no autocompletion functionality or other code intelligence features. This has meant that working with PromQL in Prometheus was a lot of guesswork and pain:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/promql-old-editor-error.png&quot; alt=&quot;Old PromQL expression editor&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://twitter.com/juliusvolz&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Julius Volz&lt;/a&gt; from PromLabs (that&apos;s me!) has long collaborated with Augustin Husson from Amadeus on building new PromQL editor functionality with support for &lt;strong&gt;syntax highlighting&lt;/strong&gt;, &lt;strong&gt;contextual autocompletion&lt;/strong&gt;, as well as &lt;strong&gt;inline linting&lt;/strong&gt; of expression errors. Up until now, this new editor functionality has only been available in the &lt;strong&gt;&lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;&lt;/strong&gt; PromQL expression builder and explainer tool by PromLabs. For Prometheus 2.26, we &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8634&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;worked to bring this new editor functionality to Prometheus itself&lt;/a&gt; and hope that this will greatly improve people&apos;s PromQL experience:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/new-promql-editor.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;The new editor is still experimental for this release, so you have to turn it on explicitly by enabling the &lt;em&gt;&quot;Use experimental editor&quot;&lt;/em&gt; checkbox. In later releases, we expect it to become the default.&lt;/p&gt;
&lt;p&gt;In case you are curious, the new editor functionality is powered by a set of open-source libraries and tools:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://codemirror.net/6/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;CodeMirror 6&lt;/a&gt; as the underlying editor provides a fantastic modular and customizable editor as a base.&lt;/li&gt;
&lt;li&gt;The PromLabs &lt;a href=&quot;https://github.com/promlabs/lezer-promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;lezer-promql&lt;/a&gt; library module implements a client-side grammar and parser for PromQL.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/prometheus-community/codemirror-promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;codemirror-promql&lt;/a&gt; extension for CodeMirror 6 uses the parse tree from &lt;code&gt;lezer-promql&lt;/code&gt; to build code intelligence features like contextual autocompletion and linting on top of it.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While we spent a lot of energy on getting the new editing features right, they are probably not 100% perfect yet. So please do file bugs or help us improve the code if you find any issues. Also, we encourage other projects and vendors to reuse this PromQL editor in their software and help us maintain it. Let&apos;s build the best PromQL text editor together!&lt;/p&gt;
&lt;p&gt;If you would like to understand and edit PromQL even better, check out &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;, which goes far beyond the PromQL text editing experience and provides advanced insight, analysis, and builder features for anyone working with the query language.&lt;/p&gt;
&lt;h2 id=&quot;experimental-trace-exemplars-support&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#experimental-trace-exemplars-support&quot; aria-label=&quot;experimental trace exemplars support permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Experimental trace exemplars support&lt;/h2&gt;
&lt;p&gt;Metrics such as the ones that Prometheus collects provide a good aggregate view of a system, while traces (such as systems like &lt;a href=&quot;https://www.jaegertracing.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Jaeger&lt;/a&gt; or &lt;a href=&quot;https://grafana.com/oss/tempo/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana Tempo&lt;/a&gt; collect) allow you to dive deep into the details of a single request. This allows you to inspect where it failed or how much time it spent in various stages.&lt;/p&gt;
&lt;p&gt;Often it&apos;s useful to be able to jump from request metrics to correlated traces. For example, in a Prometheus histogram metric that shows a lot of slow requests, you may want to quickly find a request with such high latency, to debug why it is slow.&lt;/p&gt;
&lt;p&gt;Exemplars aim to solve this by letting a service expose example trace IDs along with its metrics. For example, in &lt;a href=&quot;https://openmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenMetrics&lt;/a&gt;, the new standard for Prometheus-style metrics exposition, histogram bucket series may be annotated with trace IDs by providing the trace ID in a comment after the series value, like this (see the &lt;a href=&quot;https://github.com/OpenObservability/OpenMetrics/blob/b5a8ccf807c0d9fb1182907c3cc03f9cb41faef1/specification/OpenMetrics.md#exemplars-1&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenMetrics specification&lt;/a&gt; for details):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# TYPE foo histogram&lt;/span&gt;
foo_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.01&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;
foo_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# {} 0.054&lt;/span&gt;
foo_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;11&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# {trace_id=&quot;KOO5S4vxi0o&quot;} 0.67&lt;/span&gt;
foo_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;10&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;17&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;# {trace_id=&quot;oHg5SJYRHA0&quot;} 9.8 1520879607.789&lt;/span&gt;
foo_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;+Inf&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;17&lt;/span&gt;
foo_count &lt;span class=&quot;token number&quot;&gt;17&lt;/span&gt;
foo_sum &lt;span class=&quot;token number&quot;&gt;324789.3&lt;/span&gt;
foo_created  &lt;span class=&quot;token number&quot;&gt;1520430000.123&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;When enabled using the &lt;code&gt;--enable-feature=exemplar-storage&lt;/code&gt; flag, Prometheus now has support for storing exemplars in memory and retrieving them for PromQL queries via a &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/api/#querying-exemplars&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;new HTTP API&lt;/a&gt;. This feature was &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/6635&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;added by Callum Styan from Grafana Labs&lt;/a&gt; and can be used by tools like Grafana to jump between metrics and traces, as already &lt;a href=&quot;https://grafana.com/blog/2020/11/09/trace-discovery-in-grafana-tempo-using-prometheus-exemplars-loki-2.0-queries-and-more/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;demonstrated by Grafana Labs&lt;/a&gt; last year.&lt;/p&gt;
&lt;p&gt;Going from metrics to relevant exemplars is a complex topic. For more details, see the &lt;a href=&quot;https://docs.google.com/document/d/1ymZlc9yuTj8GvZyKz1r3KDRrhaOjZ1W1qZVW_5Gj7gA/edit#&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus exemplars design document&lt;/a&gt; as well as the &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/6635&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;pull request adding them to Prometheus&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;new-and-experimental-promql-features&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-and-experimental-promql-features&quot; aria-label=&quot;new and experimental promql features permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New and experimental PromQL features&lt;/h2&gt;
&lt;p&gt;Prometheus 2.26 added a few new PromQL features, one of which is experimental and needs to be explicitly enabled:&lt;/p&gt;
&lt;h3 id=&quot;getting-the-last-data-point-in-a-specified-time-range&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-the-last-data-point-in-a-specified-time-range&quot; aria-label=&quot;getting the last data point in a specified time range permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting the last data point in a specified time range&lt;/h3&gt;
&lt;p&gt;The new &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/functions/#aggregation_over_time&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;last_over_time()&lt;/code&gt;&lt;/a&gt; function returns the last sample value for each series in a range vector. This can occasionally be helpful as an explicit way to override the 5-minute vector selector staleness behavior for unreliable data sources.&lt;/p&gt;
&lt;p&gt;For example, to get the last seen resident memory value for any container in the last hour, you could query for:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;last_over_time&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;container_memory_rss&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;1h&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that in the usual case, data points that you still care about at a given query evaluation timestamp should be coming in regularly and freshly enough (even if their values haven&apos;t changed) that a normal vector selector (e.g. &lt;code&gt;container_memory_rss&lt;/code&gt;) should be sufficient. If used without care, &lt;code&gt;last_over_time()&lt;/code&gt; may return samples for series which you no longer care about.&lt;/p&gt;
&lt;h3 id=&quot;getting-the-numeric-sign-of-input-series&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-the-numeric-sign-of-input-series&quot; aria-label=&quot;getting the numeric sign of input series permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting the numeric sign of input series&lt;/h3&gt;
&lt;p&gt;The new &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/functions/#sgn&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;sgn(v instant-vector)&lt;/code&gt;&lt;/a&gt; function returns the numeric sign (&lt;code&gt;0&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;-1&lt;/code&gt;) for all series in an input vector:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sgn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;my_vector_of_positive_and_negative_numbers&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;clamping-an-input-vector-into-a-given-range&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#clamping-an-input-vector-into-a-given-range&quot; aria-label=&quot;clamping an input vector into a given range permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Clamping an input vector into a given range&lt;/h3&gt;
&lt;p&gt;The new &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/functions/#clamp&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;clamp(v instant-vector, min scalar, max scalar)&lt;/code&gt;&lt;/a&gt; function allows you to constrain sample values to be between a minimum and a maximum value (this is a shorthand for using &lt;code&gt;clamp_min()&lt;/code&gt; and &lt;code&gt;clamp_max()&lt;/code&gt; after another):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;clamp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;my_vector&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;negative-offsets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#negative-offsets&quot; aria-label=&quot;negative offsets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Negative offsets&lt;/h3&gt;
&lt;p&gt;As an experimental feature (enabled via &lt;code&gt;--enable-feature=promql-negative-offset&lt;/code&gt;), you can now enable support for negative offsets that move selected future data to the present time:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;my_metric offset -1h&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Most people should only ever need positive offsets, but occasionally (see the &lt;a href=&quot;https://github.com/prometheus/prometheus/issues/8458#issuecomment-778709401&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;discussion in the issue regarding this&lt;/a&gt;) negative offsets may be useful.&lt;/p&gt;
&lt;h2 id=&quot;aws-sigv4-authentication-support&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#aws-sigv4-authentication-support&quot; aria-label=&quot;aws sigv4 authentication support permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;AWS SigV4 authentication support&lt;/h2&gt;
&lt;p&gt;In December of 2020, AWS announced their &lt;a href=&quot;https://aws.amazon.com/prometheus/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Amazon Managed Prometheus&lt;/a&gt; (AMP) service that offers a cloud-based Prometheus service based on a &lt;a href=&quot;https://cortexmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt; backend. Prometheus can normally write natively to cloud-based Prometheus services like this via its &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;remote_write&lt;/code&gt;&lt;/a&gt; integration, which supports a number of standardized HTTP authentication schemes.&lt;/p&gt;
&lt;p&gt;However, AWS uses its own authentication mechanism, &lt;a href=&quot;https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Signature Version 4&lt;/a&gt; (SigV4), to handle any and all authentication to and between AWS services. Prior to Prometheus 2.26 you had to proxy any &lt;code&gt;remote_write&lt;/code&gt; requests through a special proxy sidecar that could add SigV4 authentication to outgoing samples sent to AMP. Now in 2.26, Robert Fratto from Grafana Labs &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/8509&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;added native support for SigV4 to Prometheus&lt;/a&gt;, so you can write samples directly from any Prometheus server to AMP. This makes using Prometheus with one of the largest cloud providers as a backend much easier.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;A lot has happened in Prometheus 2.26 to make it easier to use, allow new use cases, and make it interoperate better with other systems. &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.26.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Go try it out now&lt;/a&gt;!&lt;/p&gt;</content:encoded></item><item><title><![CDATA[How Exactly Does PromQL Calculate Rates?]]></title><description><![CDATA[Counters are a Prometheus metric type whose value only goes up, and which represent cumulative total counts like "How many requests have we…]]></description><link>https://promlabs.com/blog/2021/01/29/how-exactly-does-promql-calculate-rates</link><guid isPermaLink="false">https://promlabs.com/blog/2021/01/29/how-exactly-does-promql-calculate-rates</guid><pubDate>Fri, 29 Jan 2021 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Counters are a Prometheus &lt;a href=&quot;https://promlabs.com/blog/2020/09/25/metric-types-in-prometheus-and-promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;metric type&lt;/a&gt; whose value only goes up, and which represent cumulative total counts like &lt;em&gt;&quot;How many requests have we handled in total?&quot;&lt;/em&gt; or &lt;em&gt;&quot;How many seconds have we spent handling requests?&quot;&lt;/em&gt;. Since the value of a counter depends on the initial (re)start time of a process that tracks and exposes it, the absolute value of a counter is almost never useful. So before graphing or doing anything else with a counter, you typically want to wrap it in a function like &lt;code&gt;rate()&lt;/code&gt;, &lt;code&gt;irate()&lt;/code&gt;, or &lt;code&gt;increase()&lt;/code&gt; to see how fast the counter is going up.&lt;/p&gt;
&lt;p&gt;The exact behavior of those three functions is a frequent source of confusion, so in this post we will look in detail at each of them, and how they deal with counter resets and do extrapolation of data to give you a final value. Note that we will only look at the above-mentioned counter-related functions here. If you want to track the increase or decrease of a gauge metric, you will need to use the &lt;code&gt;delta()&lt;/code&gt; or &lt;code&gt;deriv()&lt;/code&gt; functions for that instead. We will cover those in a future blog post.&lt;/p&gt;
&lt;h2 id=&quot;overview&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#overview&quot; aria-label=&quot;overview permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Overview&lt;/h2&gt;
&lt;p&gt;Here&apos;s a high-level overview of the difference between the three functions for calculating the rate of increase of a counter:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;rate()&lt;/code&gt;: This calculates the rate of increase &lt;em&gt;per second&lt;/em&gt;, averaged over the entire provided time window. Example: &lt;code&gt;rate(http_requests_total[5m])&lt;/code&gt; yields the per-second rate of HTTP requests as averaged over a time window of 5 minutes. This function is the most common, as it yields a nicely smoothed rate with a predictable per-second output unit.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;irate()&lt;/code&gt; (&quot;instant rate&quot;): This calculates the rate of increase &lt;em&gt;per second&lt;/em&gt; just like &lt;code&gt;rate()&lt;/code&gt;, but only considers the &lt;em&gt;last two samples&lt;/em&gt; under the provided time window for the calculation and ignores all earlier ones. Example: &lt;code&gt;irate(http_requests_total[5m])&lt;/code&gt; looks at the two last samples under the provided 5-minute window and calculates the per-second rate of increase between them. This function can be helpful if you want to make a zoomed-in graph show very quick responses to changes in a rate, but the output will be much more spiky than for &lt;code&gt;rate()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;increase()&lt;/code&gt;: This function is &lt;em&gt;exactly equivalent&lt;/em&gt; to &lt;code&gt;rate()&lt;/code&gt; except that it does not convert the final unit to &quot;per-second&quot; (&lt;code&gt;1/s&lt;/code&gt;). Instead, the final output unit is per-provided-time-window. Example: &lt;code&gt;increase(http_requests_total[5m])&lt;/code&gt; yields the total increase in handled HTTP requests over a 5-minute window (unit: &lt;code&gt;1 / 5m&lt;/code&gt;). Thus &lt;code&gt;increase(foo[5m]) / (5 * 60)&lt;/code&gt; is 100% equivalent to &lt;code&gt;rate(foo[5m])&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;All three functions share the requirement that they need at least two samples under the provided range window to work. Series that have less than two samples under the window are simply dropped from the result.&lt;/p&gt;
&lt;p&gt;How exactly to calculate the increase given a fixed time window and some data points falling under that window is a matter of tradeoffs and imperfect approximations. Prometheus chooses an approach that aims to provide the most correct answer on average, given only the limited data under the provided window. Let&apos;s look in more detail at how it does this:&lt;/p&gt;
&lt;h2 id=&quot;extrapolation-of-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#extrapolation-of-data&quot; aria-label=&quot;extrapolation of data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Extrapolation of data&lt;/h2&gt;
&lt;p&gt;What frequently confuses people is the extrapolating behavior of the &lt;code&gt;rate()&lt;/code&gt; and &lt;code&gt;increase()&lt;/code&gt; functions. As an example, &lt;code&gt;increase()&lt;/code&gt; can return non-integer results like &lt;code&gt;2.5883&lt;/code&gt; even for counters that only have integer increments. The reason is that &lt;code&gt;increase()&lt;/code&gt; tries to approximate the increase of a counter over the &lt;em&gt;total duration of the specified time window&lt;/em&gt; (e.g. 5 minutes in the case of &lt;code&gt;increase(foo[5m])&lt;/code&gt;). But in reality the first and last samples found under the time window will never coincide 100% with the start and end of the provided time window. Thus &lt;code&gt;increase()&lt;/code&gt; (and also &lt;code&gt;rate()&lt;/code&gt;) extrapolate the slope between those first and last data points under the window to the window boundaries, to arrive at a value that will on average be closer to the expected increase over the entire window (had there actually been samples precisely at the window boundaries).&lt;/p&gt;
&lt;p&gt;The following diagram shows an example of using &lt;code&gt;rate()&lt;/code&gt; with a 1-minute window and samples that are 15 seconds apart, with one actual counter increase by &lt;code&gt;1&lt;/code&gt; happening under the window:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/rate-extrapolation.png&quot; alt=&quot;Rate extrapolation&quot;&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the reported result is based on the slope between the first and last sample (almost true, see the next section about counter resets) under the window, and extrapolated to the window boundaries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; There are some exceptions to this extrapolating behavior: When a series looks like it &lt;em&gt;starts&lt;/em&gt; or &lt;em&gt;ends&lt;/em&gt; under the provided time window, we do not want to extrapolate too far into the direction in which the series terminates. The &lt;code&gt;rate()&lt;/code&gt; and &lt;code&gt;increase()&lt;/code&gt; functions guess that a series starts or ends under the window when the first or last sample is farther away from its respective window boundary than 1.1x the average interval between the samples under the window. In that case, the extrapolation only extends half an average sample interval toward the window boundary, but not all the way. Similarly, the functions avoid extrapolating to a negative value, since counters always start at &lt;code&gt;0&lt;/code&gt; and can never be negative. Instead, the extrapolation only happens until the expected &lt;code&gt;0&lt;/code&gt; value is hit.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/rate-partial-extrapolation.png&quot; alt=&quot;Partial rate extrapolation&quot;&gt;&lt;/p&gt;
&lt;p&gt;Since &lt;code&gt;irate()&lt;/code&gt; really only looks at the per-second increase between two samples, it does not do any of this extrapolation.&lt;/p&gt;
&lt;h2 id=&quot;dealing-with-counter-resets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dealing-with-counter-resets&quot; aria-label=&quot;dealing with counter resets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Dealing with counter resets&lt;/h2&gt;
&lt;p&gt;Although counters normally only go up, they reset to &lt;code&gt;0&lt;/code&gt; whenever a process that tracks them restarts. To not interpret these resets as actual negative rates, the counter-related functions have logic to detect and deal with those resets: when iterating over the samples under the provided time window, the functions check whether any sample has a lower value than the previous one, and interpret this situation as a counter reset. Using the further assumption that counters always start at &lt;code&gt;0&lt;/code&gt; after a reset, these functions then just add the new sample value to the previously seen one, to compensate for the reset.&lt;/p&gt;
&lt;p&gt;The following example diagram shows how a &lt;code&gt;rate()&lt;/code&gt; calculation deals with a counter reset happening under the provided window. You can imagine this as &lt;code&gt;rate()&lt;/code&gt; creating a set of &quot;virtual&quot; samples from the underlying &quot;real&quot; samples. The final rate is then calculated from the virtual samples, as if the resets had never taken place:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/rate-reset-correction.png&quot; alt=&quot;Partial rate extrapolation&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Whenever a counter resets, there is the chance that it was incremented &lt;em&gt;after&lt;/em&gt; Prometheus&apos;s last scrape, but &lt;em&gt;before&lt;/em&gt; the reset. Those increments are lost to Prometheus forever, and there is no way to get them back. To minimize this effect, resets should happen only once in a while, and much less frequently than Prometheus scrapes your target.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The inner workings and exact outputs of the various counter-related functions in PromQL can be confusing. In this post we aimed to shed light on how the &lt;code&gt;rate()&lt;/code&gt;, &lt;code&gt;irate()&lt;/code&gt;, and &lt;code&gt;increase()&lt;/code&gt; functions deal with units, counter resets, and extrapolation. Hopefully this will give you a better understanding of their subtle behaviors.&lt;/p&gt;
&lt;p&gt;If you want to understand more about Prometheus and PromQL, you may also want to take a look at our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus training courses&lt;/a&gt;, especially our &lt;a href=&quot;https://training.promlabs.com/training/understanding-promql/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;Understanding PromQL&lt;/strong&gt;&lt;/a&gt; training.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[PromQL Queries for Exploring Your Metrics]]></title><description><![CDATA[When building PromQL queries, a frequent need for users is to get an idea of the data they are working with, and a way to explore the space…]]></description><link>https://promlabs.com/blog/2020/12/17/promql-queries-for-exploring-your-metrics</link><guid isPermaLink="false">https://promlabs.com/blog/2020/12/17/promql-queries-for-exploring-your-metrics</guid><pubDate>Thu, 17 Dec 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;When building PromQL queries, a frequent need for users is to get an idea of the data they are working with, and a way to explore the space of all available metrics and their labels. While the UI tooling for this is still evolving (&lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt; and &lt;a href=&quot;https://github.com/grafana/grafana&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana&lt;/a&gt; both have some data exploration features), you can also map out your data using PromQL queries.&lt;/p&gt;
&lt;h2 id=&quot;getting-all-series-in-the-tsdb&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-all-series-in-the-tsdb&quot; aria-label=&quot;getting all series in the tsdb permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting all series in the TSDB&lt;/h2&gt;
&lt;p&gt;The simplest (but not usually practical) possibility is to just list all series that have recent data. There are multiple ways to do this. For example, you could write a selector for any series that has a non-empty metric name (which is true for all series in Prometheus). Internally, the metric name is stored in a special label with the name &lt;code&gt;__name__&lt;/code&gt;, so you could just query for:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;!=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Caution:&lt;/strong&gt; This returns all active series, so on a large Prometheus this may overload either your server or your UI.&lt;/p&gt;
&lt;p&gt;This can make sense on small Prometheus servers, where it&apos;s feasible to digest and manually explore all series at once. Most of the time though, you will want to filter or aggregate a bit further before taking a look at the output data.&lt;/p&gt;
&lt;h2 id=&quot;getting-all-series-for-a-metric-name&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-all-series-for-a-metric-name&quot; aria-label=&quot;getting all series for a metric name permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting all series for a metric name&lt;/h2&gt;
&lt;p&gt;This is the most common use case when starting out with a query. If you already know which metric name you are working with (e.g. &lt;code&gt;demo_cpu_usage_seconds_total&lt;/code&gt;) and just want to see all associated series and their label pairs, you could query for:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;demo_cpu_usage_seconds_total&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This should work well most of the time, unless there is a huge number of series attached to the metric name.&lt;/p&gt;
&lt;h2 id=&quot;getting-all-metric-names&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-all-metric-names&quot; aria-label=&quot;getting all metric names permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting all metric names&lt;/h2&gt;
&lt;p&gt;You may also want to get a list of all metric names first. If your UI does not already show you this list in one way or another (it really should!), you can query for it by first selecting all series, then grouping by the special metric name label &lt;code&gt;__name__&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;!=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; A more efficient, non-PromQL way to get the same information is to use Prometheus&apos;s label values metadata endpoint to get all values for the &lt;code&gt;__name__&lt;/code&gt; label, e.g.: &lt;a href=&quot;https://demo.promlabs.com/api/v1/label/__name__/values&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://demo.promlabs.com/api/v1/label/&lt;strong&gt;name&lt;/strong&gt;/values&lt;/a&gt;. This is the method that UIs typically use to present you with a list of metric names. While the PromQL query above gives you the metric names of all series with &lt;em&gt;recent&lt;/em&gt; (&amp;#x3C;5m old) data, this metadata API endpoint will &lt;em&gt;by default&lt;/em&gt; give you all metric names that are known to the TSDB at any time.&lt;/p&gt;
&lt;h2 id=&quot;getting-all-values-for-a-specific-label&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-all-values-for-a-specific-label&quot; aria-label=&quot;getting all values for a specific label permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting all values for a specific label&lt;/h2&gt;
&lt;p&gt;Sometimes you are already working with a particular label name on a given metric and you may just be wondering what all of its values are. Let&apos;s say you wanted to list all possible values for the &lt;code&gt;mode&lt;/code&gt; label on the metric name &lt;code&gt;demo_cpu_usage_seconds_total&lt;/code&gt;. Then you could query for:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;demo_cpu_usage_seconds_total&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You could even do this across all metric names / all series:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;!=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In this latter case, you may again use the label values API endpoint (but this time for the &lt;code&gt;mode&lt;/code&gt; label) instead of a PromQL query.&lt;/p&gt;
&lt;h2 id=&quot;breaking-up-series-cost-by-job-instance-metric-name-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#breaking-up-series-cost-by-job-instance-metric-name-&quot; aria-label=&quot;breaking up series cost by job instance metric name  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Breaking up series cost by job, instance, metric name, ...&lt;/h2&gt;
&lt;p&gt;As a Prometheus server administrator, the total number of time series that a server needs to keep track of is one of the main memory and scaling bottlenecks to watch out for. To get a feeling where &quot;all those series&quot; are coming from, you can write PromQL queries to count how many series there are for a given job, instance (target), metric name, or other type of dimensional grouping. Here are just a few examples of these types of debug queries, sorted by largest count first:&lt;/p&gt;
&lt;p&gt;Number of series per metric name:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sort_desc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;!=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Number of series per target:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sort_desc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;instance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;!=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Number of series per job and metric name combination:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sort_desc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;!=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You may already suspect that a particular label name has many different values. To count how many different values the &lt;code&gt;le&lt;/code&gt; histogram bucket label has in a given histogram metric (e.g. &lt;code&gt;demo_api_request_duration_seconds_bucket&lt;/code&gt;), you could query for:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;le&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;demo_api_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;...and you can take this further to count how many series there are for any dimensional combination, such as the &lt;code&gt;le&lt;/code&gt; label per job in the same histogram:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token operator&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;le&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;demo_api_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This way, you are able to get a good idea about the cost split-up of your metrics.&lt;/p&gt;
&lt;h2 id=&quot;getting-the-meaning-and-type-of-a-metric-name&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#getting-the-meaning-and-type-of-a-metric-name&quot; aria-label=&quot;getting the meaning and type of a metric name permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Getting the meaning and type of a metric name&lt;/h2&gt;
&lt;p&gt;For understanding the semantic meaning of your metrics, their documentation string and metric type information (counter, gauge, histogram, summary) are very useful. This information is not directly accessible via PromQL, but the Prometheus server keeps it in memory for each target and it can be queried via another metadata API endpoint. For example: &lt;a href=&quot;https://demo.promlabs.com/api/v1/metadata&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://demo.promlabs.com/api/v1/metadata&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To make this data more accessible, &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt; offers a built-in metrics explorer that allows fuzzy-searching across all metric names and that shows their metadata:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/metrics-explorer.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;This metrics explorer is still pretty simple, but we have a lot of ideas for evolving it into a more powerful metrics exploration toolkit!&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;While there is still ongoing work in metrics exploration UIs in Prometheus, there are a lot of PromQL queries you can run in the meantime to get a better overview over your metrics and their cost. We hope that this article will be useful the next time you are looking at the data available in a Prometheus server.&lt;/p&gt;
&lt;p&gt;And by the way: If you would like to learn more about PromQL and Prometheus in a structured way and from the ground up, be sure to also check out our &lt;a href=&quot;https://training.promlabs.com&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;self-paced Prometheus training courses&lt;/a&gt;.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Showcasing PromLens 0.11.0]]></title><description><![CDATA[Today we are happy to announce version 0.11.0 of PromLens. PromLens is the ultimate power tool for PromQL that helps you build, analyze…]]></description><link>https://promlabs.com/blog/2020/12/15/showcasing-promlens-0.11.0</link><guid isPermaLink="false">https://promlabs.com/blog/2020/12/15/showcasing-promlens-0.11.0</guid><pubDate>Tue, 15 Dec 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today we are happy to announce version 0.11.0 of &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;. PromLens is the ultimate power tool for PromQL that helps you build, analyze, explain, and visualize your queries. In case you are unfamiliar with it, &lt;a href=&quot;https://demo.promlens.com/?example&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;try a demo here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here is a summary of the most important changes since version 0.10.0 that help you edit your PromQL expressions more confidently and effectively:&lt;/p&gt;
&lt;h2 id=&quot;showing-values-for-label-names&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#showing-values-for-label-names&quot; aria-label=&quot;showing values for label names permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Showing values for label names&lt;/h2&gt;
&lt;p&gt;When looking at part of a query, you often want to get a quick overview not only of its label names, but what the label values look like for each of those names. When hovering over a label name in the tree view, PromLens now shows you the top 5 label values for each label name, according to their number of occurrences in the sub-expression&apos;s result:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/label-value-examples.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;Clicking on a label name will insert a new query below the current one that calculates the full list of values for that label, sorted by their number of occurrences:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/querying-all-label-values.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;This allows you to get much quicker insight into the data you are working with when building a query.&lt;/p&gt;
&lt;h2 id=&quot;query-hints-and-quick-fix-actions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#query-hints-and-quick-fix-actions&quot; aria-label=&quot;query hints and quick fix actions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Query hints and quick-fix actions&lt;/h2&gt;
&lt;p&gt;It&apos;s easy to make mistakes when editing PromQL, and building some constructs manually is cumbersome. PromLens now shows warning hints and quick-fix buttons for nodes in the tree view when something seems off with part of a query. For example, if you try to run a counter-only function like &lt;code&gt;rate()&lt;/code&gt; on something that looks like a gauge metric, you will get a warning, along with a suggestion to switch to &lt;code&gt;deriv&lt;/code&gt; instead:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/rate-noncounter-hint.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;Or when you forget to keep the &lt;code&gt;le&lt;/code&gt; label in an aggregated histogram before feeding it into &lt;code&gt;histogram_quantile()&lt;/code&gt;, you will get a warning about the missing label, while a quick-fix button allows to you to add the label to the aggregation:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/histogram-missing-le.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;As another example, if you have just selected a histogram metric, PromLens will recognize this and offer you a quick-action button to compute an aggregated quantile from it:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/histogram-quantile-action.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;p&gt;There are a number of other query hints and quick action buttons that will help make your PromQL editing experience more smooth.&lt;/p&gt;
&lt;p&gt;Like the other stats in the tree view, you can turn these query hints and quick actions on or off in the global settings menu:&lt;/p&gt;
&lt;video playsinline muted autoplay loop&gt;
  &lt;source src=&quot;/images/node-stats-configurability.mp4&quot; type=&quot;video/mp4&quot; /&gt;
  &lt;p&gt;Sorry, your browser does not support videos.&lt;/p&gt;
&lt;/video&gt;
&lt;h2 id=&quot;cleaning-up-old-shared-links&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cleaning-up-old-shared-links&quot; aria-label=&quot;cleaning up old shared links permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cleaning up old shared links&lt;/h2&gt;
&lt;p&gt;The full version of PromLens allows you to persist and share links to the full state of a PromLens page. Shared links are currently stored either in a Google Cloud Storage (GCS) bucket or in an SQL-based database. For SQL-based link-sharing databases, a new &lt;code&gt;--shared-links.sql.retention&lt;/code&gt; flag now allows setting a maximum retention time after which the links are deleted by a cleanup loop in the PromLens backend.&lt;/p&gt;
&lt;p&gt;For limiting the retention time in GCS-based storage, we recommend &lt;a href=&quot;https://cloud.google.com/storage/docs/bucket-lock&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;configuring a bucket retention policy&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;become-more-productive-with-promlens-today&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#become-more-productive-with-promlens-today&quot; aria-label=&quot;become more productive with promlens today permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Become more productive with PromLens today!&lt;/h2&gt;
&lt;p&gt;We are continuously improving PromLens and hope that you will enjoy these new features. You can see the &lt;a href=&quot;https://github.com/promlabs/promlens-public/blob/master/CHANGELOG.md#0110--2020-12-15&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;full list of changes in the PromLens 0.11.0 changelog&lt;/a&gt;. Check out &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt; today, &lt;a href=&quot;https://github.com/promlabs/promlens-public#promlens&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;deploy the free preview version&lt;/a&gt;, &lt;a href=&quot;https://promlens.com/pricing&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;get the full on-premise version&lt;/a&gt;, and &lt;a href=&quot;https://github.com/promlabs/promlens-public/issues&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;report any issues or feature requests you may encounter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Happy monitoring!&lt;/p&gt;
&lt;div style=&quot;text-align:center;padding:18px;font-size:1.15em;margin-bottom:15px;background-color:#fff2ed&quot; class=&quot;container-fluid&quot;&gt;&lt;svg stroke=&quot;currentColor&quot; fill=&quot;none&quot; stroke-width=&quot;2&quot; viewBox=&quot;0 0 24 24&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; style=&quot;margin-top:-2px&quot; height=&quot;1em&quot; width=&quot;1em&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;polyline points=&quot;13 17 18 12 13 7&quot;&gt;&lt;/polyline&gt;&lt;polyline points=&quot;6 17 11 12 6 7&quot;&gt;&lt;/polyline&gt;&lt;/svg&gt; &lt;strong&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://promlens.com/pricing&quot; style=&quot;text-decoration:underline&quot;&gt;Get PromLens now!&lt;/a&gt;&lt;/strong&gt; &lt;svg stroke=&quot;currentColor&quot; fill=&quot;none&quot; stroke-width=&quot;2&quot; viewBox=&quot;0 0 24 24&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; style=&quot;margin-top:-2px&quot; height=&quot;1em&quot; width=&quot;1em&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;polyline points=&quot;11 17 6 12 11 7&quot;&gt;&lt;/polyline&gt;&lt;polyline points=&quot;18 17 13 12 18 7&quot;&gt;&lt;/polyline&gt;&lt;/svg&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[An Update on PromQL Compatibility Across Vendors]]></title><description><![CDATA[Prometheus's query language PromQL is one of the cornerstones of the Prometheus ecosystem. Back in our August blog post, Comparing PromQL…]]></description><link>https://promlabs.com/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors</link><guid isPermaLink="false">https://promlabs.com/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors</guid><pubDate>Tue, 01 Dec 2020 00:00:00 GMT</pubDate><content:encoded>&lt;div style=&quot;background-color: #f6f6f6; padding: 20px 20px 0 20px; margin-bottom: 25px;&quot;&gt;
&lt;i&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; See the details of all PromQL compliance test results on our &lt;a href=&quot;https://promlabs.com/promql-compliance-tests&quot;&gt;PromQL Compliance Test Results page&lt;/a&gt; or in the table below:&lt;/i&gt;
&lt;table class=&quot;mt-3 table&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Test target&lt;/th&gt;&lt;th&gt;Passing&lt;/th&gt;&lt;th&gt;Cross-cutting issues&lt;/th&gt;&lt;th&gt;More details&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://chronosphere.io/&quot;&gt;Chronosphere&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;525 / 525 cases (&lt;strong&gt;100%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/chronosphere&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://cortexmetrics.io/&quot;&gt;Cortex&lt;/a&gt;&lt;/strong&gt; (v1.5.0 - chunks)&lt;/td&gt;&lt;td&gt;523 / 525 cases (&lt;strong&gt;99.62%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/cortex-chunks&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://cortexmetrics.io/&quot;&gt;Cortex&lt;/a&gt;&lt;/strong&gt; (v1.5.0 - blocks)&lt;/td&gt;&lt;td&gt;525 / 525 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/cortex-blocks&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://grafana.com/&quot;&gt;Grafana Cloud&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;525 / 525 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/grafanacloud&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://m3db.io/&quot;&gt;M3&lt;/a&gt;&lt;/strong&gt; (v1.0.0)&lt;/td&gt;&lt;td&gt;525 / 525 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/m3&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://metricfire.com/&quot;&gt;MetricFire&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;523 / 525 cases (&lt;strong&gt;99.62%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/metricfire&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://newrelic.com/&quot;&gt;New Relic&lt;/a&gt;&lt;/strong&gt; (hosted)&lt;/td&gt;&lt;td&gt;163 / 525 cases (&lt;strong&gt;31.05%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/newrelic&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/timescale/promscale&quot;&gt;Promscale&lt;/a&gt;&lt;/strong&gt; (0.1.2)&lt;/td&gt;&lt;td&gt;525 / 525 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/promscale&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://thanos.io/&quot;&gt;Thanos&lt;/a&gt;&lt;/strong&gt; (v0.17.0)&lt;/td&gt;&lt;td&gt;525 / 525 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/thanos&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;&lt;a href=&quot;https://victoriametrics.com/&quot;&gt;VictoriaMetrics&lt;/a&gt;&lt;/strong&gt; (v1.47.0)&lt;/td&gt;&lt;td&gt;312 / 525 cases (&lt;strong&gt;59.43%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-12-01/victoriametrics&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Prometheus&apos;s query language &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/getting_started/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL&lt;/a&gt; is one of the cornerstones of the Prometheus ecosystem. Back in our August blog post, &lt;a href=&quot;/blog/2020/08/06/comparing-promql-correctness-across-vendors&quot;&gt;Comparing PromQL Correctness Across Vendors&lt;/a&gt;, we looked at several external projects and monitoring vendors that claimed to offer PromQL-compatible APIs. Using an &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;open-source compliance checker tool&lt;/a&gt;, we evaluated each implementation by running a set of test queries against both the native Prometheus server and the vendor implementation. As a result, we found multiple bugs in the tested projects, and mapped out in detail how each deviated from the upstream implementation.&lt;/p&gt;
&lt;p&gt;Meanwhile, more vendors have entered the PromQL space, while existing projects have worked on improving their PromQL support as a result of our last blog post. Today, we are presenting an updated set of PromQL test results both for existing projects and a couple of new ones. We tested each of these implementations against the latest Prometheus version, &lt;a href=&quot;https://github.com/prometheus/prometheus/releases/tag/v2.23.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v2.23.0&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;before-we-start-a-note-on-interpreting-test-scores&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#before-we-start-a-note-on-interpreting-test-scores&quot; aria-label=&quot;before we start a note on interpreting test scores permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Before we start: a note on interpreting test scores&lt;/h2&gt;
&lt;p&gt;When looking at individual test results, please note that the numeric scores alone paint a limited picture. They don&apos;t necessarily tell you how impactful implementation errors are, nor how many distinct behavioral differences there are. Since PromQL expressions naturally compose and build on top of each other, it is infeasible to isolate all possible query errors into fully independent test cases. Many of the test queries will contain the same constructs as other queries, in a nested way. For example: If an implementation selects data incorrectly, then this breaks not only a simple data selection test query, but also all other test query cases that try to run a function, operator, or other transformation based on selected data. The test cases also include a lot of variations of the same type of query, but with different ranges, quantile values, or other parameters. So if e.g. a function is broken in a general way, it may cause multiple test case variants to fail at the same time.&lt;/p&gt;
&lt;p&gt;Another matter of more subtle interpretation are vendor extensions and extreme edge-case behavior. For example, a vendor may choose to not raise an error when executing a function with a parameter value that is illegal in native PromQL, but legal and sensical in the extended language. Or a vendor may return a different value for an unusual edge-case behavior, such as running &lt;code&gt;histogram_quantile()&lt;/code&gt; with a quantile value larger than &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We still provide the numeric test scores as a quick way to map out the vendor landscape and to motivate the ecosystem towards achieving a 100% score. But if you need to understand behavioral differences in more depth, please &lt;a href=&quot;/promql-compliance-tests&quot;&gt;take a look at the full test results&lt;/a&gt; and read on for the details.&lt;/p&gt;
&lt;h2 id=&quot;criteria-for-including-a-vendor-in-tests&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#criteria-for-including-a-vendor-in-tests&quot; aria-label=&quot;criteria for including a vendor in tests permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Criteria for including a vendor in tests&lt;/h2&gt;
&lt;p&gt;We are always on the lookout for new PromQL implementations to include in these tests. To include a project or vendor, we look for two criteria:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Someone is either advertising full or partial PromQL compatibility of their system, and/or otherwise positioning their solution as a drop-in replacement for an existing PromQL implementation.&lt;/li&gt;
&lt;li&gt;For practical purposes, we need to be able to ingest test data into the system and query it back via a PromQL-style HTTP API. Otherwise, we can&apos;t run any tests.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Unfortunately, some vendors failed the second criterium for now, so we couldn&apos;t include them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://sysdig.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Sysdig&lt;/a&gt; &lt;a href=&quot;https://docs.sysdig.com/en/using-promql.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertises PromQL support&lt;/a&gt;, but has no &lt;code&gt;remote_write&lt;/code&gt; protocol support to ingest arbitrary test data. According to contacts at Sysdig, &lt;code&gt;remote_write&lt;/code&gt; may be supported at some point in the future, but we couldn&apos;t get a recent update on its availability timeline.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.wavefront.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Wavefront&lt;/a&gt; &lt;a href=&quot;https://docs.wavefront.com/wavefront_prometheus.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertises partial PromQL support&lt;/a&gt;, but they lack an HTTP endpoint against which to run test queries. Their PromQL support is only available within their own user interface so far, which makes it difficult to test against. However, judging by the various compatibility caveats listed in their documentation, we do not expect that they would reach a high test score if we could test them.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We hope to be able to test even more vendors in the future.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; After publishing, we received questions about PromQL support in two more vendors:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.influxdata.com/products/influxdb/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;InfluxDB&lt;/a&gt; once &lt;a href=&quot;https://github.com/influxdata/promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;started implementing PromQL support&lt;/a&gt; (coincidentally with the help of the author of this blog post), but as far as we are aware, this effort has been paused and PromQL support in InfluxDB is neither currently available nor is it being advertised.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.elastic.co/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Elastic&lt;/a&gt; recently &lt;a href=&quot;https://www.elastic.co/blog/elastic-metrics-7-7-0-released&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertised PromQL support in Elastic Metrics&lt;/a&gt;. However, the announced feature is only about Elastic Metrics being able to run queries against an &lt;em&gt;existing&lt;/em&gt; external PromQL endpoint (such as Prometheus) to then ingest the query result as metrics into Elasticsearch. There is no way to run PromQL on the resulting data stored in Elasticsearch itself.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;minor-updates-to-the-test-query-set&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#minor-updates-to-the-test-query-set&quot; aria-label=&quot;minor updates to the test query set permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Minor updates to the test query set&lt;/h2&gt;
&lt;p&gt;Since the last testing round in August, we made minor changes to the test query set:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For queries that looked at the absolute values of counter metrics (e.g. with no &lt;code&gt;rate()&lt;/code&gt; or similar counter-related function applied), we changed the selected metrics to be gauges instead. This helps keep test cases somewhat more independent for a vendor like New Relic, which does not support storing or retrieving absolute values for counters.&lt;/li&gt;
&lt;li&gt;We added a query selecting an intermittently present series to test whether &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/basics/#staleness&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;staleness handling&lt;/a&gt; works.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;lets-get-started-updated-comparisons&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lets-get-started-updated-comparisons&quot; aria-label=&quot;lets get started updated comparisons permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Let&apos;s get started: Updated comparisons&lt;/h2&gt;
&lt;p&gt;In this round of tests, we tested the following projects and vendors, in alphabetical order:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://chronosphere.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Chronosphere&lt;/a&gt; - A hosted monitoring and observability platform.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cortexmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt; - An open-source, horizontally scalable reimplementation of Prometheus.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://grafana.com/products/cloud/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana Cloud&lt;/a&gt; - A hosted monitoring and observability service.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://m3db.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;M3&lt;/a&gt; - An open-source metrics engine and time series database.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.metricfire.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;MetricFire&lt;/a&gt; - A hosted monitoing and observability service.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://newrelic.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;New Relic&lt;/a&gt; - A hosted monitoring and observability service.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://thanos.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Thanos&lt;/a&gt; - An open-source project to provide query aggregation for long-term storage and HA on top of Prometheus.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/timescale/promscale&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Promscale&lt;/a&gt; (&lt;a href=&quot;https://www.timescale.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;TimescaleDB&lt;/a&gt;) - An open-source project to store Prometheus data in TimescaleDB.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://victoriametrics.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;VictoriaMetrics&lt;/a&gt; - An open-source time-series database and monitoring system.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&apos;s look at the test results for each of these systems:&lt;/p&gt;
&lt;h3 id=&quot;chronosphere&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#chronosphere&quot; aria-label=&quot;chronosphere permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Chronosphere&lt;/h3&gt;
&lt;p&gt;Chronosphere does not have a self-service account creation system yet, but they helpfully provided us with a test account with &lt;code&gt;remote_write&lt;/code&gt; and PromQL HTTP API support. Chronosphere is built on top of M3 (tested below), so we expected similar test results for the two. After an initial test run against an outdated test environment using an older M3 version, Chronosphere updated our test account and we achieved a test score of &lt;strong&gt;100%&lt;/strong&gt; against it.&lt;/p&gt;
&lt;h3 id=&quot;cortex&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cortex&quot; aria-label=&quot;cortex permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cortex&lt;/h3&gt;
&lt;p&gt;Last time we tested Cortex we encountered two minor issues: floating-point input timestamps were &lt;a href=&quot;https://github.com/cortexproject/cortex/issues/2932&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;not rounded in the same way&lt;/a&gt; as in Prometheus, and the system did not &lt;a href=&quot;https://github.com/cortexproject/cortex/issues/416&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;support executing queries without a metric name&lt;/a&gt;. The first issue has been resolved entirely, while the second one is being addressed by a new storage mode in Cortex - the new &lt;a href=&quot;https://cortexmetrics.io/docs/blocks-storage/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;blocks storage mode&lt;/a&gt; vs. the older chunks storage mode.&lt;/p&gt;
&lt;p&gt;Let&apos;s look at &lt;a href=&quot;https://github.com/cortexproject/cortex/releases/tag/v1.5.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;version 1.5.0 of Cortex&lt;/a&gt; and see what scores each of these modes received:&lt;/p&gt;
&lt;h5 id=&quot;cortex-with-chunks-storage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cortex-with-chunks-storage&quot; aria-label=&quot;cortex with chunks storage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cortex with chunks storage&lt;/h5&gt;
&lt;p&gt;When testing Cortex with the old chunks storage, we can now remove the query tweak to align input timestamps, since that bug has been fixed. Other than that, we still get the same test score of &lt;strong&gt;99.62%&lt;/strong&gt; due to the chunks mode not supporting queries without metric names.&lt;/p&gt;
&lt;h5 id=&quot;cortex-with-blocks-storage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cortex-with-blocks-storage&quot; aria-label=&quot;cortex with blocks storage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cortex with blocks storage&lt;/h5&gt;
&lt;p&gt;Cortex with blocks storage mode now also does not require any query tweaks anymore and passes with a score of &lt;strong&gt;100%&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;grafana-cloud&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#grafana-cloud&quot; aria-label=&quot;grafana cloud permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Grafana Cloud&lt;/h3&gt;
&lt;p&gt;Grafana Cloud is a new test candidate that &lt;a href=&quot;https://grafana.com/docs/grafana-cloud/metrics/prometheus/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;advertises full hosted Prometheus functionality&lt;/a&gt;. Under the hood, Grafana Cloud uses Cortex to offer this service. According to representatives from Grafana Labs, they are in the process of phasing out the last (shared) chunks-based Cortex cluster, while all new Cortex clusters are already using blocks as their storage mode.&lt;/p&gt;
&lt;p&gt;To be able to cache PromQL queries, Grafana Cloud aligns incoming query start and end timestamps to the query resolution step width (10 seconds in our case). This is currently not configurable on the Grafana Cloud side, so we had to apply a cross-cutting query tweak to align input timestamps to our reference Prometheus server in the same way, to get comparable results.&lt;/p&gt;
&lt;p&gt;With this in mind, we tested a Grafana Cloud account via &lt;code&gt;remote_write&lt;/code&gt; and their Prometheus-style HTTP query API on both the remaining legacy cluster and a new dedicated blocks-storage cluster, and we got the same &lt;strong&gt;99.62%&lt;/strong&gt; and &lt;strong&gt;100%&lt;/strong&gt; test scores as for Cortex itself. Since the chunks-mode cluster is being retired this month, we count that as an overall &lt;strong&gt;100%&lt;/strong&gt; score for Grafana Cloud.&lt;/p&gt;
&lt;h3 id=&quot;m3&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#m3&quot; aria-label=&quot;m3 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;M3&lt;/h3&gt;
&lt;p&gt;M3 is also a new candidate in this group that states, &quot;M3 can be used as Prometheus Remote Storage and has 100% PromQL compatibility&quot;, &lt;a href=&quot;https://m3db.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;on its homepage&lt;/a&gt;. Its documentation also mentions &lt;a href=&quot;https://m3db.io/docs/integrations/prometheus/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus and PromQL integrations&lt;/a&gt; that include &lt;code&gt;remote_write&lt;/code&gt; support and a PromQL HTTP API endpoint. Using these with M3 version v1.0.0, we ran our test suite and received a test score of &lt;strong&gt;100%&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For PromQL to work 100% the same as in Prometheus, we had to ensure that our test query was only hitting raw, non-aggregated data in M3 (vs. data that has been downsampled into a lower resolution). We did this by not configuring any aggregation in our test M3 database.&lt;/p&gt;
&lt;h3 id=&quot;metricfire&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#metricfire&quot; aria-label=&quot;metricfire permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;MetricFire&lt;/h3&gt;
&lt;p&gt;MetricFire, a hosted service by the people behind &lt;a href=&quot;https://www.hostedgraphite.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;hostedgraphite.com&lt;/a&gt;, is still pretty new in the Prometheus space. While MetricFire documents how to write data into the system using the &lt;code&gt;remote_write&lt;/code&gt; protocol, there is no officially supported way to run external PromQL queries against the collected data using an HTTP API yet. However, MetricFire representatives kindly explained a way to do this. We won&apos;t detail it here, but we expect that there will be a documented public HTTP API soon. In our talks with MetricFire we learned that they also use Cortex to back their service, and we also managed to point out minor issues around their HTTP API, which were quickly resolved.&lt;/p&gt;
&lt;p&gt;MetricFire is still using a slightly outdated version of Cortex, so we ran into similar input timestamp parsing inaccuracies as with Cortex in August, and queries without a metric name are not yet supported due to using chunks-based storage. With a cross-cutting input timestamp query tweak applied, MetricFire finally achieved a score of &lt;strong&gt;99.62%&lt;/strong&gt; in our tests. Hopefully, a Cortex upgrade will resolve the remaining timestamp and metric name issues automatically in the future.&lt;/p&gt;
&lt;h3 id=&quot;new-relic&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-relic&quot; aria-label=&quot;new relic permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New Relic&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Disclosure:&lt;/em&gt; The author of this blog post has been consulting for New Relic as a freelance contractor (not currently as part of PromLabs) on working towards improved PromQL support.&lt;/p&gt;
&lt;p&gt;New Relic is a hosted observability platform that has recently released features that allow writing Prometheus data into New Relic and querying it via a PromQL-style API. The &lt;a href=&quot;https://docs.newrelic.com/docs/integrations/grafana-integrations/get-started/grafana-support-prometheus-promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;documentation advertises PromQL support and the ability to use New Relic as a Prometheus datasource for existing Grafana dashboards&lt;/a&gt;. Further documentation explains &lt;a href=&quot;https://docs.newrelic.com/docs/integrations/prometheus-integrations/view-query-data/supported-promql-features&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;differences in implementation&lt;/a&gt; and chooses to use the term &quot;PromQL-style&quot; rather than &quot;PromQL&quot;.&lt;/p&gt;
&lt;p&gt;An overall challenge for New Relic&apos;s PromQL support is that it is based on a transpilation approach, where any PromQL query has to be translated into New Relic&apos;s existing query language, &lt;a href=&quot;https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/get-started/nrql-syntax-clauses-functions&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;NRQL&lt;/a&gt;. Not only does NRQL work very differently from PromQL, the underlying data model is also not always possible to reconcile with PromQL&apos;s needs. For example, New Relic differentiates metric types (counter, gauge, etc.) on the database level and stores counter metric samples only as deltas (relative increments to the previous sample). Prometheus&apos;s TSDB does not have a concept of metric types and stores absolute values for all samples. To determine that an incoming metric from Prometheus is a counter and subsequently transform its absolute value into a delta, New Relic currently applies a heuristic that treats metrics with suffixes such as &lt;code&gt;_total&lt;/code&gt;, &lt;code&gt;_count&lt;/code&gt;, &lt;code&gt;_sum&lt;/code&gt;, or &lt;code&gt;_bucket&lt;/code&gt; as counters, and other metrics as gauges. This is not perfect and can miscategorize counters as gauges, and vice versa. Recent changes in Prometheus to allow &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/6815&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;propgation of metric metadata&lt;/a&gt; via the &lt;code&gt;remote_write&lt;/code&gt; interface will hopefully improve this situation somewhat.&lt;/p&gt;
&lt;p&gt;In our testing, we encountered a large number of behavioral differences in comparison to Prometheus. Here are some examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Binary operators between two vectors are not yet supported with any vector matching or grouping options.&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-decoration: line-through&quot;&gt;Range vector selectors (like &lt;code&gt;my_metric[5m]&lt;/code&gt;) ignore the time range that is passed into them and always select a fixed (short) time range. Thus functions like &lt;code&gt;rate()&lt;/code&gt;, &lt;code&gt;resets()&lt;/code&gt;, &lt;code&gt;delta()&lt;/code&gt;, etc. may return completely different results relative to Prometheus.&lt;/span&gt; &lt;strong&gt;UPDATE:&lt;/strong&gt; Initially we interpreted the slight difference in output values as a lack of range vector duration support (which was the case for New Relic once), but range vectors with user-specified durations are supported now. Thanks to New Relic for finding this mistake!&lt;/li&gt;
&lt;li&gt;Querying for special float value literals like &lt;code&gt;NaN&lt;/code&gt; or &lt;code&gt;Inf&lt;/code&gt; results in a query for a corresponding metric name, rather than returning that float value.&lt;/li&gt;
&lt;li&gt;Selectors that don&apos;t match anything (and return an empty result in native PromQL) return a single time series with the sample value &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Staleness handling of intermittently present metrics is not supported.&lt;/li&gt;
&lt;li&gt;Several numeric functions or operators (e.g. &lt;code&gt;max()&lt;/code&gt;, &lt;code&gt;min()&lt;/code&gt;, and &lt;code&gt;quantile()&lt;/code&gt;) return either slightly or significantly different numeric sample values.&lt;/li&gt;
&lt;li&gt;Many query types and functions still return &quot;HTTP 501 Not implemented&quot; errors.&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-decoration: line-through&quot;&gt;Scalar-vector binary arithmetic operators apply the operands in the incorrect order (e.g. &lt;code&gt;42 / foo&lt;/code&gt; results in the same value as &lt;code&gt;foo / 42&lt;/code&gt;).&lt;/span&gt; &lt;strong&gt;UPDATE:&lt;/strong&gt; As a contact at New Relic pointed out, this is not actually true, and we too quickly misinterpreted some difference in sample values. The actual reasons for differences in some of the binary operator cases are either different interpretations for certain operators (like &lt;code&gt;%&lt;/code&gt; with floating-point values), precedence, or other not fully explored reasons.&lt;/li&gt;
&lt;li&gt;Operator precedence works a bit differently (e.g. &lt;code&gt;-1 ^ 2&lt;/code&gt; resulting in &lt;code&gt;1&lt;/code&gt; vs. &lt;code&gt;-1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;...and multiple other behavioral differences.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In our testing, New Relic received an overall score of &lt;strong&gt;31.05%&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;We do want to thank New Relic for contributing support for custom HTTP headers, a TSV output mode, and treating unsupported queries separately in results, to the &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL Compliance Tester&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;promscale-timescaledb&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promscale-timescaledb&quot; aria-label=&quot;promscale timescaledb permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Promscale (TimescaleDB)&lt;/h3&gt;
&lt;p&gt;Last time we tested TimescaleDB PromQL support via its &lt;a href=&quot;https://github.com/timescale/timescale-prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;timescale-prometheus adapter&lt;/a&gt;. To give this adapter more visibility, Timescale (the company behind TimescaleDB) spun it out into a new project named &lt;a href=&quot;https://github.com/timescale/promscale&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Promscale&lt;/a&gt;. Thus, we tested Promscale &lt;a href=&quot;https://github.com/timescale/promscale/releases/tag/0.1.2&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v0.1.2&lt;/a&gt; this time around.&lt;/p&gt;
&lt;p&gt;We are happy to say that Promscale also received a &lt;strong&gt;100%&lt;/strong&gt; passing score in our tests.&lt;/p&gt;
&lt;h3 id=&quot;thanos&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#thanos&quot; aria-label=&quot;thanos permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Thanos&lt;/h3&gt;
&lt;p&gt;For Thanos, we tested version v0.14.0 last time and the latest version &lt;a href=&quot;https://github.com/thanos-io/thanos/releases/tag/v0.17.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v0.17.0&lt;/a&gt; this time around. In August, Thanos&apos; only issue was the same input timestamp parsing bug as Cortex had. However, this bug has been fixed in Thanos as well by now, and thus it passes &lt;strong&gt;100%&lt;/strong&gt; of all tests now without any query tweaks.&lt;/p&gt;
&lt;h3 id=&quot;victoriametrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#victoriametrics&quot; aria-label=&quot;victoriametrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;VictoriaMetrics&lt;/h3&gt;
&lt;p&gt;For VictoriaMetrics, we tested version v1.39.1 in our last round, and we are looking at version &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.47.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v1.47.0&lt;/a&gt; this time around. Their &lt;a href=&quot;https://victoriametrics.github.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;documentation site&lt;/a&gt; still says &quot;MetricsQL is backwards-compatible with PromQL&quot; before listing known deviations that relativize this statement further down in the document.  In our previous testing round we filed multiple issues for discrepancies that we found between Prometheus&apos; and VictoriaMetrics&apos; behavior, some of which have been fixed. Other behavioral differences are intentional in VictoriaMetrics. A summary of what we know has happened since our last round:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/672&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;issue we filed about &lt;code&gt;label_replace()&lt;/code&gt; not raising an error even for invalid target label names&lt;/a&gt; was closed because MetricsQL does support arbitrary characters in label names. That makes sense from the perspective of a language that aims to be a superset of another.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/673&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;issue about incorrect sample values in scalar-to-vector filter operations&lt;/a&gt; got fixed in VictoriaMetrics v1.39.4.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/674&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;issue about transformations that alter the meaning of a series not dropping the metric name&lt;/a&gt; first got fixed, but then the &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/674#issuecomment-707037763&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;fix got reverted again&lt;/a&gt;. We do not agree with the VictoriaMetrics&apos; interpretation that the metrics have the same meaning after the listed transformations, but independent of anyone&apos;s interpretation it is a behavioral difference to native PromQL.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/675&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;issue about unary operator precedence&lt;/a&gt; was fixed in VictoriaMetrics v1.39.4.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Other than that, most issues remain &lt;a href=&quot;/blog/2020/08/06/comparing-promql-correctness-across-vendors#victoriametrics&quot;&gt;the same as in our last round of tests&lt;/a&gt;. We did discover additional brokenness in behavior (that didn&apos;t occur with other vendors) when running the compliance tester over a range of time that was so far only partially populated with test data (because the ingester hadn&apos;t been running for a long time yet): boolean comparison operators between an instant vector and scalar (like &lt;code&gt;demo_memory_usage_bytes &gt; bool 1.2345&lt;/code&gt;) returned &lt;code&gt;0&lt;/code&gt;-valued samples instead of empty results for resolution steps at which the metric &lt;code&gt;demo_memory_usage_bytes&lt;/code&gt; didn&apos;t exist. This was also true for time-related functions such as &lt;code&gt;day_of_month()&lt;/code&gt;, &lt;code&gt;minute()&lt;/code&gt;, and others, when applying an offset to the input data. Given that it is a common real-world situation for query ranges to span beginnings and ends of time series (or intermittent series in general), we believe this is relevant for the overall result.&lt;/p&gt;
&lt;p&gt;Given this, VictoriaMetrics achieved a &lt;strong&gt;59.43%&lt;/strong&gt; overall score.&lt;/p&gt;
&lt;h2 id=&quot;recommendations-for-implementers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#recommendations-for-implementers&quot; aria-label=&quot;recommendations for implementers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Recommendations for implementers&lt;/h2&gt;
&lt;p&gt;When studying (and working on) different implementation types of PromQL, a pattern of three levels of increasing difficulty emerges:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Implementations that &lt;strong&gt;reuse the native PromQL engine&lt;/strong&gt; code on top of a compatible database system have by far the easiest and most reliable path towards good compatibility, as the interface to the underlying storage subsystem is relatively simple and easy to replicate.&lt;/li&gt;
&lt;li&gt;Implementations that &lt;strong&gt;rewrite the PromQL engine&lt;/strong&gt; from scratch are way more challenging to get right, as there are many subtle (but often important) behaviors encoded into the native implementation.&lt;/li&gt;
&lt;li&gt;Implementations that &lt;strong&gt;transpile PromQL into an existing query language&lt;/strong&gt; are the hardest to build. Most other query languages are so different from PromQL that a correct mapping of one language into the other becomes infeasible even with custom-built extensions in the target query language.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Thus, we highly recommend organizations and developers to reuse the native engine code whenever possible.&lt;/p&gt;
&lt;h2 id=&quot;future-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#future-work&quot; aria-label=&quot;future work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Future work&lt;/h2&gt;
&lt;p&gt;Much of the &lt;a href=&quot;/blog/2020/08/06/comparing-promql-correctness-across-vendors#victoriametrics&quot;&gt;previous round&apos;s &quot;Future work&quot; section&lt;/a&gt; still applies. For repeatability, it would be especially great to put all the above-mentioned manual testing into code and automate it more. And for anyone who would like to help improve the testing tool, please file issues or pull requests against the &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL Compliance Tester repository&lt;/a&gt;!&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;There is a lot of movement in the PromQL space. Existing projects and vendors are improving their PromQL implementations, while new ones are entering the space. There is a lot of variability in their quality of PromQL support, and we hope that our ongoing testing efforts help by shining a light on these differences. We believe that compatibility with the native PromQL API is important for the Prometheus ecosystem, and we thus also encourage vendors to work towards becoming fully compliant when using the term &quot;PromQL&quot; to advertise their systems. We hope to see you again soon for another round of testing!&lt;/p&gt;
&lt;p&gt;To view all test results, head to our &lt;a href=&quot;/promql-compliance-tests&quot;&gt;PromQL Compliance Tests&lt;/a&gt; page, also available from our &quot;Resources&quot; menu item at the top of the page.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;We thank &lt;a href=&quot;https://grafana.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana Labs&lt;/a&gt; for supporting our PromQL compatibility testing work with funding. We do our best to provide neutral and objective compatibility testing results, independent of any such support.&lt;/em&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Showcasing PromLens 0.10.0]]></title><description><![CDATA[Today we are happy to announce version 0.10.0 of PromLens. PromLens is the ultimate power tool for PromQL that helps you build, analyze…]]></description><link>https://promlabs.com/blog/2020/10/19/showcasing-promlens-0.10.0</link><guid isPermaLink="false">https://promlabs.com/blog/2020/10/19/showcasing-promlens-0.10.0</guid><pubDate>Mon, 19 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Today we are happy to announce version 0.10.0 of &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt;. PromLens is the ultimate power tool for PromQL that helps you build, analyze, explain, and visualize your queries. In case you are unfamiliar with it, this is what it looks like:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://demo.promlens.com/?l=OTuO7josUeU&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;img src=&quot;/images/promlens-screenshot.png&quot; alt=&quot;PromLens screenshot&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is a summary of the most important changes relative to version 0.9.0 that help you take your PromQL productivity to the next level:&lt;/p&gt;
&lt;h2 id=&quot;promql-expression-editing-on-steroids&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql-expression-editing-on-steroids&quot; aria-label=&quot;promql expression editing on steroids permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL expression editing on steroids&lt;/h2&gt;
&lt;p&gt;Starting with this release, we feel that PromLens offers the world&apos;s best PromQL text editing experience, with even more exhaustive and informative autocompletion than before, as well as better inline error detection and display. Rather than relying on rough heuristics and regular expressions for making sense of the typed input, the editor implements a full PromQL parser with support for partial expressions and error recovery, which enables deep and accurate code intelligence.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/em&gt; The (unstyled) core of this editing experience was created as a collaboration between &lt;a href=&quot;https://github.com/Nexucis&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Augustin Husson&lt;/a&gt; (Amadeus) and &lt;a href=&quot;https://twitter.com/juliusvolz&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Julius Volz&lt;/a&gt; (PromLabs) and is available as an open-source &lt;a href=&quot;https://github.com/prometheus-community/codemirror-promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL extension&lt;/a&gt; for the &lt;a href=&quot;https://codemirror.net/6/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;CodeMirror Next&lt;/a&gt; editor. Special thanks to Augustin for the productive collaboration!&lt;/p&gt;
&lt;h3 id=&quot;autocompletion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#autocompletion&quot; aria-label=&quot;autocompletion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Autocompletion&lt;/h3&gt;
&lt;p&gt;The text editor now autocompletes PromQL language constructs much more precisely and exhaustively, while providing additional new hints about completion suggestions.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/autocomplete-demo.gif&quot; alt=&quot;General autocompletion demo&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Metric name&lt;/em&gt; suggestions now include the metric type and documentation string:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/complete-metric.png&quot; alt=&quot;Metric name autocompletion&quot;&gt;&lt;/p&gt;
&lt;p&gt;Please note that showing metric name metadata requires your PromQL datasource to support Prometheus&apos;s &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;metric metadata API&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Snippets&lt;/em&gt; include the intended meaning of the snippet operation:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/complete-snippet.png&quot; alt=&quot;Snippet autocompletion&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Functions, aggregation operators, and modifiers&lt;/em&gt; each show a brief description of their meaning:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/complete-function.png&quot; alt=&quot;Function autocompletion&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/complete-keyword.png&quot; alt=&quot;Keyword autocompletion&quot;&gt;&lt;/p&gt;
&lt;p&gt;We also optimized the autocompletion code to work more efficiently and not block the browser for potentially long periods of time when processing large result sets for label names and values.&lt;/p&gt;
&lt;h3 id=&quot;linting&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#linting&quot; aria-label=&quot;linting permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linting&lt;/h3&gt;
&lt;p&gt;The in-line linter now reports all PromQL errors that can be detected during parse time. Some examples of linter errors showing you the exact position and nature of problems are:&lt;/p&gt;
&lt;p&gt;Passing the wrong argument type to a function:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/linter-argtype.png&quot; alt=&quot;Wrong argument type&quot;&gt;&lt;/p&gt;
&lt;p&gt;Trying to use a set operator with a scalar operand:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/linter-setop.png&quot; alt=&quot;Scalar set operator operand&quot;&gt;&lt;/p&gt;
&lt;p&gt;Including the same label name in both an &lt;code&gt;on()&lt;/code&gt; and &lt;code&gt;group_left()&lt;/code&gt; clause at once:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/linter-group-left.png&quot; alt=&quot;Double label usage&quot;&gt;&lt;/p&gt;
&lt;p&gt;The linter not only saves you time and frustration by pointing out errors earlier in the query building process, it also shows you exactly where the errors are happening in the PromQL expression.&lt;/p&gt;
&lt;h3 id=&quot;configuring-the-editor&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#configuring-the-editor&quot; aria-label=&quot;configuring the editor permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Configuring the editor&lt;/h3&gt;
&lt;p&gt;Although we expect most people to love the advanced editor functionality that PromLens offers, we know that some users prefer a minimal experience without syntax highlighting, autocompletion, and/or inline linting. Thus, we made all of these features configurable:&lt;/p&gt;
&lt;img src=&quot;/images/editor-settings.gif&quot; alt=&quot;Editor settings&quot; style=&quot;width: 70%; margin-left: auto; margin-right: auto&quot;&gt;
&lt;p&gt;These settings are saved in the browser&apos;s local storage, so that each user can choose the editor configuration they prefer.&lt;/p&gt;
&lt;h2 id=&quot;new-metrics-explorer&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#new-metrics-explorer&quot; aria-label=&quot;new metrics explorer permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;New metrics explorer&lt;/h2&gt;
&lt;p&gt;While autocomplete is great for quickly finding a metric name, it still requires you to already know at least part of the metric you are looking for. The autocomplete dropdown is also just not very convenient for getting a more comprehensive view of all available metric names.&lt;/p&gt;
&lt;p&gt;To make the metrics exploration process easier, PromLens 0.10.0 adds a new metrics explorer that shows all metric names, along with their type and documentation string. It also allows fuzzy-filtering of the metric names:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/metrics-explorer.gif&quot; alt=&quot;Metrics explorer&quot;&gt;&lt;/p&gt;
&lt;p&gt;You can use the metrics explorer to either copy one of the metric names, or to insert it at the last cursor position into your expression input.&lt;/p&gt;
&lt;p&gt;The current iteration of the metrics explorer is still simple, but we plan on adding more advanced exploration features soon, such as drilling down and grouping by specific labels. Please give us feedback if you have specific wishes around this!&lt;/p&gt;
&lt;h2 id=&quot;linking-directly-to-a-query&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#linking-directly-to-a-query&quot; aria-label=&quot;linking directly to a query permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Linking directly to a query&lt;/h2&gt;
&lt;p&gt;Sometimes it&apos;s convenient to be able to link directly to a specific PromQL query without creating a persisted shared page link first. You can now do this by appending a &lt;code&gt;q&lt;/code&gt; query parameter to the PromLens URL. For example, &lt;a href=&quot;https://demo.promlens.com/?q=up&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://demo.promlens.com/?q=up&lt;/a&gt; directly displays and executes the query &lt;code&gt;up&lt;/code&gt;. For more complex shared pages, we still recommend creating a full shared page link, as this allows more control over the tree view state, as well as the selected visualization methods.&lt;/p&gt;
&lt;h2 id=&quot;cleaner-tree-view&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cleaner-tree-view&quot; aria-label=&quot;cleaner tree view permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cleaner tree view&lt;/h2&gt;
&lt;p&gt;The tree view got a minor cleanup to hopefully be easier to read and understand.&lt;/p&gt;
&lt;p&gt;Tree nodes now don&apos;t include placeholder indicators for child nodes anymore, since the child nodes are shown in the tree itself anyway:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/tree-cleanup.png&quot; alt=&quot;Cleaner tree view&quot;&gt;&lt;/p&gt;
&lt;p&gt;Edit buttons are now always shown for placeholder nodes, not only when hovering over them. The only purpose of placeholders is to fill them out, so their editability should be pointed out more clearly:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/placeholder-buttons.png&quot; alt=&quot;Placeholder buttons&quot;&gt;&lt;/p&gt;
&lt;p&gt;The edit buttons now also have text labels to make their meaning clearer.&lt;/p&gt;
&lt;h2 id=&quot;become-more-productive-with-promlens-today&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#become-more-productive-with-promlens-today&quot; aria-label=&quot;become more productive with promlens today permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Become more productive with PromLens today!&lt;/h2&gt;
&lt;p&gt;We are continuously improving PromLens and hope that you will enjoy these new features. You can see the &lt;a href=&quot;https://github.com/promlabs/promlens-public/blob/master/CHANGELOG.md&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;full list of changes in the PromLens 0.10.0 changelog&lt;/a&gt;. Check out &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt; today, &lt;a href=&quot;https://github.com/promlabs/promlens-public#promlens&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;deploy the free preview version&lt;/a&gt;, &lt;a href=&quot;https://promlens.com/pricing&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;get the full on-premise version&lt;/a&gt;, and &lt;a href=&quot;https://github.com/promlabs/promlens-public/issues&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;report any issues or feature requests you may encounter&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Happy monitoring!&lt;/p&gt;
&lt;div style=&quot;text-align:center;padding:18px;font-size:1.15em;margin-bottom:15px;background-color:#fff2ed&quot; class=&quot;container-fluid&quot;&gt;&lt;svg stroke=&quot;currentColor&quot; fill=&quot;none&quot; stroke-width=&quot;2&quot; viewBox=&quot;0 0 24 24&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; style=&quot;margin-top:-2px&quot; height=&quot;1em&quot; width=&quot;1em&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;polyline points=&quot;13 17 18 12 13 7&quot;&gt;&lt;/polyline&gt;&lt;polyline points=&quot;6 17 11 12 6 7&quot;&gt;&lt;/polyline&gt;&lt;/svg&gt; &lt;strong&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://promlens.com/pricing&quot; style=&quot;text-decoration:underline&quot;&gt;Get PromLens now!&lt;/a&gt;&lt;/strong&gt; &lt;svg stroke=&quot;currentColor&quot; fill=&quot;none&quot; stroke-width=&quot;2&quot; viewBox=&quot;0 0 24 24&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; style=&quot;margin-top:-2px&quot; height=&quot;1em&quot; width=&quot;1em&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;polyline points=&quot;11 17 6 12 11 7&quot;&gt;&lt;/polyline&gt;&lt;polyline points=&quot;18 17 13 12 18 7&quot;&gt;&lt;/polyline&gt;&lt;/svg&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[The Meaning of "Prometheus" - A Tale of Implementations and Interfaces]]></title><description><![CDATA[What people mean when they say that they "use Prometheus" or "support Prometheus" is evolving over time. Initially, the Prometheus landscape…]]></description><link>https://promlabs.com/blog/2020/10/13/the-meaning-of-prometheus</link><guid isPermaLink="false">https://promlabs.com/blog/2020/10/13/the-meaning-of-prometheus</guid><pubDate>Tue, 13 Oct 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;What people mean when they say that they &lt;em&gt;&quot;use Prometheus&quot;&lt;/em&gt; or &lt;em&gt;&quot;support Prometheus&quot;&lt;/em&gt; is evolving over time. Initially, the Prometheus landscape was very focused on a specific set of component implementations, whereas nowadays the focus is shifting more towards component interfaces and interoperability. Let&apos;s have a closer look at what this means, why this is happening, and in which ways this may be good or bad.&lt;/p&gt;
&lt;h2 id=&quot;prometheus-as-an-implementation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#prometheus-as-an-implementation&quot; aria-label=&quot;prometheus as an implementation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Prometheus as an implementation&lt;/h2&gt;
&lt;p&gt;When the Prometheus Team initially announced Prometheus to the world in 2015, we focused a lot on specific implementations of servers and libraries that together formed a Prometheus deployment. You could draw an architecture diagram of a fairly complete setup in this way:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-component-implementations.svg&quot; alt=&quot;Prometheus component implementations&quot;&gt;&lt;/p&gt;
&lt;p&gt;Initially all boxes in this diagram would be using binaries or at least client libraries provided by the official Prometheus project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Service targets were using one of the &lt;a href=&quot;https://prometheus.io/docs/instrumenting/clientlibs/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;official Prometheus client libraries&lt;/a&gt; to track and expose metrics.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/prometheus/prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;official Prometheus server&lt;/a&gt; was collecting and processing all data.&lt;/li&gt;
&lt;li&gt;Querying via PromQL would always happen via the Prometheus server as well.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://github.com/prometheus/alertmanager&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;official Alertmanager server&lt;/a&gt; was processing all alerts and sending notifications.&lt;/li&gt;
&lt;li&gt;There was no remote storage integration yet, but it is outlined above because we will be speaking about it later.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In general, people focused a lot on the Prometheus server&apos;s architecture, its TSDB implementation and efficiency, the operational simplicity and Go-based implementation, service-discovery integration to enable monitoring of dynamic environments, how to achieve highly available deployment setups with the vanilla Prometheus server, and so on. The same was true for the Alertmanager and other core components.&lt;/p&gt;
&lt;h2 id=&quot;prometheus-as-a-set-of-interfaces&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#prometheus-as-a-set-of-interfaces&quot; aria-label=&quot;prometheus as a set of interfaces permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Prometheus as a set of interfaces&lt;/h2&gt;
&lt;p&gt;Fast forward to 2020. When people say that they &quot;do Prometheus&quot;, it is harder to determine what they exactly mean, since the focus of the word has shifted more towards the set of interfaces connecting the boxes in the diagram, than on the boxes themselves:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-interfaces.svg&quot; alt=&quot;Prometheus interfaces&quot;&gt;&lt;/p&gt;
&lt;p&gt;It is clear that any box in the diagram can be replaced by a different implementation, as long as the boxes still speak the same language. Let&apos;s look at what this means for the various components and interfaces:&lt;/p&gt;
&lt;h3 id=&quot;exposition&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#exposition&quot; aria-label=&quot;exposition permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exposition&lt;/h3&gt;
&lt;p&gt;For exposing metrics to a Prometheus server, the only thing that really matters is to implement an HTTP endpoint that serves the &lt;a href=&quot;https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus metrics exposition format&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-exposition-interface.svg&quot; alt=&quot;Prometheus exposition interface&quot;&gt;&lt;/p&gt;
&lt;p&gt;While the official Prometheus client libraries are still the most popular way to output Prometheus-compatible metrics from a process, there are now many third-party libraries as well, or even people writing ad-hoc custom serialization code, since the format is so simple (and simplicity of generation has always been the intention!). A slight evolution of this metrics format is also being standardized as part of the &lt;a href=&quot;https://openmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenMetrics project&lt;/a&gt;, which the Prometheus server can already scrape, and which &lt;a href=&quot;https://opentelemetry.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;OpenTelemetry&lt;/a&gt; will support as an output format.&lt;/p&gt;
&lt;h3 id=&quot;metrics-collection&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#metrics-collection&quot; aria-label=&quot;metrics collection permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Metrics collection&lt;/h3&gt;
&lt;p&gt;On the other end of that same interface, the Prometheus server usually collects metrics from the scraped target:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-exposition-interface.svg&quot; alt=&quot;Prometheus exposition interface&quot;&gt;&lt;/p&gt;
&lt;p&gt;There are many third-party solutions that support collection of metrics in this way, as the format is simple and there are multiple available parsers.&lt;/p&gt;
&lt;p&gt;Believe it or not, some &quot;Prometheus&quot;-style setups these days don&apos;t even include a Prometheus server, but just run an agent that scrapes metrics in the Prometheus format and forwards them to a remote storage system. One prominent example is the &lt;a href=&quot;https://github.com/grafana/agent&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana Agent&lt;/a&gt; that collects and forwards metrics using the remote write protocol (see further down), without even storing any metrics locally. The same is true for agents of some other monitoring SaaS providers, like the &lt;a href=&quot;https://docs.sysdig.com/en/docs/sysdig-monitor/monitoring-integrations/legacy-integrations/legacycollect-prometheus-metrics/working-with-prometheus-metrics/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Sysdig Agent&lt;/a&gt; and the &lt;a href=&quot;https://www.datadoghq.com/blog/monitor-prometheus-metrics/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Datadog Agent&lt;/a&gt;. Unfortunately, one benefit of the Prometheus server that these scraping alternatives don&apos;t always retain is Prometheus&apos;s excellent integration with service discovery and the detailed labeling of targets that it enables.&lt;/p&gt;
&lt;h3 id=&quot;promql&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql&quot; aria-label=&quot;promql permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL&lt;/h3&gt;
&lt;p&gt;The Prometheus Query Language (PromQL) is the core piece of Prometheus that enables ad-hoc diagnostics, graphing, and alerting, all using a single unified language. It is usually served on a set of HTTP endpoints in the Prometheus server:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-promql-interface.svg&quot; alt=&quot;Prometheus PromQL interface&quot;&gt;&lt;/p&gt;
&lt;p&gt;Many open-source projects and vendors now say that they support PromQL in their custom storage systems, while the actual level of compatibility varies. We previously looked at the PromQL compatibility of different implementations in more detail in &lt;a href=&quot;/blog/2020/08/06/comparing-promql-correctness-across-vendors&quot;&gt;another blog post&lt;/a&gt; and will have a follow-up post to share soon. Compatibility for PromQL is important as it is the key way for working with data in Prometheus. Most importantly, if alerting rules break in undetected ways due to an incompatible implementation, the cost to the user may be significant.&lt;/p&gt;
&lt;p&gt;PromQL is by far the largest and trickiest interface to reimplement from scratch. Not only does it consist of many different functions, operators, and syntactical constructs, but it also has a lot of subtle execution behaviors that were either carefully designed or got introduced by historical accident. In practice we have seen the highest level of compatibility in projects that reuse the &lt;a href=&quot;https://github.com/prometheus/prometheus/tree/master/promql&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;upstream Prometheus PromQL engine code&lt;/a&gt; and only replace the storage integration.&lt;/p&gt;
&lt;h3 id=&quot;remote-write-and-remote-storage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#remote-write-and-remote-storage&quot; aria-label=&quot;remote write and remote storage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Remote write and remote storage&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;remote write protocol&lt;/a&gt; allows Prometheus to forward scraped data to a remote storage system:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-remote-write-interface.svg&quot; alt=&quot;Prometheus remote write interface&quot;&gt;&lt;/p&gt;
&lt;p&gt;Even more intentionally than for the other interfaces, the purpose of this protocol has always been to enable a large ecosystem of third-party implementations accepting data on the remote side. Those third-party implementations may then choose different tradeoffs for the storage and processing of metrics, especially providing better durability and horizontal scalability than the vanilla Prometheus server.&lt;/p&gt;
&lt;p&gt;By now there are many systems accepting the remote write protocol (and some also the remote read protocol, a way to read back samples via Prometheus). &lt;a href=&quot;https://github.com/cortexproject/cortex&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt; and &lt;a href=&quot;https://github.com/timescale/promscale&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Promscale&lt;/a&gt; are two examples, with a &lt;a href=&quot;https://prometheus.io/docs/operating/integrations/#remote-endpoints-and-storage&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;larger list documented on the Prometheus website&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The remote write protocol has probably been the biggest enabler for commercial SaaS providers to support Prometheus features, as it allows ingesting on-premise data into a vendor&apos;s storage cloud.&lt;/p&gt;
&lt;h3 id=&quot;alert-dispatching&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#alert-dispatching&quot; aria-label=&quot;alert dispatching permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Alert dispatching&lt;/h3&gt;
&lt;p&gt;When Prometheus determines that an alert should fire, it sends an ongoing stream of notifications about this to the Alertmanager:&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 65%&quot; src=&quot;/images/prometheus-alerting-interface.svg&quot; alt=&quot;Prometheus alerting interface&quot;&gt;&lt;/p&gt;
&lt;p&gt;This interface is not reimplemented much (&lt;a href=&quot;https://prometheus.io/docs/alerting/latest/clients/#sending-alerts&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;although it has been documented&lt;/a&gt;), and even the few replacements for Alertmanager tend to not be full reimplementations. This is due to the fact that this protocol is fairly low-level and puts a large burden on the receiver implementation: alerts are sent repeatedly as long as they are still firing, and the receiver (normally Alertmanager) carries the responsibility of aggregating the raw alert stream over time and across label sets, and then routing notifications to their destinations. Usually the Prometheus Team does not encourage full reimplementations of this protocol, especially on the receiving side.&lt;/p&gt;
&lt;h2 id=&quot;other-interfaces&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-interfaces&quot; aria-label=&quot;other interfaces permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other interfaces&lt;/h2&gt;
&lt;p&gt;Besides the interfaces discussed above, there are a number of other integration points to be aware of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://prometheus.io/docs/operating/integrations/#alertmanager-webhook-receiver&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Alertmanager webhook receiver&lt;/a&gt; allows building custom notification mechanisms that are not supported out of the box, and there are a myriad of integrations for it.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Alerting rule&lt;/a&gt; and &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/configuration/recording_rules/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;recording rule&lt;/a&gt; files and the evaluation of the rules contained therein are reimplemented in some third-party systems like Cortex.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://prometheus.io/docs/operating/integrations/#file-service-discovery&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;file-based service discovery&lt;/a&gt; mechanism in Prometheus allows implementing external custom service discovery mechanisms.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We won&apos;t discuss these interfaces in detail here, but they show more flexible ways for people to openly integrate with Prometheus.&lt;/p&gt;
&lt;h2 id=&quot;why-is-this-happening&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-is-this-happening&quot; aria-label=&quot;why is this happening permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why is this happening?&lt;/h2&gt;
&lt;p&gt;The reorientation around interfaces and their implementation in third-party systems is happening for a variety of reasons. The most obvious ones are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;People are looking for different tradeoffs&lt;/strong&gt; than the ones in Prometheus itself. For example, Cortex aims to be a horizontally scalable clustered storage system, whereas a vanilla Prometheus server explicitly aims to be simple and does not support clustering.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;People need to integrate with existing systems&lt;/strong&gt;, and it&apos;s often not possible to replace all parts of an existing monitoring infrastructure at once.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Existing monitoring vendors want a piece of the cake&lt;/strong&gt;, and in a world in which Prometheus is the de-facto standard for open-source monitoring, it is immensely valuable to companies both from a marketing perspective and also for their customers to offer Prometheus support.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The above reasons also often mean that only some of the boxes in the architecture diagram get replaced, while others remain vanilla upstream Prometheus implementations. Thus the official Prometheus components are likely still the most popular overall.&lt;/p&gt;
&lt;h2 id=&quot;what-do-you-need-to-watch-out-for&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-do-you-need-to-watch-out-for&quot; aria-label=&quot;what do you need to watch out for permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What do you need to watch out for?&lt;/h2&gt;
&lt;p&gt;It is encouraging to see such a huge adoption of Prometheus&apos;s interfaces across the entire monitoring world. At the same time it does mean that the landscape has become more challenging to understand and to keep honest:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When an engineer or marketing person claims &lt;em&gt;&quot;Prometheus support&quot;&lt;/em&gt; for their system, ask them which of these interfaces they actually mean, and whether you are happy with the specific tradeoffs that their compatible reimplementation is choosing.&lt;/li&gt;
&lt;li&gt;When someone claims specific support for an interface like PromQL, how compatible are they really?&lt;/li&gt;
&lt;li&gt;When choosing alternative interface implementations, you will generally need to do more research about what options are available to you.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Besides these words of caution, we think that it is a huge net win that people are creating a vibrant ecosystem around Prometheus&apos;s open interfaces! We should just aim to maintain as much clarity and compatibility as possible.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In recent years, the focus has shifted from a specific set of Prometheus component implementations to the open interfaces that connect them. This has enabled all kinds of flexible re-combinations of monitoring architectures with different tradeoffs and better integration into existing ecosystems. Hopefully this will also lead to greater longevity of those interfaces, as they are now becoming a cornerstone of the world&apos;s monitoring infrastructure. Just keep in mind that this open landscape will also require a bit more research by users as to which specific technologies with (claimed) Prometheus support they should use, and when. In our role as part of the Prometheus Team, we are the shepherds of the Prometheus ecosystem and need to give more guidance on this, both to avoid overly broad marketing claims and to support the projects and companies actively wanting to support Prometheus-style monitoring. In our role as PromLabs, we are happy to help customers navigate this space and aid vendors in building correct implementations of these interfaces.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Metric Types in Prometheus and PromQL]]></title><description><![CDATA[Prometheus has the concept of different metric types: counters, gauges, histograms, and summaries. If you've ever wondered what these terms…]]></description><link>https://promlabs.com/blog/2020/09/25/metric-types-in-prometheus-and-promql</link><guid isPermaLink="false">https://promlabs.com/blog/2020/09/25/metric-types-in-prometheus-and-promql</guid><pubDate>Fri, 25 Sep 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Prometheus has the concept of different &lt;em&gt;metric types&lt;/em&gt;: counters, gauges, histograms, and summaries. If you&apos;ve ever wondered what these terms were about, this blog post is for you! We&apos;ll look at the meaning of each metric type, how to use it when instrumenting application code, how the type is exposed to Prometheus over HTTP, and what to watch out for when using metrics of different types in PromQL.&lt;/p&gt;
&lt;h2 id=&quot;overview&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#overview&quot; aria-label=&quot;overview permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Overview&lt;/h2&gt;
&lt;p&gt;Prometheus differentiates between &lt;a href=&quot;https://prometheus.io/docs/concepts/metric_types/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;four types of metrics&lt;/a&gt; that are used to track aspects of a system. These types are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Gauge:&lt;/strong&gt; A gauge is for tracking current tallies, or things that can naturally go up or down, like memory usage, queue lengths, in-flight requests, or current CPU usage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Counter:&lt;/strong&gt; A counter is for tracking cumulative totals over a number of events or quantities like the total number of HTTP requests or the total number of seconds spent handling requests. Counters only decrease in value when the process that exposes them restarts, in which case they get reset to &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Histogram:&lt;/strong&gt; A histogram is used to track the distribution of a set of observed values (like request latencies) across a set of buckets. It also tracks the total number of observed values, as well as the cumulative sum of the observed values.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Summary:&lt;/strong&gt; A summary is used to track the distribution of a set of observed values (like request latencies) as a set of quantiles / percentiles. It also tracks the total number of observed values, as well as the cumulative sum of the observed values.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Below, we will look at how these metric types manifest themselves across the entire Prometheus pipeline, from instrumentation over exposition and processing, to PromQL:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/metric_types_across_stages.svg&quot; alt=&quot;Metric type handling across stages&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;metric-types-in-instrumentation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#metric-types-in-instrumentation&quot; aria-label=&quot;metric types in instrumentation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Metric types in instrumentation&lt;/h2&gt;
&lt;p&gt;Metric types are most visible when you are instrumenting a service using one of the Prometheus client libraries, as each metric type&apos;s API object offers you methods specific to that type. Using the &lt;a href=&quot;https://github.com/prometheus/client_golang&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus Go client library&lt;/a&gt; as an example, let&apos;s take a look at how these types differ in usage. We will omit steps here that work the same across metric types, such as registering the metrics to be served via HTTP. We will also focus on metrics without any additional explicit label dimensions (like splitting requests up by endpoint, method, etc.).&lt;/p&gt;
&lt;h3 id=&quot;gauge-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#gauge-metrics&quot; aria-label=&quot;gauge metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Gauge metrics&lt;/h3&gt;
&lt;p&gt;Creating a gauge metric is as simple as giving it a name and documentation string:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;queueLength &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NewGauge&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;GaugeOpts&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	Name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;queue_length&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Help&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;The number of items in the queue.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Gauge metrics are allowed to go up or down, and they can also be set to explicit values, so the gauge metric type exposes methods for that:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Use Set() when you know the absolute value from some other source.&lt;/span&gt;
queueLength&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Use these methods when your code directly observes the increase or decrease of something, such as adding an item to a queue.&lt;/span&gt;
queueLength&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Inc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Increment by 1.&lt;/span&gt;
queueLength&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Dec&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Decrement by 1.&lt;/span&gt;
queueLength&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
queueLength&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Sub&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Since gauges are frequently used to expose Unix timestamps as sample values, there is also a convenience method to set a gauge to the current timestamp:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;demoTimestamp&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;SetToCurrentTime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;counter-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#counter-metrics&quot; aria-label=&quot;counter metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Counter metrics&lt;/h3&gt;
&lt;p&gt;Creating a counter metric is similar to a gauge:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;totalRequests &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NewCounter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;CounterOpts&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	Name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;http_requests_total&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	Help&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;The total number of handled HTTP requests.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;But unlike gauges, counters may only increase over time, so you cannot set them to an arbitrary absolute value or decrease them (nor should you ever want to):&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;totalRequests&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Inc&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
totalRequests&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Counters do reset to &lt;code&gt;0&lt;/code&gt; when the service process restarts, but this is fine, as functions like &lt;code&gt;rate()&lt;/code&gt; know how to handle this.&lt;/p&gt;
&lt;h3 id=&quot;histogram-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#histogram-metrics&quot; aria-label=&quot;histogram metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Histogram metrics&lt;/h3&gt;
&lt;p&gt;Creating a histogram metric is a bit more involved, as you will need to configure the number of buckets you want to categorize observations into, and the upper boundary of each bucket. Prometheus histograms are &lt;em&gt;cumulative&lt;/em&gt;, meaning that each subsequent bucket contains the observation count of the previous bucket, or put into other words, all bucket lower boundaries start at zero. So you will not need to explicitly configure the lower bound of each bucket, only the upper bound:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;requestDurations &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NewHistogram&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;HistogramOpts&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  Name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;    &lt;span class=&quot;token string&quot;&gt;&quot;http_request_duration_seconds&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  Help&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;    &lt;span class=&quot;token string&quot;&gt;&quot;A histogram of the HTTP request durations in seconds.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// Bucket configuration: the first bucket includes all requests finishing in 0.05 seconds, the last one includes all requests finishing in 10 seconds.&lt;/span&gt;
  Buckets&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;float64&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0.05&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.25&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Since enumerating all buckets can be tedious, there are helper functions like &lt;code&gt;prometheus.LinearBuckets()&lt;/code&gt; and &lt;code&gt;prometheus.ExponentialBuckets()&lt;/code&gt; that can help you generate linear or exponential bucketing schemes.&lt;/p&gt;
&lt;p&gt;A histogram automatically categorizes and counts distributions of values for you, so it only has an &lt;code&gt;Observe()&lt;/code&gt; method, which you call whenever you handle something to track in your code. For example, if you just handled an HTTP request which took 0.42 seconds, you would do:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;requestDurations&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Observe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0.42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The Go client library provides helper functions for timing durations and then automatically observing them into a histogram:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;timer &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NewTimer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;requestDurations&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// [...Handle the request...]&lt;/span&gt;
timer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ObserveDuration&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;summary-metrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary-metrics&quot; aria-label=&quot;summary metrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary metrics&lt;/h3&gt;
&lt;p&gt;Creating and using a summary is similar to a histogram, except that you will need to specify which quantiles you want to track and don&apos;t have to deal with buckets. For example, if you wanted to track the 50th, 90th, and 99th percentiles across HTTP request latencies, you would create a summary like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;requestDurations &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NewSummary&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prometheus&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;SummaryOpts&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Name&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;       &lt;span class=&quot;token string&quot;&gt;&quot;http_request_duration_seconds&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    Help&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;       &lt;span class=&quot;token string&quot;&gt;&quot;A summary of the HTTP request durations in seconds.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    Objectives&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;float64&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;float64&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token number&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.05&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;   &lt;span class=&quot;token comment&quot;&gt;// 50th percentile with a max. absolute error of 0.05.&lt;/span&gt;
      &lt;span class=&quot;token number&quot;&gt;0.9&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;   &lt;span class=&quot;token comment&quot;&gt;// 90th percentile with a max. absolute error of 0.01.&lt;/span&gt;
      &lt;span class=&quot;token number&quot;&gt;0.99&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.001&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 99th percentile with a max. absolute error of 0.001.&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;After creation, tracking durations works exactly like for histograms:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;requestDurations&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Observe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0.42&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;a-note-on-histograms-vs-summaries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#a-note-on-histograms-vs-summaries&quot; aria-label=&quot;a note on histograms vs summaries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A note on histograms vs. summaries&lt;/h3&gt;
&lt;p&gt;It is important to note that while histogram buckets can be aggregated across dimensions (such as endpoint, HTTP method, etc.), this is not statistically valid for summary quantiles! See also the &lt;a href=&quot;https://prometheus.io/docs/practices/histograms/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;best practices documentation about histogram and summary metrics&lt;/a&gt; to learn more about the tradeoffs of histograms and summaries, and how to choose histogram bucket boundaries correctly.&lt;/p&gt;
&lt;h2 id=&quot;exposition&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#exposition&quot; aria-label=&quot;exposition permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exposition&lt;/h2&gt;
&lt;p&gt;Now let&apos;s see how each of our examples above would be serialized into the HTTP exposition format, which Prometheus sees when it scrapes a target.&lt;/p&gt;
&lt;p&gt;Our gauge (with no explicit user-specified labels) gets rendered out as a single time series:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# HELP queue_length The number of items in the queue.&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE queue_length gauge&lt;/span&gt;
queue_length &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Our HTTP request counter also gets sent as a single series:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# HELP http_requests_total The total number of handled HTTP requests.&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE http_requests_total counter&lt;/span&gt;
http_requests_total &lt;span class=&quot;token number&quot;&gt;7734&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As you can see, the documentation string and metric type also make it into the exposition format.&lt;/p&gt;
&lt;p&gt;However, histograms and summaries track more complex information that can&apos;t be expressed as a single series. Since Prometheus only understands individual time series when scraping, these two metric types need to be mapped into a set of time series that together encode all relevant information.&lt;/p&gt;
&lt;p&gt;Our histogram example would end up being rendered like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# HELP http_request_duration_seconds A histogram of the HTTP request durations in seconds.&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE http_request_duration_seconds histogram&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.05&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;4599&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;24128&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.25&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;45311&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.5&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;59983&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60345&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;2.5&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;114003&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;5&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;201325&lt;/span&gt;
http_request_duration_seconds_bucket&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;le&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;+Inf&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;227420&lt;/span&gt;
http_request_duration_seconds_sum &lt;span class=&quot;token number&quot;&gt;88364.234&lt;/span&gt;
http_request_duration_seconds_count &lt;span class=&quot;token number&quot;&gt;227420&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Each configured bucket ends up as one counter time series with a &lt;code&gt;_bucket&lt;/code&gt; suffix, indicating the upper bound of that bucket using an &lt;code&gt;le&lt;/code&gt; (&quot;less-than-or-equal&quot;) label. An implicit bucket with the upper bound &lt;code&gt;+Inf&lt;/code&gt; is also exposed to catch requests that took longer than the largest configured bucket boundary. Lastly, the exposition format includes the cumulative sum and count over all observations using the suffixes &lt;code&gt;_sum&lt;/code&gt; and &lt;code&gt;_count&lt;/code&gt;. Each of these time series is conceptually a counter (individual values that can only go up), although they were created as part of a histogram in the instrumentation library.&lt;/p&gt;
&lt;p&gt;Our summary is exposed much like the histogram, except that a &lt;code&gt;quantile&lt;/code&gt; label is used to indicate per-quantile series, and those series don&apos;t have a suffix that extends the metric name:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# HELP http_request_duration_seconds A summary of the HTTP request durations in seconds.&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# TYPE http_request_duration_seconds summary&lt;/span&gt;
http_request_duration_seconds&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;quantile&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.5&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.052&lt;/span&gt;
http_request_duration_seconds&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;quantile&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.90&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0.564&lt;/span&gt;
http_request_duration_seconds&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;quantile&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;0.99&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2.372&lt;/span&gt;
http_request_duration_seconds_sum &lt;span class=&quot;token number&quot;&gt;88364.234&lt;/span&gt;
http_request_duration_seconds_count &lt;span class=&quot;token number&quot;&gt;227420&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;how-the-prometheus-server-processes-metric-types&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-the-prometheus-server-processes-metric-types&quot; aria-label=&quot;how the prometheus server processes metric types permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How the Prometheus server processes metric types&lt;/h3&gt;
&lt;p&gt;For the longest time, the Prometheus server simply threw away any metric type (and documentation string) metadata when it scraped time series from a target. Starting with Prometheus 2.4.0, the server now stores this metadata in memory for each scrape target, and external users can query the metadata using an &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;API endpoint&lt;/a&gt;. This is useful for user interfaces such as &lt;a href=&quot;https://promlens.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens&lt;/a&gt; or &lt;a href=&quot;https://grafana.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Grafana&lt;/a&gt; that want to show additional help to users while building queries.&lt;/p&gt;
&lt;p&gt;Other than tracking and exposing the metadata in this way, the Prometheus server itself does not do any further processing of this metadata yet. There is a &lt;a href=&quot;https://github.com/prometheus/prometheus/pull/7771&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;proposal for propagating metric types to remote storage systems&lt;/a&gt; via Prometheus&apos;s &lt;code&gt;remote_write&lt;/code&gt; protocol, but this has not been implemented yet.&lt;/p&gt;
&lt;h3 id=&quot;metric-types-in-promql&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#metric-types-in-promql&quot; aria-label=&quot;metric types in promql permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Metric types in PromQL&lt;/h3&gt;
&lt;p&gt;As mentioned in our previous post on &lt;a href=&quot;https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;The Anatomy of a PromQL Query&lt;/a&gt;, PromQL surprisingly has no direct concept or knowledge of the four different metric types at all. All it knows on a fundamental level are flat time series with metric names, label sets, and samples (timestamp / value pairs) attached to them. &lt;em&gt;However&lt;/em&gt;, PromQL includes some functions that expect the input series to look and behave like a specific metric type.&lt;/p&gt;
&lt;p&gt;The most prominent examples of these metric-type-aware functions are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;rate()&lt;/code&gt; / &lt;code&gt;irate()&lt;/code&gt; / &lt;code&gt;increase()&lt;/code&gt; / &lt;code&gt;resets()&lt;/code&gt;: These functions only work properly for &lt;em&gt;counter&lt;/em&gt; metrics, as they interpret any decrease in value over time as a counter reset. In the case of the &lt;code&gt;rate()&lt;/code&gt;-style functions, these resets will be approximated away and only positive rates are computed, leading to totally incorrect results when using these functions on gauge metrics.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;delta()&lt;/code&gt; / &lt;code&gt;idelta()&lt;/code&gt; / &lt;code&gt;deriv()&lt;/code&gt; / &lt;code&gt;predict_linear()&lt;/code&gt;: These functions only work properly for &lt;em&gt;gauge&lt;/em&gt; metrics, as they treat increases and decreases in input metrics the same, and don&apos;t interpret decreases as counter resets.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;histogram_quantile()&lt;/code&gt;: This function only works for &lt;em&gt;histogram&lt;/em&gt; metrics: each input series needs to have a sensical &lt;code&gt;le&lt;/code&gt; label to indicate the bucket boundary, and the cumulative value counts between buckets need to make sense.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are no functions that are specific to summary metrics (as there is not much you can compute over a quantile value), but you can conceptually see the quantile values exported from a summary metric as a set of gauges.&lt;/p&gt;
&lt;p&gt;PromQL functions can usually not figure out and complain automatically when you are passing in the wrong metric type, but we recommend following the &lt;a href=&quot;https://prometheus.io/docs/practices/naming/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus metric naming best practices&lt;/a&gt; to at least make it easy for humans to see what type of metric they are dealing with. For example, counters should end with &lt;code&gt;_total&lt;/code&gt;, whereas gauges should not have such a suffix.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;As we have seen, metric types are conceptually most visible when instrumenting services with a client library, become less pronounced when Prometheus ingests metrics, and then become implicitly relevant again when building queries in PromQL. Metric type metadata might be used and propagated more strongly in future Prometheus versions, but for now it is important to understand the differences between types as a user to build correct instrumentation and queries.&lt;/p&gt;
&lt;h2 id=&quot;related-content&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#related-content&quot; aria-label=&quot;related content permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Related Content&lt;/h2&gt;
&lt;p&gt;We also made a video about the 4 metric types in Prometheus and PromQL:&lt;/p&gt;
&lt;div style=&quot;max-width: 530px; margin: auto;&quot;&gt;
  &lt;div style=&quot;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden&quot;&gt;
    &lt;iframe style=&quot;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0&quot; style=&quot;margin: auto; display: block&quot; src=&quot;https://www.youtube.com/embed/fhx0ehppMGM&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen&gt;&lt;/iframe&gt;
  &lt;/div&gt;
&lt;/div&gt;</content:encoded></item><item><title><![CDATA[Comparing PromQL Correctness Across Vendors]]></title><description><![CDATA[UPDATE: See our follow-up blog post from December 1 for the latest round of PromQL vendor test results. Prometheus' query language PromQL is…]]></description><link>https://promlabs.com/blog/2020/08/06/comparing-promql-correctness-across-vendors</link><guid isPermaLink="false">https://promlabs.com/blog/2020/08/06/comparing-promql-correctness-across-vendors</guid><pubDate>Thu, 06 Aug 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; See our &lt;a href=&quot;/blog/2020/11/26/an-update-on-promql-compatibility-across-vendors&quot;&gt;follow-up blog post from December 1&lt;/a&gt; for the latest round of PromQL vendor test results.&lt;/p&gt;
&lt;div style=&quot;background-color: #f6f6f6; padding: 20px 20px 0 20px; margin-bottom: 25px;&quot;&gt;
&lt;i&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; See the details of all PromQL compliance test results on our &lt;a href=&quot;https://promlabs.com/promql-compliance-tests&quot;&gt;PromQL Compliance Test Results page&lt;/a&gt; or in the table below:&lt;/i&gt;
&lt;table class=&quot;mt-3 table&quot;&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Test target&lt;/th&gt;&lt;th&gt;Passing&lt;/th&gt;&lt;th&gt;Cross-cutting issues&lt;/th&gt;&lt;th&gt;More details&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Cortex&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;521 / 523 cases (&lt;strong&gt;99.62%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/cortex&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Thanos&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;523 / 523 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/thanos&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;TimescaleDB&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;523 / 523 cases (&lt;strong&gt;100.00%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/timescaledb&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;VictoriaMetrics&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;356 / 523 cases (&lt;strong&gt;68.07%&lt;/strong&gt;)&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/victoriametrics&quot;&gt;Detailed results&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Prometheus&apos; query language &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/getting_started/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL&lt;/a&gt; is one of the most important interfaces in the Prometheus ecosystem. Organizations rely on it to build their dashboards, critical alerting, and automation. It enables flexible data processing, but it also includes subtle semantics that are important to get right. With Prometheus becoming more popular, we are seeing more and more PromQL implementations outside of Prometheus itself, both in open-source long-term storage projects and in hosted monitoring providers. Some of these PromQL implementations reuse parts of the Prometheus code base, while others opt for a complete reimplementation from scratch.&lt;/p&gt;
&lt;p&gt;Seeing PromQL being adopted in external products and services is great! At the same time, we believe it is in the interest of the Prometheus community for implementations claiming to be PromQL-compatible to behave exactly like native PromQL. The reasons for this are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Avoiding user confusion&lt;/strong&gt;, where a user might expect two PromQL implementations to behave the same when they don&apos;t. In the worst case, this can lead to broken alerting and undetected outages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoiding ecosystem fragmentation&lt;/strong&gt;, similar to how there are now many diverging SQL dialects despite the existence of an SQL standard.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Avoiding vendor lock-in&lt;/strong&gt;, where a user is unable to switch between long-term storage providers, because they started to rely on specific query language quirks of that provider.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In this blog post, we want to start shining a light onto the correctness of different PromQL implementations, with two goals in mind: &lt;em&gt;creating transparency for users&lt;/em&gt; (enabling them to make better choices), and making it easier for projects or vendors to &lt;em&gt;spot and fix bugs&lt;/em&gt; in their PromQL implementations. For this purpose, we started building an &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;open-source PromQL compliance testing tool&lt;/a&gt; that checks the correctness of a given PromQL implementation and generates a test report. We&apos;ll dive into the details of this tool in this post, as well as some first comparison results.&lt;/p&gt;
&lt;h2 id=&quot;what-is-correct-in-the-absence-of-a-specification&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-is-correct-in-the-absence-of-a-specification&quot; aria-label=&quot;what is correct in the absence of a specification permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is &quot;correct&quot; in the absence of a specification?&lt;/h2&gt;
&lt;p&gt;While PromQL is &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/getting_started/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;documented on the Prometheus website&lt;/a&gt;, the documentation is not specific enough to serve as a full specification of all subtle behaviors. In the absence of a spec, how do we judge correctness? Since we care about portability and compatibility between implementations, we treat the actual exhibited behavior of the native PromQL engine as the specification (while taking cues from its code to consider edge cases to test). So to determine whether a given PromQL implementation executes a specific query correctly, we can run the query against both the native PromQL engine and the vendor implementation and compare the results. Given a comprehensive-enough set of test queries, this should at least unveil many common (or less common) misbehaviors.&lt;/p&gt;
&lt;h2 id=&quot;the-promql-compliance-tester&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-promql-compliance-tester&quot; aria-label=&quot;the promql compliance tester permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The PromQL Compliance Tester&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL Compliance Tester&lt;/a&gt; is an open-source tool which runs a set of configured range queries against a reference PromQL HTTP API endpoint (usually this would be a Prometheus server) and a test endpoint (the vendor implementation):&lt;/p&gt;
&lt;p&gt;&lt;img style=&quot;width: 50%&quot; src=&quot;/images/promql-compliance-tester.svg&quot; alt=&quot;PromQL Compliance Tester architecture&quot;&gt;&lt;/p&gt;
&lt;p&gt;The tester expects you to pre-load both storage implementations with the same data, so that query results become comparable. It then runs a deep comparison of the returned query results for each test case, and records any differences. Finally, it outputs a text or HTML report, including a summary of the number of tests that have passed and failed, and the exact differences for failed cases.&lt;/p&gt;
&lt;p&gt;An &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester/blob/master/promql-compliance-tester.yml&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;example configuration file&lt;/a&gt; in the repository contains a set of PromQL queries that aim to test many prominent features of the language. The configuration file allows templating of queries to allow introducing automatic combinatorial variations of function names, operator types, duration ranges, etc.. This allows for easier creation of test cases, without having to manually write out all possible query variants for a pattern.&lt;/p&gt;
&lt;h2 id=&quot;handling-different-types-of-behavior-deviations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#handling-different-types-of-behavior-deviations&quot; aria-label=&quot;handling different types of behavior deviations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Handling different types of behavior deviations&lt;/h2&gt;
&lt;p&gt;Not all differences in behavior are created equal. Depending on your use case, some differences may even be acceptable, while others are problematic violations. Also, some behavioral differences are specific to a single PromQL function, while others affect the overall structure of all queries. The latter may require applying general query parameter restrictions or output transformations, in order to still be able to compare results further. How to judge such differences is ultimately up to the user, but it&apos;s important to make those differences transparent in the comparison output report.&lt;/p&gt;
&lt;p&gt;We will detail some of these cases and how we handled them further down.&lt;/p&gt;
&lt;h2 id=&quot;first-comparisons&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#first-comparisons&quot; aria-label=&quot;first comparisons permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;First comparisons&lt;/h2&gt;
&lt;p&gt;While the PromQL Compliance Tester is still in an early stage, it is already useful to get an overall idea of the correctness of different implementations. For this iteration, we ran a Prometheus server configured against a set of demo metrics targets:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yml&quot;&gt;&lt;pre class=&quot;language-yml&quot;&gt;&lt;code class=&quot;language-yml&quot;&gt;&lt;span class=&quot;token key atrule&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;scrape_interval&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; 5s

&lt;span class=&quot;token key atrule&quot;&gt;scrape_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;job_name&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo&apos;&lt;/span&gt;
  &lt;span class=&quot;token key atrule&quot;&gt;static_configs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo.promlabs.com:10000&apos;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo.promlabs.com:10001&apos;&lt;/span&gt;
      &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;demo.promlabs.com:10002&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;With the data collected by this configuration, we ran the query patterns provided in the &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester/blob/master/promql-compliance-tester.yml&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;example tester configuration file&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For now, we tested &lt;a href=&quot;https://cortexmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt;, &lt;a href=&quot;https://thanos.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Thanos&lt;/a&gt;, &lt;a href=&quot;https://victoriametrics.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;VictoriaMetrics&lt;/a&gt;, and &lt;a href=&quot;https://www.timescale.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;TimescaleDB&lt;/a&gt;. To replicate the same data into each of these systems, we either added a &lt;code&gt;remote_write&lt;/code&gt; configuration to the above Prometheus configuration file, or in the case of Thanos, we simply pointed the compliance tester at the Thanos querier. This does not test Thanos&apos; long-term storage integration, but we also didn&apos;t differentiate storage tiers in the other providers either yet.&lt;/p&gt;
&lt;h3 id=&quot;cortex&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cortex&quot; aria-label=&quot;cortex permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cortex&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://cortexmetrics.io/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex&lt;/a&gt; reuses the PromQL library from Prometheus, while swapping out the underlying storage implementation. This makes it a likely candidate for good compliance. We tested &lt;a href=&quot;https://github.com/cortexproject/cortex/releases/tag/v1.2.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Cortex version 1.2.0&lt;/a&gt;. Let&apos;s see how it fared in practice.&lt;/p&gt;
&lt;p&gt;First, the tester uncovered that Cortex was affected by a &lt;a href=&quot;https://github.com/cortexproject/cortex/issues/2932&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;small query start/end timestamp parsing rounding bug&lt;/a&gt; that had already been resolved in Prometheus a while ago. The bug has just been fixed in Cortex now, so the next Cortex release should not have this issue anymore. To make query results comparable for now, we enabled a tester option to only choose integer start/end query timestamps for queries and thus achieve identical parsing.&lt;/p&gt;
&lt;p&gt;After accounting for this issue, we saw &lt;strong&gt;99.62% of test cases passing&lt;/strong&gt; against Cortex.&lt;/p&gt;
&lt;p&gt;While no test cases failed in the result comparison state, two test queries failed to execute at all:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;QUERY: {mode=&quot;idle&quot;, instance!=&quot;demo.promlabs.com:10000&quot;}
START: 2020-08-05 17:16:32 +0200 CEST, STOP: 2020-08-05 17:26:32 +0200 CEST, STEP: 10s
RESULT: FAILED: Query failed unexpectedly: execution: expanding series: query must contain metric name&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;QUERY: histogram_quantile(0.9, {__name__=~&quot;demo_api_request_duration_seconds_.+&quot;})
START: 2020-08-05 17:16:32 +0200 CEST, STOP: 2020-08-05 17:26:32 +0200 CEST, STEP: 10s
RESULT: FAILED: Query failed unexpectedly: execution: expanding series: query must contain metric name&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The reason for these failures is that Cortex does not support vector selectors without an exact metric name, such as queries that use regular expressions against the metric name. This is a &lt;a href=&quot;https://github.com/cortexproject/cortex/issues/416&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;known issue&lt;/a&gt; due to the way that Cortex indexes metrics and might get addressed at some point. In practice, this limitation will mostly affect debug-style queries, such as counting how many time series exist per job, per target, or per metric name (e.g. &lt;code&gt;sort_desc(count by(__name__, job) ({__name__=~&quot;.+&quot;}))&lt;/code&gt;). It is less likely to affect regular dashboard or alerting queries, and the failure will be explicit.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/cortex&quot;&gt;See the full results for Cortex&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;thanos&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#thanos&quot; aria-label=&quot;thanos permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Thanos&lt;/h3&gt;
&lt;p&gt;Thanos also reuses the upstream PromQL implementation. This makes it another likely candidate for near-100% compliance. Let&apos;s see if this ends up being true. We tested Thanos &lt;a href=&quot;https://github.com/thanos-io/thanos/releases/tag/v0.14.0&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;v0.14.0&lt;/a&gt; by running a Thanos Sidecar against our reference Prometheus server and pointing a Thanos Query component at it.&lt;/p&gt;
&lt;p&gt;Thanos ended up having the same &lt;a href=&quot;https://github.com/thanos-io/thanos/issues/2971&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;query timestamp parsing rounding bug&lt;/a&gt; as Cortex. We accounted for this in the same way as before. We also had to apply another test result transformation tweak to remove external labels in query results that had to be added for Thanos.&lt;/p&gt;
&lt;p&gt;After accounting for these issues, we saw &lt;strong&gt;100% of test cases passing&lt;/strong&gt; against Thanos.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/thanos&quot;&gt;See the full results for Thanos&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;victoriametrics&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#victoriametrics&quot; aria-label=&quot;victoriametrics permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;VictoriaMetrics&lt;/h3&gt;
&lt;p&gt;As the only contender in this group, VictoriaMetrics does not base its PromQL support on Prometheus&apos; upstream implementation. Instead, VictoriaMetrics implements its own MetricsQL language that offers features beyond standard PromQL, but claims to be &quot;backwards compatible with PromQL&quot; as well. A few differences to native PromQL are already called out in their &lt;a href=&quot;https://docs.victoriametrics.com/MetricsQL.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;MetricsQL documentation&lt;/a&gt;. Let&apos;s see how these appear in the tests, and what other differences we may discover.&lt;/p&gt;
&lt;p&gt;First, it turns out that VictoriaMetrics does not support arbitrary and millisecond-precision query start/end timestamps as in native PromQL, but rather aligns all input timestamps to be multiples of the range query&apos;s resolution timestamp. To be more precise, it &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/669#issuecomment-668700353&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;apparently only does so under certain conditions&lt;/a&gt;. To compensate for this cross-cutting issue and to be able to compare results further, we configured the tester to only query for already-aligned timestamps in the first place.&lt;/p&gt;
&lt;p&gt;After applying the general timestamp tweak across all queries, we still saw only &lt;strong&gt;68% of test cases passing&lt;/strong&gt; against VictoriaMetrics.&lt;/p&gt;
&lt;p&gt;The differences in VictoriaMetrics query results stem from a number of issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://docs.victoriametrics.com/MetricsQL.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;As documented&lt;/a&gt;, range windows like &lt;code&gt;[5m]&lt;/code&gt; behave differently in VictoriaMetrics and always select a sample before the window as well. This even causes some over-time aggregations (like &lt;code&gt;sum_over_time(demo_cpu_usage_seconds_total[1s])&lt;/code&gt;) to return results where Prometheus returns none. It also causes generally different numeric results.&lt;/li&gt;
&lt;li&gt;Hexadecimal scalar literals like &lt;code&gt;0x3d&lt;/code&gt; cannot be parsed.&lt;/li&gt;
&lt;li&gt;Any time series with a value of &lt;code&gt;NaN&lt;/code&gt; is removed in results, instead of being included with an &lt;code&gt;NaN&lt;/code&gt; sample value. &lt;code&gt;NaN&lt;/code&gt; series can still be very relevant in expressions, so this one could pose a real problem. Apparently this is a &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/642#issuecomment-662446678&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;known or intended behavior&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Some queries succeed in VictoriaMetrics that fail in Prometheus. For example, series selectors without at least one non-empty matcher (&lt;code&gt;{__name__=~&quot;.*&quot;}&lt;/code&gt;) or negative offsets (&lt;code&gt;demo_cpu_usage_seconds_total offset -1m&lt;/code&gt;). Since MetricsQL advertises itself as a superset of PromQL, some of these differences are likely intentional and expected. However, &lt;code&gt;label_replace()&lt;/code&gt; also succeeds in VictoriaMetrics when supplying an invalid target label name, which might lead to problems. We &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/672&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;opened an issue&lt;/a&gt; for this.&lt;/li&gt;
&lt;li&gt;Some queries don&apos;t handle illegal parameter values the same as native PromQL, such as calculating quantiles with an invalid quantile parameter (&lt;code&gt;quantile(-0.5, demo_cpu_usage_seconds_total)&lt;/code&gt;) returning a normal number instead of &lt;code&gt;NaN&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Binary filter operators between a scalar and a vector (e.g. &lt;code&gt;0.12345 &amp;#x3C; demo_cpu_usage_seconds_total&lt;/code&gt;) must always return the sample value from the vector side of the operation, no matter which side of the operator it is on. VictoriaMetrics always returns the sample value from the left-hand side, even if it is the scalar value. We &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/673&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;filed an issue&lt;/a&gt; for this as well.&lt;/li&gt;
&lt;li&gt;Some functions like &lt;code&gt;avg_over_time()&lt;/code&gt;, &lt;code&gt;round()&lt;/code&gt;, etc. incorrectly keep the metric name of the input series where Prometheus deletes it (to signal that the time series no longer has the original metric name&apos;s meaning). We &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/674&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;filed another issue&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Subqueries yield different numeric values, maybe due to the same reason as vector selectors.&lt;/li&gt;
&lt;li&gt;Unary and power operator precedence seems to be inverted, such that &lt;code&gt;-1^2&lt;/code&gt; yields &lt;code&gt;-1&lt;/code&gt; in Prometheus, but &lt;code&gt;1&lt;/code&gt; in VictoriaMetrics. We &lt;a href=&quot;https://github.com/VictoriaMetrics/VictoriaMetrics/issues/675&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;filed another issue&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some of these issues are minor and are unlikely to cause trouble in day-to-day queries, while others (like &lt;code&gt;NaN&lt;/code&gt; series being filtered out or wrong sample values being calculated) may cause significant problems. We hope that VictoriaMetrics will improve on these points, or otherwise adjust their claims around PromQL compatibility.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/victoriametrics&quot;&gt;See the full results for VictoriaMetrics&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;timescaledb&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#timescaledb&quot; aria-label=&quot;timescaledb permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;TimescaleDB&lt;/h3&gt;
&lt;p&gt;TimescaleDB (via its &lt;a href=&quot;https://github.com/timescale/timescale-prometheus&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus adapter&lt;/a&gt;) also reuses the upstream PromQL implementation, putting it yet again into a good position to easily achieve close compliance.&lt;/p&gt;
&lt;p&gt;When starting to run tests against TimescaleDB&apos;s PromQL implementation, there was no official release of it yet. In the process of testing, we discovered some query errors that we found hard to explain (like metric names missing on some selected time series). Since we were already coincidentally communicating with the TimescaleDB developers at this time, they managed to find and fix the underlying bugs quickly (including a caching issue) and in that process also cut a first beta release (&lt;code&gt;0.1.0-beta.1&lt;/code&gt;) including the PromQL support.&lt;/p&gt;
&lt;p&gt;With this first beta release, we saw &lt;strong&gt;100% of test cases passing&lt;/strong&gt; against TimescaleDB, without needing any further cross-cutting query corrections.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;/promql-compliance-test-results/2020-08-06/timescaledb&quot;&gt;See the full results for TimescaleDB&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;future-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#future-work&quot; aria-label=&quot;future work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Future work&lt;/h2&gt;
&lt;p&gt;It&apos;s still early days for the PromQL Compliance Tester. In particular, we would love to add and improve the following points:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Test instant queries in addition to range queries.&lt;/li&gt;
&lt;li&gt;Add more variation and configurability to input timestamps.&lt;/li&gt;
&lt;li&gt;Flesh out a more comprehensive (and less overlapping) set of input test queries.&lt;/li&gt;
&lt;li&gt;Automate and integrate data loading into different systems.&lt;/li&gt;
&lt;li&gt;Test more vendor implementations of PromQL (for example, Sysdig and New Relic).&lt;/li&gt;
&lt;li&gt;Version test results and make pretty output presentations easier.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Many people will be interested in benchmarking performance differences between PromQL implementations. While this is important as well, the PromQL Compliance Tester focuses solely on correctness testing.&lt;/p&gt;
&lt;p&gt;If you would like to help flesh out the tester, please file issues or pull requests against the &lt;a href=&quot;https://github.com/promlabs/promql-compliance-tester&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL Compliance Tester repository&lt;/a&gt;!&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;We hope that these early results are already useful for creating a more correct and transparent PromQL implementation landscape. Already in these early tests, the tool has managed to find a number of bugs in all tested implementations. We also hope to publish regular updates on vendor implementation correctness.&lt;/p&gt;
&lt;p&gt;To view all test results, head to our &lt;a href=&quot;/promql-compliance-tests&quot;&gt;PromQL Compliance Tests&lt;/a&gt; page, available from our &quot;Resources&quot; menu item at the top starting today.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Selecting Data in PromQL]]></title><description><![CDATA[In our last post, we looked at the overall anatomy of a PromQL query. Today, let's look a bit closer at the two ways of selecting data in…]]></description><link>https://promlabs.com/blog/2020/07/02/selecting-data-in-promql</link><guid isPermaLink="false">https://promlabs.com/blog/2020/07/02/selecting-data-in-promql</guid><pubDate>Thu, 02 Jul 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In our last post, we looked at the overall &lt;a href=&quot;/blog/2020/06/18/the-anatomy-of-a-promql-query&quot;&gt;anatomy of a PromQL query&lt;/a&gt;. Today, let&apos;s look a bit closer at the two ways of selecting data in PromQL: instant vector selectors and range vector selectors. We will examine their use cases, the reasoning behind them, and some implementation details you should be aware of. Selecting data from Prometheus&apos;s TSDB forms the basis of almost any useful PromQL query before transforming, aggregating, or filtering that data further, so it&apos;s good to understand this fundamental step first.&lt;/p&gt;
&lt;h2 id=&quot;refresher-prometheus-data-model&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#refresher-prometheus-data-model&quot; aria-label=&quot;refresher prometheus data model permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Refresher: Prometheus data model&lt;/h2&gt;
&lt;p&gt;Before we talk about selecting data, let&apos;s refresh our knowledge of the shape of the data that Prometheus stores. Prometheus&apos;s &lt;a href=&quot;https://prometheus.io/docs/concepts/data_model/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;data model&lt;/a&gt; is simple: it stores numeric &lt;em&gt;time series&lt;/em&gt;. Each time series has an identity (its metric name and a unique set of &lt;code&gt;key=&quot;value&quot;&lt;/code&gt; label pairs that create dimensionality within that metric name), as well as a set of &lt;em&gt;samples&lt;/em&gt;. Each sample has an &lt;code&gt;int64&lt;/code&gt; Unix timestamp in milliseconds and a &lt;code&gt;float64&lt;/code&gt; sample value (even if it just contains an integer value). That is it! Here is a visual representation of one series:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/prometheus-data-model.svg&quot; alt=&quot;Prometheus data model&quot;&gt;&lt;/p&gt;
&lt;p&gt;In queries, we either want to select the latest sample of a set of series at a given query step, or a historical range of samples to aggregate over in some way. Let&apos;s look at how to do that.&lt;/p&gt;
&lt;h2 id=&quot;instant-vector-selectors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#instant-vector-selectors&quot; aria-label=&quot;instant vector selectors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Instant vector selectors&lt;/h2&gt;
&lt;p&gt;An instant vector selector allows you to select the &lt;em&gt;latest&lt;/em&gt; sample value at every evaluation resolution step of a &lt;a href=&quot;/blog/2020/06/18/the-anatomy-of-a-promql-query#range-queries&quot;&gt;range query&lt;/a&gt;, or in an &lt;a href=&quot;/blog/2020/06/18/the-anatomy-of-a-promql-query#instant-queries&quot;&gt;instant query&lt;/a&gt;, at a single evaluation timestamp. It&apos;s called a &lt;em&gt;vector&lt;/em&gt; selector because it returns a whole set (vector) of series, with one sample for each series (thus an &lt;em&gt;instant&lt;/em&gt; vector).&lt;/p&gt;
&lt;h3 id=&quot;matcher-syntax&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#matcher-syntax&quot; aria-label=&quot;matcher syntax permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Matcher syntax&lt;/h3&gt;
&lt;p&gt;To select the latest value for any series with the metric name &lt;code&gt;api_http_requests_total&lt;/code&gt;, you simply write the metric name:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;api_http_requests_total&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;To only select series with the method &lt;code&gt;POST&lt;/code&gt; and the handler &lt;code&gt;/api/widgets&lt;/code&gt;, you can add some label matchers in curly braces that restrict the output:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;api_http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;POST&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;handler&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;/api/widgets&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Besides equality matching, you can also use &lt;code&gt;!=&lt;/code&gt; for inequality, &lt;code&gt;=~&lt;/code&gt; for full-string regex matches, or &lt;code&gt;!~&lt;/code&gt; for negative regex matches against label values. So the following would select requests with the method &lt;code&gt;POST&lt;/code&gt; on any handler that starts with &lt;code&gt;/api/&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;api_http_requests_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;POST&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;handler&lt;/span&gt;=~&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;/api/.*&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Under the hood the metric name (&lt;code&gt;api_http_requests_total&lt;/code&gt;) is just stored as another label with the special (reserved) label name &lt;code&gt;__name__&lt;/code&gt;. So the query &lt;code&gt;api_http_requests_total&lt;/code&gt; would be 100% equivalent to the following query:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;api_http_requests_total&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This can be useful if you ever want to do regex matching against the metric name itself (e.g. for debugging purposes). For example, to select any series with a metric name starting with &lt;code&gt;api_&lt;/code&gt;, just write:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;__name__&lt;/span&gt;=~&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;api_.*&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;lookback-delta&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lookback-delta&quot; aria-label=&quot;lookback delta permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lookback delta&lt;/h3&gt;
&lt;p&gt;An instant vector selector serves the use case of &quot;give me the latest sample value at a given time for a set of series&quot;. It&apos;s useful for graphing the development of series over time, looking at their latest sample values in a table, or basing transformations (such as aggregations) on a single sample value at each time slice.&lt;/p&gt;
&lt;p&gt;However, the trickiness comes in when having to define &quot;latest&quot;. Prometheus does not have a concept of a fixed interval between samples, so it&apos;s hard to say absolutely whether there is a &quot;current&quot; latest sample for a given series. If the latest sample for a series is a week old, you probably wouldn&apos;t want to include it in the result of an instant vector selector at the current timestamp (this would lead to many outdated series &quot;flatlining&quot; in your graphs). On the other hand, you can&apos;t expect samples to exactly match the evaluation timestamp either, since samples in the Prometheus TSDB are not aligned on some time grid and can have arbitrary timestamps.&lt;/p&gt;
&lt;p&gt;So some kind of middle ground is needed. To select latest samples that are neither too outdated, nor require super fast scrape intervals or even grid-aligned sample timestamps, instant vector selectors look back a maximum of 5 minutes relative to the evaluation timestamp. Samples with a timestamp older than 5 minutes are dropped from the result.&lt;/p&gt;
&lt;h3 id=&quot;staleness&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#staleness&quot; aria-label=&quot;staleness permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Staleness&lt;/h3&gt;
&lt;p&gt;The 5-minute rule above is a good compromise between excluding old data and including recent-enough samples. However, there are situations where it is annoying to have series stick around in instant vector selector results longer than strictly needed. For example, if you are running a service on Kubernetes and track the pod name in a label value, then all series identities (label sets) change when you re-deploy that service (because the pod names change). You will have old series with one set of pod names and new series with a new set. However, for a period of 5 minutes, you will see both the new and the old series in your graphs, which can be confusing. It&apos;s even more confusing if you base aggregations on this data. If you calculate the sum over the memory usage of all pods, then for a period of 5 minutes you will see &lt;em&gt;double&lt;/em&gt; the total usage that you should be seeing!&lt;/p&gt;
&lt;p&gt;To resolve this, Prometheus supports marking series as explicitly &lt;em&gt;stale&lt;/em&gt;: When Prometheus detects that a series will go extinct (because its target has disappeared, or it&apos;s no longer returned in the scrape of its target, or because a recording rule stopped returning it), Prometheus writes out an explicit staleness marker for this series. Under the hood, staleness markers are just a normal sample for that series in the TSDB, but with a &lt;a href=&quot;https://github.com/prometheus/prometheus/blob/c6399296dcc059bbc496f40e31aa2c7b7a341951/pkg/value/value.go#L28&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;special kind of &lt;code&gt;NaN&lt;/code&gt; sample value&lt;/a&gt; to signal staleness.&lt;/p&gt;
&lt;p&gt;When instant vector selectors encounter a staleness marker as the last-seen sample value before their evaluation timestamp, the corresponding series will not be included in the result. This solves the &quot;double count&quot; and &quot;flatlining&quot; issues more quickly.&lt;/p&gt;
&lt;h2 id=&quot;range-vector-selectors&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#range-vector-selectors&quot; aria-label=&quot;range vector selectors permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Range vector selectors&lt;/h2&gt;
&lt;p&gt;Range vector selectors allow you to select an entire range of samples over time, again at each evaluation step of a query. This allows you to run aggregations over the time window: rates of increase, averages, min/max, quantiles, and so on.&lt;/p&gt;
&lt;p&gt;You write range vector selectors exactly like instant vector selectors, but with the desired range time window appended in square brackets. For example, this would return the last 5 minutes of samples of each series with the &lt;code&gt;api_http_requests_total&lt;/code&gt; metric name:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;api_http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You always need to include a time unit (&lt;code&gt;m&lt;/code&gt; for minute in this case). The available units are: &lt;code&gt;s&lt;/code&gt; (seconds), &lt;code&gt;m&lt;/code&gt; (minutes), &lt;code&gt;h&lt;/code&gt; (hours), &lt;code&gt;d&lt;/code&gt; (days), &lt;code&gt;w&lt;/code&gt; (weeks), &lt;code&gt;y&lt;/code&gt; (years).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note that you cannot graph a range vector selector by itself&lt;/em&gt;, since it would mean somehow graphing multiple samples for each series &lt;em&gt;at each graph resolution step&lt;/em&gt;. You always need to transform the returned range vector into an instant vector first (giving you a single output sample for each series), for example by computing its per-second rate of increase:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;api_http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Conceptually, range vector selectors are actually much simpler than instant vector selectors: They have no notion of lookback deltas or staleness, as the selection time range is completely determined by the user-provided time window.&lt;/p&gt;
&lt;h2 id=&quot;offsets&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#offsets&quot; aria-label=&quot;offsets permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Offsets&lt;/h2&gt;
&lt;p&gt;Sometimes you want to make data from a while ago appear like current data in your queries. For example, you might want to compare the request rates of a week ago with the current request rates. For this, PromQL supports a &lt;code&gt;&amp;#x3C;vector selector&gt; offset &amp;#x3C;duration&gt;&lt;/code&gt; modifier on individual vector selectors which allows time-shifting data from the past into the current time.&lt;/p&gt;
&lt;p&gt;For example, to query for the API request rate from a week ago:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;api_http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;] &lt;span class=&quot;token operator&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;token context-range&quot;&gt;&lt;span class=&quot;token range-duration number&quot;&gt;1w&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;You could then calculate the difference between the current request rate and the rate from last week:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;api_http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;] &lt;span class=&quot;token operator&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;token context-range&quot;&gt;&lt;span class=&quot;token range-duration number&quot;&gt;1w&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; - &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;api_http_requests_total&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; Offsets can only look back, not forward. This is consistent with PromQL&apos;s general computational model, where data selectors can look backwards in time, but not into the future (where data may still be missing or changing). If you really want to look into the future, then run the overall query with a timestamp (or time range) in the future.&lt;/p&gt;
&lt;h2 id=&quot;confusion-alert-instantrange-selectors-vs-instantrange-queries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#confusion-alert-instantrange-selectors-vs-instantrange-queries&quot; aria-label=&quot;confusion alert instantrange selectors vs instantrange queries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Confusion alert! Instant/range &lt;em&gt;selectors&lt;/em&gt; vs. instant/range &lt;em&gt;queries&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;Beware: The terms &quot;instant&quot; and &quot;range&quot; can be confusing in Prometheus, because they are used both for types of entire PromQL queries as well as for types of individual selectors contained in queries. For an explanation of range and instant queries, see the &lt;a href=&quot;/blog/2020/06/18/the-anatomy-of-a-promql-query&quot;&gt;blog post about the anatomy of PromQL queries&lt;/a&gt;. That concept is about the overall query execution, and whether a query as a whole is evaluated at a single timestamp (instant), or at multiple subsequent time steps (range). Instant and range &lt;em&gt;vector selectors&lt;/em&gt;, on the other hand, are about whether you select a single sample at each evaluation timestamp, or a whole time range.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusion&quot; aria-label=&quot;conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In this post we looked at the basis for useful PromQL queries: selecting current samples values, as well as selecting ranges of data to aggregate over. We learned how to use label matchers, how instant vectors decide which samples to include, and how to time-shift old data into the present. This is a good foundation for then processing that data further in PromQL.&lt;/p&gt;
&lt;h2 id=&quot;related-content&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#related-content&quot; aria-label=&quot;related content permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Related Content&lt;/h2&gt;
&lt;p&gt;We also made a video about data selection in PromQL:&lt;/p&gt;
&lt;div style=&quot;max-width: 530px; margin: auto;&quot;&gt;
  &lt;div style=&quot;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden&quot;&gt;
    &lt;iframe style=&quot;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0&quot; style=&quot;margin: auto; display: block&quot; src=&quot;https://www.youtube.com/embed/xIAEEQwUBXQ&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share&quot; allowfullscreen&gt;&lt;/iframe&gt;
  &lt;/div&gt;
&lt;/div&gt;</content:encoded></item><item><title><![CDATA[The Anatomy of a PromQL Query]]></title><description><![CDATA[Let's have a look at the anatomy of a PromQL query. PromQL has operators, functions, selectors, and more, but let's not get bogged down by…]]></description><link>https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query</link><guid isPermaLink="false">https://promlabs.com/blog/2020/06/18/the-anatomy-of-a-promql-query</guid><pubDate>Thu, 18 Jun 2020 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Let&apos;s have a look at the anatomy of a &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/basics/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromQL&lt;/a&gt; query. PromQL has operators, functions, selectors, and more, but let&apos;s not get bogged down by those details in this post. Let&apos;s instead look at the overall nature of a query: &lt;em&gt;How are PromQL queries structured and typed, and how are they evaluated over time?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This blog post assumes that you have a very rough idea of what a PromQL query and the &lt;a href=&quot;https://prometheus.io/docs/concepts/data_model/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus data model&lt;/a&gt; looks like, but nothing beyond that. Let&apos;s get started!&lt;/p&gt;
&lt;h2 id=&quot;promql-is-a-nested-functional-language&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#promql-is-a-nested-functional-language&quot; aria-label=&quot;promql is a nested functional language permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;PromQL is a nested functional language&lt;/h2&gt;
&lt;p&gt;Unlike SQL or some other query languages that tend to be more imperative (&lt;code&gt;SELECT * FROM ...&lt;/code&gt;), PromQL is a nested functional language. That means that you describe the data you are looking for as a nested set of expressions that each evaluate (without side effects) to an intermediary value. Each intermediary value is used as an argument or operand of the expressions surrounding it, while the outer-most expression of your query represents the final return value that you get to see in a table, graph, or similar use case.&lt;/p&gt;
&lt;p&gt;An example query could look like this:&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# Root of the query, final result, approximates a quantile.&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;histogram_quantile&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;# 1st argument to histogram_quantile(), the target quantile.&lt;/span&gt;
  &lt;span class=&quot;token number&quot;&gt;0.9&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;# 2nd argument to histogram_quantile(), an aggregated histogram.&lt;/span&gt;
  &lt;span class=&quot;token operator&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;token context-aggregation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;le&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;method&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;# Argument to sum(), the per-second increase of a histogram over 5m.&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;rate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token comment&quot;&gt;# Argument to rate(), the raw histogram series over the last 5m.&lt;/span&gt;
      demo_api_request_duration_seconds_bucket&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;job&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;demo&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token context-range&quot;&gt;[&lt;span class=&quot;token range-duration number&quot;&gt;5m&lt;/span&gt;&lt;/span&gt;]
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;A PromQL expression is not just the entire query, but any nested part of a query (like the &lt;code&gt;rate(…)&lt;/code&gt; part above) that you could run as a query by itself. In the example above, each commented line represents one expression.&lt;/p&gt;
&lt;p&gt;When you analyze the same query in PromLabs&apos; &lt;a href=&quot;https://demo.promlens.com/?l=E7B5fVU6KQ3&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;PromLens query visualizer&lt;/a&gt;, this nested structure of expressions containing sub-expressions becomes especially clear:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://demo.promlens.com/?l=E7B5fVU6KQ3&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;&lt;img src=&quot;/images/promlens_query_visualization.png&quot; alt=&quot;Visualized query structure in PromLens&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In PromLens, you can click on each tree node to evaluate its sub-expression separately, to get an idea of what data you are working with in each part of the nested expression tree.&lt;/p&gt;
&lt;h2 id=&quot;expressions-are-typed-but-maybe-not-like-you-think&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#expressions-are-typed-but-maybe-not-like-you-think&quot; aria-label=&quot;expressions are typed but maybe not like you think permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Expressions are typed, but maybe not like you think&lt;/h2&gt;
&lt;p&gt;There are two concepts of &quot;type&quot; that come up in Prometheus:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&quot;https://prometheus.io/docs/concepts/metric_types/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;type of a metric&lt;/a&gt;, as reported by a scraped target: counter, gauge, histogram, summary, or untyped.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/basics/#expression-language-data-types&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;type of a PromQL expression&lt;/a&gt;: string, scalar, instant vector, or range vector.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;PromQL completely ignores &lt;em&gt;metric types&lt;/em&gt; and only concerns itself with &lt;em&gt;expression types&lt;/em&gt;: Each expression has a type, and each function, operator, or other type of operation requires its arguments to be of a certain expression type. For example, the &lt;code&gt;rate()&lt;/code&gt; function requires its argument to be a range vector, but &lt;code&gt;rate()&lt;/code&gt; itself evaluates to an instant vector. Thus in turn, the result of &lt;code&gt;rate()&lt;/code&gt; can only be used in places that expect instant vectors.&lt;/p&gt;
&lt;p&gt;The possible expression types in PromQL are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;string:&lt;/strong&gt; A string like &lt;code&gt;&quot;I am a string!&quot;&lt;/code&gt;. These only show up as arguments to certain functions (like &lt;code&gt;label_join()&lt;/code&gt;) and are otherwise not used much in PromQL.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;scalar:&lt;/strong&gt; A single numeric value like &lt;code&gt;1.234&lt;/code&gt; without label dimensions. You&apos;ll see these as numeric parameters to functions such as &lt;code&gt;histogram_quantile(0.9, …)&lt;/code&gt; or &lt;code&gt;topk(3, …)&lt;/code&gt;, and also in arithmetic operations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;instant vector:&lt;/strong&gt; A set of labeled time series, with &lt;em&gt;one sample for each series&lt;/em&gt;, all at the same timestamp. Instant vectors can result either directly from a TSDB time series selector like &lt;code&gt;node_cpu_seconds_total&lt;/code&gt;, or from any function or other transformation that returns them.
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;node_cpu_seconds_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cpu&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;0&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;idle&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;   → &lt;span class=&quot;token number&quot;&gt;19165078.75&lt;/span&gt; @ timestamp_1
node_cpu_seconds_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cpu&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;0&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;system&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; →   &lt;span class=&quot;token number&quot;&gt;381598.72&lt;/span&gt; @ timestamp_1
node_cpu_seconds_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cpu&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;0&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;   → &lt;span class=&quot;token number&quot;&gt;23211630.97&lt;/span&gt; @ timestamp_1&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;range vector:&lt;/strong&gt; A set of labeled time series, with a &lt;em&gt;range of samples over time&lt;/em&gt; for each series. There are only two ways to produce range vectors in PromQL: by using a literal range vector selector in your query (like &lt;code&gt;node_cpu_seconds_total[5m]&lt;/code&gt;), or by using a subquery (like &lt;code&gt;&amp;#x3C;expression&gt;[5m:10s]&lt;/code&gt;). Range vectors are useful for when you want to aggregate over the behavior of a series over a specified time window, like you would with &lt;code&gt;rate(node_cpu_seconds_total[5m])&lt;/code&gt; to calculate the average per-second rate of increase over the last 5 minutes of the &lt;code&gt;node_cpu_seconds_total&lt;/code&gt; metric.
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;promql&quot;&gt;&lt;pre class=&quot;language-promql&quot;&gt;&lt;code class=&quot;language-promql&quot;&gt;node_cpu_seconds_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cpu&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;0&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;idle&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;   → &lt;span class=&quot;token number&quot;&gt;19165078.75&lt;/span&gt; @ timestamp_1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;token number&quot;&gt;19165136.3&lt;/span&gt; @ timestamp_2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;19165167.72&lt;/span&gt; @ timestamp_3
node_cpu_seconds_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cpu&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;0&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;system&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; → &lt;span class=&quot;token number&quot;&gt;381598.72&lt;/span&gt;   @ timestamp_1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;   &lt;span class=&quot;token number&quot;&gt;381599.98&lt;/span&gt; @ timestamp_2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;   &lt;span class=&quot;token number&quot;&gt;381600.58&lt;/span&gt; @ timestamp_3
node_cpu_seconds_total&lt;span class=&quot;token context-labels&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token label-key /attr-name/&quot;&gt;cpu&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;0&quot;&lt;/span&gt;, &lt;span class=&quot;token label-key /attr-name/&quot;&gt;mode&lt;/span&gt;=&lt;span class=&quot;token label-value /attr-value/&quot;&gt;&quot;user&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;   → &lt;span class=&quot;token number&quot;&gt;23211630.97&lt;/span&gt; @ timestamp_1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;23211711.34&lt;/span&gt; @ timestamp_2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;23211748.64&lt;/span&gt; @ timestamp_3&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;strong&gt;Note:&lt;/strong&gt; The timestamps of the samples in a range vector are not necessarily the same across all series. For example, samples from different targets (and thus different scrapes) will usually have slightly different timestamps.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;But what of metric types?&lt;/strong&gt; If you have already used PromQL, you might know that certain functions only work on metrics of a specific type! For example, the &lt;code&gt;histogram_quantile()&lt;/code&gt; function only works on histogram metrics, &lt;code&gt;rate()&lt;/code&gt; only works on counter metrics, and &lt;code&gt;deriv()&lt;/code&gt; only works on gauges. &lt;em&gt;But PromQL does not actually check that you pass in the right type of metric&lt;/em&gt; - these functions will often happily run and return something nonsensical for the wrong type of input metric, and it is up to the user to pass in time series that obey certain assumptions (like having a sensical &lt;code&gt;le&lt;/code&gt; label in case of a histogram, or increasing monotonically in case of a counter). However, in the future we will likely see UIs such as PromLens try to warn you if you pass an incompatible metric type to a function.&lt;/p&gt;
&lt;h2 id=&quot;how-does-time-come-in-range-and-instant-queries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-does-time-come-in-range-and-instant-queries&quot; aria-label=&quot;how does time come in range and instant queries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How does time come in? Range and instant queries!&lt;/h2&gt;
&lt;p&gt;You may have noticed that the only references to time in PromQL queries are relative references (such as &lt;code&gt;[5m]&lt;/code&gt;, looking back 5 minutes). So how do you specify an absolute graph time range, or a timestamp at which to show query results in a table? In PromQL, such time parameters are sent separately from the expression to the &lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/api/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Prometheus query API&lt;/a&gt;, and the exact time parameters depend on the type of query you are sending. Prometheus knows two types of PromQL queries: instant queries and range queries.&lt;/p&gt;
&lt;h3 id=&quot;instant-queries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#instant-queries&quot; aria-label=&quot;instant queries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Instant queries&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Instant queries&lt;/a&gt; are used for &lt;strong&gt;table-like views&lt;/strong&gt;, where you want to show the result of a PromQL query at a single point in time.&lt;/p&gt;
&lt;p&gt;An instant query has the following parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The PromQL expression.&lt;/li&gt;
&lt;li&gt;An evaluation timestamp.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The expression is evaluated at the evaluation timestamp, and any data selectors in the query are allowed to select data stretching from that timestamp back into the past (&lt;code&gt;foo[1h]&lt;/code&gt; selects the last hour of data for &lt;code&gt;foo&lt;/code&gt; series), but never into the future (&lt;code&gt;foo[-1h]&lt;/code&gt; is not valid PromQL). Accessing a window of past data is often useful for computing aggregates like rates or averages over a period of time.&lt;/p&gt;
&lt;p&gt;An instant query can return any valid PromQL expression type (string, scalar, instant and range vectors).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example instant query&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;Let&apos;s look at one instant query example to see how its evaluation works. Imagine evaluating the expression &lt;code&gt;http_requests_total&lt;/code&gt; at a given timestamp. &lt;code&gt;http_requests_total&lt;/code&gt; is an instant vector selector that selects the latest sample for any time series with the metric name &lt;code&gt;http_requests_total&lt;/code&gt;. More specifically, &quot;latest&quot; means &quot;at most 5 minutes old and not stale&quot;, relative to the evaluation timestamp. So this selector will only yield a result for series that have a sample at most 5 minutes prior to the evaluation timestamp, and where the last sample before the evaluation timestamp is not a stale marker (an explicit way of marking a series as terminating at a certain time in the Prometheus TSDB).&lt;/p&gt;
&lt;p&gt;If we run this query at a timestamp where there are recent samples, the result will contain &lt;strong&gt;two series with a single sample&lt;/strong&gt; each:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/instant_query_non_stale.svg&quot; alt=&quot;Non-stale instant query diagram&quot;&gt;&lt;/p&gt;
&lt;p&gt;Note that the output timestamp of each returned sample is no longer the original sample timestamp, but gets set to the evaluation timestamp.&lt;/p&gt;
&lt;p&gt;Imagine executing this same query at a timestamp where there is a &gt;5m gap in data before the timestamp:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/instant_query_stale.svg&quot; alt=&quot;Stale instant query diagram&quot;&gt;&lt;/p&gt;
&lt;p&gt;In this case, the query would return an &lt;strong&gt;empty result&lt;/strong&gt;, since all matching samples are too old to be included.&lt;/p&gt;
&lt;h3 id=&quot;range-queries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#range-queries&quot; aria-label=&quot;range queries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Range queries&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Range queries&lt;/a&gt; are mostly used for &lt;strong&gt;graphs&lt;/strong&gt;, where you want to show a PromQL expression over a given time range. A range query works exactly like many completely independent instant queries that are evaluated at subsequent time steps over a given range of time. Of course this is highly optimized under the hood and Prometheus doesn&apos;t actually run many independent instant queries in this case.&lt;/p&gt;
&lt;p&gt;A range query has the following parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The PromQL expression.&lt;/li&gt;
&lt;li&gt;A start time.&lt;/li&gt;
&lt;li&gt;An end time.&lt;/li&gt;
&lt;li&gt;A resolution step.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;After evaluating the expression at every resolution step between the start and end time, the individually evaluated time slices are stitched together into a single range vector. Range queries allow passing in either instant-vector-typed or scalar-typed expressions, but always return a range vector (the result of the scalar or instant vector being evaluated over a range of time).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example range query&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;If we evaluate the example expression from above as a range query, it would look like this (with the example query&apos;s resolution step being 2.5 minutes):&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/range_query.svg&quot; alt=&quot;Range query diagram&quot;&gt;&lt;/p&gt;
&lt;p&gt;Note how each evaluation step behaves exactly like an independent instant query, and each independent instant query has no concept of the overall range of the query. Note also how some subsequent resolution steps end up selecting the same underlying raw sample as their output sample value, when that raw sample happens to still be the latest one (and not older than 5 minutes) for both of those steps.&lt;/p&gt;
&lt;p&gt;The final result in this case will be a range vector that has samples for the two selected series over a range of time, but that will also contain gaps in series data at some of the time steps.&lt;/p&gt;
&lt;h2 id=&quot;in-conclusion&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#in-conclusion&quot; aria-label=&quot;in conclusion permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;In conclusion...&lt;/h2&gt;
&lt;p&gt;Hopefully this blog post has given you a better idea of the overall structure of PromQL queries, the type checking (or lack thereof) that is going on, and the evaluation of queries over time. Comment below with any questions or remarks you have, and stay tuned for more posts on PromQL!&lt;/p&gt;</content:encoded></item></channel></rss>