From 9937c818f1073bceffcf5811c7cc543b9043e646 Mon Sep 17 00:00:00 2001 From: Abhishek Dixit Date: Mon, 8 Jun 2015 22:59:54 +0530 Subject: [PATCH] Transaction Id added in response Signed-off-by: Abhishek Dixit dixitabhi@gmail.com (cherry picked from commit b711e3124f8f73c17ebd19b38807a1b77f201e44) Conflicts: src/rgw/rgw_rest.cc the prototype of the end_header( function in the context of the diff changed --- src/rgw/rgw_common.cc | 12 ++++++++++++ src/rgw/rgw_common.h | 4 ++++ src/rgw/rgw_main.cc | 2 ++ src/rgw/rgw_rest.cc | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index f3988cffd3486..f5b9a9b246158 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -169,6 +169,18 @@ req_state::~req_state() { delete object_acl; } +void req_state::gen_trans_id() +{ + char buf[256]; + timeval timetest; + gettimeofday(&timetest, NULL); + if (strftime(buf, sizeof(buf), "%Y%m%d:%H%M%S",gmtime(&(timetest.tv_sec))) == 0) + return; + + snprintf(buf + strlen(buf), sizeof(buf)-strlen(buf) ,":%03ld", timetest.tv_usec/1000); + trans_id = req_id + "-" + buf; +} + struct str_len { const char *str; int len; diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 6c7912bd983c7..0f46b63f9fdff 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1057,10 +1057,14 @@ struct req_state { string req_id; + string trans_id; + req_info info; req_state(CephContext *_cct, class RGWEnv *e); ~req_state(); + + void gen_trans_id(); }; /** Store basic data on an object */ diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 2a247e4191f24..10a672a4b4b15 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -556,6 +556,8 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC s->req_id = store->unique_id(req->id); + s->gen_trans_id(); + req->log(s, "initializing"); RGWOp *op = NULL; diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index d385d6233c722..b59d6866a43fd 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -492,10 +492,22 @@ void dump_start(struct req_state *s) } } +void dump_trans_id(req_state *s) +{ + if (s->prot_flags & RGW_REST_SWIFT) { + s->cio->print("X-Trans-Id: ts-%s\r\n", s->trans_id.c_str()); + } + else { + s->cio->print("x-amz-request-id: %s\r\n", s->trans_id.c_str()); + } +} + void end_header(struct req_state *s, RGWOp *op, const char *content_type, const int64_t proposed_content_length) { string ctype; + dump_trans_id(s); + if (op) { dump_access_control(s, op); } -- 2.39.5