]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw/logging: add mtime to get-bucket-logging response
authorYuval Lifshitz <ylifshit@ibm.com>
Tue, 20 May 2025 08:44:05 +0000 (08:44 +0000)
committerYuval Lifshitz <ylifshit@ibm.com>
Thu, 22 May 2025 11:11:01 +0000 (11:11 +0000)
Fixes: https://tracker.ceph.com/issues/71385
Signed-off-by: Yuval Lifshitz <ylifshit@ibm.com>
doc/radosgw/s3/bucketops.rst
src/rgw/rgw_common.h
src/rgw/rgw_rest_bucket_logging.cc

index 8153d7e57e5fbb47200cd5dcbbb0e6ca24437e06..0002c1c750d14a6e683f4b882a8c7cdb674bfade 100644 (file)
@@ -862,7 +862,8 @@ Syntax
 Response Entities
 ~~~~~~~~~~~~~~~~~
 
-Response is XML encoded in the body of the request, in the following format:
+Response header contains ``Last-Modified`` date/time of the logging configuration.
+Logging configuration is XML encoded in the body of the response, in the following format:
 
 ::
 
index 45814fb341e3a3fa4395f558d5904a69e8d5f71e..a01377a1eb4d9d206098e2670396650516e2e717 100644 (file)
@@ -110,6 +110,7 @@ using ceph::crypto::MD5;
 #define RGW_ATTR_X_ROBOTS_TAG  RGW_ATTR_PREFIX "x-robots-tag"
 #define RGW_ATTR_STORAGE_CLASS  RGW_ATTR_PREFIX "storage_class"
 #define RGW_ATTR_BUCKET_LOGGING RGW_ATTR_PREFIX "logging"
+#define RGW_ATTR_BUCKET_LOGGING_MTIME RGW_ATTR_PREFIX "logging-mtime"
 #define RGW_ATTR_BUCKET_LOGGING_SOURCES RGW_ATTR_PREFIX "logging-sources"
 
 /* S3 Object Lock*/
index 60a4b5b2b66bfddad47a75ed1b712b42330f45bf..e0b8d4cb06fd295a61cecdf0dc4af12522355782 100644 (file)
@@ -32,12 +32,21 @@ namespace {
     }
     return 0;
   }
+
+  void update_mtime_attribute(const DoutPrefixProvider* dpp, rgw::sal::Attrs& attrs) {
+    bufferlist mtime_bl;
+    const auto mtime = ceph::coarse_real_time::clock::now();
+    encode(mtime, mtime_bl);
+    attrs[RGW_ATTR_BUCKET_LOGGING_MTIME] = std::move(mtime_bl);
+    ldpp_dout(dpp, 20) << "INFO: logging config modified at: " << mtime << dendl;
+  }
 }
 
 // GET /<bucket name>/?logging
 // reply is XML encoded
 class RGWGetBucketLoggingOp : public RGWOp {
   rgw::bucketlogging::configuration configuration;
+  std::optional<ceph::real_time> mtime;
 
 public:
   int verify_permission(optional_yield y) override {
@@ -73,6 +82,20 @@ public:
       try {
         configuration.enabled = true;
         decode(configuration, iter->second);
+        if (auto mtime_it = src_bucket->get_attrs().find(RGW_ATTR_BUCKET_LOGGING_MTIME);
+            mtime_it != src_bucket->get_attrs().end()) {
+          try {
+            ceph::real_time tmp_mtime;
+            decode(tmp_mtime, mtime_it->second);
+            mtime = std::move(tmp_mtime);
+          } catch (buffer::error& err) {
+            ldpp_dout(this, 5) << "WARNING: failed to decode logging mtime attribute '" << RGW_ATTR_BUCKET_LOGGING_MTIME
+              << "' for bucket '" << src_bucket_id << "', error: " << err.what() << dendl;
+          }
+        } else {
+          ldpp_dout(this, 5) << "WARNING: no logging mtime attribute '" << RGW_ATTR_BUCKET_LOGGING_MTIME
+            << "' for bucket '" << src_bucket_id << "'" << dendl;
+        }
       } catch (buffer::error& err) {
         ldpp_dout(this, 1) << "WARNING: failed to decode logging attribute '" << RGW_ATTR_BUCKET_LOGGING
           << "' for bucket '" << src_bucket_id << "', error: " << err.what() << dendl;
@@ -89,6 +112,9 @@ public:
 
   void send_response() override {
     dump_errno(s);
+    if (mtime) {
+      dump_last_modified(s, *mtime);
+    }
     end_header(s, this, to_mime_type(s->format));
     dump_start(s);
 
@@ -253,6 +279,7 @@ class RGWPutBucketLoggingOp : public RGWDefaultResponseOp {
         if (!old_conf || (old_conf && *old_conf != configuration)) {
           // conf changed (or was unknown) - update
           it->second = conf_bl;
+          update_mtime_attribute(this, attrs);
           return src_bucket->merge_and_store_attrs(this, attrs, y);
         }
         // nothing to update
@@ -260,6 +287,7 @@ class RGWPutBucketLoggingOp : public RGWDefaultResponseOp {
       }
       // conf was added
       attrs.insert(std::make_pair(RGW_ATTR_BUCKET_LOGGING, conf_bl));
+      update_mtime_attribute(this, attrs);
       return src_bucket->merge_and_store_attrs(this, attrs, y);
     }, y);
     if (op_ret < 0) {