When multiple teams share a Kubernetes cluster, alerts from Prometheus need to reach the right team based on business dimensions such as environment (env:prod) or service (service:iam). Application Real-Time Monitoring Service (ARMS) Alert Management can enrich Prometheus alerts with pod labels from the cluster so that notification policies route each alert to the correct contacts automatically.
How it works
ARMS enriches alerts with Kubernetes labels through the following flow:
kube-state-metrics exposes label metrics for each Kubernetes resource, such as
kube_pod_labelsandkube_node_labels.You add a special annotation (
_aliyun_arms_enrich_desc) to a Prometheus alert rule. The annotation value is a PromQL statement that queries label metrics for the alerting pod.When the alert fires, ARMS runs the PromQL statement, retrieves the pod labels, and attaches them to the alert. Notification policies then match on these labels and route the alert to the appropriate contacts.
The following diagram summarizes the data flow:
Pod labels ──► kube-state-metrics ──► kube_pod_labels metric
│
Alert fires ──► ARMS runs PromQL ───────────┘
│
▼
Alert enriched with pod labels
│
▼
Notification policy matches on labels ──► Contacts notifiedPrerequisites
Before you begin, make sure that you have:
A Container Service for Kubernetes (ACK) cluster with kube-state-metrics
A Prometheus instance monitoring the ACK cluster. For setup instructions, see Create a Prometheus instance to monitor an ACK cluster
Label a pod in the ACK cluster
Add a custom label to the pod template of your target application:
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find your cluster and click Applications in the Actions column.
On the Deployments page, find the target application and choose More > View in YAML in the Actions column.
In the pod template section of the YAML, add a custom label. For example, add
app: arms-prom-ack-arms-prometheus.
Click Update.
Create a Prometheus alert rule
Create an alert rule that triggers on the condition you want to monitor:
Log on to the ARMS console. In the left-side navigation pane, choose Managed Service for Prometheus > Prometheus Alert Rules.
In the upper-right corner of the Prometheus Alert Rules page, click Create Prometheus Alert Rule.
Set Alert Name to
EnrichDemoand set Alert Condition toWhen Container CPU Usage Greater than 2%, Meet the alarm conditions.Configure the remaining parameters and click Save. For details, see Create an alert rule for a Prometheus instance.
Enrich alerts with pod labels
While still on the Create Prometheus Alert Rule page, expand Advanced Settings and add an annotation with the following values:
| Field | Value | Description |
|---|---|---|
| Key | _aliyun_arms_enrich_desc | Reserved annotation key that tells ARMS to enrich the alert |
| Value | A valid PromQL statement | Queries the label metrics for the alerting pod. Use ${xxx} to reference labels from the alert |
Example annotation value:
kube_pod_labels{pod_name=${pod_name}}In this statement, ${pod_name} is replaced at runtime with the pod name from the firing alert. ARMS runs the query, retrieves all labels for that pod, and attaches them to the alert.
The annotation value must be a valid, executable PromQL statement.
The PromQL query must return exactly one time series.
All labels returned by the query are attached to the alert.
kube_pod_labelsadds alabel_prefix to all label keys. For example, a pod labelappbecomeslabel_appin the alert. Account for this prefix when you configure notification policy matchers.If the query returns more than 10 time series, only the first 10 are enriched with labels.
Configure a notification policy
Add a label-based matcher to a notification policy so that enriched alerts are routed to the correct contacts:
In the ARMS console, open the Notification Policies page.
In the Match Alert Event Rules section, add a condition. For example: This condition matches all alerts from pods with the label
app: arms-prom-ack-arms-prometheusand routes them to the contacts defined in this policy.label_app Equal To arms-prom-ack-arms-prometheus
For details on creating and managing notification policies, see Notification policies.
Verify alert dispatch
After you configure the alert rule and notification policy, verify that alerts are dispatched correctly:
In the ARMS console, go to the Alert Sending History page. For details, see View historical alerts.
Confirm that alerts carry the expected labels (for example,
label_app: arms-prom-ack-arms-prometheus) and are routed to the correct contacts.
Limits
| Item | Limit |
|---|---|
| Time series per enrichment query | 1 (the PromQL query must return exactly one time series) |
| Maximum enriched time series | 10 (if the query returns more than 10, only the first 10 are enriched) |
| Label key prefix | kube_pod_labels adds a label_ prefix to all label keys |