]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/prometheus: use get_module_option() wrapper
authorKefu Chai <kchai@redhat.com>
Tue, 24 Nov 2020 05:40:48 +0000 (13:40 +0800)
committerBoris Ranto <branto@redhat.com>
Thu, 28 Jan 2021 14:54:24 +0000 (15:54 +0100)
for better readability

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 5700419b272786b5a5e2e7b8d3d5e9d9917a9469)

src/pybind/mgr/prometheus/module.py

index 80fe79d1e67bb07b92e46c69b9b606f724a0d938..c7bafa0356a5b73d98d61159e4cbc9f01e1078ab 100644 (file)
@@ -9,7 +9,7 @@ import re
 import socket
 import threading
 import time
-from mgr_module import MgrModule, MgrStandbyModule, CommandResult, PG_STATES
+from mgr_module import MgrModule, MgrStandbyModule, PG_STATES
 from mgr_util import get_default_addr, profile_method
 from rbd import RBD
 from collections import namedtuple
@@ -198,9 +198,8 @@ class MetricCollectionThread(threading.Thread):
                 start_time = time.time()
                 data = self.mod.collect()
                 duration = time.time() - start_time
-
                 self.mod.log.debug('collecting cache in thread done')
-                
+
                 sleep_time = self.mod.scrape_interval - duration
                 if sleep_time < 0:
                     self.mod.log.warning(
@@ -1144,26 +1143,8 @@ class Module(MgrModule):
                 if service['type'] != 'mgr':
                     continue
                 id_ = service['id']
-                # get port for prometheus module at mgr with id_
-                # TODO use get_config_prefix or get_config here once
-                # https://github.com/ceph/ceph/pull/20458 is merged
-                result = CommandResult("")
-                assert isinstance(_global_instance, Module)
-                _global_instance.send_command(
-                    result, "mon", '',
-                    json.dumps({
-                        "prefix": "config-key get",
-                        'key': "config/mgr/mgr/prometheus/{}/server_port".format(id_),
-                    }),
-                    "")
-                r, outb, outs = result.wait()
-                if r != 0:
-                    _global_instance.log.error("Failed to retrieve port for mgr {}: {}".format(id_, outs))
-                    targets.append('{}:{}'.format(hostname, DEFAULT_PORT))
-                else:
-                    port = json.loads(outb)
-                    targets.append('{}:{}'.format(hostname, port))
-
+                port = self._get_module_option('server_port', DEFAULT_PORT, id_)
+                targets.append(f'{hostname}:{port}')
         ret = [
             {
                 "targets": targets,