From 3cae01c969677c850efe6123f77ebc55a1ab6bf9 Mon Sep 17 00:00:00 2001 From: Vaibhav Bhembre Date: Thu, 31 May 2018 10:35:19 -0400 Subject: [PATCH] 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) --- src/cls/rgw/cls_rgw_types.cc | 48 ++++++++++++++++++++++++++++++++++++ src/cls/rgw/cls_rgw_types.h | 4 +++ src/test/encoding/types.h | 1 + 3 files changed, 53 insertions(+) diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index c16218a594a69..788058288868c 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -578,6 +578,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 fa08a48b9a133..e1cfdb645fb04 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -857,6 +857,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 9c355068dbf7d..8e9e8f8e61a2a 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -324,6 +324,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) -- 2.39.5