From: Sage Weil Date: Wed, 31 May 2017 16:37:22 +0000 (-0400) Subject: common/LogEntry: include EntityName in log entries X-Git-Tag: ses5-milestone6~9^2~9^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6c520ffb0f2e4a9d17901cdf86e2e0290a149991;p=ceph.git common/LogEntry: include EntityName in log entries 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 --- diff --git a/src/common/LogClient.cc b/src/common/LogClient.cc index 3dc77588e868c..07c53e80d9ff7 100644 --- a/src/common/LogClient.cc +++ b/src/common/LogClient.cc @@ -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); diff --git a/src/common/LogClient.h b/src/common/LogClient.h index 59e96ac3920f9..337d2599803d0 100644 --- a/src/common/LogClient.h +++ b/src/common/LogClient.h @@ -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: diff --git a/src/common/LogEntry.cc b/src/common/LogEntry.cc index 218894a3c6463..d97b0480d7072 100644 --- a/src/common/LogEntry.cc +++ b/src/common/LogEntry.cc @@ -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); diff --git a/src/common/LogEntry.h b/src/common/LogEntry.h index afe8533acd432..a4f8f9d1ed3bd 100644 --- a/src/common/LogEntry.h +++ b/src/common/LogEntry.h @@ -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; } diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index c8e746377ab04..bf30f3b4bd505 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -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;