]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_log.h
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
15 namespace rgw
{ namespace sal
{
19 struct rgw_log_entry
{
21 using headers_map
= boost::container::flat_map
<std::string
, std::string
>;
22 using Clock
= req_state::Clock
;
24 rgw_user object_owner
;
25 rgw_user bucket_owner
;
27 Clock::time_point time
;
28 std::string remote_addr
;
33 std::string http_status
;
34 std::string error_code
;
35 uint64_t bytes_sent
= 0;
36 uint64_t bytes_received
= 0;
37 uint64_t obj_size
= 0;
38 Clock::duration total_time
{};
39 std::string user_agent
;
41 std::string bucket_id
;
42 headers_map x_headers
;
44 std::vector
<std::string
> token_claims
;
45 uint32_t identity_type
;
46 std::string access_key_id
;
48 bool temp_url
{false};
50 void encode(bufferlist
&bl
) const {
51 ENCODE_START(13, 5, bl
);
52 encode(object_owner
.id
, bl
);
53 encode(bucket_owner
.id
, bl
);
56 encode(remote_addr
, bl
);
61 encode(http_status
, bl
);
62 encode(error_code
, bl
);
63 encode(bytes_sent
, bl
);
65 encode(total_time
, bl
);
66 encode(user_agent
, bl
);
68 encode(bytes_received
, bl
);
69 encode(bucket_id
, bl
);
71 encode(object_owner
, bl
);
72 encode(bucket_owner
, bl
);
73 encode(x_headers
, bl
);
75 encode(token_claims
, bl
);
76 encode(identity_type
,bl
);
77 encode(access_key_id
, bl
);
82 void decode(bufferlist::const_iterator
&p
) {
83 DECODE_START_LEGACY_COMPAT_LEN(13, 5, 5, p
);
84 decode(object_owner
.id
, p
);
86 decode(bucket_owner
.id
, p
);
89 decode(remote_addr
, p
);
94 decode(http_status
, p
);
95 decode(error_code
, p
);
96 decode(bytes_sent
, p
);
98 decode(total_time
, p
);
99 decode(user_agent
, p
);
102 decode(bytes_received
, p
);
111 snprintf(buf
, sizeof(buf
), "%" PRIu64
, id
);
114 decode(bucket_id
, p
);
123 decode(object_owner
, p
);
124 decode(bucket_owner
, p
);
127 decode(x_headers
, p
);
129 if (struct_v
>= 10) {
132 if (struct_v
>= 11) {
133 decode(token_claims
, p
);
135 if (struct_v
>= 12) {
136 decode(identity_type
, p
);
138 if (struct_v
>= 13) {
139 decode(access_key_id
, p
);
145 void dump(ceph::Formatter
*f
) const;
146 static void generate_test_instances(std::list
<rgw_log_entry
*>& o
);
148 WRITE_CLASS_ENCODER(rgw_log_entry
)
152 virtual int log(struct req_state
* s
, struct rgw_log_entry
& entry
) = 0;
153 virtual ~OpsLogSink() = default;
156 class OpsLogManifold
: public OpsLogSink
{
157 std::vector
<OpsLogSink
*> sinks
;
159 ~OpsLogManifold() override
;
160 void add_sink(OpsLogSink
* sink
);
161 int log(struct req_state
* s
, struct rgw_log_entry
& entry
) override
;
164 class JsonOpsLogSink
: public OpsLogSink
{
165 ceph::Formatter
*formatter
;
166 ceph::mutex lock
= ceph::make_mutex("JsonOpsLogSink");
168 void formatter_to_bl(bufferlist
& bl
);
170 virtual int log_json(struct req_state
* s
, bufferlist
& bl
) = 0;
173 ~JsonOpsLogSink() override
;
174 int log(struct req_state
* s
, struct rgw_log_entry
& entry
) override
;
177 class OpsLogFile
: public JsonOpsLogSink
, public Thread
, public DoutPrefixProvider
{
179 ceph::mutex mutex
= ceph::make_mutex("OpsLogFile");
180 std::vector
<bufferlist
> log_buffer
;
181 std::vector
<bufferlist
> flush_buffer
;
182 ceph::condition_variable cond
;
186 uint64_t max_data_size
;
188 std::atomic_bool need_reopen
;
192 int log_json(struct req_state
* s
, bufferlist
& bl
) override
;
193 void *entry() override
;
195 OpsLogFile(CephContext
* cct
, std::string
& path
, uint64_t max_data_size
);
196 ~OpsLogFile() override
;
197 CephContext
*get_cct() const override
{ return cct
; }
198 unsigned get_subsys() const override
{ return dout_subsys
; }
199 std::ostream
& gen_prefix(std::ostream
& out
) const override
{ return out
<< "rgw OpsLogFile: "; }
205 class OpsLogSocket
: public OutputDataSocket
, public JsonOpsLogSink
{
207 int log_json(struct req_state
* s
, bufferlist
& bl
) override
;
208 void init_connection(bufferlist
& bl
) override
;
211 OpsLogSocket(CephContext
*cct
, uint64_t _backlog
);
214 class OpsLogRados
: public OpsLogSink
{
215 // main()'s Store pointer as a reference, possibly modified by RGWRealmReloader
216 rgw::sal::Store
* const& store
;
219 OpsLogRados(rgw::sal::Store
* const& store
);
220 int log(struct req_state
* s
, struct rgw_log_entry
& entry
) override
;
225 int rgw_log_op(RGWREST
* const rest
, struct req_state
* s
,
226 const std::string
& op_name
, OpsLogSink
* olog
);
227 void rgw_log_usage_init(CephContext
* cct
, rgw::sal::Store
* store
);
228 void rgw_log_usage_finalize();
229 void rgw_format_ops_log_entry(struct rgw_log_entry
& entry
,
230 ceph::Formatter
*formatter
);
232 #endif /* CEPH_RGW_LOG_H */