From: Sage Weil Date: Tue, 30 Jul 2019 16:23:57 +0000 (-0500) Subject: mon: refactor/simplify health [detail] X-Git-Tag: v15.1.0~1877^2~25 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=062681a72f3bb48b8bf0abb41439e94bdcfdcfa9;p=ceph.git mon: refactor/simplify health [detail] Get rid of single caller helpers. Instead, assimilate all the checks together at once, and have two separate blocks, one for formatted, and one for plaintext output. Much easier to follow! Signed-off-by: Sage Weil --- diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 713dbe040752..a4f06b763127 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2784,39 +2784,70 @@ health_status_t Monitor::get_health_status( const char *sep1, const char *sep2) { + health_check_map_t all; + for (auto& svc : paxos_service) { + all.merge(svc->get_health_checks()); + } health_status_t r = HEALTH_OK; + for (auto& p : all.checks) { + 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"); - } - - string summary; - string *psummary = f ? nullptr : &summary; - for (auto& svc : paxos_service) { - r = std::min(r, svc->get_health_checks().dump_summary( - f, psummary, sep2, want_detail)); - } + for (auto& p : all.checks) { + f->open_object_section(p.first.c_str()); + f->dump_stream("severity") << p.second.severity; - if (f) { + 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->dump_stream("status") << r; f->close_section(); } else { // one-liner: HEALTH_FOO[ thing1[; thing2 ...]] + string summary; + for (auto& p : all.checks) { + if (!summary.empty()) { + summary += sep2; + } + summary += p.second.summary; + } *plain = stringify(r); if (summary.size()) { *plain += sep1; *plain += summary; } *plain += "\n"; - } - - if (want_detail && !f) { - for (auto& svc : paxos_service) { - svc->get_health_checks().dump_detail(plain); + // detail + for (auto& p : all.checks) { + *plain += p.first + ": " + p.second.summary + "\n"; + for (auto& d : p.second.detail) { + *plain += " "; + *plain += d; + *plain += "\n"; + } } } - return r; } diff --git a/src/mon/health_check.h b/src/mon/health_check.h index 112ab8b53d47..54dc93b92a3c 100644 --- a/src/mon/health_check.h +++ b/src/mon/health_check.h @@ -134,52 +134,6 @@ struct health_check_map_t { } } - health_status_t dump_summary(ceph::Formatter *f, std::string *plain, - const char *sep, bool detail) const { - health_status_t r = HEALTH_OK; - for (auto& p : checks) { - if (r > p.second.severity) { - r = p.second.severity; - } - if (f) { - f->open_object_section(p.first.c_str()); - f->dump_stream("severity") << p.second.severity; - - f->open_object_section("summary"); - f->dump_string("message", p.second.summary); - f->close_section(); - - if (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(); - } else { - if (!plain->empty()) { - *plain += sep; - } - *plain += p.second.summary; - } - } - return r; - } - - void dump_detail(std::string *plain) const { - for (auto& p : checks) { - *plain += p.first + ": " + p.second.summary + "\n"; - for (auto& d : p.second.detail) { - *plain += " "; - *plain += d; - *plain += "\n"; - } - } - } - friend bool operator==(const health_check_map_t& l, const health_check_map_t& r) { return l.checks == r.checks;