1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
7 #include <boost/container/flat_map.hpp>
8 #include "rgw_common.h"
9 #include "common/OutputDataSocket.h"
13 #define dout_subsys ceph_subsys_rgw
17 struct rgw_log_entry
{
19 using headers_map
= boost::container::flat_map
<std::string
, std::string
>;
20 using Clock
= req_state::Clock
;
22 rgw_user object_owner
;
23 rgw_user bucket_owner
;
25 Clock::time_point time
;
33 uint64_t bytes_sent
= 0;
34 uint64_t bytes_received
= 0;
35 uint64_t obj_size
= 0;
36 Clock::duration total_time
{};
40 headers_map x_headers
;
42 std::vector
<string
> token_claims
;
44 void encode(bufferlist
&bl
) const {
45 ENCODE_START(11, 5, bl
);
46 encode(object_owner
.id
, bl
);
47 encode(bucket_owner
.id
, bl
);
50 encode(remote_addr
, bl
);
55 encode(http_status
, bl
);
56 encode(error_code
, bl
);
57 encode(bytes_sent
, bl
);
59 encode(total_time
, bl
);
60 encode(user_agent
, bl
);
62 encode(bytes_received
, bl
);
63 encode(bucket_id
, bl
);
65 encode(object_owner
, bl
);
66 encode(bucket_owner
, bl
);
67 encode(x_headers
, bl
);
69 encode(token_claims
, bl
);
72 void decode(bufferlist::const_iterator
&p
) {
73 DECODE_START_LEGACY_COMPAT_LEN(11, 5, 5, p
);
74 decode(object_owner
.id
, p
);
76 decode(bucket_owner
.id
, p
);
79 decode(remote_addr
, p
);
84 decode(http_status
, p
);
85 decode(error_code
, p
);
86 decode(bytes_sent
, p
);
88 decode(total_time
, p
);
89 decode(user_agent
, p
);
92 decode(bytes_received
, p
);
101 snprintf(buf
, sizeof(buf
), "%" PRIu64
, id
);
104 decode(bucket_id
, p
);
113 decode(object_owner
, p
);
114 decode(bucket_owner
, p
);
117 decode(x_headers
, p
);
119 if (struct_v
>= 10) {
122 if (struct_v
>= 11) {
123 decode(token_claims
, p
);
127 void dump(ceph::Formatter
*f
) const;
128 static void generate_test_instances(list
<rgw_log_entry
*>& o
);
130 WRITE_CLASS_ENCODER(rgw_log_entry
)
134 virtual int log(struct req_state
* s
, struct rgw_log_entry
& entry
) = 0;
135 virtual ~OpsLogSink() = default;
138 class OpsLogManifold
: public OpsLogSink
{
139 std::vector
<OpsLogSink
*> sinks
;
141 ~OpsLogManifold() override
;
142 void add_sink(OpsLogSink
* sink
);
143 int log(struct req_state
* s
, struct rgw_log_entry
& entry
) override
;
146 class JsonOpsLogSink
: public OpsLogSink
{
147 ceph::Formatter
*formatter
;
148 ceph::mutex lock
= ceph::make_mutex("JsonOpsLogSink");
150 void formatter_to_bl(bufferlist
& bl
);
152 virtual int log_json(struct req_state
* s
, bufferlist
& bl
) = 0;
155 ~JsonOpsLogSink() override
;
156 int log(struct req_state
* s
, struct rgw_log_entry
& entry
) override
;
159 class OpsLogFile
: public JsonOpsLogSink
, public Thread
, public DoutPrefixProvider
{
161 ceph::mutex log_mutex
= ceph::make_mutex("OpsLogFile_log");
162 ceph::mutex flush_mutex
= ceph::make_mutex("OpsLogFile_flush");
163 std::vector
<bufferlist
> log_buffer
;
164 std::vector
<bufferlist
> flush_buffer
;
165 ceph::condition_variable cond_flush
;
169 uint64_t max_data_size
;
173 int log_json(struct req_state
* s
, bufferlist
& bl
) override
;
174 void *entry() override
;
176 OpsLogFile(CephContext
* cct
, std::string
& path
, uint64_t max_data_size
);
177 ~OpsLogFile() override
;
178 CephContext
*get_cct() const override
{ return cct
; }
179 unsigned get_subsys() const override
{ return dout_subsys
; }
180 std::ostream
& gen_prefix(std::ostream
& out
) const override
{ return out
<< "rgw OpsLogFile: "; }
185 class OpsLogSocket
: public OutputDataSocket
, public JsonOpsLogSink
{
187 int log_json(struct req_state
* s
, bufferlist
& bl
) override
;
188 void init_connection(bufferlist
& bl
) override
;
191 OpsLogSocket(CephContext
*cct
, uint64_t _backlog
);
194 class OpsLogRados
: public OpsLogSink
{
197 OpsLogRados(RGWRados
* store
);
198 int log(struct req_state
* s
, struct rgw_log_entry
& entry
) override
;
203 int rgw_log_op(RGWREST
* const rest
, struct req_state
* s
,
204 const std::string
& op_name
, OpsLogSink
* olog
);
205 void rgw_log_usage_init(CephContext
*cct
, RGWRados
*store
);
206 void rgw_log_usage_finalize();
207 void rgw_format_ops_log_entry(struct rgw_log_entry
& entry
,
208 ceph::Formatter
*formatter
);
210 #endif /* CEPH_RGW_LOG_H */