private ExportResult HandleFailures(HttpMessage httpMessage) { ExportResult result = ExportResult.Failure; byte[] content; int retryInterval; if (!httpMessage.HasResponse) { // HttpRequestException content = HttpPipelineHelper.GetRequestContent(httpMessage.Request.Content); result = _storage.SaveTelemetry(content, HttpPipelineHelper.MinimumRetryInterval); } else { switch (httpMessage.Response.Status) { case ResponseStatusCodes.PartialSuccess: // Parse retry-after header // Send Failed Messages To Storage TrackResponse trackResponse = HttpPipelineHelper.GetTrackResponse(httpMessage); content = HttpPipelineHelper.GetPartialContentForRetry(trackResponse, httpMessage.Request.Content); if (content != null) { retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); result = _storage.SaveTelemetry(content, retryInterval); } break; case ResponseStatusCodes.RequestTimeout: case ResponseStatusCodes.ResponseCodeTooManyRequests: case ResponseStatusCodes.ResponseCodeTooManyRequestsAndRefreshCache: // Parse retry-after header // Send Messages To Storage content = HttpPipelineHelper.GetRequestContent(httpMessage.Request.Content); retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); result = _storage.SaveTelemetry(content, retryInterval); break; case ResponseStatusCodes.InternalServerError: case ResponseStatusCodes.BadGateway: case ResponseStatusCodes.ServiceUnavailable: case ResponseStatusCodes.GatewayTimeout: // Send Messages To Storage content = HttpPipelineHelper.GetRequestContent(httpMessage.Request.Content); result = _storage.SaveTelemetry(content, HttpPipelineHelper.MinimumRetryInterval); break; default: // Log Non-Retriable Status and don't retry or store; break; } } return(result); }
private void HandleFailures(HttpMessage httpMessage, IPersistentBlob blob) { int retryInterval; if (!httpMessage.HasResponse) { // HttpRequestException // Extend lease time so that it is not picked again for retry. blob.Lease(HttpPipelineHelper.MinimumRetryInterval); } else { switch (httpMessage.Response.Status) { case ResponseStatusCodes.PartialSuccess: // Parse retry-after header // Send Failed Messages To Storage // Delete existing file TrackResponse trackResponse = HttpPipelineHelper.GetTrackResponse(httpMessage); var content = HttpPipelineHelper.GetPartialContentForRetry(trackResponse, httpMessage.Request.Content); if (content != null) { retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Delete(); _storage.SaveTelemetry(content, retryInterval); } break; case ResponseStatusCodes.RequestTimeout: case ResponseStatusCodes.ResponseCodeTooManyRequests: case ResponseStatusCodes.ResponseCodeTooManyRequestsAndRefreshCache: // Extend lease time using retry interval period // so that it is not picked up again before that. retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Lease(retryInterval); break; case ResponseStatusCodes.InternalServerError: case ResponseStatusCodes.BadGateway: case ResponseStatusCodes.ServiceUnavailable: case ResponseStatusCodes.GatewayTimeout: // Extend lease time so that it is not picked up again blob.Lease(HttpPipelineHelper.MinimumRetryInterval); break; default: // Log Non-Retriable Status and don't retry or store; // File will be cleared by maintenance job break; } } }
private void HandleFailures(HttpMessage httpMessage, IPersistentBlob blob) { int retryInterval; int statusCode = 0; bool shouldRetry = true; if (!httpMessage.HasResponse) { // HttpRequestException // Extend lease time so that it is not picked again for retry. blob.Lease(HttpPipelineHelper.MinimumRetryInterval); } else { statusCode = httpMessage.Response.Status; switch (statusCode) { case ResponseStatusCodes.PartialSuccess: // Parse retry-after header // Send Failed Messages To Storage // Delete existing file TrackResponse trackResponse = HttpPipelineHelper.GetTrackResponse(httpMessage); var content = HttpPipelineHelper.GetPartialContentForRetry(trackResponse, httpMessage.Request.Content); if (content != null) { retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Delete(); _storage.SaveTelemetry(content, retryInterval); } break; case ResponseStatusCodes.RequestTimeout: case ResponseStatusCodes.ResponseCodeTooManyRequests: case ResponseStatusCodes.ResponseCodeTooManyRequestsAndRefreshCache: // Extend lease time using retry interval period // so that it is not picked up again before that. retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Lease(retryInterval); break; case ResponseStatusCodes.InternalServerError: case ResponseStatusCodes.BadGateway: case ResponseStatusCodes.ServiceUnavailable: case ResponseStatusCodes.GatewayTimeout: // Extend lease time so that it is not picked up again blob.Lease(HttpPipelineHelper.MinimumRetryInterval); break; default: // Log Non-Retriable Status and don't retry or store; // File will be cleared by maintenance job shouldRetry = false; break; } } if (shouldRetry) { AzureMonitorExporterEventSource.Log.WriteWarning("FailedToTransmitFromStorage", $"Error code is {statusCode}: Telemetry is stored offline for retry"); } else { AzureMonitorExporterEventSource.Log.WriteWarning("FailedToTransmitFromStorage", $"Error code is {statusCode}: Telemetry is dropped"); } }
private ExportResult HandleFailures(HttpMessage httpMessage) { ExportResult result = ExportResult.Failure; int statusCode = 0; byte[] content; int retryInterval; if (!httpMessage.HasResponse) { // HttpRequestException content = HttpPipelineHelper.GetRequestContent(httpMessage.Request.Content); result = _storage.SaveTelemetry(content, HttpPipelineHelper.MinimumRetryInterval); } else { statusCode = httpMessage.Response.Status; switch (statusCode) { case ResponseStatusCodes.PartialSuccess: // Parse retry-after header // Send Failed Messages To Storage TrackResponse trackResponse = HttpPipelineHelper.GetTrackResponse(httpMessage); content = HttpPipelineHelper.GetPartialContentForRetry(trackResponse, httpMessage.Request.Content); if (content != null) { retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); result = _storage.SaveTelemetry(content, retryInterval); } break; case ResponseStatusCodes.RequestTimeout: case ResponseStatusCodes.ResponseCodeTooManyRequests: case ResponseStatusCodes.ResponseCodeTooManyRequestsAndRefreshCache: // Parse retry-after header // Send Messages To Storage content = HttpPipelineHelper.GetRequestContent(httpMessage.Request.Content); retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); result = _storage.SaveTelemetry(content, retryInterval); break; case ResponseStatusCodes.InternalServerError: case ResponseStatusCodes.BadGateway: case ResponseStatusCodes.ServiceUnavailable: case ResponseStatusCodes.GatewayTimeout: // Send Messages To Storage content = HttpPipelineHelper.GetRequestContent(httpMessage.Request.Content); result = _storage.SaveTelemetry(content, HttpPipelineHelper.MinimumRetryInterval); break; default: // Log Non-Retriable Status and don't retry or store; break; } } if (result == ExportResult.Success) { AzureMonitorExporterEventSource.Log.WriteWarning("FailedToTransmit", $"Error code is {statusCode}: Telemetry is stored offline for retry"); } else { AzureMonitorExporterEventSource.Log.WriteWarning("FailedToTransmit", $"Error code is {statusCode}: Telemetry is dropped"); } return(result); }