Skip to content

Commit 81e09be

Browse files
committed
rgw/logging: add mtime to get-bucket-logging response
Fixes: https://tracker.ceph.com/issues/71385 Signed-off-by: Yuval Lifshitz <[email protected]>
1 parent ff1d7c9 commit 81e09be

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

doc/radosgw/s3/bucketops.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ Syntax
862862
Response Entities
863863
~~~~~~~~~~~~~~~~~
864864

865-
Response is XML encoded in the body of the request, in the following format:
865+
Response header contains ``Last-Modified`` date/time of the logging configuration.
866+
Logging configuration is XML encoded in the body of the response, in the following format:
866867

867868
::
868869

src/rgw/rgw_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ using ceph::crypto::MD5;
110110
#define RGW_ATTR_X_ROBOTS_TAG RGW_ATTR_PREFIX "x-robots-tag"
111111
#define RGW_ATTR_STORAGE_CLASS RGW_ATTR_PREFIX "storage_class"
112112
#define RGW_ATTR_BUCKET_LOGGING RGW_ATTR_PREFIX "logging"
113+
#define RGW_ATTR_BUCKET_LOGGING_MTIME RGW_ATTR_PREFIX "logging-mtime"
113114
#define RGW_ATTR_BUCKET_LOGGING_SOURCES RGW_ATTR_PREFIX "logging-sources"
114115

115116
/* S3 Object Lock*/

src/rgw/rgw_rest_bucket_logging.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,21 @@ namespace {
3232
}
3333
return 0;
3434
}
35+
36+
void update_mtime_attribute(const DoutPrefixProvider* dpp, rgw::sal::Attrs& attrs) {
37+
bufferlist mtime_bl;
38+
const auto mtime = ceph::coarse_real_time::clock::now();
39+
encode(mtime, mtime_bl);
40+
attrs[RGW_ATTR_BUCKET_LOGGING_MTIME] = std::move(mtime_bl);
41+
ldpp_dout(dpp, 20) << "INFO: logging config modified at: " << mtime << dendl;
42+
}
3543
}
3644

3745
// GET /<bucket name>/?logging
3846
// reply is XML encoded
3947
class RGWGetBucketLoggingOp : public RGWOp {
4048
rgw::bucketlogging::configuration configuration;
49+
std::optional<ceph::real_time> mtime;
4150

4251
public:
4352
int verify_permission(optional_yield y) override {
@@ -73,6 +82,20 @@ class RGWGetBucketLoggingOp : public RGWOp {
7382
try {
7483
configuration.enabled = true;
7584
decode(configuration, iter->second);
85+
if (auto mtime_it = src_bucket->get_attrs().find(RGW_ATTR_BUCKET_LOGGING_MTIME);
86+
mtime_it != src_bucket->get_attrs().end()) {
87+
try {
88+
ceph::real_time tmp_mtime;
89+
decode(tmp_mtime, mtime_it->second);
90+
mtime = std::move(tmp_mtime);
91+
} catch (buffer::error& err) {
92+
ldpp_dout(this, 5) << "WARNING: failed to decode logging mtime attribute '" << RGW_ATTR_BUCKET_LOGGING_MTIME
93+
<< "' for bucket '" << src_bucket_id << "', error: " << err.what() << dendl;
94+
}
95+
} else {
96+
ldpp_dout(this, 5) << "WARNING: no logging mtime attribute '" << RGW_ATTR_BUCKET_LOGGING_MTIME
97+
<< "' for bucket '" << src_bucket_id << "'" << dendl;
98+
}
7699
} catch (buffer::error& err) {
77100
ldpp_dout(this, 1) << "WARNING: failed to decode logging attribute '" << RGW_ATTR_BUCKET_LOGGING
78101
<< "' for bucket '" << src_bucket_id << "', error: " << err.what() << dendl;
@@ -89,6 +112,9 @@ class RGWGetBucketLoggingOp : public RGWOp {
89112

90113
void send_response() override {
91114
dump_errno(s);
115+
if (mtime) {
116+
dump_last_modified(s, *mtime);
117+
}
92118
end_header(s, this, to_mime_type(s->format));
93119
dump_start(s);
94120

@@ -253,13 +279,15 @@ class RGWPutBucketLoggingOp : public RGWDefaultResponseOp {
253279
if (!old_conf || (old_conf && *old_conf != configuration)) {
254280
// conf changed (or was unknown) - update
255281
it->second = conf_bl;
282+
update_mtime_attribute(this, attrs);
256283
return src_bucket->merge_and_store_attrs(this, attrs, y);
257284
}
258285
// nothing to update
259286
return 0;
260287
}
261288
// conf was added
262289
attrs.insert(std::make_pair(RGW_ATTR_BUCKET_LOGGING, conf_bl));
290+
update_mtime_attribute(this, attrs);
263291
return src_bucket->merge_and_store_attrs(this, attrs, y);
264292
}, y);
265293
if (op_ret < 0) {

0 commit comments

Comments
 (0)