From fa89cfd2e4ccb8a80666ac1c8aeea91717fdb2e9 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Fri, 19 Apr 2013 19:26:51 +0100 Subject: [PATCH] mon: QuorumService: return health status on get_health() This allows us to return the appropriate overall health status on Monitor::get_health(). Fixes: 4574 Signed-off-by: Joao Eduardo Luis --- src/mon/ConfigKeyService.h | 7 +++++-- src/mon/DataHealthService.cc | 12 ++++++++++-- src/mon/DataHealthService.h | 2 +- src/mon/HealthMonitor.cc | 2 +- src/mon/HealthMonitor.h | 2 +- src/mon/HealthService.h | 2 +- src/mon/Monitor.cc | 8 ++++++-- src/mon/QuorumService.h | 2 +- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/mon/ConfigKeyService.h b/src/mon/ConfigKeyService.h index aee85bc085997..49e15acdfc652 100644 --- a/src/mon/ConfigKeyService.h +++ b/src/mon/ConfigKeyService.h @@ -58,8 +58,11 @@ public: * @{ */ virtual void init() { } - virtual void get_health(Formatter *f, - list > *detail) { } + virtual health_status_t get_health( + Formatter *f, + list > *detail) { + return HEALTH_OK; + } virtual bool service_dispatch(Message *m); virtual void start_epoch() { } diff --git a/src/mon/DataHealthService.cc b/src/mon/DataHealthService.cc index 2410cbc4d680b..d1a227fe0fd66 100644 --- a/src/mon/DataHealthService.cc +++ b/src/mon/DataHealthService.cc @@ -54,8 +54,9 @@ void DataHealthService::start_epoch() last_warned_percent = 0; } -void DataHealthService::get_health(Formatter *f, - list > *detail) +health_status_t DataHealthService::get_health( + Formatter *f, + list > *detail) { dout(10) << __func__ << dendl; assert(f != NULL); @@ -63,6 +64,8 @@ void DataHealthService::get_health(Formatter *f, f->open_object_section("data_health"); f->open_array_section("mons"); + health_status_t overall_status = HEALTH_OK; + for (map::iterator it = stats.begin(); it != stats.end(); ++it) { string mon_name = mon->monmap->get_name(it->first.addr); @@ -78,6 +81,9 @@ void DataHealthService::get_health(Formatter *f, health_detail = "low disk space!"; } + if (overall_status > health_status) + overall_status = health_status; + if (detail && health_status != HEALTH_OK) { stringstream ss; ss << "mon." << mon_name << " addr " << it->first.addr @@ -101,6 +107,8 @@ void DataHealthService::get_health(Formatter *f, f->close_section(); // mons f->close_section(); // data_health + + return overall_status; } int DataHealthService::update_stats() diff --git a/src/mon/DataHealthService.h b/src/mon/DataHealthService.h index de7ab0ac25877..c94327f312942 100644 --- a/src/mon/DataHealthService.h +++ b/src/mon/DataHealthService.h @@ -75,7 +75,7 @@ public: start_tick(); } - virtual void get_health(Formatter *f, + virtual health_status_t get_health(Formatter *f, list > *detail); virtual int get_type() { diff --git a/src/mon/HealthMonitor.cc b/src/mon/HealthMonitor.cc index cf3d962b2c4f2..b62ed7da31ec4 100644 --- a/src/mon/HealthMonitor.cc +++ b/src/mon/HealthMonitor.cc @@ -78,7 +78,7 @@ void HealthMonitor::service_shutdown() services.clear(); } -void HealthMonitor::get_health(Formatter *f, +health_status_t HealthMonitor::get_health(Formatter *f, list > *detail) { assert(f != NULL); f->open_object_section("health"); diff --git a/src/mon/HealthMonitor.h b/src/mon/HealthMonitor.h index 85581edde9b6a..e0255d20081aa 100644 --- a/src/mon/HealthMonitor.h +++ b/src/mon/HealthMonitor.h @@ -47,7 +47,7 @@ public: * @{ */ virtual void init(); - virtual void get_health(Formatter *f, + virtual health_status_t get_health(Formatter *f, list > *detail); virtual bool service_dispatch(Message *m); diff --git a/src/mon/HealthService.h b/src/mon/HealthService.h index b62ed5991eb45..1e041f5739ebd 100644 --- a/src/mon/HealthService.h +++ b/src/mon/HealthService.h @@ -44,7 +44,7 @@ public: HealthService *get() { return static_cast(RefCountedObject::get()); } - virtual void get_health(Formatter *f, + virtual health_status_t get_health(Formatter *f, list > *detail) = 0; virtual int get_type() = 0; virtual string get_name() const = 0; diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index e3d33ce9d6098..da6a7e662bd77 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2297,8 +2297,12 @@ void Monitor::get_health(string& status, bufferlist *detailbl, Formatter *f) if (f) f->close_section(); - if (f) - health_monitor->get_health(f, (detailbl ? &detail : NULL)); + if (f) { + health_status_t hmstatus = + health_monitor->get_health(f, (detailbl ? &detail : NULL)); + if (overall > hmstatus) + overall = hmstatus; + } stringstream fss; fss << overall; diff --git a/src/mon/QuorumService.h b/src/mon/QuorumService.h index dfa4f4165e952..7506421caf4e4 100644 --- a/src/mon/QuorumService.h +++ b/src/mon/QuorumService.h @@ -133,7 +133,7 @@ public: virtual void init() { } - virtual void get_health(Formatter *f, + virtual health_status_t get_health(Formatter *f, list > *detail) = 0; virtual int get_type() = 0; virtual string get_name() const = 0; -- 2.39.5