Logical bit-wise AND of two boolean instant vectors on PromQL

514 views
Skip to first unread message

Samuel Alfageme

unread,
Dec 4, 2019, 9:24:18 AM12/4/19
to Prometheus Users
(I'm cross-posting this one from StackOverflow - https://stackoverflow.com/questions/59153907)

I'm trying to define an E2E access availability of a service from a user perspective as the result of applying the bit-wise AND operation between two (Boolean) instant vectors representing individual service availability (e.g. S1 and S2).

I'm fetching the probe_success results of pinging these two services from a "user node" with a blackbox_exporter preinstalled:

            +-------+     +---------------------+     +-------+
            |S1     |     |                     |     |     S2|
            |       |     |   User node with    |     |       |
            |       +<----+  blackbox_exporter  +---->+       |
            |       | icmp|                     |icmp6|       |
            +-------+     +---------------------+     +-------+

+-------------------------------------+-----+---+---+---+---+ | probe_success{user="foo", job="S1"} | ... | 0 | 0 | 1 | 1 | +-------------------------------------+-----+---+---+---+---+ | probe_success{user="foo", job="S2"} | ... | 0 | 1 | 0 | 1 | +-------------------------------------+-----+---+---+---+---+ | E2E{user="foo"} | ... | 0 | 0 | 0 | 1 | +-------------------------------------+-----+---+---+---+---+

Since the targets are probed using different modules (icmp and icmp6) I'm using two jobs and therefore getting two instant vectors:

probe_success{job="S1", user="foo"}
# AND
probe_success{job="S2", user="foo"}

As I read on Prometheus' (querying) logical operators docs(https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators), that logical and is not exactly what I'm looking for. ¿Is there an easy way to perform these kind of "bit-wise" operations in PromQL?

A user on SO suggested trying a recording rule to generate a new instant vector that does the trick:

  (scalar(probe_success{job="S1", user="foo"}) + scalar(probe_success{job="S2", user="foo"})) == bool(2)

But, since scalar() drops the matching labels of the original metrics (i.e. 'user') I cannot use the rule applied to different users; being forced to use one per user. As this does not scale at all, I ask you guys; do you know a better way to use this kind of logic with PromQL? Is my reasoning flawed?

Brian Brazil

unread,
Dec 4, 2019, 9:37:26 AM12/4/19
to Samuel Alfageme, Prometheus Users
On Wed, 4 Dec 2019 at 14:24, Samuel Alfageme <samuel....@gmail.com> wrote:
(I'm cross-posting this one from StackOverflow - https://stackoverflow.com/questions/59153907)

I'm trying to define an E2E access availability of a service from a user perspective as the result of applying the bit-wise AND operation between two (Boolean) instant vectors representing individual service availability (e.g. S1 and S2).

I'm fetching the probe_success results of pinging these two services from a "user node" with a blackbox_exporter preinstalled:

            +-------+     +---------------------+     +-------+
            |S1     |     |                     |     |     S2|
            |       |     |   User node with    |     |       |
            |       +<----+  blackbox_exporter  +---->+       |
            |       | icmp|                     |icmp6|       |
            +-------+     +---------------------+     +-------+

+-------------------------------------+-----+---+---+---+---+ | probe_success{user="foo", job="S1"} | ... | 0 | 0 | 1 | 1 | +-------------------------------------+-----+---+---+---+---+ | probe_success{user="foo", job="S2"} | ... | 0 | 1 | 0 | 1 | +-------------------------------------+-----+---+---+---+---+ | E2E{user="foo"} | ... | 0 | 0 | 0 | 1 | +-------------------------------------+-----+---+---+---+---+

Since the targets are probed using different modules (icmp and icmp6) I'm using two jobs and therefore getting two instant vectors:

probe_success{job="S1", user="foo"}
# AND
probe_success{job="S2", user="foo"}

As I read on Prometheus' (querying) logical operators docs(https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators), that logical and is not exactly what I'm looking for. ¿Is there an easy way to perform these kind of "bit-wise" operations in PromQL?

PromQL has no bitwise operators, however you don't need them in this case. See https://www.robustperception.io/booleans-logic-and-math a min ignoring(job)(probe_success) should cover you here.

Brian



A user on SO suggested trying a recording rule to generate a new instant vector that does the trick:

  (scalar(probe_success{job="S1", user="foo"}) + scalar(probe_success{job="S2", user="foo"})) == bool(2)

But, since scalar() drops the matching labels of the original metrics (i.e. 'user') I cannot use the rule applied to different users; being forced to use one per user. As this does not scale at all, I ask you guys; do you know a better way to use this kind of logic with PromQL? Is my reasoning flawed?

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/0176df7e-ef3d-42ac-9e2f-923102f81eba%40googlegroups.com.


--

Julien Pivotto

unread,
Dec 4, 2019, 9:44:46 AM12/4/19
to Brian Brazil, Samuel Alfageme, Prometheus Users
On 04 Dec 14:37, Brian Brazil wrote:
> On Wed, 4 Dec 2019 at 14:24, Samuel Alfageme <samuel....@gmail.com>
> wrote:
>
> >
> > *(I'm cross-posting this one from StackOverflow -
> > https://stackoverflow.com/questions/59153907
> > <https://stackoverflow.com/questions/59153907>)*
> >
> > I'm trying to define an E2E access availability of a service from a user
> > perspective as the result of applying the *bit-wise AND operation*
it is without(), not ignoring():

min without(job) probe_success

>
> --
> Brian Brazil
> www.robustperception.io
>
> --
> You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAHJKeLqf5qUfOT628_Vn7v_nqib7bEE9L%2BB3RkW%3DFNb1LXFAqA%40mail.gmail.com.

--
(o- Julien Pivotto
//\ Open-Source Consultant
V_/_ Inuits - https://www.inuits.eu
signature.asc

Samuel Alfageme

unread,
Dec 5, 2019, 6:12:45 AM12/5/19
to Prometheus Users
Awesome; Brian, Julien. Thank you so much for your help.

In order to get the desired metric; I ended up querying:

min by (user)(probe_success{job=~"S1|S2"})

Since I do have more blackbox_exporter jobs reporting with the same users involved the without(job) would mix up those.

Now I can simply aggregate with an avg() those to get a rough overview of the platform's SLA. Great!

Best,
Samuel
> To unsubscribe from this group and stop receiving emails from it, send an email to promethe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages