Skip to content

Commit dcb9280

Browse files
Ensure MongoDbDegraded works with multiple shards
Currently, all shards are scrapped by a single `job`, to the job label is always `shard0-data` for every shard. Issue: ZENKO-5097
1 parent 5f6295e commit dcb9280

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

monitoring/mongodb/alerts.test.yaml

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ tests:
1313
- name: MongoDbDown
1414
interval: 30s
1515
input_series:
16-
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-mongos", pod="data-db-mongodb-sharded-mongos-0"}
16+
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-shard0-data", pod="data-db-mongodb-sharded-shard0-data-0"}
1717
values: 1 1 0 0 0 0 1 1 1
18-
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-mongos", pod="data-db-mongodb-sharded-mongos-1"}
18+
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-shard0-data", pod="data-db-mongodb-sharded-shard0-data-1"}
1919
values: 1 1 1 1 0 0 0 1 1
20-
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-mongos", pod="data-db-mongodb-sharded-mongos-2"}
20+
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-shard0-data", pod="data-db-mongodb-sharded-shard0-data-2"}
2121
values: 1 1 1 1 1 0 0 0 1
22-
- series: kube_statefulset_replicas{namespace="zenko", statefulset="data-db-mongodb-sharded-mongos", job="kube-state-metrics"}
23-
values: 3x9
22+
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-shard0-data", pod="data-db-mongodb-sharded-shard1-data-0"}
23+
values: 1x9
24+
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-shard0-data", pod="data-db-mongodb-sharded-shard1-data-1"}
25+
values: 1x9
26+
- series: up{namespace="zenko", job="zenko/data-db-mongodb-sharded-shard0-data", pod="data-db-mongodb-sharded-shard1-data-2"}
27+
values: 1x9
2428
- series: kube_statefulset_replicas{namespace="zenko", statefulset="data-db-mongodb-sharded-shard0-data", job="kube-state-metrics"}
2529
values: 3x9
30+
- series: kube_statefulset_replicas{namespace="zenko", statefulset="data-db-mongodb-sharded-shard1-data", job="kube-state-metrics"}
31+
values: 3x9
2632
alert_rule_test:
2733
- { alertname: MongoDbDegraded, eval_time: 30s, exp_alerts: [] }
2834

@@ -33,58 +39,58 @@ tests:
3339
exp_alerts:
3440
- exp_labels:
3541
severity: warning
36-
job: mongos
37-
statefulset: data-db-mongodb-sharded-mongos
42+
job: shard0-data
43+
statefulset: data-db-mongodb-sharded-shard0-data
3844
exp_annotations:
39-
description: "Less than 100% of MongoDb mongos instances are up and healthy: 2."
40-
summary: MongoDb mongos service degraded
45+
description: "Less than 100% of MongoDb shard0-data instances are up and healthy: 2."
46+
summary: MongoDb shard0-data service degraded
4147

4248
- alertname: MongoDbDegraded
4349
eval_time: 120s
4450
exp_alerts:
4551
- exp_labels:
4652
severity: warning
47-
job: mongos
48-
statefulset: data-db-mongodb-sharded-mongos
53+
job: shard0-data
54+
statefulset: data-db-mongodb-sharded-shard0-data
4955
exp_annotations:
50-
description: "Less than 100% of MongoDb mongos instances are up and healthy: 1."
51-
summary: MongoDb mongos service degraded
56+
description: "Less than 100% of MongoDb shard0-data instances are up and healthy: 1."
57+
summary: MongoDb shard0-data service degraded
5258

5359
- alertname: MongoDbDegraded
5460
eval_time: 150s
5561
exp_alerts:
5662
- exp_labels:
5763
severity: warning
58-
job: mongos
59-
statefulset: data-db-mongodb-sharded-mongos
64+
job: shard0-data
65+
statefulset: data-db-mongodb-sharded-shard0-data
6066
exp_annotations:
61-
description: "Less than 100% of MongoDb mongos instances are up and healthy: 0."
62-
summary: MongoDb mongos service degraded
67+
description: "Less than 100% of MongoDb shard0-data instances are up and healthy: 0."
68+
summary: MongoDb shard0-data service degraded
6369
- exp_labels:
6470
severity: critical
65-
job: mongos
66-
statefulset: data-db-mongodb-sharded-mongos
71+
job: shard0-data
72+
statefulset: data-db-mongodb-sharded-shard0-data
6773
exp_annotations:
68-
description: "Less than 50% of MongoDb mongos instances are up and healthy: 0."
69-
summary: MongoDb mongos service critical
74+
description: "Less than 50% of MongoDb shard0-data instances are up and healthy: 0."
75+
summary: MongoDb shard0-data service critical
7076

7177
- alertname: MongoDbDegraded
7278
eval_time: 180s
7379
exp_alerts:
7480
- exp_labels:
7581
severity: warning
76-
job: mongos
77-
statefulset: data-db-mongodb-sharded-mongos
82+
job: shard0-data
83+
statefulset: data-db-mongodb-sharded-shard0-data
7884
exp_annotations:
79-
description: "Less than 100% of MongoDb mongos instances are up and healthy: 1."
80-
summary: MongoDb mongos service degraded
85+
description: "Less than 100% of MongoDb shard0-data instances are up and healthy: 1."
86+
summary: MongoDb shard0-data service degraded
8187
- exp_labels:
8288
severity: critical
83-
job: mongos
84-
statefulset: data-db-mongodb-sharded-mongos
89+
job: shard0-data
90+
statefulset: data-db-mongodb-sharded-shard0-data
8591
exp_annotations:
86-
description: "Less than 50% of MongoDb mongos instances are up and healthy: 1."
87-
summary: MongoDb mongos service critical
92+
description: "Less than 50% of MongoDb shard0-data instances are up and healthy: 1."
93+
summary: MongoDb shard0-data service critical
8894

8995
- name: NoPrimary
9096
interval: 1m

monitoring/mongodb/alerts.yaml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ groups:
3535
- alert: MongoDbDegraded
3636
expr: |
3737
label_replace(
38-
label_replace(
39-
sum(up{namespace="${namespace}",pod=~"${service}.*"}) by(job)
40-
, "statefulset", "$1", "job", "(?:${namespace}/)?(${service}-?.*)")
41-
< on(statefulset)
38+
sum(
39+
label_replace(
40+
up{namespace="${namespace}",pod=~"${service}.*"}
41+
, "statefulset", "$1", "pod", "(${service}-?.*)-\\d+")
42+
) by(statefulset)
43+
< on(statefulset)
4244
kube_statefulset_replicas{statefulset=~"${service}.*", namespace="${namespace}"}
4345
, "job", "$1", "statefulset", "${service}-?(.*)")
4446
for: 30s
@@ -52,10 +54,12 @@ groups:
5254
- alert: MongoDbDegraded
5355
expr: |
5456
label_replace(
55-
label_replace(
56-
sum(up{namespace="${namespace}",pod=~"${service}.*"}) by(job)
57-
, "statefulset", "$1", "job", "(?:${namespace}/)?(${service}-?.*)")
58-
< on(statefulset)
57+
sum(
58+
label_replace(
59+
up{namespace="${namespace}",pod=~"${service}.*"}
60+
, "statefulset", "$1", "pod", "(${service}-?.*)-\\d+")
61+
) by(statefulset)
62+
< on(statefulset)
5963
kube_statefulset_replicas{statefulset=~"${service}.*", namespace="${namespace}"} / 2
6064
, "job", "$1", "statefulset", "${service}-?(.*)")
6165
for: 30s

0 commit comments

Comments
 (0)