]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_log.h
e8ac71cc053a150e3245adf6a96a9405b8a8dadd
[ceph.git] / 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
3
4 #ifndef CEPH_RGW_LOG_H
5 #define CEPH_RGW_LOG_H
6
7 #include <boost/container/flat_map.hpp>
8 #include "rgw_common.h"
9 #include "common/OutputDataSocket.h"
10
11 class RGWRados;
12
13 struct rgw_log_entry {
14
15 using headers_map = boost::container::flat_map<std::string, std::string>;
16 using Clock = req_state::Clock;
17
18 rgw_user object_owner;
19 rgw_user bucket_owner;
20 string bucket;
21 Clock::time_point time;
22 string remote_addr;
23 string user;
24 rgw_obj_key obj;
25 string op;
26 string uri;
27 string http_status;
28 string error_code;
29 uint64_t bytes_sent = 0;
30 uint64_t bytes_received = 0;
31 uint64_t obj_size = 0;
32 Clock::duration total_time{};
33 string user_agent;
34 string referrer;
35 string bucket_id;
36 headers_map x_headers;
37 string trans_id;
38
39 void encode(bufferlist &bl) const {
40 ENCODE_START(10, 5, bl);
41 encode(object_owner.id, bl);
42 encode(bucket_owner.id, bl);
43 encode(bucket, bl);
44 encode(time, bl);
45 encode(remote_addr, bl);
46 encode(user, bl);
47 encode(obj.name, bl);
48 encode(op, bl);
49 encode(uri, bl);
50 encode(http_status, bl);
51 encode(error_code, bl);
52 encode(bytes_sent, bl);
53 encode(obj_size, bl);
54 encode(total_time, bl);
55 encode(user_agent, bl);
56 encode(referrer, bl);
57 encode(bytes_received, bl);
58 encode(bucket_id, bl);
59 encode(obj, bl);
60 encode(object_owner, bl);
61 encode(bucket_owner, bl);
62 encode(x_headers, bl);
63 encode(trans_id, bl);
64 ENCODE_FINISH(bl);
65 }
66 void decode(bufferlist::const_iterator &p) {
67 DECODE_START_LEGACY_COMPAT_LEN(10, 5, 5, p);
68 decode(object_owner.id, p);
69 if (struct_v > 3)
70 decode(bucket_owner.id, p);
71 decode(bucket, p);
72 decode(time, p);
73 decode(remote_addr, p);
74 decode(user, p);
75 decode(obj.name, p);
76 decode(op, p);
77 decode(uri, p);
78 decode(http_status, p);
79 decode(error_code, p);
80 decode(bytes_sent, p);
81 decode(obj_size, p);
82 decode(total_time, p);
83 decode(user_agent, p);
84 decode(referrer, p);
85 if (struct_v >= 2)
86 decode(bytes_received, p);
87 else
88 bytes_received = 0;
89
90 if (struct_v >= 3) {
91 if (struct_v <= 5) {
92 uint64_t id;
93 decode(id, p);
94 char buf[32];
95 snprintf(buf, sizeof(buf), "%" PRIu64, id);
96 bucket_id = buf;
97 } else {
98 decode(bucket_id, p);
99 }
100 } else {
101 bucket_id = "";
102 }
103 if (struct_v >= 7) {
104 decode(obj, p);
105 }
106 if (struct_v >= 8) {
107 decode(object_owner, p);
108 decode(bucket_owner, p);
109 }
110 if (struct_v >= 9) {
111 decode(x_headers, p);
112 }
113 if (struct_v >= 10) {
114 decode(trans_id, p);
115 }
116 DECODE_FINISH(p);
117 }
118 void dump(ceph::Formatter *f) const;
119 static void generate_test_instances(list<rgw_log_entry*>& o);
120 };
121 WRITE_CLASS_ENCODER(rgw_log_entry)
122
123 class OpsLogSocket : public OutputDataSocket {
124 ceph::Formatter *formatter;
125 ceph::mutex lock = ceph::make_mutex("OpsLogSocket");
126
127 void formatter_to_bl(bufferlist& bl);
128
129 protected:
130 void init_connection(bufferlist& bl) override;
131
132 public:
133 OpsLogSocket(CephContext *cct, uint64_t _backlog);
134 ~OpsLogSocket() override;
135
136 void log(struct rgw_log_entry& entry);
137 };
138
139 class RGWREST;
140
141 int rgw_log_op(RGWRados *store, RGWREST* const rest, struct req_state *s,
142 const string& op_name, OpsLogSocket *olog);
143 void rgw_log_usage_init(CephContext *cct, RGWRados *store);
144 void rgw_log_usage_finalize();
145 void rgw_format_ops_log_entry(struct rgw_log_entry& entry,
146 ceph::Formatter *formatter);
147
148 #endif /* CEPH_RGW_LOG_H */
149