|
13 | 13 |
|
14 | 14 | from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT, HandleCommandResult, CLIWriteCommand |
15 | 15 | 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 |
17 | 17 | from rbd import RBD |
18 | 18 |
|
19 | 19 | 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: |
646 | 646 | _global_instance = self |
647 | 647 | self.metrics_thread = MetricCollectionThread(_global_instance) |
648 | 648 | self.health_history = HealthHistory(self) |
649 | | - self.modify_instance_id = self.get_orch_status() and self.get_module_option( |
650 | | - 'exclude_perf_counters') |
651 | 649 |
|
652 | 650 | def _setup_static_metrics(self) -> Dict[str, Metric]: |
653 | 651 | metrics = {} |
@@ -864,10 +862,12 @@ def _setup_static_metrics(self) -> Dict[str, Metric]: |
864 | 862 |
|
865 | 863 | return metrics |
866 | 864 |
|
867 | | - def get_orch_status(self) -> bool: |
| 865 | + def orch_is_available(self) -> bool: |
868 | 866 | try: |
869 | 867 | 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 |
871 | 871 | return False |
872 | 872 |
|
873 | 873 | def get_server_addr(self) -> str: |
@@ -1292,18 +1292,22 @@ def _get_pool_info(pool: Dict[str, Any]) -> Tuple[str, str]: |
1292 | 1292 | # Populate other servers metadata |
1293 | 1293 | # If orchestrator is available and ceph-exporter is running modify rgw instance id |
1294 | 1294 | # 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: |
1296 | 1297 | daemons = raise_if_exception(self.list_daemons(daemon_type='rgw')) |
1297 | 1298 | 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 "" |
1298 | 1303 | 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}", |
1301 | 1305 | str(daemon.hostname), |
1302 | 1306 | str(daemon.version), |
1303 | | - str(daemon.daemon_id).split(".")[2])) |
| 1307 | + instance_id)) |
1304 | 1308 | for key, value in servers.items(): |
1305 | 1309 | 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: |
1307 | 1311 | hostname, version, name = value |
1308 | 1312 | self.metrics['rgw_metadata'].set( |
1309 | 1313 | 1, |
|
0 commit comments