]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: expose object store alerts
authorIgor Fedotov <ifedotov@suse.com>
Tue, 25 Dec 2018 17:25:21 +0000 (20:25 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Sat, 26 Jan 2019 14:21:47 +0000 (17:21 +0300)
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/osd/OSD.cc
src/osd/OSD.h
src/osd/osd_types.cc
src/osd/osd_types.h

index 84dd0c7c41c3ba807c60b3979bac01d620ac65e8..b083d26dfa0387ff9c4885b4d9f2cded94420799 100644 (file)
@@ -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
index ee5302950f8b040a9699837c42efea777c3a21cc..3ff1fcfa21d376362707c1117dbe01d6bbff1488 100644 (file)
@@ -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<int>& 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() {
index 8b64e5439555aa02915c1d6d6700b3cd150c988c..2a531b2ab3d5b13e8ba97abf951b2c9cfcfbf4a6 100644 (file)
@@ -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<osd_stat_t*>& 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 --
index faae78bed8d8e2260b7c5ef48063317cb6d1c31e..0f6e22521626a698a979391b9abe2b3ed0607356 100644 (file)
@@ -113,6 +113,9 @@ string ceph_osd_op_flag_string(unsigned flags);
 string ceph_osd_alloc_hint_flag_string(unsigned flags);
 
 typedef map<string,string> osd_alert_list_t;
+/// map osd id -> alert_list_t
+typedef map<int, osd_alert_list_t> 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);