]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
log: set hostname and fsid for graylog
authorKefu Chai <kchai@redhat.com>
Mon, 5 Jul 2021 01:38:57 +0000 (09:38 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 5 Jul 2021 04:17:49 +0000 (12:17 +0800)
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 <ed6876e1-9265-11ea-bc94-1ad2db8b5489> (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 <kchai@redhat.com>
src/common/ceph_context.cc
src/log/Log.cc
src/log/Log.h

index f02728e38fe4ce7645e3bf5a41b4cfb8b73fdaaa..df23ae7a60f1842ef03bbcba828bfeb3c0b59c61 100644 (file)
@@ -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<uuid_d>("fsid"));
       } else if (! (conf->log_to_graylog && conf->err_to_graylog)) {
        log->stop_graylog();
       }
index de99a3dd4ee813149bf1759f10ef9fefc70774dc..81fb3ff5cc4033aadb803e0700c56e1cb66b1cc5 100644 (file)
@@ -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<Graylog>(m_subs, "dlog");
+    m_graylog->set_hostname(host);
+    m_graylog->set_fsid(fsid);
+  }
 }
 
 
index ad3a44b4fee3122ba1cfe9b06b4db91e466b8fc8..0d83ff037f75ccbdcfe6074eab89cc6b567bcbae 100644 (file)
@@ -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);