]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/prometheus: Make standby discoverable 43464/head
authorRoland Sommer <rol@ndsommer.de>
Fri, 8 Oct 2021 06:40:26 +0000 (08:40 +0200)
committerRoland Sommer <rol@ndsommer.de>
Thu, 11 Nov 2021 07:28:40 +0000 (08:28 +0100)
Enable config settings to modify standby's behaviour on the index page
This makes the standby discoverable by reverse proxy or loadbalancer
setups. Testing for the empty response of the '/metrics' endpoint would
trigger metric collection on the active manager instance.

The newly added configuration options settings standby_behaviour and
standby_error_status_code are documented and flagged as runtime, as
modifying both settings has an immediate effect (no restart required).

Co-authored-by: Ernesto Puerta <37327689+epuertat@users.noreply.github.com>
Signed-off-by: Roland Sommer <rol@ndsommer.de>
Fixes: https://tracker.ceph.com/issues/53229
doc/mgr/prometheus.rst
src/pybind/mgr/prometheus/module.py

index 0328a582f14711e8b123ed0ba1e69cf58c1680e1..a8774ff332342c1cd354182d42343fb1b4c975f2 100644 (file)
@@ -37,6 +37,8 @@ Configuration
 .. confval:: stale_cache_strategy
 .. confval:: rbd_stats_pools
 .. confval:: rbd_stats_pools_refresh_interval
+.. confval:: standby_behaviour
+.. confval:: standby_error_status_code
 
 By default the module will accept HTTP requests on port ``9283`` on all IPv4
 and IPv6 addresses on the host.  The port and listen address are both
@@ -96,6 +98,24 @@ If you are confident that you don't require the cache, you can disable it::
 
     ceph config set mgr mgr/prometheus/cache false
 
+If you are using the prometheus module behind some kind of reverse proxy or
+loadbalancer, you can simplify discovering the active instance by switching
+to ``error``-mode::
+
+    ceph config set mgr mgr/prometheus/standby_behaviour error
+
+If set, the prometheus module will repond with a HTTP error when requesting ``/``
+from the standby instance. The default error code is 500, but you can configure
+the HTTP response code with::
+
+    ceph config set mgr mgr/prometheus/standby_error_status_code 503
+
+Valid error codes are between 400-599.
+
+To switch back to the default behaviour, simply set the config key to ``default``::
+
+    ceph config set mgr mgr/prometheus/standby_behaviour default
+
 .. _prometheus-rbd-io-statistics:
 
 RBD IO statistics
index cfc7bff00db4b92d34bc450f6d15bc2fccccaedc..9b885cbfb7ee0a274d9641d62f16489f6324ad77 100644 (file)
@@ -298,6 +298,21 @@ class Module(MgrModule):
             name='rbd_stats_pools_refresh_interval',
             type='int',
             default=300
+        ),
+        Option(
+            name='standby_behaviour',
+            type='str',
+            default='default',
+            enum_allowed=['default', 'error'],
+            runtime=True
+        ),
+        Option(
+            name='standby_error_status_code',
+            type='int',
+            default=500,
+            min=400,
+            max=599,
+            runtime=True
         )
     ]
 
@@ -1440,7 +1455,8 @@ class StandbyModule(MgrStandbyModule):
         cherrypy.config.update({
             'server.socket_host': server_addr,
             'server.socket_port': server_port,
-            'engine.autoreload.on': False
+            'engine.autoreload.on': False,
+            'request.show_tracebacks': False
         })
 
         module = self
@@ -1448,8 +1464,10 @@ class StandbyModule(MgrStandbyModule):
         class Root(object):
             @cherrypy.expose
             def index(self) -> str:
-                active_uri = module.get_active_uri()
-                return '''<!DOCTYPE html>
+                standby_behaviour = module.get_module_option('standby_behaviour')
+                if standby_behaviour == 'default':
+                    active_uri = module.get_active_uri()
+                    return '''<!DOCTYPE html>
 <html>
     <head><title>Ceph Exporter</title></head>
     <body>
@@ -1457,6 +1475,9 @@ class StandbyModule(MgrStandbyModule):
         <p><a href='{}metrics'>Metrics</a></p>
     </body>
 </html>'''.format(active_uri)
+                else:
+                    status = module.get_module_option('standby_error_status_code')
+                    raise cherrypy.HTTPError(status, message="Keep on looking")
 
             @cherrypy.expose
             def metrics(self) -> str: