openrca / orca

Root Cause Analysis for Kubernetes
https://openrca.io
Apache License 2.0
90 stars 10 forks source link

Make Prometheus alert severity optional #124

Closed bzurkowski closed 3 years ago

bzurkowski commented 3 years ago

If the severity is not defined in the alert rule, the following error occurs:

10:27:25 api.1   | [2021-03-02 10:27:25,768] ERROR in app: Exception on /v1/ingestor/prometheus [POST]
10:27:25 api.1   | Traceback (most recent call last):
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
10:27:25 api.1   |     rv = self.dispatch_request()
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
10:27:25 api.1   |     return self.view_functions[rule.endpoint](**req.view_args)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/flask_restx/api.py", line 375, in wrapper
10:27:25 api.1   |     resp = resource(*args, **kwargs)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/flask/views.py", line 89, in view
10:27:25 api.1   |     return self.dispatch_request(*args, **kwargs)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/flask_restx/resource.py", line 44, in dispatch_request
10:27:25 api.1   |     resp = meth(*args, **kwargs)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/api/apis/v1/ingestor.py", line 36, in post
10:27:25 api.1   |     self._ingestor.ingest(payload)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/topology/alerts/prometheus/ingestor.py", line 23, in ingest
10:27:25 api.1   |     super().ingest(alert)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/topology/ingestor.py", line 32, in ingest
10:27:25 api.1   |     self._ingest_event(event)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/topology/alerts/ingestor.py", line 23, in _ingest_event
10:27:25 api.1   |     alert = self._extractor.extract(event)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/topology/alerts/extractor.py", line 45, in extract
10:27:25 api.1   |     properties = self._extract_properties(entity)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/topology/alerts/prometheus/extractor.py", line 51, in _extract_properties
10:27:25 api.1   |     properties['severity'] = self._extract_severity(entity)
10:27:25 api.1   |   File "/usr/local/lib/python3.7/site-packages/orca/topology/alerts/prometheus/extractor.py", line 59, in _extract_severity
10:27:25 api.1   |     return labels['severity']
10:27:25 api.1   | KeyError: 'severity'