2

For example if I have two time series like below.

metric_1{id=1} 1
metric_1{id=2} 1
metric_1{id=3} 1
metric_2{id=1} 1
metric_2{id=3} 1

I would like to get this as the query result since id=2 is not in metric_2.

{id=2} 1

Similar to this question Comparison Query to Compare Two SQL Server Tables but in Promql. Thanks for any help.

Pol
  • 23
  • 3

1 Answers1

0

So you basically want to drop all series in metric_1 that have a value for the label id that can be also found in the series metric_2. In SQL this would look something like this:

metric_1 left outer join metric_2 on id

In Prometheus first you might come across group_left. (read more about this here "Left joins in PromQL". But this will not work. Instead, we use the unless operator.

metric_1 unless on (id) metric_2
trallnag
  • 2,041
  • 1
  • 17
  • 33
  • 1
    Thank you. This works. I somehow missed reading this in the docs. Here it is in case someone needs it https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators. Also more info and an example using `unless` can be found here https://www.robustperception.io/absent-alerting-for-scraped-metrics. – Pol Oct 22 '20 at 15:20