Difference between groups and list of rules

24 views
Skip to first unread message

rashmi Rashmitha

unread,
Jan 10, 2022, 11:22:10 PMJan 10
to Prometheus Users
Hi,

can someone please help me understand with what is the difference between using two different groups in rule.yml and using one group with list of two rules?
in which situation groups should be preferred and a list of rules in one group?
please find below for reference.

groups:
  - name: Spring-boot
    rules:
    - alert: response_time_mtr
      expr: histogram_quantile(.99, sum(rate(http_server_requests_seconds_bucket{uri="<uri>",status="200",appName="app"}[5m])) by (le,appName)) > 2
      labels:
        app_name: app
        group: Spring-boot
      annotations:
        summary: '(instance {{ $labels.instance }})'
  - name: grp_2
    rules:
    - alert: up_mtr
      expr: up{job="springapp"} == 0
      labels:
        app_name: app
        group: grp_2
      annotations:
        summary: "app down alert"

------------------------------------
groups:
  - name: Spring-boot
    rules:
    - alert: response_time_mtr
      expr: histogram_quantile(.99, sum(rate(http_server_requests_seconds_bucket{uri="<uri>",status="200",appName="app"}[5m])) by (le,appName)) > bool 2
      labels:
        app_name: app
      annotations:
        summary: '(instance {{ $labels.instance }})'
    - alert: up_mtr
      expr: up{job="springapp"} == 0
      labels:
        app_name: app
      annotations:
        summary: "app down alert"
Thanks

Brian Candler

unread,
Jan 11, 2022, 6:00:40 AMJan 11
to Prometheus Users
Not much.  The main thing is that all rules within a rule group have the same evaluation interval; so if you want to have a rule evaluated at a different interval, it must be in a different group.

Matthias Rampke

unread,
Jan 13, 2022, 3:29:29 PMJan 13
to Brian Candler, Prometheus Users
Just to check my understanding: I think rules within one group are also evaluated in order, while groups (even at the same interval) can be evaluated concurrently.

If you have multiple rules that build on top of one another (using the output of one rule in the next) put them in one group, with the most basic rule first and those that rely on it later. This ensures that each rule sees current and complete data from those before it.

On the other hand, if you have several rules that take a while to evaluate, and independent, put them in separate groups. This allows Prometheus to take advantage of multiple CPUs and I/O parallelism to make sure that each group finishes evaluation within its interval.

Do I remember this correctly?

/MR

--
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/4f4d976b-925a-47b4-abe3-23eab9f6a0f5n%40googlegroups.com.

Brian Brazil

unread,
Jan 13, 2022, 3:32:04 PMJan 13
to Matthias Rampke, Brian Candler, Prometheus Users
On Thu, 13 Jan 2022 at 20:29, Matthias Rampke <matt...@prometheus.io> wrote:
Just to check my understanding: I think rules within one group are also evaluated in order, while groups (even at the same interval) can be evaluated concurrently.

If you have multiple rules that build on top of one another (using the output of one rule in the next) put them in one group, with the most basic rule first and those that rely on it later. This ensures that each rule sees current and complete data from those before it.

On the other hand, if you have several rules that take a while to evaluate, and independent, put them in separate groups. This allows Prometheus to take advantage of multiple CPUs and I/O parallelism to make sure that each group finishes evaluation within its interval.

Do I remember this correctly?

Yes, that's correct.

Brian
 

rashmi Rashmitha

unread,
Jan 14, 2022, 4:16:13 PMJan 14
to Brian Brazil, Matthias Rampke, Brian Candler, Prometheus Users
Hi,

so the list of rules in a group will execute sequentially but it throws an alert when that particular alert rule condition is met.
example:
groups:
  - name: grp1
    rules:
    - alert: A1

      expr: histogram_quantile(.99, sum(rate(http_server_requests_seconds_bucket{uri="<uri>",status="200",appName="app"}[5m])) by (le,appName)) > bool 2
      labels:
        app_name: app
      annotations:
        summary: '(instance {{ $labels.instance }})'
    - alert: A2

      expr: up{job="springapp"} == 0
      labels:
        app_name: app
      annotations:
        summary: "app down alert"

In the background, A1 is executed first and then A2 rule. but if the A1 condition has not been met, and A2 has met then an alert for A2 is thrown irrespective of A1. is this correct?

Brian Candler

unread,
Jan 15, 2022, 11:26:19 AMJan 15
to Prometheus Users
For alerting rules it doesn't really make any practical difference.  Yes, the alert rule evaluations within a group are handled sequentially rather than in parallel, but the alerts don't interfere with each other.  You can still have one firing but not the other, or both, or neither.

Where it matters is for recording rules, when one recording rule uses as its input the output of the preceding recording rule.

Reply all
Reply to author
Forward
0 new messages