From b9f2113472972a1cc2de3fdc460c4026309014aa Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Mon, 28 Oct 2024 14:21:23 +0200 Subject: [PATCH] Move the Prometheus startup to the end of the server initialization. Fixes #919 Signed-off-by: Gil Bregman --- control/server.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/control/server.py b/control/server.py index 4bb97052..9aac809b 100644 --- a/control/server.py +++ b/control/server.py @@ -199,6 +199,15 @@ def _wait_for_group_id(self): self.logger.info("The MonitorGroup gRPC server stopped...") self.monitor_server = None + def start_prometheus(self): + ###Starts the prometheus endpoint if enabled by the config.### + + if self.config.getboolean_with_default("gateway", "enable_prometheus_exporter", True): + self.logger.info("Prometheus endpoint is enabled") + start_exporter(self.spdk_rpc_client, self.config, self.gateway_rpc, self.logger) + else: + self.logger.info(f"Prometheus endpoint is disabled. To enable, set the config option 'enable_prometheus_exporter = True'") + def serve(self): """Starts gateway server.""" self.logger.info(f"Starting serve, monitor client version: {self._monitor_client_version()}") @@ -238,13 +247,6 @@ def serve(self): # Start server self.server.start() - # Start the prometheus endpoint if enabled by the config - if self.config.getboolean_with_default("gateway", "enable_prometheus_exporter", True): - self.logger.info("Prometheus endpoint is enabled") - start_exporter(self.spdk_rpc_client, self.config, self.gateway_rpc, self.logger) - else: - self.logger.info(f"Prometheus endpoint is disabled. To enable, set the config option 'enable_prometheus_exporter = True'") - # Set SPDK log level log_level_args = {} log_level = self.config.get_with_default("spdk", "log_level", None) @@ -255,6 +257,9 @@ def serve(self): self._register_service_map() + # This should be at the end of the function, after the server is up + self.start_prometheus() + def _register_service_map(self): # show gateway in "ceph status" output conn = self.omap_state.conn