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