From b18ddf4d37f631f15199d3dce32400cda55631a3 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Thu, 20 Sep 2018 13:10:57 +0300 Subject: [PATCH] mgr: add osd_perf_query methods to ActivePyModules Signed-off-by: Mykola Golub --- src/mgr/ActivePyModules.cc | 13 +++++++++++++ src/mgr/ActivePyModules.h | 5 +++++ src/mgr/BaseMgrModule.cc | 34 ++++++++++++++++++++++++++++++++++ src/pybind/mgr/mgr_module.py | 17 +++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 0ba80c79239..1c89dcc3188 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -888,4 +888,17 @@ void ActivePyModules::set_uri(const std::string& module_name, modules[module_name]->set_uri(uri); } +OSDPerfMetricQueryID ActivePyModules::add_osd_perf_query( + const OSDPerfMetricQuery &query) +{ + return server.add_osd_perf_query(query); +} +void ActivePyModules::remove_osd_perf_query(OSDPerfMetricQueryID query_id) +{ + int r = server.remove_osd_perf_query(query_id); + if (r < 0) { + dout(0) << "remove_osd_perf_query for query_id=" << query_id << " failed: " + << cpp_strerror(r) << dendl; + } +} diff --git a/src/mgr/ActivePyModules.h b/src/mgr/ActivePyModules.h index 91fc09697ec..35476c1bbc8 100644 --- a/src/mgr/ActivePyModules.h +++ b/src/mgr/ActivePyModules.h @@ -28,9 +28,11 @@ #include "DaemonState.h" #include "ClusterState.h" +#include "OSDPerfMetricQuery.h" class health_check_map_t; class DaemonServer; +struct OSDPerfMetricQuery; class ActivePyModules { @@ -91,6 +93,9 @@ public: const std::string &svc_id, const std::string &path) const; + OSDPerfMetricQueryID add_osd_perf_query(const OSDPerfMetricQuery &query); + void remove_osd_perf_query(OSDPerfMetricQueryID query_id); + bool get_store(const std::string &module_name, const std::string &key, std::string *val) const; PyObject *get_store_prefix(const std::string &module_name, diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 6cc3cda87a5..a6fe20d8f3d 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -614,6 +614,34 @@ ceph_dispatch_remote(BaseMgrModule *self, PyObject *args) return result; } +static PyObject* +ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args) +{ + // TODO: parse args to build OSDPerfMetricQuery. + // For now it is ignored and can be anything. + PyObject *query_ = nullptr; + if (!PyArg_ParseTuple(args, "O:ceph_add_osd_perf_query", &query_)) { + derr << "Invalid args!" << dendl; + return nullptr; + } + + OSDPerfMetricQuery query; + auto query_id = self->py_modules->add_osd_perf_query(query); + return PyLong_FromLong(query_id); +} + +static PyObject* +ceph_remove_osd_perf_query(BaseMgrModule *self, PyObject *args) +{ + OSDPerfMetricQueryID query_id; + if (!PyArg_ParseTuple(args, "i:ceph_remove_osd_perf_query", &query_id)) { + derr << "Invalid args!" << dendl; + return nullptr; + } + + self->py_modules->remove_osd_perf_query(query_id); + Py_RETURN_NONE; +} PyMethodDef BaseMgrModule_methods[] = { {"_ceph_get", (PyCFunction)ceph_state_get, METH_VARARGS, @@ -683,6 +711,12 @@ PyMethodDef BaseMgrModule_methods[] = { {"_ceph_dispatch_remote", (PyCFunction)ceph_dispatch_remote, METH_VARARGS, "Dispatch a call to another module"}, + {"_ceph_add_osd_perf_query", (PyCFunction)ceph_add_osd_perf_query, + METH_VARARGS, "Add an osd perf query"}, + + {"_ceph_remove_osd_perf_query", (PyCFunction)ceph_remove_osd_perf_query, + METH_VARARGS, "Remove an osd perf query"}, + {NULL, NULL, 0, NULL} }; diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index b672b1f23a6..c920df1a102 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -883,3 +883,20 @@ class MgrModule(ceph_module.BaseMgrModule): """ return self._ceph_dispatch_remote(module_name, method_name, args, kwargs) + + def add_osd_perf_query(self, query): + """ + Fetch the daemon metadata for a particular service. + + :param object query: query + :rtype: int (query id) + """ + return self._ceph_add_osd_perf_query(query) + + def remove_osd_perf_query(self, query_id): + """ + Fetch the daemon metadata for a particular service. + + :param int query_id: query ID + """ + return self._ceph_remove_osd_perf_query(query_id) -- 2.47.3