]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon/HealthMonitor: move get_health_status()
authorSage Weil <sage@redhat.com>
Wed, 31 Jul 2019 05:27:26 +0000 (00:27 -0500)
committerSage Weil <sage@redhat.com>
Thu, 15 Aug 2019 01:40:08 +0000 (20:40 -0500)
This operates exclusively on HealthMonitor members.  Make public member
private again.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/HealthMonitor.cc
src/mon/HealthMonitor.h
src/mon/MgrMonitor.cc
src/mon/Monitor.cc
src/mon/Monitor.h

index 3f8ed8f9ab544cb28b87d954c38724593c369dc6..9437c2617803a95e640328a33cdd1437b3ffb0c0 100644 (file)
@@ -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;
index a80d32da94ef0280420822ae5cf549b77a4ff74a..2f8b330cf61331deb12e320bafd0fb0e33643d81 100644 (file)
@@ -21,12 +21,10 @@ class HealthMonitor : public PaxosService
   version_t version = 0;
   map<int,health_check_map_t> quorum_checks;  // for each quorum member
   health_check_map_t leader_checks;           // leader only
+  map<string,health_mute_t> mutes;
 
   map<string,health_mute_t> pending_mutes;
 
-public:
-  map<string,health_mute_t> 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
index a867dbad0a7e2df43bda34f0280a37a2d8bdbbd7..368416d724387f997a12a3ba3085af49abc1569c 100644 (file)
@@ -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<MMgrDigest>();
 
     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();
 
index 96c8da73dc634445dbe809f31f5d6931c01d1e46..acc4c34f0616dade3ca486e8fc3c35227dbe43aa 100644 (file)
@@ -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<Formatter> 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);
index 8509b41587c3b4a2c7a344b4538b471cb926bfc7..81d9c66f781c14b6068147ac225f4c575c4f2c61 100644 (file)
@@ -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,