]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: refactor/simplify health [detail]
authorSage Weil <sage@redhat.com>
Tue, 30 Jul 2019 16:23:57 +0000 (11:23 -0500)
committerSage Weil <sage@redhat.com>
Thu, 15 Aug 2019 01:37:00 +0000 (20:37 -0500)
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 <sage@redhat.com>
src/mon/Monitor.cc
src/mon/health_check.h

index 713dbe04075210e5af084f399c3665691b2a7526..a4f06b76312799a53cd966289feb26b46d55aac0 100644 (file)
@@ -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;
 }
 
index 112ab8b53d4775a1e2277e4508875d4076edbefa..54dc93b92a3cd95fd5b46857cae4129667cd2839 100644 (file)
@@ -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;