]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: enable addition custom Prometheus alerts
authorPatrick Seidensal <pseidensal@suse.com>
Thu, 25 Aug 2022 12:47:52 +0000 (14:47 +0200)
committerPatrick Seidensal <pseidensal@suse.com>
Mon, 29 Aug 2022 15:01:21 +0000 (17:01 +0200)
Fixes: https://tracker.ceph.com/issues/57294
Signed-off-by: Patrick Seidensal <pseidensal@suse.com>
doc/cephadm/services/monitoring.rst
src/pybind/mgr/cephadm/services/monitoring.py
src/pybind/mgr/cephadm/tests/test_services.py

index c316da67f796fea27884fc26fd970f3db15282d1..e64778ecceb39444dc25dd4757f12a1d7a779b4b 100644 (file)
@@ -231,6 +231,7 @@ set``:
 - ``services/grafana/ceph-dashboard.yml``
 - ``services/grafana/grafana.ini``
 - ``services/prometheus/prometheus.yml``
+- ``services/prometheus/alerting/custom_alerts.yml``
 - ``services/loki.yml``
 - ``services/promtail.yml``
 
@@ -280,6 +281,15 @@ Example
   # reconfig the prometheus service
   ceph orch reconfig prometheus
 
+.. code-block:: bash
+
+  # set additional custom alerting rules for Prometheus
+  ceph config-key set mgr/cephadm/services/prometheus/alerting/custom_alerts.yml \
+    -i $PWD/custom_alerts.yml
+
+  # Note that custom alerting rules are not parsed by Jinja and hence escaping
+  # will not be an issue.
+
 Deploying monitoring without cephadm
 ------------------------------------
 
index c98a8345db8586635d39412739cce05d570a4dfc..bcffa15f0eb3b4590d2b77e9368bebbc58a3077f 100644 (file)
@@ -319,6 +319,23 @@ class PrometheusService(CephadmService):
                 alerts = f.read()
             r['files']['/etc/prometheus/alerting/ceph_alerts.yml'] = alerts
 
+        # Include custom alerts if present in key value store. This enables the
+        # users to add custom alerts. Write the file in any case, so that if the
+        # content of the key value store changed, that file is overwritten
+        # (emptied in case they value has been removed from the key value
+        # store). This prevents the necessity to adapt `cephadm` binary to
+        # remove the file.
+        #
+        # Don't use the template engine for it as
+        #
+        #   1. the alerts are always static and
+        #   2. they are a template themselves for the Go template engine, which
+        #      use curly braces and escaping that is cumbersome and unnecessary
+        #      for the user.
+        #
+        r['files']['/etc/prometheus/alerting/custom_alerts.yml'] = \
+            self.mgr.get_store('services/prometheus/alerting/custom_alerts.yml', '')
+
         return r, sorted(self.calculate_deps())
 
     def calculate_deps(self) -> List[str]:
index d4d95da3aad9b6abf17308e38c9259c19e4b990e..6b1afb8bc80dcc44a887d59465356cbafef33cd9 100644 (file)
@@ -430,7 +430,8 @@ class TestMonitoring:
                         '--config-json', '-',
                         '--tcp-ports', '9095'
                     ],
-                    stdin=json.dumps({"files": {"prometheus.yml": y, "root_cert.pem": ''}}),
+                    stdin=json.dumps({"files": {"prometheus.yml": y, "root_cert.pem": '',
+                                                "/etc/prometheus/alerting/custom_alerts.yml": ""}}),
                     image='')
 
     @patch("cephadm.serve.CephadmServe._run_cephadm")