From eaf49d968f5cbda1de3ccd45ce4d764d4bed2352 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Tue, 27 Feb 2018 10:45:26 +0100 Subject: [PATCH] lib-http: client: Fix request statistics text to properly report send attempts. If the request was first sent in the same ioloop cycle in which the text is generated, the text would claim it was not sent at all yet. With this commit the text now explicitly makes the distinction between request attempts and actual send attempts. The number of attempts is increased at each retry, while the send attempts are increased each time the request is actually being sent to a server. --- src/lib-http/http-client-private.h | 2 +- src/lib-http/http-client-request.c | 16 ++++++++++------ src/lib-http/http-client.h | 5 ++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 8d3544e971..85e7a4d574 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -121,7 +121,7 @@ struct http_client_request { uoff_t response_offset, request_offset; uoff_t bytes_in, bytes_out; - unsigned int attempts; + unsigned int attempts, send_attempts; unsigned int redirects; uint64_t sent_global_ioloop_usecs; uint64_t sent_http_ioloop_usecs; diff --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index dddadd8975..8ba2f5df45 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -703,7 +703,8 @@ void http_client_request_get_stats(struct http_client_request *req, /* number of attempts for this request */ stats_r->attempts = req->attempts; - + /* number of send attempts for this request */ + stats_r->send_attempts = req->send_attempts; } void http_client_request_append_stats_text(struct http_client_request *req, @@ -720,14 +721,16 @@ void http_client_request_append_stats_text(struct http_client_request *req, str_printfa(str, "queued %u.%03u secs ago", stats.total_msecs/1000, stats.total_msecs%1000); + if (stats.attempts > 0) + str_printfa(str, ", %u times retried", stats.attempts); - if (stats.first_sent_msecs == 0) + if (stats.send_attempts == 0) { str_append(str, ", not yet sent"); - else { - str_printfa(str, ", %u attempts in %u.%03u secs", - stats.attempts + 1, + } else { + str_printfa(str, ", %u send attempts in %u.%03u secs", + stats.send_attempts, stats.first_sent_msecs/1000, stats.first_sent_msecs%1000); - if (stats.attempts > 0) { + if (stats.send_attempts > 1) { str_printfa(str, ", %u.%03u in last attempt", stats.last_sent_msecs/1000, stats.last_sent_msecs%1000); @@ -1294,6 +1297,7 @@ static int http_client_request_send_real(struct http_client_request *req, iov[2].iov_len = 2; req->state = HTTP_REQUEST_STATE_PAYLOAD_OUT; + req->send_attempts++; if (req->first_sent_time.tv_sec == 0) req->first_sent_time = ioloop_timeval; req->sent_time = ioloop_timeval; diff --git a/src/lib-http/http-client.h b/src/lib-http/http-client.h index 7c530f5049..eee589bf21 100644 --- a/src/lib-http/http-client.h +++ b/src/lib-http/http-client.h @@ -201,8 +201,11 @@ struct http_client_request_stats { /* Total time spent on waiting for file locks */ unsigned int lock_msecs; - /* Number of attempts for this request */ + /* Number of times this request was retried */ unsigned int attempts; + /* Number of times the client attempted to actually send the request + to a server */ + unsigned int send_attempts; }; typedef void