From: Kefu Chai Date: Mon, 5 Jul 2021 01:38:57 +0000 (+0800) Subject: log: set hostname and fsid for graylog X-Git-Tag: v17.1.0~1463^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0bedd067bee2c7abffb527e1aa24a1821076f5b8;p=ceph-ci.git log: set hostname and fsid for graylog in which, hostname is mandatory per https://docs.graylog.org/en/4.0/pages/gelf.html#gelf-payload-specification, so without this change, if user enables `log_to_graylog` and/or `err_to_graylog`, failures like java.lang.IllegalArgumentException: GELF message (received from <10.10.10.12:36509>) has empty mandatory "host" field. is expected. after this change, this field is set. Fixes: https://tracker.ceph.com/issues/45457 Signed-off-by: Kefu Chai --- diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index f02728e38fe..df23ae7a60f 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -31,6 +31,7 @@ #include "common/debug.h" #include "common/config.h" #include "common/ceph_crypto.h" +#include "common/hostname.h" #include "common/HeartbeatMap.h" #include "common/errno.h" #include "common/Graylog.h" @@ -346,7 +347,7 @@ public: log->set_graylog_level(l, l); if (conf->log_to_graylog || conf->err_to_graylog) { - log->start_graylog(); + log->start_graylog(conf->host, conf.get_val("fsid")); } else if (! (conf->log_to_graylog && conf->err_to_graylog)) { log->stop_graylog(); } diff --git a/src/log/Log.cc b/src/log/Log.cc index de99a3dd4ee..81fb3ff5cc4 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -12,6 +12,7 @@ #include "include/ceph_assert.h" #include "include/compat.h" #include "include/on_exit.h" +#include "include/uuid.h" #include "Entry.h" #include "LogClock.h" @@ -165,11 +166,15 @@ void Log::set_graylog_level(int log, int crash) m_graylog_crash = crash; } -void Log::start_graylog() +void Log::start_graylog(const std::string& host, + const uuid_d& fsid) { std::scoped_lock lock(m_flush_mutex); - if (! m_graylog.get()) + if (! m_graylog.get()) { m_graylog = std::make_shared(m_subs, "dlog"); + m_graylog->set_hostname(host); + m_graylog->set_fsid(fsid); + } } diff --git a/src/log/Log.h b/src/log/Log.h index ad3a44b4fee..0d83ff037f7 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -18,6 +18,8 @@ #include "log/Entry.h" +struct uuid_d; + namespace ceph { namespace logging { @@ -107,7 +109,8 @@ public: void set_stderr_level(int log, int crash); void set_graylog_level(int log, int crash); - void start_graylog(); + void start_graylog(const std::string& host, + const uuid_d& fsid); void stop_graylog(); void set_journald_level(int log, int crash);