Skip to content

Commit

Permalink
Merge PR ceph#29214 into master
Browse files Browse the repository at this point in the history
* refs/pull/29214/head:
	mgr: templatize/generalize metrics collection interface

Reviewed-by: Patrick Donnelly <pdonnell@redhat.com>
  • Loading branch information
liewegas committed Dec 9, 2019
2 parents 5993dd8 + efcebe1 commit 946a8f7
Show file tree
Hide file tree
Showing 19 changed files with 634 additions and 277 deletions.
9 changes: 8 additions & 1 deletion src/messages/MMgrConfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define CEPH_MMGRCONFIGURE_H_

#include "msg/Message.h"
#include "mgr/MetricTypes.h"
#include "mgr/OSDPerfMetricTypes.h"

/**
Expand All @@ -24,7 +25,7 @@
*/
class MMgrConfigure : public Message {
private:
static constexpr int HEAD_VERSION = 3;
static constexpr int HEAD_VERSION = 4;
static constexpr int COMPAT_VERSION = 1;

public:
Expand All @@ -35,6 +36,8 @@ class MMgrConfigure : public Message {

std::map<OSDPerfMetricQuery, OSDPerfMetricLimits> osd_perf_metric_queries;

boost::optional<MetricConfigMessage> metric_config_message;

void decode_payload() override
{
using ceph::decode;
Expand All @@ -46,13 +49,17 @@ class MMgrConfigure : public Message {
if (header.version >= 3) {
decode(osd_perf_metric_queries, p);
}
if (header.version >= 4) {
decode(metric_config_message, p);
}
}

void encode_payload(uint64_t features) override {
using ceph::encode;
encode(stats_period, payload);
encode(stats_threshold, payload);
encode(osd_perf_metric_queries, payload);
encode(metric_config_message, payload);
}

std::string_view get_type_name() const override { return "mgrconfigure"; }
Expand Down
9 changes: 8 additions & 1 deletion src/messages/MMgrReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <boost/optional.hpp>

#include "msg/Message.h"
#include "mgr/MetricTypes.h"
#include "mgr/OSDPerfMetricTypes.h"

#include "common/perf_counters.h"
Expand Down Expand Up @@ -73,7 +74,7 @@ WRITE_CLASS_ENCODER(PerfCounterType)

class MMgrReport : public Message {
private:
static constexpr int HEAD_VERSION = 8;
static constexpr int HEAD_VERSION = 9;
static constexpr int COMPAT_VERSION = 1;

public:
Expand Down Expand Up @@ -107,6 +108,8 @@ class MMgrReport : public Message {

std::map<OSDPerfMetricQuery, OSDPerfMetricReport> osd_perf_metric_reports;

boost::optional<MetricReportMessage> metric_report_message;

void decode_payload() override
{
using ceph::decode;
Expand All @@ -132,6 +135,9 @@ class MMgrReport : public Message {
if (header.version >= 8) {
decode(task_status, p);
}
if (header.version >= 9) {
decode(metric_report_message, p);
}
}

void encode_payload(uint64_t features) override {
Expand All @@ -146,6 +152,7 @@ class MMgrReport : public Message {
encode(config_bl, payload);
encode(osd_perf_metric_reports, payload);
encode(task_status, payload);
encode(metric_report_message, payload);
}

std::string_view get_type_name() const override { return "mgrreport"; }
Expand Down
6 changes: 3 additions & 3 deletions src/mgr/ActivePyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,14 @@ void ActivePyModules::set_uri(const std::string& module_name,
modules.at(module_name)->set_uri(uri);
}

OSDPerfMetricQueryID ActivePyModules::add_osd_perf_query(
MetricQueryID ActivePyModules::add_osd_perf_query(
const OSDPerfMetricQuery &query,
const std::optional<OSDPerfMetricLimit> &limit)
{
return server.add_osd_perf_query(query, limit);
}

void ActivePyModules::remove_osd_perf_query(OSDPerfMetricQueryID query_id)
void ActivePyModules::remove_osd_perf_query(MetricQueryID query_id)
{
int r = server.remove_osd_perf_query(query_id);
if (r < 0) {
Expand All @@ -1027,7 +1027,7 @@ void ActivePyModules::remove_osd_perf_query(OSDPerfMetricQueryID query_id)
}
}

PyObject *ActivePyModules::get_osd_perf_counters(OSDPerfMetricQueryID query_id)
PyObject *ActivePyModules::get_osd_perf_counters(MetricQueryID query_id)
{
std::map<OSDPerfMetricKey, PerformanceCounters> counters;

Expand Down
6 changes: 3 additions & 3 deletions src/mgr/ActivePyModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class ActivePyModules
const std::string &svc_id,
const std::string &path) const;

OSDPerfMetricQueryID add_osd_perf_query(
MetricQueryID add_osd_perf_query(
const OSDPerfMetricQuery &query,
const std::optional<OSDPerfMetricLimit> &limit);
void remove_osd_perf_query(OSDPerfMetricQueryID query_id);
PyObject *get_osd_perf_counters(OSDPerfMetricQueryID query_id);
void remove_osd_perf_query(MetricQueryID query_id);
PyObject *get_osd_perf_counters(MetricQueryID query_id);

bool get_store(const std::string &module_name,
const std::string &key, std::string *val) const;
Expand Down
5 changes: 3 additions & 2 deletions src/mgr/BaseMgrModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "mon/MonClient.h"
#include "common/errno.h"
#include "common/version.h"
#include "mgr/Types.h"

#include "PyUtil.h"
#include "BaseMgrModule.h"
Expand Down Expand Up @@ -992,7 +993,7 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
static PyObject*
ceph_remove_osd_perf_query(BaseMgrModule *self, PyObject *args)
{
OSDPerfMetricQueryID query_id;
MetricQueryID query_id;
if (!PyArg_ParseTuple(args, "i:ceph_remove_osd_perf_query", &query_id)) {
derr << "Invalid args!" << dendl;
return nullptr;
Expand All @@ -1005,7 +1006,7 @@ ceph_remove_osd_perf_query(BaseMgrModule *self, PyObject *args)
static PyObject*
ceph_get_osd_perf_counters(BaseMgrModule *self, PyObject *args)
{
OSDPerfMetricQueryID query_id;
MetricQueryID query_id;
if (!PyArg_ParseTuple(args, "i:ceph_get_osd_perf_counters", &query_id)) {
derr << "Invalid args!" << dendl;
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions src/mgr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(WITH_MGR)
Gil.cc
Mgr.cc
MgrStandby.cc
MetricCollector.cc
OSDPerfMetricTypes.cc
OSDPerfMetricCollector.cc
PyFormatter.cc
Expand Down
11 changes: 8 additions & 3 deletions src/mgr/DaemonServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,11 @@ bool DaemonServer::handle_report(const ref_t<MMgrReport>& m)
osd_perf_metric_collector.process_reports(m->osd_perf_metric_reports);
}

if (m->metric_report_message) {
const MetricReportMessage &message = *m->metric_report_message;
boost::apply_visitor(HandlePayloadVisitor(this), message.payload);
}

return true;
}

Expand Down Expand Up @@ -2857,20 +2862,20 @@ void DaemonServer::_send_configure(ConnectionRef c)
c->send_message2(configure);
}

OSDPerfMetricQueryID DaemonServer::add_osd_perf_query(
MetricQueryID DaemonServer::add_osd_perf_query(
const OSDPerfMetricQuery &query,
const std::optional<OSDPerfMetricLimit> &limit)
{
return osd_perf_metric_collector.add_query(query, limit);
}

int DaemonServer::remove_osd_perf_query(OSDPerfMetricQueryID query_id)
int DaemonServer::remove_osd_perf_query(MetricQueryID query_id)
{
return osd_perf_metric_collector.remove_query(query_id);
}

int DaemonServer::get_osd_perf_counters(
OSDPerfMetricQueryID query_id,
MetricQueryID query_id,
std::map<OSDPerfMetricKey, PerformanceCounters> *counters)
{
return osd_perf_metric_collector.get_counters(query_id, counters);
Expand Down
32 changes: 27 additions & 5 deletions src/mgr/DaemonServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <set>
#include <string>
#include <boost/variant.hpp>

#include "common/ceph_mutex.h"
#include "common/LogClient.h"
Expand All @@ -29,6 +30,7 @@
#include "ServiceMap.h"
#include "MgrSession.h"
#include "DaemonState.h"
#include "MetricCollector.h"
#include "OSDPerfMetricCollector.h"

class MMgrReport;
Expand Down Expand Up @@ -107,8 +109,7 @@ class DaemonServer : public Dispatcher, public md_config_obs_t
void tick();
void schedule_tick_locked(double delay_sec);

class OSDPerfMetricCollectorListener :
public OSDPerfMetricCollector::Listener {
class OSDPerfMetricCollectorListener : public MetricListener {
public:
OSDPerfMetricCollectorListener(DaemonServer *server)
: server(server) {
Expand All @@ -123,6 +124,27 @@ class DaemonServer : public Dispatcher, public md_config_obs_t
OSDPerfMetricCollector osd_perf_metric_collector;
void handle_osd_perf_metric_query_updated();

void handle_metric_payload(const OSDMetricPayload &payload) {
osd_perf_metric_collector.process_reports(payload);
}

void handle_metric_payload(const UnknownMetricPayload &payload) {
ceph_abort();
}

struct HandlePayloadVisitor : public boost::static_visitor<void> {
DaemonServer *server;

HandlePayloadVisitor(DaemonServer *server)
: server(server) {
}

template <typename MetricPayload>
inline void operator()(const MetricPayload &payload) const {
server->handle_metric_payload(payload);
}
};

public:
int init(uint64_t gid, entity_addrvec_t client_addrs);
void shutdown();
Expand Down Expand Up @@ -157,11 +179,11 @@ class DaemonServer : public Dispatcher, public md_config_obs_t

void _send_configure(ConnectionRef c);

OSDPerfMetricQueryID add_osd_perf_query(
MetricQueryID add_osd_perf_query(
const OSDPerfMetricQuery &query,
const std::optional<OSDPerfMetricLimit> &limit);
int remove_osd_perf_query(OSDPerfMetricQueryID query_id);
int get_osd_perf_counters(OSDPerfMetricQueryID query_id,
int remove_osd_perf_query(MetricQueryID query_id);
int get_osd_perf_counters(MetricQueryID query_id,
std::map<OSDPerfMetricKey, PerformanceCounters> *c);

virtual const char** get_tracked_conf_keys() const override;
Expand Down
Loading

0 comments on commit 946a8f7

Please sign in to comment.