]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/LogEntry: include EntityName in log entries
authorSage Weil <sage@redhat.com>
Wed, 31 May 2017 16:37:22 +0000 (12:37 -0400)
committerSage Weil <sage@redhat.com>
Wed, 31 May 2017 18:39:54 +0000 (14:39 -0400)
We want the auth name (mon.hostname), not the entity_name_t (mon.0) to
appear in the log messages.  In particular this is helpful for the mgr,
which will now appear as mgr.hostname instead of client.1234.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/LogClient.cc
src/common/LogClient.h
src/common/LogEntry.cc
src/common/LogEntry.h
src/mon/LogMonitor.cc

index 3dc77588e868ce1f43dcb8720f5b4ca6615e7956..07c53e80d9ff7201c4af5b52381fc7cadef1e76d 100644 (file)
@@ -223,6 +223,7 @@ void LogChannel::do_log(clog_type prio, const std::string& s)
   e.stamp = ceph_clock_now();
   // seq and who should be set for syslog/graylog/log_to_mon
   e.who = parent->get_myinst();
+  e.name = parent->get_myname();
   e.seq = parent->get_next_seq();
   e.prio = prio;
   e.msg = s;
@@ -342,6 +343,11 @@ const entity_inst_t& LogClient::get_myinst()
   return messenger->get_myinst();
 }
 
+const EntityName& LogClient::get_myname()
+{
+  return cct->_conf->name;
+}
+
 bool LogClient::handle_log_ack(MLogAck *m)
 {
   Mutex::Locker l(log_lock);
index 59e96ac3920f9fc32ff8b6d3d7279e5de2d1abf6..337d2599803d0101378ba2499963eff0bce8f4ea 100644 (file)
@@ -231,6 +231,7 @@ public:
 
   uint64_t get_next_seq();
   const entity_inst_t& get_myinst();
+  const EntityName& get_myname();
   version_t queue(LogEntry &entry);
 
 private:
index 218894a3c64635d37bda730bf27a8c619248c4f3..d97b0480d70720969670451cecd051ad676bdd2f 100644 (file)
@@ -181,7 +181,7 @@ void LogEntry::log_to_syslog(string level, string facility)
 
 void LogEntry::encode(bufferlist& bl, uint64_t features) const
 {
-  ENCODE_START(3, 2, bl);
+  ENCODE_START(4, 2, bl);
   __u16 t = prio;
   ::encode(who, bl, features);
   ::encode(stamp, bl);
@@ -189,12 +189,13 @@ void LogEntry::encode(bufferlist& bl, uint64_t features) const
   ::encode(t, bl);
   ::encode(msg, bl);
   ::encode(channel, bl);
+  ::encode(name, bl);
   ENCODE_FINISH(bl);
 }
 
 void LogEntry::decode(bufferlist::iterator& bl)
 {
-  DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl);
+  DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl);
   __u16 t;
   ::decode(who, bl);
   ::decode(stamp, bl);
@@ -210,12 +211,16 @@ void LogEntry::decode(bufferlist::iterator& bl)
     // clue of what a 'channel' is.
     channel = CLOG_CHANNEL_CLUSTER;
   }
+  if (struct_v >= 4) {
+    ::decode(name, bl);
+  }
   DECODE_FINISH(bl);
 }
 
 void LogEntry::dump(Formatter *f) const
 {
   f->dump_stream("who") << who;
+  f->dump_stream("name") << name;
   f->dump_stream("stamp") << stamp;
   f->dump_unsigned("seq", seq);
   f->dump_string("channel", channel);
index afe8533acd432af222ac4fa01ee88292a9ebfee5..a4f8f9d1ed3bdaf998a04bc4d32ef9d58f07dd93 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "include/utime.h"
 #include "msg/msg_types.h" // for entity_inst_t
+#include "common/entity_name.h"
 
 namespace ceph {
   class Formatter;
@@ -73,6 +74,7 @@ static inline bool operator==(const LogEntryKey& l, const LogEntryKey& r) {
 
 struct LogEntry {
   entity_inst_t who;
+  EntityName name;
   utime_t stamp;
   uint64_t seq;
   clog_type prio;
@@ -139,7 +141,8 @@ inline ostream& operator<<(ostream& out, clog_type t)
 
 inline ostream& operator<<(ostream& out, const LogEntry& e)
 {
-  return out << e.stamp << " " << e.who << " " << e.seq << " : "
+  return out << e.stamp << " " << e.name << " " << e.who
+            << " " << e.seq << " : "
              << e.channel << " " << e.prio << " " << e.msg;
 }
 
index c8e746377ab048a5d95ec2ae5651e67316d3f578..bf30f3b4bd505b3062f0353030fd8c0a49d9f67c 100644 (file)
@@ -63,6 +63,7 @@ void LogMonitor::create_initial()
   dout(10) << "create_initial -- creating initial map" << dendl;
   LogEntry e;
   memset(&e.who, 0, sizeof(e.who));
+  e.name = g_conf->name;
   e.stamp = ceph_clock_now();
   e.prio = CLOG_INFO;
   std::stringstream ss;
@@ -414,6 +415,7 @@ bool LogMonitor::prepare_command(MonOpRequestRef op)
     cmd_getval(g_ceph_context, cmdmap, "logtext", logtext);
     LogEntry le;
     le.who = m->get_orig_source_inst();
+    le.name = session->entity_name;
     le.stamp = m->get_recv_stamp();
     le.seq = 0;
     le.prio = CLOG_INFO;