]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: add helper for emitting logs by health status
authorJohn Spray <john.spray@redhat.com>
Fri, 1 Sep 2017 09:33:16 +0000 (05:33 -0400)
committerNathan Cutler <ncutler@suse.com>
Tue, 5 Sep 2017 15:20:06 +0000 (17:20 +0200)
We were starting to repeat our little "if(status==HEALTH_ERR"
blocks in too many places.

Signed-off-by: John Spray <john.spray@redhat.com>
(cherry picked from commit 618a27868d65aa152ac67cce8057a75c4d61def9)

src/common/LogClient.h
src/mon/Monitor.cc

index be70e4512837b8c1975631c76514f95ef35739d1..77a98514b0d299f64bfda3fb810ac5648c38c345 100644 (file)
@@ -18,6 +18,7 @@
 #include <atomic>
 #include "common/LogEntry.h"
 #include "common/Mutex.h"
+#include "include/health.h"
 
 class LogClient;
 class MLog;
@@ -91,6 +92,23 @@ public:
   void debug(std::stringstream &s) {
     do_log(CLOG_DEBUG, s);
   }
+  /**
+   * Convenience function mapping health status to
+   * the appropriate cluster log severity.
+   */
+  LogClientTemp health(health_status_t health) {
+    switch(health) {
+      case HEALTH_OK:
+        return info();
+      case HEALTH_WARN:
+        return warn();
+      case HEALTH_ERR:
+        return error();
+      default:
+        // Invalid health_status_t value
+        ceph_abort();
+    }
+  }
   LogClientTemp info() {
     return LogClientTemp(CLOG_INFO, *this);
   }
index 87c8892fe2a4d4f9fa21a823f58d5d5439a5062a..fc57fea4a1cb6c0d89cdd281082f1c5229366e0a 100644 (file)
@@ -2431,14 +2431,7 @@ void Monitor::do_health_to_clog(bool force)
        summary == health_status_cache.summary &&
        level == health_status_cache.overall)
       return;
-    if (level == HEALTH_OK)
-      clog->info() << "overall " << summary;
-    else if (level == HEALTH_WARN)
-      clog->warn() << "overall " << summary;
-    else if (level == HEALTH_ERR)
-      clog->error() << "overall " << summary;
-    else
-      ceph_abort();
+    clog->health(level) << "overall " << summary;
     health_status_cache.summary = summary;
     health_status_cache.overall = level;
   } else {
@@ -2560,20 +2553,14 @@ void Monitor::log_health(
       ostringstream ss;
       ss << "Health check failed: " << p.second.summary << " ("
          << p.first << ")";
-      if (p.second.severity == HEALTH_WARN)
-       clog->warn() << ss.str();
-      else
-       clog->error() << ss.str();
+      clog->health(p.second.severity) << ss.str();
     } else {
       if (p.second.summary != q->second.summary ||
          p.second.severity != q->second.severity) {
        // summary or severity changed (ignore detail changes at this level)
        ostringstream ss;
         ss << "Health check update: " << p.second.summary << " (" << p.first << ")";
-       if (p.second.severity == HEALTH_WARN)
-         clog->warn() << ss.str();
-       else
-         clog->error() << ss.str();
+        clog->health(p.second.severity) << ss.str();
       }
     }
   }
@@ -4785,10 +4772,7 @@ void Monitor::handle_timecheck_leader(MonOpRequestRef op)
 
   ostringstream ss;
   health_status_t status = timecheck_status(ss, skew_bound, latency);
-  if (status == HEALTH_ERR)
-    clog->error() << other << " " << ss.str();
-  else if (status == HEALTH_WARN)
-    clog->warn() << other << " " << ss.str();
+  clog->health(status) << other << " " << ss.str();
 
   dout(10) << __func__ << " from " << other << " ts " << m->timestamp
           << " delta " << delta << " skew_bound " << skew_bound