]> git.apps.os.sepia.ceph.com Git - ceph-ci.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)
committerJohn Spray <john.spray@redhat.com>
Fri, 1 Sep 2017 09:53:13 +0000 (05:53 -0400)
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>
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 eb720e183febe3aab0f2e25b0efc37ffdd39855c..8fd219fc61805a6c86b18e5294856304d8c1c2ae 100755 (executable)
@@ -2439,14 +2439,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 {
@@ -2568,20 +2561,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();
       }
     }
   }
@@ -4794,10 +4781,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