]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/LogEntry: addr -> addrs
authorSage Weil <sage@redhat.com>
Fri, 25 May 2018 20:11:32 +0000 (15:11 -0500)
committerSage Weil <sage@redhat.com>
Sun, 27 May 2018 22:26:26 +0000 (17:26 -0500)
We want to switch to an addrvec.  This requires multiple parts:

 - switch the Key type to use just the rank
 - separate entity_name_t rank
 - compat encoding
 - graylog field naming has changed (includes name)
 - syslog output formatting has changed (includes name)
 - LogEntry operator<< modified a bit

Signed-off-by: Sage Weil <sage@redhat.com>
PendingReleaseNotes
src/common/Graylog.cc
src/common/LogClient.cc
src/common/LogClient.h
src/common/LogEntry.cc
src/common/LogEntry.h
src/librados/RadosClient.cc
src/mon/LogMonitor.cc
src/pybind/mgr/dashboard/frontend/package.json
src/test/mon/test_mon_workloadgen.cc

index e70891fd30192b18e802a178166e9349ab41cd28..4ffdf12f8e16473c091951206abe6f3573a24d45 100644 (file)
@@ -5,3 +5,12 @@
   an Telegraf Agent over TCP, UDP or a UNIX Socket. Telegraf can then
   send the statistics to databases like InfluxDB, ElasticSearch, Graphite
   and many more.
+
+* The graylog fields naming the originator of a log event have
+  changed: the string-form name is now included (e.g., ``"name":
+  "mgr.foo"``), and the rank-form name is now in a nested section
+  (e.g., ``"rank": {"type": "mgr", "num": 43243}``).
+
+* If the cluster log is directed at syslog, the entries are now
+  prefixed by both the string-form name and the rank-form name (e.g.,
+  ``mgr.x mgr.12345 ...`` instead of just ``mgr.12345 ...``).
index 52ef259df7539d9e5fbad101dffdb78cb7c72615..3ed10434a2d2baea52ce11a97efe5061e5f730dc 100644 (file)
@@ -121,9 +121,14 @@ void Graylog::log_log_entry(LogEntry const * const e)
     m_formatter->dump_float("timestamp", e->stamp.sec() + (e->stamp.usec() / 1000000.0));
     m_formatter->dump_string("_app", "ceph");
 
-    m_formatter_section->open_object_section("");
-    e->who.addr.dump(m_formatter_section.get());
-    e->who.name.dump(m_formatter_section.get());
+    m_formatter->dump_string("name", e->name.to_str());
+
+    m_formatter_section->open_object_section("rank");
+    e->rank.dump(m_formatter_section.get());
+    m_formatter_section->close_section();
+
+    m_formatter_section->open_object_section("addrs");
+    e->addrs.dump(m_formatter_section.get());
     m_formatter_section->close_section();
 
     m_ostream_section.clear();
index 56975d8771ebbfd9f8fe7518afb66153eccce510..91edf920a122b7d1aebca4130d45b01f1b9c71ca 100644 (file)
@@ -220,8 +220,9 @@ void LogChannel::do_log(clog_type prio, const std::string& s)
   LogEntry e;
   e.stamp = ceph_clock_now();
   // seq and who should be set for syslog/graylog/log_to_mon
-  e.who = parent->get_myinst();
+  e.addrs = parent->get_myaddrs();
   e.name = parent->get_myname();
+  e.rank = parent->get_myrank();
   e.prio = prio;
   e.msg = s;
   e.channel = get_log_channel();
@@ -339,9 +340,14 @@ uint64_t LogClient::get_next_seq()
   return ++last_log;
 }
 
-const entity_inst_t& LogClient::get_myinst()
+entity_addrvec_t LogClient::get_myaddrs()
 {
-  return messenger->get_myinst();
+  return entity_addrvec_t(messenger->get_myaddr());
+}
+
+entity_name_t LogClient::get_myrank()
+{
+  return messenger->get_myname();
 }
 
 const EntityName& LogClient::get_myname()
index 77a98514b0d299f64bfda3fb810ac5648c38c345..2241f9cb062cd65cee9e94a62281dda8351b7a79 100644 (file)
@@ -249,8 +249,9 @@ public:
   }
 
   uint64_t get_next_seq();
-  const entity_inst_t& get_myinst();
+  entity_addrvec_t get_myaddrs();
   const EntityName& get_myname();
+  entity_name_t get_myrank();
   version_t queue(LogEntry &entry);
 
 private:
index 7fbb5d33fe9495ce9e8f47e7e4a8e703b802ba8d..e0103478672af0f06c6d0bacb57d325162d08565 100644 (file)
@@ -13,7 +13,7 @@
 
 void LogEntryKey::dump(Formatter *f) const
 {
-  f->dump_stream("who") << who;
+  f->dump_stream("rank") << rank;
   f->dump_stream("stamp") << stamp;
   f->dump_unsigned("seq", seq);
 }
@@ -21,7 +21,7 @@ void LogEntryKey::dump(Formatter *f) const
 void LogEntryKey::generate_test_instances(list<LogEntryKey*>& o)
 {
   o.push_back(new LogEntryKey);
-  o.push_back(new LogEntryKey(entity_inst_t(), utime_t(1,2), 34));
+  o.push_back(new LogEntryKey(entity_name_t::CLIENT(1234), utime_t(1,2), 34));
 }
 
 clog_type LogEntry::str_to_level(std::string const &str)
@@ -182,8 +182,9 @@ void LogEntry::log_to_syslog(string level, string facility)
   int l = clog_type_to_syslog_level(prio);
   if (l <= min) {
     int f = string_to_syslog_facility(facility);
-    syslog(l | f, "%s %llu : %s",
-          stringify(who).c_str(),
+    syslog(l | f, "%s %s %llu : %s",
+          name.to_cstr(),
+          stringify(rank).c_str(),
           (long long unsigned)seq,
           msg.c_str());
   }
@@ -191,46 +192,81 @@ void LogEntry::log_to_syslog(string level, string facility)
 
 void LogEntry::encode(bufferlist& bl, uint64_t features) const
 {
-  ENCODE_START(4, 2, bl);
+  if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) {
+    ENCODE_START(4, 2, bl);
+    __u16 t = prio;
+    entity_inst_t who;
+    who.name = rank;
+    who.addr = addrs.legacy_addr();
+    encode(who, bl, features);
+    encode(stamp, bl);
+    encode(seq, bl);
+    encode(t, bl);
+    encode(msg, bl);
+    encode(channel, bl);
+    encode(name, bl);
+    ENCODE_FINISH(bl);
+    return;
+  }
+  ENCODE_START(5, 5, bl);
   __u16 t = prio;
-  encode(who, bl, features);
+  encode(name, bl);
+  encode(rank, bl);
+  encode(addrs, bl, features);
   encode(stamp, bl);
   encode(seq, bl);
   encode(t, bl);
   encode(msg, bl);
   encode(channel, bl);
-  encode(name, bl);
   ENCODE_FINISH(bl);
 }
 
 void LogEntry::decode(bufferlist::const_iterator& bl)
 {
-  DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl);
-  __u16 t;
-  decode(who, bl);
-  decode(stamp, bl);
-  decode(seq, bl);
-  decode(t, bl);
-  prio = (clog_type)t;
-  decode(msg, bl);
-  if (struct_v >= 3) {
-    decode(channel, bl);
+  DECODE_START_LEGACY_COMPAT_LEN(5, 2, 2, bl);
+  if (struct_v < 5) {
+    __u16 t;
+    entity_inst_t who;
+    decode(who, bl);
+    rank = who.name;
+    addrs.v.clear();
+    addrs.v.push_back(who.addr);
+    decode(stamp, bl);
+    decode(seq, bl);
+    decode(t, bl);
+    prio = (clog_type)t;
+    decode(msg, bl);
+    if (struct_v >= 3) {
+      decode(channel, bl);
+    } else {
+      // prior to having logging channels we only had a cluster log.
+      // Ensure we keep that appearance when the other party has no
+      // clue of what a 'channel' is.
+      channel = CLOG_CHANNEL_CLUSTER;
+    }
+    if (struct_v >= 4) {
+      decode(name, bl);
+    }
   } else {
-    // prior to having logging channels we only had a cluster log.
-    // Ensure we keep that appearance when the other party has no
-    // clue of what a 'channel' is.
-    channel = CLOG_CHANNEL_CLUSTER;
-  }
-  if (struct_v >= 4) {
+    __u16 t;
     decode(name, bl);
+    decode(rank, bl);
+    decode(addrs, bl);
+    decode(stamp, bl);
+    decode(seq, bl);
+    decode(t, bl);
+    prio = (clog_type)t;
+    decode(msg, bl);
+    decode(channel, bl);
   }
   DECODE_FINISH(bl);
 }
 
 void LogEntry::dump(Formatter *f) const
 {
-  f->dump_stream("who") << who;
   f->dump_stream("name") << name;
+  f->dump_stream("rank") << rank;
+  f->dump_object("addrs", addrs);
   f->dump_stream("stamp") << stamp;
   f->dump_unsigned("seq", seq);
   f->dump_string("channel", channel);
index ead28cfd48c8da88ea1f81d4fb4a4b103c19a55f..3eb8446f07f6dfff75c6fa62e1cad3a5986387ca 100644 (file)
@@ -16,7 +16,7 @@
 #define CEPH_LOGENTRY_H
 
 #include "include/utime.h"
-#include "msg/msg_types.h" // for entity_inst_t
+#include "msg/msg_types.h"
 #include "common/entity_name.h"
 
 namespace ceph {
@@ -58,18 +58,18 @@ private:
   uint64_t _hash = 0;
 
   void _calc_hash() {
-    hash<entity_inst_t> h;
-    _hash = seq + h(who);
+    hash<entity_name_t> h;
+    _hash = seq + h(rank);
   }
 
-  entity_inst_t who;
+  entity_name_t rank;
   utime_t stamp;
   uint64_t seq = 0;
 
 public:
   LogEntryKey() {}
-  LogEntryKey(const entity_inst_t& w, utime_t t, uint64_t s)
-    : who(w), stamp(t), seq(s) {
+  LogEntryKey(const entity_name_t& w, utime_t t, uint64_t s)
+    : rank(w), stamp(t), seq(s) {
     _calc_hash();
   }
 
@@ -81,7 +81,7 @@ public:
   static void generate_test_instances(list<LogEntryKey*>& o);
 
   friend bool operator==(const LogEntryKey& l, const LogEntryKey& r) {
-    return l.who == r.who && l.stamp == r.stamp && l.seq == r.seq;
+    return l.rank == r.rank && l.stamp == r.stamp && l.seq == r.seq;
   }
 };
 
@@ -94,8 +94,9 @@ namespace std {
 } // namespace std
 
 struct LogEntry {
-  entity_inst_t who;
   EntityName name;
+  entity_name_t rank;
+  entity_addrvec_t addrs;
   utime_t stamp;
   uint64_t seq;
   clog_type prio;
@@ -104,7 +105,7 @@ struct LogEntry {
 
   LogEntry() : seq(0), prio(CLOG_DEBUG) {}
 
-  LogEntryKey key() const { return LogEntryKey(who, stamp, seq); }
+  LogEntryKey key() const { return LogEntryKey(rank, stamp, seq); }
 
   void log_to_syslog(string level, string facility);
 
@@ -170,8 +171,8 @@ inline ostream& operator<<(ostream& out, const clog_type t)
 
 inline ostream& operator<<(ostream& out, const LogEntry& e)
 {
-  return out << e.stamp << " " << e.name << " " << e.who
-            << " " << e.seq << " : "
+  return out << e.stamp << " " << e.name << " (" << e.rank
+            << " " << e.addrs << ") " << e.seq << " : "
              << e.channel << " " << e.prio << " " << e.msg;
 }
 
index b94d3ef877203a29030d5c532f9cabcd5ec8780b..785b567fba326d817f65585422a597eeaef16cfd 100644 (file)
@@ -1042,7 +1042,7 @@ void librados::RadosClient::handle_log(MLog *m)
         ostringstream ss;
         ss << e.stamp << " " << e.name << " " << e.prio << " " << e.msg;
         string line = ss.str();
-        string who = stringify(e.who);
+        string who = stringify(e.rank) + " " + stringify(e.addrs);
        string name = stringify(e.name);
         string level = stringify(e.prio);
         struct timespec stamp;
index f06754be34ca56c09b506c16f040404084ae2898..73856f85807d430939bd66ab83bfc71a424ebdf8 100644 (file)
@@ -63,6 +63,8 @@ void LogMonitor::create_initial()
   dout(10) << "create_initial -- creating initial map" << dendl;
   LogEntry e;
   e.name = g_conf->name;
+  e.rank = entity_name_t::MON(mon->rank);
+  e.addrs.v.push_back(mon->messenger->get_myaddr());
   e.stamp = ceph_clock_now();
   e.prio = CLOG_INFO;
   std::stringstream ss;
@@ -528,7 +530,8 @@ bool LogMonitor::prepare_command(MonOpRequestRef op)
     vector<string> logtext;
     cmd_getval(g_ceph_context, cmdmap, "logtext", logtext);
     LogEntry le;
-    le.who = m->get_orig_source_inst();
+    le.rank = m->get_orig_source();
+    le.addrs.v.push_back(m->get_orig_source_addr());
     le.name = session->entity_name;
     le.stamp = m->get_recv_stamp();
     le.seq = 0;
index edf141d9165d7ba53e6b02772b14eecf2a8a3b14..010e38207e9cf3fb75e8512df7be2d6fe825ba61 100644 (file)
   "jest": {
     "preset": "jest-preset-angular",
     "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
-    "transformIgnorePatterns": ["node_modules/(?!@ngrx|ngx-bootstrap|@progress)"],
+    "transformIgnorePatterns": [
+      "node_modules/(?!@ngrx|ngx-bootstrap|@progress)"
+    ],
     "transform": {
       "^.+\\.(ts|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js",
       "^.+\\.js$": "babel-jest"
     },
-    "setupFiles": ["jest-canvas-mock"],
-    "coverageReporters" : [
+    "setupFiles": [
+      "jest-canvas-mock"
+    ],
+    "coverageReporters": [
       "text",
       "cobertura"
     ]
index 0fa1502297899adc8cfa65c1004766cb3c7cbc45..ed7012339f7d2af43a4177a8084ce672a7a8f242 100644 (file)
@@ -703,7 +703,8 @@ class OSDStub : public TestStub
     int seq = 0;
     for (; num_entries > 0; --num_entries) {
       LogEntry e;
-      e.who = messenger->get_myinst();
+      e.rank = messenger->get_myname();
+      e.addrs.v.push_back(messenger->get_myaddr());
       e.stamp = now;
       e.seq = seq++;
       e.prio = CLOG_DEBUG;