Skip to content

Commit

Permalink
Merge pull request #28 from microsoft/improve_logging
Browse files Browse the repository at this point in the history
Improve logging and request timeout handling
  • Loading branch information
alberto-baron authored Jul 26, 2022
2 parents 97d2b9d + 809e2a8 commit 18d30d5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/PackageUploader.Application/Operations/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public async Task<int> RunAsync(CancellationToken ct)
await ProcessAsync(ct).ConfigureAwait(false);
return 0;
}
catch (TaskCanceledException)
{
_logger.LogWarning("Operation cancelled.");
return 1;
}
catch (Exception e)
{
_logger.LogError(e.Message);
_logger.LogTrace(e, "Exception thrown.");
if (ct.IsCancellationRequested)
{
_logger.LogWarning("Operation cancelled.");
return 1;
}
_logger.LogError(e.Message);
return 3;
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override async Task ProcessAsync(CancellationToken ct)
var packageBranch = await _storeBrokerService.GetGamePackageBranch(product, _config, ct).ConfigureAwait(false);
var marketGroupPackage = await _storeBrokerService.GetGameMarketGroupPackage(product, packageBranch, _config, ct).ConfigureAwait(false);

var delta = false; // Unfortunately UWP cannot and never will support delta upload.
const bool delta = false; // Unfortunately UWP cannot and never will support delta upload.
var gamePackage = await _storeBrokerService.UploadGamePackageAsync(product, packageBranch, marketGroupPackage, _config.PackageFilePath, null, _config.MinutesToWaitForProcessing, delta, ct).ConfigureAwait(false);
_logger.LogInformation("Uploaded package with id: {gamePackageId}", gamePackage.Id);

Expand Down
1 change: 1 addition & 0 deletions src/PackageUploader.Application/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private static void ConfigureLogging(HostBuilderContext context, ILoggingBuilder
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Warning);
logging.AddFilter("PackageUploader", invocationContext.GetOptionValue(VerboseOption) ? LogLevel.Trace : LogLevel.Information);
logging.AddFilter<FileLoggerProvider>("PackageUploader", LogLevel.Trace);
logging.AddSimpleFile(options =>
{
options.SingleLine = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Polly;
using Polly.Contrib.WaitAndRetry;
using Polly.Extensions.Http;
using Polly.Timeout;
using System;
using System.Net.Http;
using System.Net.Mime;

namespace PackageUploader.ClientApi.Client.Ingestion;
Expand All @@ -25,14 +27,18 @@ public static IServiceCollection AddIngestionService(this IServiceCollection ser

var ingestionConfig = serviceProvider.GetRequiredService<IOptions<IngestionConfig>>().Value;
httpClient.BaseAddress = new Uri(ingestionConfig.BaseAddress);
httpClient.Timeout = TimeSpan.FromMilliseconds(ingestionConfig.HttpTimeoutMs);
})
.AddHttpMessageHandler<IngestionAuthenticationDelegatingHandler>()
.AddPolicyHandler((serviceProvider, httpRequestMessage) =>
{
var ingestionConfig = serviceProvider.GetRequiredService<IOptions<IngestionConfig>>().Value;
var delay = Backoff.DecorrelatedJitterBackoffV2(TimeSpan.FromMilliseconds(ingestionConfig.MedianFirstRetryDelayMs), ingestionConfig.RetryCount);
return HttpPolicyExtensions.HandleTransientHttpError().WaitAndRetryAsync(delay);
return HttpPolicyExtensions.HandleTransientHttpError().Or<TimeoutRejectedException>().WaitAndRetryAsync(delay);
})
.AddPolicyHandler((serviceProvider, httpRequestMessage) =>
{
var ingestionConfig = serviceProvider.GetRequiredService<IOptions<IngestionConfig>>().Value;
return Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromMilliseconds(ingestionConfig.HttpTimeoutMs));
});

return services;
Expand Down

0 comments on commit 18d30d5

Please sign in to comment.