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