From 85267cf6afce1cfda2247233f639f464f3c3296e Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 18 Dec 2013 17:03:21 -0800 Subject: [PATCH] rgw: sign loadgen requests Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_loadgen.cc | 37 ++++++++++++++++++++++++++ src/rgw/rgw_loadgen.h | 4 +++ src/rgw/rgw_main.cc | 59 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/rgw/rgw_loadgen.cc b/src/rgw/rgw_loadgen.cc index 56c96b0787150..01cf1a35f094b 100644 --- a/src/rgw/rgw_loadgen.cc +++ b/src/rgw/rgw_loadgen.cc @@ -2,10 +2,46 @@ #include #include "rgw_loadgen.h" +#include "rgw_auth_s3.h" #define dout_subsys ceph_subsys_rgw +void RGWLoadGenRequestEnv::set_date(utime_t& tm) +{ + stringstream s; + tm.asctime(s); + date_str = s.str(); +} + +int RGWLoadGenRequestEnv::sign(RGWAccessKey& access_key) +{ + map meta_map; + map sub_resources; + + string canonical_header; + string digest; + + rgw_create_s3_canonical_header(request_method.c_str(), + NULL, /* const char *content_md5 */ + content_type.c_str(), + date_str.c_str(), + meta_map, + uri.c_str(), + sub_resources, + canonical_header); + + int ret = rgw_get_s3_header_digest(canonical_header, access_key.key, digest); + if (ret < 0) { + return ret; + } + + headers["HTTP_DATE"] = date_str; + headers["HTTP_AUTHORIZATION"] = string("AWS ") + access_key.id + ":" + digest; + + return 0; +} + int RGWLoadGenIO::write_data(const char *buf, int len) { return len; @@ -38,6 +74,7 @@ void RGWLoadGenIO::init_env(CephContext *cct) env.set("CONTENT_LENGTH", buf); env.set("CONTENT_TYPE", req->content_type.c_str()); + env.set("HTTP_DATE", req->date_str.c_str()); for (map::iterator iter = req->headers.begin(); iter != req->headers.end(); ++iter) { env.set(iter->first.c_str(), iter->second.c_str()); diff --git a/src/rgw/rgw_loadgen.h b/src/rgw/rgw_loadgen.h index 4a7f16120dee1..5459330ce3867 100644 --- a/src/rgw/rgw_loadgen.h +++ b/src/rgw/rgw_loadgen.h @@ -11,10 +11,14 @@ struct RGWLoadGenRequestEnv { string request_method; string uri; string query_string; + string date_str; map headers; RGWLoadGenRequestEnv() : port(0), content_length(0) {} + + void set_date(utime_t& tm); + int sign(RGWAccessKey& access_key); }; class RGWLoadGenIO : public RGWClientIO diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 3990950bed72c..5df04d5abe35a 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -322,10 +322,12 @@ void RGWFCGXProcess::run() } struct RGWLoadGenRequest : public RGWRequest { - const char *method; + string method; + string resource; int content_length; - RGWLoadGenRequest(const char *_m, int _cl) : method(_m), content_length(_cl) {} + + RGWLoadGenRequest(const string& _m, const string& _r, int _cl) : method(_m), resource(_r), content_length(_cl) {} }; class RGWLoadGenProcess : public RGWProcess { @@ -334,29 +336,66 @@ public: RGWLoadGenProcess(CephContext *cct, RGWProcessEnv *pe, int num_threads, RGWFrontendConfig *_conf) : RGWProcess(cct, pe, num_threads, _conf) {} void run(); + void checkpoint(); void handle_request(RGWRequest *req); - void gen_request(const char *method, int content_length); + void gen_request(const string& method, const string& resource, int content_length); void close_fd() { } void set_access_key(RGWAccessKey& key) { access_key = key; } }; +void RGWLoadGenProcess::checkpoint() +{ + m_tp.drain(); +} + void RGWLoadGenProcess::run() { m_tp.start(); /* start thread pool */ - for (int i = 0; i < 1000; i++) { - gen_request("PUT", 4096); + int i; + + int num_objs = 1000; + + string bucket = "mybucket"; + + string bucket_resource = string("/") + bucket; + + /* first create a bucket */ + gen_request("PUT", bucket_resource, 0); + + checkpoint(); + + string *objs = new string[num_objs]; + + for (i = 0; i < num_objs; i++) { + char buf[32]; + snprintf(buf, sizeof(buf), "obj-%d", i); + objs[i] = bucket_resource + "/" + buf; + } + + for (i = 0; i < num_objs; i++) { + gen_request("PUT", objs[i], 4096); + } +#if 0 + for (i = 0; i < 10; i++) { + gen_request("GET", 4096); } + for (i = 0; i < 10; i++) { + gen_request("DELETE", 4096); + } +#endif m_tp.drain(); m_tp.stop(); + + delete[] objs; } -void RGWLoadGenProcess::gen_request(const char *method, int content_length) +void RGWLoadGenProcess::gen_request(const string& method, const string& resource, int content_length) { - RGWLoadGenRequest *req = new RGWLoadGenRequest(method, content_length); + RGWLoadGenRequest *req = new RGWLoadGenRequest(method, resource, content_length); req->id = ++max_req_id; dout(10) << "allocated request req=" << hex << req << dec << dendl; req_throttle.get(1); @@ -573,11 +612,15 @@ void RGWLoadGenProcess::handle_request(RGWRequest *r) RGWLoadGenRequestEnv env; + utime_t tm = ceph_clock_now(NULL); + env.port = 80; env.content_length = req->content_length; env.content_type = "binary/octet-stream"; env.request_method = req->method; - env.uri = "/foo/bar"; + env.uri = req->resource; + env.set_date(tm); + env.sign(access_key); RGWLoadGenIO client_io(&env); -- 2.39.5