]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/common/logclient.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crimson / common / logclient.h
1 #ifndef CEPH_LOGCLIENT_H
2 #define CEPH_LOGCLIENT_H
3
4 #include "common/LogEntry.h"
5 #include "common/ostream_temp.h"
6 #include "common/ref.h"
7 #include "include/health.h"
8 #include "crimson/net/Fwd.h"
9
10 #include <seastar/core/future.hh>
11 #include <seastar/core/gate.hh>
12 #include <seastar/core/lowres_clock.hh>
13 #include <seastar/core/shared_ptr.hh>
14 #include <seastar/core/timer.hh>
15
16 class LogClient;
17 class MLog;
18 class MLogAck;
19 class Message;
20 struct uuid_d;
21 struct Connection;
22
23 class LogChannel;
24
25 namespace ceph {
26 namespace logging {
27 class Graylog;
28 }
29 }
30
31 template<typename Message> using Ref = boost::intrusive_ptr<Message>;
32 namespace crimson::net {
33 class Messenger;
34 }
35
36 enum class log_flushing_t {
37 NO_FLUSH,
38 FLUSH
39 };
40
41 int parse_log_client_options(CephContext *cct,
42 std::map<std::string,std::string> &log_to_monitors,
43 std::map<std::string,std::string> &log_to_syslog,
44 std::map<std::string,std::string> &log_channels,
45 std::map<std::string,std::string> &log_prios,
46 std::map<std::string,std::string> &log_to_graylog,
47 std::map<std::string,std::string> &log_to_graylog_host,
48 std::map<std::string,std::string> &log_to_graylog_port,
49 uuid_d &fsid,
50 std::string &host);
51
52 /** Manage where we output to and at which priority
53 *
54 * Not to be confused with the LogClient, which is the almighty coordinator
55 * of channels. We just deal with the boring part of the logging: send to
56 * syslog, send to file, generate LogEntry and queue it for the LogClient.
57 *
58 * Past queueing the LogEntry, the LogChannel is done with the whole thing.
59 * LogClient will deal with sending and handling of LogEntries.
60 */
61 class LogChannel : public LoggerSinkSet
62 {
63 public:
64 LogChannel(LogClient *lc, const std::string &channel);
65 LogChannel(LogClient *lc, const std::string &channel,
66 const std::string &facility, const std::string &prio);
67
68 OstreamTemp debug() {
69 return OstreamTemp(CLOG_DEBUG, this);
70 }
71 void debug(std::stringstream &s) final {
72 do_log(CLOG_DEBUG, s);
73 }
74 /**
75 * Convenience function mapping health status to
76 * the appropriate cluster log severity.
77 */
78 OstreamTemp health(health_status_t health) {
79 switch(health) {
80 case HEALTH_OK:
81 return info();
82 case HEALTH_WARN:
83 return warn();
84 case HEALTH_ERR:
85 return error();
86 default:
87 // Invalid health_status_t value
88 ceph_abort();
89 }
90 }
91 OstreamTemp info() final {
92 return OstreamTemp(CLOG_INFO, this);
93 }
94 void info(std::stringstream &s) final {
95 do_log(CLOG_INFO, s);
96 }
97 OstreamTemp warn() final {
98 return OstreamTemp(CLOG_WARN, this);
99 }
100 void warn(std::stringstream &s) final {
101 do_log(CLOG_WARN, s);
102 }
103 OstreamTemp error() final {
104 return OstreamTemp(CLOG_ERROR, this);
105 }
106 void error(std::stringstream &s) final {
107 do_log(CLOG_ERROR, s);
108 }
109 OstreamTemp sec() final {
110 return OstreamTemp(CLOG_SEC, this);
111 }
112 void sec(std::stringstream &s) final {
113 do_log(CLOG_SEC, s);
114 }
115
116 void set_log_to_monitors(bool v);
117 void set_log_to_syslog(bool v) {
118 log_to_syslog = v;
119 }
120 void set_log_channel(const std::string& v) {
121 log_channel = v;
122 }
123 void set_log_prio(const std::string& v) {
124 log_prio = v;
125 }
126 void set_syslog_facility(const std::string& v) {
127 syslog_facility = v;
128 }
129 const std::string& get_log_prio() const { return log_prio; }
130 const std::string& get_log_channel() const { return log_channel; }
131 const std::string& get_syslog_facility() const { return syslog_facility; }
132 bool must_log_to_syslog() const { return log_to_syslog; }
133 /**
134 * Do we want to log to syslog?
135 *
136 * @return true if log_to_syslog is true and both channel and prio
137 * are not empty; false otherwise.
138 */
139 bool do_log_to_syslog() {
140 return must_log_to_syslog() &&
141 !log_prio.empty() && !log_channel.empty();
142 }
143 bool must_log_to_monitors() { return log_to_monitors; }
144
145 bool do_log_to_graylog() {
146 return (graylog != nullptr);
147 }
148
149 using Ref = seastar::lw_shared_ptr<LogChannel>;
150
151 /**
152 * update config values from parsed k/v std::map for each config option
153 *
154 * Pick out the relevant value based on our channel.
155 */
156 void update_config(std::map<std::string,std::string> &log_to_monitors,
157 std::map<std::string,std::string> &log_to_syslog,
158 std::map<std::string,std::string> &log_channels,
159 std::map<std::string,std::string> &log_prios,
160 std::map<std::string,std::string> &log_to_graylog,
161 std::map<std::string,std::string> &log_to_graylog_host,
162 std::map<std::string,std::string> &log_to_graylog_port,
163 uuid_d &fsid,
164 std::string &host);
165
166 void do_log(clog_type prio, std::stringstream& ss) final;
167 void do_log(clog_type prio, const std::string& s) final;
168
169 private:
170 LogClient *parent;
171 std::string log_channel;
172 std::string log_prio;
173 std::string syslog_facility;
174 bool log_to_syslog;
175 bool log_to_monitors;
176 seastar::shared_ptr<ceph::logging::Graylog> graylog;
177 };
178
179 using LogChannelRef = LogChannel::Ref;
180
181 class LogClient
182 {
183 public:
184 enum logclient_flag_t {
185 NO_FLAGS = 0,
186 FLAG_MON = 0x1,
187 };
188
189 LogClient(crimson::net::Messenger *m, logclient_flag_t flags);
190
191 virtual ~LogClient() = default;
192
193 seastar::future<> handle_log_ack(Ref<MLogAck> m);
194 MessageURef get_mon_log_message(log_flushing_t flush_flag);
195 bool are_pending() const;
196
197 LogChannelRef create_channel() {
198 return create_channel(CLOG_CHANNEL_DEFAULT);
199 }
200
201 LogChannelRef create_channel(const std::string& name);
202
203 void destroy_channel(const std::string& name) {
204 channels.erase(name);
205 }
206
207 void shutdown() {
208 channels.clear();
209 }
210
211 uint64_t get_next_seq();
212 entity_addrvec_t get_myaddrs() const;
213 const EntityName& get_myname() const;
214 entity_name_t get_myrank();
215 version_t queue(LogEntry &entry);
216 void reset();
217 seastar::future<> set_fsid(const uuid_d& fsid);
218
219 private:
220 MessageURef _get_mon_log_message();
221
222 crimson::net::Messenger *messenger;
223 bool is_mon;
224 version_t last_log_sent;
225 version_t last_log;
226 std::deque<LogEntry> log_queue;
227
228 std::map<std::string, LogChannelRef> channels;
229 uuid_d m_fsid;
230 };
231 #endif
232