From 29d74309aaf4fa878d8b899efa91b64cb176f3f5 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 31 Jul 2019 00:27:26 -0500 Subject: [PATCH] mon/HealthMonitor: move get_health_status() This operates exclusively on HealthMonitor members. Make public member private again. Signed-off-by: Sage Weil --- src/mon/HealthMonitor.cc | 120 +++++++++++++++++++++++++++++++++++ src/mon/HealthMonitor.h | 10 ++- src/mon/MgrMonitor.cc | 3 +- src/mon/Monitor.cc | 134 ++------------------------------------- src/mon/Monitor.h | 6 -- 5 files changed, 136 insertions(+), 137 deletions(-) diff --git a/src/mon/HealthMonitor.cc b/src/mon/HealthMonitor.cc index 3f8ed8f9ab5..9437c261780 100644 --- a/src/mon/HealthMonitor.cc +++ b/src/mon/HealthMonitor.cc @@ -394,6 +394,126 @@ void HealthMonitor::gather_all_health_checks(health_check_map_t *all) } } +health_status_t HealthMonitor::get_health_status( + bool want_detail, + Formatter *f, + std::string *plain, + const char *sep1, + const char *sep2) +{ + health_check_map_t all; + gather_all_health_checks(&all); + health_status_t r = HEALTH_OK; + for (auto& p : all.checks) { + if (!mutes.count(p.first)) { + if (r > p.second.severity) { + r = p.second.severity; + } + } + } + if (f) { + f->open_object_section("health"); + f->dump_stream("status") << r; + f->open_object_section("checks"); + for (auto& p : all.checks) { + f->open_object_section(p.first.c_str()); + f->dump_stream("severity") << p.second.severity; + f->dump_bool("muted", mutes.count(p.first)); + f->open_object_section("summary"); + f->dump_string("message", p.second.summary); + f->close_section(); + if (want_detail) { + f->open_array_section("detail"); + for (auto& d : p.second.detail) { + f->open_object_section("detail_item"); + f->dump_string("message", d); + f->close_section(); + } + f->close_section(); + } + f->close_section(); + } + f->close_section(); + f->open_array_section("mutes"); + for (auto& p : mutes) { + f->dump_object("mute", p.second); + } + f->close_section(); + f->close_section(); + } else { + auto now = ceph_clock_now(); + // one-liner: HEALTH_FOO[ thing1[; thing2 ...]] + string summary; + for (auto& p : all.checks) { + if (!mutes.count(p.first)) { + if (!summary.empty()) { + summary += sep2; + } + summary += p.second.summary; + } + } + *plain = stringify(r); + if (summary.size()) { + *plain += sep1; + *plain += summary; + } + if (!mutes.empty()) { + if (summary.size()) { + *plain += sep2; + } else { + *plain += sep1; + } + *plain += "(muted:"; + for (auto& p : mutes) { + *plain += " "; + *plain += p.first; + if (p.second.ttl) { + if (p.second.ttl > now) { + auto left = p.second.ttl; + left -= now; + *plain += "("s + utimespan_str(left) + ")"; + } else { + *plain += "(0s)"; + } + } + } + *plain += ")"; + } + *plain += "\n"; + // detail + if (want_detail) { + for (auto& p : all.checks) { + auto q = mutes.find(p.first); + if (q != mutes.end()) { + *plain += "(MUTED"; + if (q->second.ttl != utime_t()) { + if (q->second.ttl > now) { + auto left = q->second.ttl; + left -= now; + *plain += " ttl "; + *plain += utimespan_str(left); + } else { + *plain += "0s"; + } + } + if (q->second.sticky) { + *plain += ", STICKY"; + } + *plain += ") "; + } + *plain += "["s + short_health_string(p.second.severity) + "] " + + p.first + ": " + p.second.summary + "\n"; + for (auto& d : p.second.detail) { + *plain += " "; + *plain += d; + *plain += "\n"; + } + } + } + } + return r; +} + bool HealthMonitor::check_member_health() { dout(20) << __func__ << dendl; diff --git a/src/mon/HealthMonitor.h b/src/mon/HealthMonitor.h index a80d32da94e..2f8b330cf61 100644 --- a/src/mon/HealthMonitor.h +++ b/src/mon/HealthMonitor.h @@ -21,12 +21,10 @@ class HealthMonitor : public PaxosService version_t version = 0; map quorum_checks; // for each quorum member health_check_map_t leader_checks; // leader only + map mutes; map pending_mutes; -public: - map mutes; - public: HealthMonitor(Monitor *m, Paxos *p, const string& service_name); @@ -59,6 +57,12 @@ public: void tick() override; void gather_all_health_checks(health_check_map_t *all); + health_status_t get_health_status( + bool want_detail, + Formatter *f, + std::string *plain, + const char *sep1 = " ", + const char *sep2 = "; "); /** * @} // HealthMonitor_Inherited_h diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index a867dbad0a7..368416d7243 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -22,6 +22,7 @@ #include "mgr/mgr_commands.h" #include "OSDMonitor.h" #include "ConfigMonitor.h" +#include "HealthMonitor.h" #include "MgrMonitor.h" @@ -633,7 +634,7 @@ void MgrMonitor::send_digests() auto mdigest = make_message(); JSONFormatter f; - mon->get_health_status(true, &f, nullptr, nullptr, nullptr); + mon->healthmon()->get_health_status(true, &f, nullptr, nullptr, nullptr); f.flush(mdigest->health_json); f.reset(); diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 96c8da73dc6..acc4c34f061 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2767,7 +2767,7 @@ void Monitor::do_health_to_clog(bool force) dout(10) << __func__ << (force ? " (force)" : "") << dendl; string summary; - health_status_t level = get_health_status(false, nullptr, &summary); + health_status_t level = healthmon()->get_health_status(false, nullptr, &summary); if (!force && summary == health_status_cache.summary && level == health_status_cache.overall) @@ -2777,126 +2777,6 @@ void Monitor::do_health_to_clog(bool force) health_status_cache.overall = level; } -health_status_t Monitor::get_health_status( - bool want_detail, - Formatter *f, - std::string *plain, - const char *sep1, - const char *sep2) -{ - health_check_map_t all; - healthmon()->gather_all_health_checks(&all); - health_status_t r = HEALTH_OK; - for (auto& p : all.checks) { - if (!healthmon()->mutes.count(p.first)) { - if (r > p.second.severity) { - r = p.second.severity; - } - } - } - if (f) { - f->open_object_section("health"); - f->dump_stream("status") << r; - f->open_object_section("checks"); - for (auto& p : all.checks) { - f->open_object_section(p.first.c_str()); - f->dump_stream("severity") << p.second.severity; - f->dump_bool("muted", healthmon()->mutes.count(p.first)); - f->open_object_section("summary"); - f->dump_string("message", p.second.summary); - f->close_section(); - if (want_detail) { - f->open_array_section("detail"); - for (auto& d : p.second.detail) { - f->open_object_section("detail_item"); - f->dump_string("message", d); - f->close_section(); - } - f->close_section(); - } - f->close_section(); - } - f->close_section(); - f->open_array_section("mutes"); - for (auto& p : healthmon()->mutes) { - f->dump_object("mute", p.second); - } - f->close_section(); - f->close_section(); - } else { - auto now = ceph_clock_now(); - // one-liner: HEALTH_FOO[ thing1[; thing2 ...]] - string summary; - for (auto& p : all.checks) { - if (!healthmon()->mutes.count(p.first)) { - if (!summary.empty()) { - summary += sep2; - } - summary += p.second.summary; - } - } - *plain = stringify(r); - if (summary.size()) { - *plain += sep1; - *plain += summary; - } - if (!healthmon()->mutes.empty()) { - if (summary.size()) { - *plain += sep2; - } else { - *plain += sep1; - } - *plain += "(muted:"; - for (auto& p : healthmon()->mutes) { - *plain += " "; - *plain += p.first; - if (p.second.ttl) { - if (p.second.ttl > now) { - auto left = p.second.ttl; - left -= now; - *plain += "("s + utimespan_str(left) + ")"; - } else { - *plain += "(0s)"; - } - } - } - *plain += ")"; - } - *plain += "\n"; - // detail - if (want_detail) { - for (auto& p : all.checks) { - auto q = healthmon()->mutes.find(p.first); - if (q != healthmon()->mutes.end()) { - *plain += "(MUTED"; - if (q->second.ttl != utime_t()) { - if (q->second.ttl > now) { - auto left = q->second.ttl; - left -= now; - *plain += " ttl "; - *plain += utimespan_str(left); - } else { - *plain += "0s"; - } - } - if (q->second.sticky) { - *plain += ", STICKY"; - } - *plain += ") "; - } - *plain += "["s + short_health_string(p.second.severity) + "] " + - p.first + ": " + p.second.summary + "\n"; - for (auto& d : p.second.detail) { - *plain += " "; - *plain += d; - *plain += "\n"; - } - } - } - } - return r; -} - void Monitor::log_health( const health_check_map_t& updated, const health_check_map_t& previous, @@ -3010,7 +2890,7 @@ void Monitor::get_cluster_status(stringstream &ss, Formatter *f) mono_clock::time_point now = mono_clock::now(); if (f) { f->dump_stream("fsid") << monmap->get_fsid(); - get_health_status(false, f, nullptr); + healthmon()->get_health_status(false, f, nullptr); f->dump_unsigned("election_epoch", get_epoch()); { f->open_array_section("quorum"); @@ -3056,8 +2936,8 @@ void Monitor::get_cluster_status(stringstream &ss, Formatter *f) ss << " id: " << monmap->get_fsid() << "\n"; string health; - get_health_status(false, nullptr, &health, - "\n ", "\n "); + healthmon()->get_health_status(false, nullptr, &health, + "\n ", "\n "); ss << " health: " << health << "\n"; ss << "\n \n services:\n"; @@ -3601,7 +3481,7 @@ void Monitor::handle_command(MonOpRequestRef op) rdata.append(ds); } else if (prefix == "health") { string plain; - get_health_status(detail == "detail", f.get(), f ? nullptr : &plain); + healthmon()->get_health_status(detail == "detail", f.get(), f ? nullptr : &plain); if (f) { f->flush(rdata); } else { @@ -3648,7 +3528,7 @@ void Monitor::handle_command(MonOpRequestRef op) tagstr = tagstr.substr(0, tagstr.find_last_of(' ')); f->dump_string("tag", tagstr); - get_health_status(true, f.get(), nullptr); + healthmon()->get_health_status(true, f.get(), nullptr); monmon()->dump_info(f.get()); osdmon()->dump_info(f.get()); @@ -4736,7 +4616,7 @@ void Monitor::handle_ping(MonOpRequestRef op) boost::scoped_ptr f(new JSONFormatter(true)); f->open_object_section("pong"); - get_health_status(false, f.get(), nullptr); + healthmon()->get_health_status(false, f.get(), nullptr); { stringstream ss; get_mon_status(f.get(), ss); diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index 8509b41587c..81d9c66f781 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -737,12 +737,6 @@ public: void do_health_to_clog_interval(); void do_health_to_clog(bool force = false); - health_status_t get_health_status( - bool want_detail, - Formatter *f, - std::string *plain, - const char *sep1 = " ", - const char *sep2 = "; "); void log_health( const health_check_map_t& updated, const health_check_map_t& previous, -- 2.39.5