Skip to content

Commit 997e4af

Browse files
authored
grab 'status' label for cortex_alertmanager_alerts_received_total metric (#4907)
* grab 'status' label for cortex_alertmanager_alerts_received_total metric Signed-off-by: Alvin Lin <[email protected]> * Update CHANGELOG Signed-off-by: Alvin Lin <[email protected]> Signed-off-by: Alvin Lin <[email protected]>
1 parent 7c798bc commit 997e4af

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* [CHANGE] Compactor: Added `cortex_compactor_runs_interrupted_total` to separate compaction interruptions from failures
4545
* [CHANGE] Enable PromQL `@` modifier, negative offset always. #4927
4646
* [CHANGE] Store-gateway: Add user label to `cortex_bucket_store_blocks_loaded` metric. #4918
47+
* [CHANGE] AlertManager: include `status` label in `cortex_alertmanager_alerts_received_total`. #4907
4748
* [ENHANCEMENT] AlertManager: Retrying AlertManager Get Requests (Get Alertmanager status, Get Alertmanager Receivers) on next replica on error #4840
4849
* [ENHANCEMENT] Querier/Ruler: Retry store-gateway in case of unexpected failure, instead of failing the query. #4532 #4839
4950
* [ENHANCEMENT] Ring: DoBatch prioritize 4xx errors when failing. #4783

pkg/alertmanager/alertmanager_metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func newAlertmanagerMetrics() *alertmanagerMetrics {
7272
alertsReceived: prometheus.NewDesc(
7373
"cortex_alertmanager_alerts_received_total",
7474
"The total number of received alerts.",
75-
[]string{"user"}, nil),
75+
[]string{"user", "status"}, nil),
7676
alertsInvalid: prometheus.NewDesc(
7777
"cortex_alertmanager_alerts_invalid_total",
7878
"The total number of received alerts that were invalid.",
@@ -288,7 +288,7 @@ func (m *alertmanagerMetrics) Describe(out chan<- *prometheus.Desc) {
288288
func (m *alertmanagerMetrics) Collect(out chan<- prometheus.Metric) {
289289
data := m.regs.BuildMetricFamiliesPerUser()
290290

291-
data.SendSumOfCountersPerUser(out, m.alertsReceived, "alertmanager_alerts_received_total")
291+
data.SendSumOfCountersPerUserWithLabels(out, m.alertsReceived, "alertmanager_alerts_received_total", "status")
292292
data.SendSumOfCountersPerUser(out, m.alertsInvalid, "alertmanager_alerts_invalid_total")
293293

294294
data.SendSumOfCountersPerUserWithLabels(out, m.numNotifications, "alertmanager_notifications_total", "integration")

pkg/alertmanager/alertmanager_metrics_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ func TestAlertmanagerMetricsStore(t *testing.T) {
4848
cortex_alertmanager_alerts_invalid_total{user="user3"} 200
4949
# HELP cortex_alertmanager_alerts_received_total The total number of received alerts.
5050
# TYPE cortex_alertmanager_alerts_received_total counter
51-
cortex_alertmanager_alerts_received_total{user="user1"} 10
52-
cortex_alertmanager_alerts_received_total{user="user2"} 100
53-
cortex_alertmanager_alerts_received_total{user="user3"} 1000
51+
cortex_alertmanager_alerts_received_total{status="firing",user="user1"} 4
52+
cortex_alertmanager_alerts_received_total{status="resolved",user="user1"} 6
53+
cortex_alertmanager_alerts_received_total{status="firing",user="user2"} 40
54+
cortex_alertmanager_alerts_received_total{status="resolved",user="user2"} 60
55+
cortex_alertmanager_alerts_received_total{status="firing",user="user3"} 400
56+
cortex_alertmanager_alerts_received_total{status="resolved",user="user3"} 600
5457
# HELP cortex_alertmanager_config_hash Hash of the currently loaded alertmanager configuration.
5558
# TYPE cortex_alertmanager_config_hash gauge
5659
cortex_alertmanager_config_hash{user="user1"} 0
@@ -327,9 +330,12 @@ func TestAlertmanagerMetricsRemoval(t *testing.T) {
327330
328331
# HELP cortex_alertmanager_alerts_received_total The total number of received alerts.
329332
# TYPE cortex_alertmanager_alerts_received_total counter
330-
cortex_alertmanager_alerts_received_total{user="user1"} 10
331-
cortex_alertmanager_alerts_received_total{user="user2"} 100
332-
cortex_alertmanager_alerts_received_total{user="user3"} 1000
333+
cortex_alertmanager_alerts_received_total{status="firing",user="user1"} 4
334+
cortex_alertmanager_alerts_received_total{status="resolved",user="user1"} 6
335+
cortex_alertmanager_alerts_received_total{status="firing",user="user2"} 40
336+
cortex_alertmanager_alerts_received_total{status="resolved",user="user2"} 60
337+
cortex_alertmanager_alerts_received_total{status="firing",user="user3"} 400
338+
cortex_alertmanager_alerts_received_total{status="resolved",user="user3"} 600
333339
334340
# HELP cortex_alertmanager_config_hash Hash of the currently loaded alertmanager configuration.
335341
# TYPE cortex_alertmanager_config_hash gauge
@@ -611,8 +617,10 @@ func TestAlertmanagerMetricsRemoval(t *testing.T) {
611617
612618
# HELP cortex_alertmanager_alerts_received_total The total number of received alerts.
613619
# TYPE cortex_alertmanager_alerts_received_total counter
614-
cortex_alertmanager_alerts_received_total{user="user1"} 10
615-
cortex_alertmanager_alerts_received_total{user="user2"} 100
620+
cortex_alertmanager_alerts_received_total{status="firing",user="user1"} 4
621+
cortex_alertmanager_alerts_received_total{status="resolved",user="user1"} 6
622+
cortex_alertmanager_alerts_received_total{status="firing",user="user2"} 40
623+
cortex_alertmanager_alerts_received_total{status="resolved",user="user2"} 60
616624
617625
# HELP cortex_alertmanager_config_hash Hash of the currently loaded alertmanager configuration.
618626
# TYPE cortex_alertmanager_config_hash gauge

0 commit comments

Comments
 (0)