Page MenuHomePhabricator

[metricsinfra] allow custom routing for Toolforge alerts
Closed, ResolvedPublic

Description

Background

In the parent task T432863: Define alert conditions in Prometheus (if possible) I would like to add three new alerts to https://gitlab.wikimedia.org/repos/cloud/toolforge/alerts. These new alerts are not tagged with team: wmcs as they are destined to tool maintainers, not toolforge admins. Eventually, the plan is to let tool maintainers receive email notifications for these alerts (T432865: Email tool maintainers when an alert condition is detected).

The issue

Currently, alerts defined in https://gitlab.wikimedia.org/repos/cloud/toolforge/alerts get tagged with project: tools (where?) and the metricsinfra config in metricsinfra-controller-3 (MariaDB database) routes all alerts for that project to the default_contact_group_id, which includes the cloud-admin-feed mailing list and to #wikimedia-cloud-feed on IRC:

MariaDB [prometheusconfig]> select * from projects where name="tools";
+----+--------------+-------+--------------------------+-----------------------------------------------------+------------------+
| id | openstack_id | name  | default_contact_group_id | acl_group                                           | extra_labels     |
+----+--------------+-------+--------------------------+-----------------------------------------------------+------------------+
| 12 | tools        | tools |                        1 | cn=tools.admin,ou=servicegroups,dc=wikimedia,dc=org | {"team": "wmcs"} |
+----+--------------+-------+--------------------------+-----------------------------------------------------+------------------+
1 row in set (0.001 sec)

MariaDB [prometheusconfig]> SELECT * FROM contact_groups c JOIN contact_group_members m ON c.id=m.contact_group_id WHERE c.id = 1;
+----+------------+------------+----+------------------+-------+--------------------------------------+
| id | name       | project_id | id | contact_group_id | type  | value                                |
+----+------------+------------+----+------------------+-------+--------------------------------------+
|  1 | cloud-feed |         10 |  1 |                1 | EMAIL | cloud-admin-feed@lists.wikimedia.org |
|  1 | cloud-feed |         10 |  2 |                1 | IRC   | #wikimedia-cloud-feed                |
+----+------------+------------+----+------------------+-------+--------------------------------------+
2 rows in set (0.002 sec)

What I would like to achieve is to only route to cloud-admin-feed@ and IRC the alerts with team: wmcs, instead of all alerts with project: tools.

Possible solutions

I can think of two possible solutions:

  1. In the metricsinfra projects table (see above), edit the line for project tools, removing {"team": "wmcs"} from extra_labels and setting default_contact_group_id to NULL. Then add a custom route in alertmanager.yml.epp to route alerts with team: wmcs to IRC and cloud-admin-feed@ (similar to the existing route sending alerts to victorops).
  2. Extend the SQL structure to support an additional notification_filter where an optional filter can be specified to determine which alerts are sent to the contact groups (in this case the notification_filter would be team: wmcs)

Event Timeline

get tagged with project: tools (where?)

This is a Prometheus external label defined in https://gerrit.wikimedia.org/r/plugins/gitiles/operations/puppet/+/refs/heads/production/modules/profile/manifests/toolforge/prometheus.pp#655.

edit the line for project tools, removing {"team": "wmcs"} from extra_labels

extra_labels only affects metrics from the metricsinfra Prometheus instance, so not relevant here.


My preference in general would be option 2, with a table of specific alerting rules. The rough schema you need in pseudo-SQL is (project_id int, priority int, match jsonblob, contact_group_id int, UNIQUE KEY (project_id, priority)) and you can turn that very directly into an entry in the routes: block (under the default contact group rule, if there is one).

Then, depending on how you will actually send the alerts (per the options on T432865), you would need to either add support for custom webhook URLs in the contact_groups schema to send alerts to your own service, or build something that keeps a contact group + routing rule per each tool.

aputhin triaged this task as High priority.Aug 13 2026, 4:07 PM

Thanks @taavi, I will attempt creating a patch for option 2, and send it to you and @fgiunchedi for review.

fnegri changed the task status from Open to In Progress.Aug 17 2026, 9:10 AM
fnegri claimed this task.
fnegri moved this task from Backlog to In progress on the tools-platform-team board.

Change #1326797 had a related patch set uploaded (by FNegri; author: FNegri):

[cloud/metricsinfra/prometheus-manager@master] Add alert_routes table

https://gerrit.wikimedia.org/r/1326797

Change #1326802 had a related patch set uploaded (by FNegri; author: FNegri):

[cloud/metricsinfra/prometheus-configurator@master] alertmanager.py: Render alert_routes as nested routes

https://gerrit.wikimedia.org/r/1326802

The patches above implement option 2, I tested this locally and it seems to work as intended:

mysql> SELECT * FROM alert_routes;
+----+------------+----------+---------------------------------+------------------+
| id | project_id | priority | matchers                        | contact_group_id |
+----+------------+----------+---------------------------------+------------------+
|  1 |          1 |       10 | {"audience": "tool-maintainer"} |                2 |
+----+------------+----------+---------------------------------+------------------+
1 row in set (0.002 sec)

mysql> SELECT * FROM contact_groups;
+----+-------------------------+------------+
| id | name                    | project_id |
+----+-------------------------+------------+
|  1 | cloud-feed              |          1 |
|  2 | tool-maintainer-webhook |          1 |
+----+-------------------------+------------+
2 rows in set (0.002 sec)

Generated yaml:

route:
  group_by:
  - alertname
  - project
  group_interval: 5m
  group_wait: 30s
  receiver: blackhole
  repeat_interval: 24h
  routes:
  - match:
      project: tools
    receiver: tools_cloud-feed
    routes:
    - match:
        audience: tool-maintainer
      receiver: tools_tool-maintainer-webhook
  - receiver: blackhole

tool-maintainer-webhook is currently a contact group with zero members, which disables notifications for the matching alerts.

My follow-up plan is to add a custom webhook as part of T432865: Email tool maintainers when an alert condition is detected.

Change #1326797 merged by jenkins-bot:

[cloud/metricsinfra/prometheus-manager@master] Add alert_routes table

https://gerrit.wikimedia.org/r/1326797

Change #1326802 merged by jenkins-bot:

[cloud/metricsinfra/prometheus-configurator@master] alertmanager.py: Render alert_routes as nested routes

https://gerrit.wikimedia.org/r/1326802

fnegri moved this task from In progress to Done on the tools-platform-team board.