From: Igor Fedotov Date: Tue, 25 Dec 2018 17:25:21 +0000 (+0300) Subject: osd: expose object store alerts X-Git-Tag: v14.1.0~227^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f9e159735196267fc11defa539d2168e6b233ef;p=ceph.git osd: expose object store alerts Signed-off-by: Igor Fedotov --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 84dd0c7c41c3..b083d26dfa03 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -893,7 +893,8 @@ void OSDService::set_injectfull(s_names type, int64_t count) injectfull = count; } -void OSDService::set_statfs(const struct store_statfs_t &stbuf) +void OSDService::set_statfs(const struct store_statfs_t &stbuf, + osd_alert_list_t& alerts) { uint64_t bytes = stbuf.total; uint64_t avail = stbuf.available; @@ -925,6 +926,8 @@ void OSDService::set_statfs(const struct store_statfs_t &stbuf) std::lock_guard l(stat_lock); osd_stat.statfs = stbuf; + osd_stat.os_alerts.clear(); + osd_stat.os_alerts[whoami].swap(alerts); if (cct->_conf->fake_statfs_for_testing) { osd_stat.statfs.total = bytes; osd_stat.statfs.available = avail; @@ -2996,7 +2999,7 @@ int OSD::init() osd_alert_list_t alerts; int r = store->statfs(&stbuf, &alerts); ceph_assert(r == 0); - service.set_statfs(stbuf); + service.set_statfs(stbuf, alerts); } // i'm ready! @@ -5284,7 +5287,7 @@ void OSD::tick_without_osd_lock() osd_alert_list_t alerts; int r = store->statfs(&stbuf, &alerts); ceph_assert(r == 0); - service.set_statfs(stbuf); + service.set_statfs(stbuf, alerts); // osd_lock is not being held, which means the OSD state // might change when doing the monitor report diff --git a/src/osd/OSD.h b/src/osd/OSD.h index ee5302950f8b..3ff1fcfa21d3 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -903,7 +903,8 @@ public: osd_stat_t osd_stat; uint32_t seq = 0; - void set_statfs(const struct store_statfs_t &stbuf); + void set_statfs(const struct store_statfs_t &stbuf, + osd_alert_list_t& alerts); osd_stat_t set_osd_stat(vector& hb_peers, int num_pgs); float compute_adjusted_ratio(osd_stat_t new_stat, float *pratio, uint64_t adjust_used = 0); osd_stat_t get_osd_stat() { diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 8b64e5439555..2a531b2ab3d5 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -19,6 +19,7 @@ #include "osd_types.h" #include "include/ceph_features.h" +#include "include/stringify.h" extern "C" { #include "crush/hash.h" } @@ -165,6 +166,23 @@ ostream &operator<<(ostream &lhs, const pg_shard_t &rhs) return lhs << rhs.get_osd() << '(' << (unsigned)(rhs.shard) << ')'; } +void dump(Formatter* f, const osd_alerts_t& alerts) +{ + for (auto& a : alerts) { + string s0 = " osd: "; + s0 += stringify(a.first); + string s; + for (auto& aa : a.second) { + s = s0; + s += " "; + s += aa.first; + s += ":"; + s += aa.second; + f->dump_string("alert", s); + } + } +} + // -- osd_reqid_t -- void osd_reqid_t::dump(Formatter *f) const { @@ -369,11 +387,14 @@ void osd_stat_t::dump(Formatter *f) const f->open_object_section("perf_stat"); os_perf_stat.dump(f); f->close_section(); + f->open_array_section("alerts"); + ::dump(f, os_alerts); + f->close_section(); } void osd_stat_t::encode(bufferlist &bl, uint64_t features) const { - ENCODE_START(9, 2, bl); + ENCODE_START(10, 2, bl); //////// for compatibility //////// int64_t kb = statfs.kb(); @@ -403,7 +424,7 @@ void osd_stat_t::encode(bufferlist &bl, uint64_t features) const encode(kb_used_meta, bl); encode(statfs, bl); /////////////////////////////////// - + encode(os_alerts, bl); ENCODE_FINISH(bl); } @@ -411,7 +432,7 @@ void osd_stat_t::decode(bufferlist::const_iterator &bl) { int64_t kb, kb_used,kb_avail; int64_t kb_used_data, kb_used_omap, kb_used_meta; - DECODE_START_LEGACY_COMPAT_LEN(9, 2, 2, bl); + DECODE_START_LEGACY_COMPAT_LEN(10, 2, 2, bl); decode(kb, bl); decode(kb_used, bl); decode(kb_avail, bl); @@ -461,6 +482,11 @@ void osd_stat_t::decode(bufferlist::const_iterator &bl) statfs.omap_allocated = kb_used_omap << 10; statfs.internal_metadata = kb_used_meta << 10; } + if (struct_v >= 10) { + decode(os_alerts, bl); + } else { + os_alerts.clear(); + } DECODE_FINISH(bl); } @@ -475,6 +501,10 @@ void osd_stat_t::generate_test_instances(std::list& o) o.back()->hb_peers.push_back(7); o.back()->snap_trim_queue_len = 8; o.back()->num_snap_trimming = 99; + o.back()->os_alerts[0].emplace( + "some alert", "some alert details"); + o.back()->os_alerts[1].emplace( + "some alert2", "some alert2 details"); } // -- pg_t -- diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index faae78bed8d8..0f6e22521626 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -113,6 +113,9 @@ string ceph_osd_op_flag_string(unsigned flags); string ceph_osd_alloc_hint_flag_string(unsigned flags); typedef map osd_alert_list_t; +/// map osd id -> alert_list_t +typedef map osd_alerts_t; +void dump(Formatter* f, const osd_alerts_t& alerts); /** * osd request identifier @@ -2270,6 +2273,7 @@ struct osd_stat_t { pow2_hist_t op_queue_age_hist; objectstore_perf_stat_t os_perf_stat; + osd_alerts_t os_alerts; epoch_t up_from = 0; uint64_t seq = 0; @@ -2278,13 +2282,19 @@ struct osd_stat_t { osd_stat_t() : snap_trim_queue_len(0), num_snap_trimming(0) {} - void add(const osd_stat_t& o) { + void add(const osd_stat_t& o) { statfs.add(o.statfs); snap_trim_queue_len += o.snap_trim_queue_len; num_snap_trimming += o.num_snap_trimming; op_queue_age_hist.add(o.op_queue_age_hist); os_perf_stat.add(o.os_perf_stat); num_pgs += o.num_pgs; + for (const auto& a : o.os_alerts) { + auto& target = os_alerts[a.first]; + for (auto& i : a.second) { + target.emplace(i.first, i.second); + } + } } void sub(const osd_stat_t& o) { statfs.sub(o.statfs); @@ -2293,8 +2303,16 @@ struct osd_stat_t { op_queue_age_hist.sub(o.op_queue_age_hist); os_perf_stat.sub(o.os_perf_stat); num_pgs -= o.num_pgs; + for (const auto& a : o.os_alerts) { + auto& target = os_alerts[a.first]; + for (auto& i : a.second) { + target.erase(i.first); + } + if (target.empty()) { + os_alerts.erase(a.first); + } + } } - void dump(Formatter *f) const; void encode(bufferlist &bl, uint64_t features) const; void decode(bufferlist::const_iterator &bl);