Skip to content

Commit

Permalink
Logging Rate Limit Error to So we can Share with DevOps Artifact Team (
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu authored Mar 22, 2024
1 parent 1990a3f commit 3a1008a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ public async Task<Stream> DownloadPackageArtifact(string repoName, string buildI
private async Task<HttpResponseMessage> GetFromDevopsAsync(string request)
{
var downloadResp = await _devopsClient.GetAsync(request);


if (!downloadResp.IsSuccessStatusCode)
{
var retryAfter = downloadResp.Headers.GetValues("Retry-After");
var rateLimitResource = downloadResp.Headers.GetValues("X-RateLimit-Resource");
var rateLimitDelay = downloadResp.Headers.GetValues("X-RateLimit-Delay");
var rateLimitLimit = downloadResp.Headers .GetValues("X-RateLimit-Limit");
var rateLimitRemaining = downloadResp.Headers.GetValues("X-RateLimit-Remaining");
var rateLimitReset = downloadResp.Headers.GetValues("X-RateLimit-Reset");

var traceMessage = $"request: {request} failed with statusCode: {downloadResp.StatusCode}," +
$"retryAfter: {retryAfter}, rateLimitResource: {rateLimitResource}, rateLimitDelay: {rateLimitDelay}," +
$"rateLimitLimit: {rateLimitLimit}, rateLimitRemaining: {rateLimitRemaining}, rateLimitReset: {rateLimitReset}";

_telemetryClient.TrackTrace(traceMessage);
}

int count = 0;
int[] waitTimes = new int[] { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256 };
while ((downloadResp.StatusCode == HttpStatusCode.TooManyRequests || downloadResp.StatusCode == HttpStatusCode.BadRequest) && count < waitTimes.Length)
Expand Down

0 comments on commit 3a1008a

Please sign in to comment.