I have a method implementing the GCP Storage API in .net 6 as follows:
byte[] imageDataBytes;
string bucketName = _configuration["UPLOADS_BUCKET"];
var storage = StorageClient.Create();
using (var memoryStream = new MemoryStream())
{
try
{
await storage.DownloadObjectAsync(
bucketName,
GetImageDestination(application, environment, imageId, imageExt, width, height),
memoryStream);
}
catch (GoogleApiException e)
{
if (e.HttpStatusCode == HttpStatusCode.NotFound)
{
throw new ImageNotFoundException();
}
_logger.LogError(LogEvent.StorageFail, e, "Unhandled GoogleAPIException thrown.");
throw;
}
imageDataBytes = memoryStream.ToArray();
}
return imageDataBytes;
I have logged some (exceptionally infrequent) 503 errors when attempting to access files when GCP wasn't available. Looking into implementing a retry, documentation shows the C# client library implements an exponential backoff by default.
Is there a way to log this backoff process and each GCP API retry?
Many thanks!
Solved! Go to Solution.
Hi @BRH,
As of the moment we won't be able to check for the status to determine retries when using C#. I found this documentation wherein the author is using Python as not all exponential backoff logs are available in other languages. That's why I would like to request to file this one as a feature request however it's not a guarantee that this would be immediately available in future updates.