Skip to content

Commit

Permalink
mgr/prometheus: fixing orch check to avoid crashing during startup
Browse files Browse the repository at this point in the history
Fixes: https://tracker.ceph.com/issues/63992

Signed-off-by: Redouane Kachach <rkachach@redhat.com>
  • Loading branch information
rkachach committed Jan 12, 2024
1 parent a6110a8 commit e52cd13
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/pybind/mgr/prometheus/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT, HandleCommandResult, CLIWriteCommand
from mgr_util import get_default_addr, profile_method, build_url
from orchestrator import OrchestratorClientMixin, raise_if_exception, NoOrchestrator
from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
from rbd import RBD

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

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

return metrics

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

def get_server_addr(self) -> str:
Expand Down Expand Up @@ -1292,7 +1292,8 @@ def _get_pool_info(pool: Dict[str, Any]) -> Tuple[str, str]:
# Populate other servers metadata
# If orchestrator is available and ceph-exporter is running modify rgw instance id
# to match the one from exporter
if self.modify_instance_id:
modify_instance_id = self.orch_is_available() and self.get_module_option('exclude_perf_counters')
if modify_instance_id:
daemons = raise_if_exception(self.list_daemons(daemon_type='rgw'))
for daemon in daemons:
self.metrics['rgw_metadata'].set(1,
Expand All @@ -1303,7 +1304,7 @@ def _get_pool_info(pool: Dict[str, Any]) -> Tuple[str, str]:
str(daemon.daemon_id).split(".")[2]))
for key, value in servers.items():
service_id, service_type = key
if service_type == 'rgw' and not self.modify_instance_id:
if service_type == 'rgw' and not modify_instance_id:
hostname, version, name = value
self.metrics['rgw_metadata'].set(
1,
Expand Down

0 comments on commit e52cd13

Please sign in to comment.