From: Vaibhav Bhembre Date: Thu, 31 May 2018 14:35:19 +0000 (-0400) Subject: cls/rgw: ready rgw_usage_log_entry for extraction via ceph-dencoder X-Git-Tag: v12.2.9~123^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F23974%2Fhead;p=ceph.git cls/rgw: ready rgw_usage_log_entry for extraction via ceph-dencoder Signed-off-by: Vaibhav Bhembre vaibhav@digitalocean.com (cherry picked from commit a503cec93853235f2f94dbc53eb307618f5a437a) --- diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index 51ee342e9212..0d7b5d218111 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -575,6 +575,54 @@ void rgw_bucket_dir::dump(Formatter *f) const f->close_section(); } +void rgw_usage_log_entry::dump(Formatter *f) const +{ + f->dump_string("owner", owner.to_str()); + f->dump_string("payer", payer.to_str()); + f->dump_string("bucket", bucket); + f->dump_unsigned("epoch", epoch); + + f->open_object_section("total_usage"); + f->dump_unsigned("bytes_sent", total_usage.bytes_sent); + f->dump_unsigned("bytes_received", total_usage.bytes_received); + f->dump_unsigned("ops", total_usage.ops); + f->dump_unsigned("successful_ops", total_usage.successful_ops); + f->close_section(); + + f->open_array_section("categories"); + if (usage_map.size() > 0) { + map::const_iterator it; + for (it = usage_map.begin(); it != usage_map.end(); it++) { + const rgw_usage_data& total_usage = it->second; + f->open_object_section("entry"); + f->dump_string("category", it->first.c_str()); + f->dump_unsigned("bytes_sent", total_usage.bytes_sent); + f->dump_unsigned("bytes_received", total_usage.bytes_received); + f->dump_unsigned("ops", total_usage.ops); + f->dump_unsigned("successful_ops", total_usage.successful_ops); + f->close_section(); + } + } + f->close_section(); +} + +void rgw_usage_log_entry::generate_test_instances(list &o) +{ + rgw_usage_log_entry *entry = new rgw_usage_log_entry; + rgw_usage_data usage_data{1024, 2048}; + entry->owner = rgw_user("owner"); + entry->payer = rgw_user("payer"); + entry->bucket = "bucket"; + entry->epoch = 1234; + entry->total_usage.bytes_sent = usage_data.bytes_sent; + entry->total_usage.bytes_received = usage_data.bytes_received; + entry->total_usage.ops = usage_data.ops; + entry->total_usage.successful_ops = usage_data.successful_ops; + entry->usage_map["get_obj"] = usage_data; + o.push_back(entry); + o.push_back(new rgw_usage_log_entry); +} + void cls_rgw_reshard_entry::generate_key(const string& tenant, const string& bucket_name, string *key) { *key = tenant + ":" + bucket_name; diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index 97b53742b857..51107c325952 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -854,6 +854,10 @@ struct rgw_usage_log_entry { usage_map[category].aggregate(data); total_usage.aggregate(data); } + + void dump(Formatter* f) const; + static void generate_test_instances(list& o); + }; WRITE_CLASS_ENCODER(rgw_usage_log_entry) diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index 29a83e7d613e..3d767a06b80b 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -317,6 +317,7 @@ TYPE(rgw_bucket_dir) TYPE(rgw_bucket_entry_ver) TYPE(cls_rgw_obj_key) TYPE(rgw_bucket_olh_log_entry) +TYPE(rgw_usage_log_entry) #include "cls/rgw/cls_rgw_ops.h" TYPE(rgw_cls_obj_prepare_op)