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 <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2016-02-05 15:56:55 +08:00
parent ef1573b171
commit f5cad7ac4e
9 changed files with 67 additions and 43 deletions

View File

@ -5,16 +5,15 @@
#include <iostream>
#include <sstream>
#include <memory>
#include <arpa/inet.h>
#include <boost/asio.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/lexical_cast.hpp>
#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<char> buf(40);
fsid.print(&buf[0]);

View File

@ -7,19 +7,24 @@
#include <memory>
#include <boost/thread/mutex.hpp>
#include <boost/asio.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#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);

View File

@ -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 <sys/mount.h>
#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"

View File

@ -17,8 +17,6 @@
#include "common/LogEntry.h"
#include "common/Mutex.h"
#include "include/uuid.h"
#include "common/Graylog.h"
#include <iosfwd>
#include <sstream>
@ -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<string,string> &log_to_monitors,
map<string,string> &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<ceph::log::Graylog> graylog;
friend class LogClientTemp;

View File

@ -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"

View File

@ -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"

View File

@ -6,18 +6,17 @@
#include "common/Thread.h"
#include <assert.h>
#include <pthread.h>
#include <boost/asio.hpp>
#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<Graylog> 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> graylog() { return m_graylog; }
Entry *create_entry(int level, int subsys);
Entry *create_entry(int level, int subsys, size_t* expected_size);

View File

@ -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<std::string> &changed)
{

View File

@ -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<string,string> log_to_graylog_host;
map<string,string> log_to_graylog_port;
map<string, ceph::log::Graylog::Ref> graylogs;
map<string, shared_ptr<ceph::log::Graylog>> 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<ceph::log::Graylog> get_graylog(const string &channel);
} channels;
void update_log_channels();