@@ -57,19 +57,33 @@ def test_prometheus_alerts_inactive(prom):
57
57
assert response ["status" ] == "success"
58
58
assert "data" in response
59
59
alerts = response ["data" ]["alerts" ] or []
60
+
60
61
# (MaxN) Allow for, and filter out, alerts we'd expect to see in an AIO environment.
61
- # TODO - find a way of configuring this for SCT runs in other environments.
62
- alerts_to_ignore = [
62
+ # TODO - find a way of configuring this for SCT running in other environments.
63
+ aio_alerts_to_ignore = [
63
64
# We know our volumes are small.
64
- " StorageFillingUp" ,
65
+ { "alertname" : " StorageFillingUp", "instance" : "controller0" } ,
65
66
# This is probably due to storage space..
66
- " ElasticsearchClusterYellow" ,
67
+ { "alertname" : " ElasticsearchClusterYellow", "instance" : "controller0" } ,
67
68
# ..or because we're running in a single instance and it wants to be clustered across multiple nodes.
68
- " ElasticsearchUnassignedShards" ,
69
+ { "alertname" : " ElasticsearchUnassignedShards", "instance" : "controller0" } ,
69
70
# It's a small AIO!
70
- " LowMemory" ,
71
+ { "alertname" : " LowMemory", "instance" : "controller0" } ,
71
72
# It's only one node and expects three, see https://github.com/stackhpc/stackhpc-kayobe-config/pull/1579
72
- "RabbitMQNodeDown"
73
+ { "alertname" : "RabbitMQNodeDown" },
74
+ # This is probably because Tempest runs before pytest so the container has been recently stopped.
75
+ { "alertname" : "ContainerKilled" , "name" : "tempest" }
73
76
]
74
- alerts = [ alert for alert in alerts if alert ["labels" ]["alertname" ] not in alerts_to_ignore ]
77
+
78
+ def alert_is_ignored (alert , alerts_to_ignore ):
79
+ alert_items = alert .items ()
80
+ for alert_to_ignore in alerts_to_ignore :
81
+ alert_to_ignore_items = alert_to_ignore .items ()
82
+ # alert has more items than alerts_to_ignore
83
+ # so here we can return True if alert_to_ignore is a subset of alerts
84
+ if alert_to_ignore_items <= alert_items :
85
+ return True
86
+ return False
87
+
88
+ alerts = [ alert for alert in alerts if not alert_is_ignored (alert ["labels" ], aio_alerts_to_ignore ) ]
75
89
assert len (alerts ) == 0
0 commit comments