I checked your proposed solution:

(metric_b and metric_a>=3) or metric_a<bool 3

and it worked like expected, returning the value of metric_b when metric_a is >= 3, and 1 otherwise.

It's important to note that "VECTOR1 and VECTOR2" it's not necessarily equals to "VECTOR2 and VECTOR1". Take a look at the Prometheus documentation about this:

vector1 and vector2 results in a vector consisting of the elements of vector1 for which there are elements in vector2 with exactly matching label sets. Other elements are dropped.

The results are always from the first vector of the "and" clause.

For example, the following query:

Gives a different result of the following one:

Answer from Marcelo Ávila de Oliveira on Stack Overflow
🌐
SigNoz
signoz.io › guides › mastering promql - how to use if-else expressions
Mastering PromQL - How to Use If-Else Expressions | SigNoz
October 30, 2024 - While basic operators cover a lot, PromQL offers advanced techniques for more complex logic. The unless operator is like a "negative if." It returns data only if one condition is not true:
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
The only unary operator in PromQL is - (unary minus). It can be applied to a scalar or an instant vector. In the former case, it returns a scalar with inverted sign. In the latter case, it returns an instant vector with inverted sign for each element. The sign of a histogram sample is inverted ...
Discussions

Problems with unless in a PromQL Query in a Dashboard - Dashboards - Grafana Labs Community Forums
Hello, i have some Issues to bring a Panel to work with a query containing the unless function in promql. here is the Example that i want to implement Values Query1 : ----- Values Query 2: A --------------------------A B ------------------------- C ------------------------ C D ------------... More on community.grafana.com
🌐 community.grafana.com
0
December 13, 2023
Prometheus/PromQL/Grafana: Substraction when the right side range vector is potentially non-existent - Stack Overflow
I have two counter metrics: always_exists and sometimes_exists. I want to receive a result vector from the substraction always_exists - sometimes_exists, even if the metric sometimes_exists doesn't... More on stackoverflow.com
🌐 stackoverflow.com
Promql to detect null values - not absent
so as i understand, you want two different vectors - a list of all up series that have a client and job, where the result set only contains up with the client label - a list of up series that have a client and job="customer", again where the result set only contains up with the client label once you have those you can filter all entries from the second list out of the first using unless soooo, i haven't tested, but maybe you want something like this? count(up{client!="", job!=""}) by (client) unless count(up{job="customer", client!=""}) by (client) More on reddit.com
🌐 r/PrometheusMonitoring
3
2
September 7, 2023
prometheus - Promql filter out time series with value in label same like in another metric dynamicaly - Stack Overflow
That is now my query which has that clue i use lable_join instead of label_replace as I need both labels later on : kube_deployment_spec_replicas unless on(deployment) label_join(kube_horizontalpodautoscaler_spec_min_replicas, "deployment", "", "horizontalpodautoscaler", "(.+)") 2023-11-10... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Grafana
community.grafana.com › dashboards
Problems with unless in a PromQL Query in a Dashboard - Dashboards - Grafana Labs Community Forums
December 13, 2023 - Hello, i have some Issues to bring a Panel to work with a query containing the unless function in promql. here is the Example that i want to implement Values Query1 : ----- Values Query 2: A --------------------------A B ------------------------- C ------------------------ C D ------------...
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Want to learn more? Check out our self-paced in-depth PromQL training by the creator of PromQL.
🌐
Medium
medium.com › itir › logical-operations-in-prometheus-74244ad6d52
Logical operations in Prometheus - ITIR - Medium
February 16, 2023 - Logical operations in Prometheus Today I’ve search for a proper explanation on unless operator in Prometheus, and this article helped a lot. Prometheus Cheat Sheet - How to Join Multiple Metrics …
Find elsewhere
🌐
SigNoz
signoz.io › guides › essential promql cheat sheet - master prometheus queries
Essential PromQL Cheat Sheet - Master Prometheus Queries | SigNoz
November 29, 2024 - PromQL supports basic arithmetic operations between scalar values and time series: +: Addition · -: Subtraction · *: Multiplication · /: Division · %: Modulo · ^: Exponentiation · Example: Copy · (node_memory_MemTotal_bytes - node_memory_MemFree_bytes) / node_memory_MemTotal_bytes * 100 · Use these operators for filtering and combining time series: Comparison: ==, !=, <, <=, >, >= Logical: and, or, unless ·
🌐
pint
cloudflare.github.io › pint › checks › promql › series.html
promql/series | pint
In a query using foo unless bar only foo selector will be tested, since this query implies that the presence of bar is not guaranteed.
🌐
Last9
last9.io › blog › promql-for-beginners-getting-started-with-prometheus-query-language
PromQL for Beginners: Getting Started with Prometheus | Last9
January 2, 2025 - AND (and): Returns true if both conditions are true. OR (or): Returns true if either of the conditions is true. Unless (unless): Returns the left-hand operand unless the right-hand operand is true.
🌐
Better Stack
betterstack.com › community › guides › monitoring › promql
The Beginner’s Handbook to PromQL | Better Stack Community
February 26, 2025 - The logical operators in PromQL (and, or, unless) are used to combine or filter instant vectors based on label sets and conditions.
🌐
Robust Perception
robustperception.io › combining-alert-conditions
Combining alert conditions – Robust Perception | Prometheus Monitoring Experts
Finally there's also the unless operator, which is has the opposite logic to and. It returns a time series on the left hand side if there's not a matching time series on the right hand side. Looking to reduce alert noise with Prometheus? Contact us. Published by Brian Brazil in Posts · Tags: ...
🌐
Reddit
reddit.com › r/prometheusmonitoring › promql to detect null values - not absent
r/PrometheusMonitoring on Reddit: Promql to detect null values - not absent
September 7, 2023 -

I have metrics like these :

    up{client=“clientA”, job=“admin”}
    up{client=“clientA”, job=“customer”}
    up{client=“clientB”, job=“admin”}
    up{client=“clientB”, job=“customer”}
    up{client=“clientC”, job=“admin”}
    up{client=“clientD”, job=“admin”}

These metrics are from different jobs. I am trying to find clients who have no customer job. The job customer doesn't scrape any target for clientC and clientD hence there is no metric at all. Absent is not working in this case as the metric was not present at all.

🌐
DEV Community
dev.to › sre_panchanan › decoding-promql-a-deep-dive-into-prometheus-query-language-4h23
Decoding PromQL: A Deep Dive into Prometheus Query Language - DEV Community
November 12, 2024 - The boolean data type in Prometheus represents true or false values and is commonly used in logical expressions and conditions within PromQL queries. ... True or False: Booleans can have two possible values: true or false, representing binary logic. Logical Operators: Booleans are often used with logical operators such as == (equals), != (not equals), and, or, and unless to construct conditional expressions in PromQL queries.