From 618a27868d65aa152ac67cce8057a75c4d61def9 Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 1 Sep 2017 05:33:16 -0400 Subject: [PATCH] mon: add helper for emitting logs by health status We were starting to repeat our little "if(status==HEALTH_ERR" blocks in too many places. Signed-off-by: John Spray --- src/common/LogClient.h | 18 ++++++++++++++++++ src/mon/Monitor.cc | 24 ++++-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/common/LogClient.h b/src/common/LogClient.h index be70e451283..77a98514b0d 100644 --- a/src/common/LogClient.h +++ b/src/common/LogClient.h @@ -18,6 +18,7 @@ #include #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); } diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index eb720e183fe..8fd219fc618 100755 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -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 -- 2.39.5