Skip to content

Commit 583a355

Browse files
authored
Merge pull request ceph#55149 from rkachach/fix_issue_63992
mgr/prometheus: fix orch check to prevent Prometheus from crashing Reviewed-by: Avan Thakkar <[email protected]> Reviewed-by: Juan Miguel Olmo Martínez <[email protected]>
2 parents 6576c81 + 6d550ff commit 583a355

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/pybind/mgr/prometheus/module.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT, HandleCommandResult, CLIWriteCommand
1515
from mgr_util import get_default_addr, profile_method, build_url
16-
from orchestrator import OrchestratorClientMixin, raise_if_exception, NoOrchestrator
16+
from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
1717
from rbd import RBD
1818

1919
from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable
@@ -646,8 +646,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
646646
_global_instance = self
647647
self.metrics_thread = MetricCollectionThread(_global_instance)
648648
self.health_history = HealthHistory(self)
649-
self.modify_instance_id = self.get_orch_status() and self.get_module_option(
650-
'exclude_perf_counters')
651649

652650
def _setup_static_metrics(self) -> Dict[str, Metric]:
653651
metrics = {}
@@ -864,10 +862,12 @@ def _setup_static_metrics(self) -> Dict[str, Metric]:
864862

865863
return metrics
866864

867-
def get_orch_status(self) -> bool:
865+
def orch_is_available(self) -> bool:
868866
try:
869867
return self.available()[0]
870-
except NoOrchestrator:
868+
except (RuntimeError, OrchestratorError, ImportError):
869+
# import error could happend during startup in case
870+
# orchestrator has not been loaded yet by the mgr
871871
return False
872872

873873
def get_server_addr(self) -> str:
@@ -1292,18 +1292,22 @@ def _get_pool_info(pool: Dict[str, Any]) -> Tuple[str, str]:
12921292
# Populate other servers metadata
12931293
# If orchestrator is available and ceph-exporter is running modify rgw instance id
12941294
# to match the one from exporter
1295-
if self.modify_instance_id:
1295+
modify_instance_id = self.orch_is_available() and self.get_module_option('exclude_perf_counters')
1296+
if modify_instance_id:
12961297
daemons = raise_if_exception(self.list_daemons(daemon_type='rgw'))
12971298
for daemon in daemons:
1299+
if daemon.daemon_id and '.' in daemon.daemon_id:
1300+
instance_id = daemon.daemon_id.split(".")[2]
1301+
else:
1302+
instance_id = daemon.daemon_id if daemon.daemon_id else ""
12981303
self.metrics['rgw_metadata'].set(1,
1299-
('{}.{}'.format(str(daemon.daemon_type),
1300-
str(daemon.daemon_id)),
1304+
(f"{daemon.daemon_type}.{daemon.daemon_id}",
13011305
str(daemon.hostname),
13021306
str(daemon.version),
1303-
str(daemon.daemon_id).split(".")[2]))
1307+
instance_id))
13041308
for key, value in servers.items():
13051309
service_id, service_type = key
1306-
if service_type == 'rgw' and not self.modify_instance_id:
1310+
if service_type == 'rgw' and not modify_instance_id:
13071311
hostname, version, name = value
13081312
self.metrics['rgw_metadata'].set(
13091313
1,

0 commit comments

Comments
 (0)