From f5cad7ac4e76b0a2a23042f4cd55af38b08237fa Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 5 Feb 2016 15:56:55 +0800 Subject: [PATCH] log: remove "boost/asio.hpp" from Log.h graylog uses boost/asio.hpp which introduces the link-time dependency on libboost_system to the compilation units which includes Log.h and LogClient.h. so it appears that perfglue/heap_profiler.cc is referencing libboost_system.so, and fails the cmake build of all tests which links against tcmalloc. in this change, we: * remove unnecessary #includes from Graylog.h * forward declare Graylog class, so that "Graylog.h" is not included in any header files to avoid the link-time dependency pollution Signed-off-by: Kefu Chai --- src/common/Graylog.cc | 9 ++++----- src/common/Graylog.h | 15 ++++++++++----- src/common/LogClient.cc | 4 ++++ src/common/LogClient.h | 11 ++++++++--- src/common/ceph_context.cc | 1 + src/log/Log.cc | 1 + src/log/Log.h | 9 ++++----- src/mon/LogMonitor.cc | 27 +++++++++++++++++++++++++++ src/mon/LogMonitor.h | 33 ++++++++------------------------- 9 files changed, 67 insertions(+), 43 deletions(-) diff --git a/src/common/Graylog.cc b/src/common/Graylog.cc index 8dde3d0ad0f..dd4f3b29c0e 100644 --- a/src/common/Graylog.cc +++ b/src/common/Graylog.cc @@ -5,16 +5,15 @@ #include #include -#include #include -#include -#include -#include #include #include "common/Formatter.h" +#include "common/LogEntry.h" +#include "log/Entry.h" +#include "log/SubsystemMap.h" #include "include/uuid.h" namespace ceph { @@ -71,7 +70,7 @@ void Graylog::set_hostname(const std::string& host) m_hostname = host; } -void Graylog::set_fsid(uuid_d fsid) +void Graylog::set_fsid(const uuid_d& fsid) { std::vector buf(40); fsid.print(&buf[0]); diff --git a/src/common/Graylog.h b/src/common/Graylog.h index 7caa6564af5..bac437f1d1c 100644 --- a/src/common/Graylog.h +++ b/src/common/Graylog.h @@ -7,19 +7,24 @@ #include -#include #include #include #include -#include "log/Entry.h" -#include "log/SubsystemMap.h" -#include "common/LogEntry.h" #include "include/memory.h" +struct uuid_d; +class LogEntry; + namespace ceph { + +class Formatter; + namespace log { +struct Entry; +class SubsystemMap; + // Graylog logging backend: Convert log datastructures (LogEntry, Entry) to // GELF (http://www.graylog2.org/resources/gelf/specification) and send it // to a GELF UDP receiver @@ -45,7 +50,7 @@ class Graylog virtual ~Graylog(); void set_hostname(const std::string& host); - void set_fsid(uuid_d fsid); + void set_fsid(const uuid_d& fsid); void set_destination(const std::string& host, int port); diff --git a/src/common/LogClient.cc b/src/common/LogClient.cc index 5300c4188db..237ce4bcf9d 100644 --- a/src/common/LogClient.cc +++ b/src/common/LogClient.cc @@ -16,6 +16,7 @@ #include "include/types.h" #include "include/str_map.h" +#include "include/uuid.h" #include "msg/Messenger.h" #include "msg/Message.h" @@ -34,6 +35,9 @@ #include #endif // DARWIN +#include "common/Graylog.h" +// wipe the assert() introduced by boost headers included by Graylog.h +#include "include/assert.h" #include "common/LogClient.h" #include "common/config.h" diff --git a/src/common/LogClient.h b/src/common/LogClient.h index 84682ea88eb..3bb4e47301b 100644 --- a/src/common/LogClient.h +++ b/src/common/LogClient.h @@ -17,8 +17,6 @@ #include "common/LogEntry.h" #include "common/Mutex.h" -#include "include/uuid.h" -#include "common/Graylog.h" #include #include @@ -29,10 +27,17 @@ class MLogAck; class Messenger; class MonMap; class Message; +struct uuid_d; struct Connection; class LogChannel; +namespace ceph { +namespace log { + class Graylog; +} +} + int parse_log_client_options(CephContext *cct, map &log_to_monitors, map &log_to_syslog, @@ -177,7 +182,7 @@ private: std::string syslog_facility; bool log_to_syslog; bool log_to_monitors; - ceph::log::Graylog::Ref graylog; + shared_ptr graylog; friend class LogClientTemp; diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 5470807e952..259c2339a6a 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -27,6 +27,7 @@ #include "common/errno.h" #include "common/lockdep.h" #include "common/Formatter.h" +#include "common/Graylog.h" #include "log/Log.h" #include "auth/Crypto.h" #include "include/str_list.h" diff --git a/src/log/Log.cc b/src/log/Log.cc index 46dbb71466f..1485b25df71 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -17,6 +17,7 @@ #include "common/errno.h" #include "common/safe_io.h" #include "common/Clock.h" +#include "common/Graylog.h" #include "common/valgrind.h" #include "common/Formatter.h" #include "include/assert.h" diff --git a/src/log/Log.h b/src/log/Log.h index ba2dc41d057..bfe5e40a87c 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -6,18 +6,17 @@ #include "common/Thread.h" -#include #include -#include #include "Entry.h" #include "EntryQueue.h" #include "SubsystemMap.h" -#include "common/Graylog.h" namespace ceph { namespace log { +class Graylog; + class Log : private Thread { Log **m_indirect_this; @@ -42,7 +41,7 @@ class Log : private Thread int m_stderr_log, m_stderr_crash; int m_graylog_log, m_graylog_crash; - Graylog::Ref m_graylog; + shared_ptr m_graylog; bool m_stop; @@ -78,7 +77,7 @@ public: void start_graylog(); void stop_graylog(); - Graylog::Ref graylog() { return m_graylog; } + shared_ptr graylog() { return m_graylog; } Entry *create_entry(int level, int subsys); Entry *create_entry(int level, int subsys, size_t* expected_size); diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 5aa66e2ad05..391a3380b79 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -26,6 +26,7 @@ #include "messages/MLogAck.h" #include "common/Timer.h" +#include "common/Graylog.h" #include "osd/osd_types.h" #include "common/errno.h" @@ -743,6 +744,32 @@ bool LogMonitor::log_channel_info::do_log_to_syslog(const string &channel) { return ret; } +ceph::log::Graylog::Ref LogMonitor::log_channel_info::get_graylog( + const string &channel) +{ + generic_dout(25) << __func__ << " for channel '" + << channel << "'" << dendl; + + if (graylogs.count(channel) == 0) { + ceph::log::Graylog::Ref graylog = ceph::log::Graylog::Ref(new ceph::log::Graylog("mon")); + + graylog->set_fsid(g_conf->fsid); + graylog->set_hostname(g_conf->host); + graylog->set_destination(get_str_map_key(log_to_graylog_host, channel, + &CLOG_CONFIG_DEFAULT_KEY), + atoi(get_str_map_key(log_to_graylog_port, channel, + &CLOG_CONFIG_DEFAULT_KEY).c_str())); + + graylogs[channel] = graylog; + generic_dout(20) << __func__ << " for channel '" + << channel << "' to graylog host '" + << log_to_graylog_host[channel] << ":" + << log_to_graylog_port[channel] + << "'" << dendl; + } + return graylogs[channel]; +} + void LogMonitor::handle_conf_change(const struct md_config_t *conf, const std::set &changed) { diff --git a/src/mon/LogMonitor.h b/src/mon/LogMonitor.h index d2e3a4a8023..678c5ff3fc9 100644 --- a/src/mon/LogMonitor.h +++ b/src/mon/LogMonitor.h @@ -25,12 +25,17 @@ using namespace std; #include "common/LogEntry.h" #include "messages/MLog.h" -#include "common/Graylog.h" class MMonCommand; static const string LOG_META_CHANNEL = "$channel"; +namespace ceph { +namespace log { + class Graylog; +} +} + class LogMonitor : public PaxosService, public md_config_obs_t { private: @@ -49,7 +54,7 @@ private: map log_to_graylog_host; map log_to_graylog_port; - map graylogs; + map> graylogs; uuid_d fsid; string host; @@ -120,29 +125,7 @@ private: &CLOG_CONFIG_DEFAULT_KEY) == "true"); } - ceph::log::Graylog::Ref get_graylog(const string &channel) { - generic_dout(25) << __func__ << " for channel '" - << channel << "'" << dendl; - - if (graylogs.count(channel) == 0) { - ceph::log::Graylog::Ref graylog = ceph::log::Graylog::Ref(new ceph::log::Graylog("mon")); - - graylog->set_fsid(g_conf->fsid); - graylog->set_hostname(g_conf->host); - graylog->set_destination(get_str_map_key(log_to_graylog_host, channel, - &CLOG_CONFIG_DEFAULT_KEY), - atoi(get_str_map_key(log_to_graylog_port, channel, - &CLOG_CONFIG_DEFAULT_KEY).c_str())); - - graylogs[channel] = graylog; - generic_dout(20) << __func__ << " for channel '" - << channel << "' to graylog host '" - << log_to_graylog_host[channel] << ":" - << log_to_graylog_port[channel] - << "'" << dendl; - } - return graylogs[channel]; - } + shared_ptr get_graylog(const string &channel); } channels; void update_log_channels();