Why does group_by in the child policy not work?

  • What Grafana version and what operating system are you using?
    Grafana v12.3.1 (3a1c80ca7c)

  • What are you trying to achieve?
    To have grouped alerts by message and service name and get just one email message by message label and one more message if service_name label is different too.

  • How are you trying to achieve it?
    I tried to delete service_name, but grouping by message doesn’t appeared.

  • What happened?
    I see in web interface child policies:


    But I get all messages by evaluation period in one message.

  • What you expected to see?
    Grouped separate messages. And also I voted for this topic, because I can’t edit policies from web interface and it is hard to debug problems like this.

  • Can you copy/paste the configuration(s) that you are having problems with?

    policies:
    - receiver: grafana-default-email
    group_by:
      - grafana_folder
      - alertname
    
    group_wait: 30s
    group_interval: 5m
    repeat_interval: 4h
    
    routes:
      - receiver: grafana-default-email
        object_matchers:
          - ["message", "=~", ".+"]
        group_by: ["service_name", "message"]
        mute_time_intervals:
          - no_night
    
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No

  • Did you follow any online instructions? If so, what is the URL?
    I see that routes syntax is the same as parent Use configuration files to provision alerting resources | Grafana documentation

Hi @mihalt,

What does message refer to in this context? Is message a label that you’ve defined in the alert rule settings?

Here are some relevant docs for alert grouping:

  • Label types explains the different kinds of labels available on alerts
  • Notification grouping describes how grouping works and how to configure it in notification policies

Also, how are you provisioning your notification policies? If you’re running into issues, one practical approach is to first configure the policy in Grafana until it works as expected, and then export that configuration for provisioning.

Copy past your configuration now see any error in grafana ui , also give grafana log after restart the grafana .


logger=context userId=0 orgId=0 uname= t=2026-02-12T15:56:49.9827197+05:30 level=info msg=“Request Completed” method=GET path=/ status=302 remote_addr=[::1] time_ms=0 duration=0s size=29 referer= handler=/ status_source=server
logger=context userId=0 orgId=0 uname= t=2026-02-12T15:56:53.2778908+05:30 level=info msg=“Request Completed” method=GET path=/api/plugins/grafana-pathfinder-app/settings status=401 remote_addr=[::1] time_ms=0 duration=0s size=102 referer=http://localhost:3000/login handler=/api/plugins/:pluginId/settings status_source=server errorReason=Unauthorized errorMessageID=auth.unauthorized error=“cannot authenticate request”
logger=infra.usagestats t=2026-02-12T15:56:54.8890419+05:30 level=info msg=“Usage stats are ready to report”
logger=context userId=1 orgId=1 uname=admin t=2026-02-12T15:57:02.7952508+05:30 level=info msg=“Request Completed” method=GET path=/api/live/ws status=-1 remote_addr=[::1] time_ms=3 duration=3.6062ms size=0 referer= handler=/api/live/ws status_source=server
logger=ngalert.notifier component=alertmanager orgID=1 t=2026-02-12T15:57:06.9134582+05:30 level=info msg=“Applying new configuration to Alertmanager” configHash=8fa38196a969a59b2c835928d3efd139
logger=context userId=1 orgId=1 uname=admin t=2026-02-12T15:57:07.8548641+05:30 level=info msg=“Request Completed” method=GET path=/api/plugins/grafana-oncall-app/settings status=404 remote_addr=[::1] time_ms=19 duration=19.0215ms size=64 referer=http://localhost:3000/alerting/routes handler=/api/plugins/:pluginId/settings status_source=server

I did it in regex named capturing group in the alert_rules.yaml like:

apiVersion: 1
groups:
  - orgId: 1
    name: LogsGroup
    folder: Custom
    interval: 5m
    rules:
      - title: Error in apps
        condition: B
        data:
          - refId: LOGS
            queryType: range
            relativeTimeRange:
              from: 3600
              to: 0
            model:
              datasource:
                type: loki
              editorMode: code
              expr: "count_over_time({service_name=~\"(?P<message>.*)`\r\n[60m])"

I provision everything.

Export of Notification configuration

apiVersion: 1
contactPoints:
    - orgId: 1
      name: grafana-default-email
      receivers:
        - uid: grafana-default-email
          type: email
          settings:
            addresses: myemail@gmail.com
            message: '{{ template "custom_email.message" .}}'
            singleEmail: false
            subject: '{{ template "custom_email.subject" .}}'
          disableResolveMessage: false