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