Skip to content

Commit c40e68a

Browse files
http: add trace2 logging for retry operations
Add trace2 instrumentation to HTTP 429 retry operations to enable monitoring and debugging of rate limit scenarios in production environments. The trace2 logging captures: * Retry attempt numbers (http/429-retry-attempt) to track retry progression and identify how many attempts were needed * Retry-After header values (http/429-retry-after) from server responses to understand server-requested delays * Actual sleep durations (http/retry-sleep-seconds) within trace2 regions (http/retry-sleep) to measure time spent waiting * Error conditions (http/429-error) such as "retries-exhausted", "exceeds-max-retry-time", "no-retry-after-config", and "config-exceeds-max-retry-time" for diagnosing failures * Retry source (http/429-retry-source) indicating whether delay came from server header or config default This instrumentation provides complete visibility into retry behavior, enabling operators to monitor rate limiting patterns, diagnose retry failures, and optimize retry configuration based on real-world data.
1 parent 3b654b2 commit c40e68a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

http.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "odb.h"
2424
#include "tempfile.h"
2525
#include "date.h"
26+
#include "trace2.h"
2627

2728
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
2829
static int trace_curl_data = 1;
@@ -1738,6 +1739,8 @@ void run_active_slot(struct active_request_slot *slot)
17381739

17391740
if (waiting_for_delay) {
17401741
warning(_("rate limited, waiting %ld seconds before retry"), slot->retry_delay_seconds);
1742+
trace2_data_intmax("http", the_repository, "http/retry-sleep-seconds",
1743+
slot->retry_delay_seconds);
17411744
start_time = slot->retry_delay_start;
17421745
}
17431746

@@ -1753,6 +1756,7 @@ void run_active_slot(struct active_request_slot *slot)
17531756
}
17541757

17551758
if (elapsed_time.tv_sec >= slot->retry_delay_seconds) {
1759+
trace2_region_leave("http", "retry-sleep", the_repository);
17561760
slot->retry_delay_seconds = -1;
17571761
waiting_for_delay = 0;
17581762

@@ -1995,6 +1999,8 @@ static int handle_curl_result(struct slot_results *results)
19951999
return HTTP_REAUTH;
19962000
}
19972001
} else if (results->http_code == 429) {
2002+
trace2_data_intmax("http", the_repository, "http/429-retry-after",
2003+
results->retry_after);
19982004
return HTTP_RATE_LIMITED;
19992005
} else {
20002006
if (results->http_connectcode == 407)
@@ -2421,10 +2427,16 @@ static void sleep_for_retry(struct active_request_slot *slot, long retry_after)
24212427
static long handle_rate_limit_retry(int *rate_limit_retries, long slot_retry_after)
24222428
{
24232429
int retry_attempt = http_max_retries - *rate_limit_retries + 1;
2430+
2431+
trace2_data_intmax("http", the_repository, "http/429-retry-attempt",
2432+
retry_attempt);
2433+
24242434
if (*rate_limit_retries <= 0) {
24252435
/* Retries are disabled or exhausted */
24262436
if (http_max_retries > 0) {
24272437
error(_("too many rate limit retries, giving up"));
2438+
trace2_data_string("http", the_repository,
2439+
"http/429-error", "retries-exhausted");
24282440
}
24292441
return -1;
24302442
}
@@ -2439,6 +2451,10 @@ static long handle_rate_limit_retry(int *rate_limit_retries, long slot_retry_aft
24392451
error(_("rate limited (HTTP 429) requested %ld second delay, "
24402452
"exceeds http.maxRetryTime of %ld seconds"),
24412453
slot_retry_after, http_max_retry_time);
2454+
trace2_data_string("http", the_repository,
2455+
"http/429-error", "exceeds-max-retry-time");
2456+
trace2_data_intmax("http", the_repository,
2457+
"http/429-requested-delay", slot_retry_after);
24422458
return -1;
24432459
}
24442460
return slot_retry_after;
@@ -2448,16 +2464,21 @@ static long handle_rate_limit_retry(int *rate_limit_retries, long slot_retry_aft
24482464
/* Not configured - exit with error */
24492465
error(_("rate limited (HTTP 429) and no Retry-After header provided. "
24502466
"Configure http.retryAfter or set GIT_HTTP_RETRY_AFTER."));
2467+
trace2_data_string("http", the_repository,
2468+
"http/429-error", "no-retry-after-config");
24512469
return -1;
24522470
}
24532471
/* Check if configured default exceeds maximum allowed */
24542472
if (http_retry_after > http_max_retry_time) {
24552473
error(_("configured http.retryAfter (%ld seconds) exceeds "
24562474
"http.maxRetryTime (%ld seconds)"),
24572475
http_retry_after, http_max_retry_time);
2476+
trace2_data_string("http", the_repository,
2477+
"http/429-error", "config-exceeds-max-retry-time");
24582478
return -1;
24592479
}
2460-
2480+
trace2_data_string("http", the_repository,
2481+
"http/429-retry-source", "config-default");
24612482
return http_retry_after;
24622483
}
24632484
}

0 commit comments

Comments
 (0)