Skip to content

Commit

Permalink
lib-http: client: Fix request statistics text to properly report send…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
stephanbosch committed Feb 27, 2018
1 parent 5441373 commit eaf49d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lib-http/http-client-private.h
Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions src/lib-http/http-client-request.c
Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/lib-http/http-client.h
Expand Up @@ -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
Expand Down

0 comments on commit eaf49d9

Please sign in to comment.