From 06077827fe8344ca56d5a397f352bc4171affced Mon Sep 17 00:00:00 2001 From: Avan Thakkar Date: Sat, 8 Oct 2022 01:40:57 +0530 Subject: [PATCH] mgr/prometheus: avoid duplicates and deleted entries for rbd_stats_pool Fixes: https://tracker.ceph.com/issues/57797 Signed-off-by: Avan Thakkar Avoid duplicate entries (pool[/namespace]) for rbd_stats_pools config and also avoid deleted pools. --- src/pybind/mgr/prometheus/module.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/prometheus/module.py b/src/pybind/mgr/prometheus/module.py index afcf49820e5ac..984006be16e2e 100644 --- a/src/pybind/mgr/prometheus/module.py +++ b/src/pybind/mgr/prometheus/module.py @@ -1282,7 +1282,10 @@ class Module(MgrModule): # stats are collected for every namespace in the pool. The wildcard # '*' can be used to indicate all pools or namespaces pools_string = cast(str, self.get_localized_module_option('rbd_stats_pools')) - pool_keys = [] + pool_keys = set() + osd_map = self.get('osd_map') + rbd_pools = [pool['pool_name'] for pool in osd_map['pools'] + if 'rbd' in pool.get('application_metadata', {})] for x in re.split(r'[\s,]+', pools_string): if not x: continue @@ -1295,13 +1298,11 @@ class Module(MgrModule): if pool_name == "*": # collect for all pools - osd_map = self.get('osd_map') - for pool in osd_map['pools']: - if 'rbd' not in pool.get('application_metadata', {}): - continue - pool_keys.append((pool['pool_name'], namespace_name)) + for pool in rbd_pools: + pool_keys.add((pool, namespace_name)) else: - pool_keys.append((pool_name, namespace_name)) + if pool_name in rbd_pools: + pool_keys.add((pool_name, namespace_name)) # avoids adding deleted pool pools = {} # type: Dict[str, Set[str]] for pool_key in pool_keys: -- 2.39.5