diff --git a/build/docker-images/HealthChecks.UI.Image/Extensions/IEndpointRouteBuilderExtensions.cs b/build/docker-images/HealthChecks.UI.Image/Extensions/IEndpointRouteBuilderExtensions.cs index fcf588bb85..7972ea1568 100644 --- a/build/docker-images/HealthChecks.UI.Image/Extensions/IEndpointRouteBuilderExtensions.cs +++ b/build/docker-images/HealthChecks.UI.Image/Extensions/IEndpointRouteBuilderExtensions.cs @@ -33,7 +33,7 @@ private static void MapHealthCheckPushEndpoint(this IEndpointRouteBuilder builde if (context.Request.IsAuthenticated()) { using var streamReader = new StreamReader(context.Request.Body); - var content = await streamReader.ReadToEndAsync(); + var content = await streamReader.ReadToEndAsync().ConfigureAwait(false); var endpoint = JsonDocument.Parse(content); var root = endpoint.RootElement; @@ -47,15 +47,15 @@ private static void MapHealthCheckPushEndpoint(this IEndpointRouteBuilder builde if (type == PushServiceKeys.ServiceAdded) { - await pushService.AddAsync(name, uri); + await pushService.AddAsync(name, uri).ConfigureAwait(false); } else if (type == PushServiceKeys.ServiceRemoved) { - await pushService.RemoveAsync(name); + await pushService.RemoveAsync(name).ConfigureAwait(false); } else if (type == PushServiceKeys.ServiceUpdated) { - await pushService.UpdateAsync(name, uri); + await pushService.UpdateAsync(name, uri).ConfigureAwait(false); } } } diff --git a/build/docker-images/HealthChecks.UI.Image/PushService/HealthChecksPushService.cs b/build/docker-images/HealthChecks.UI.Image/PushService/HealthChecksPushService.cs index b2fe1fcab5..6e121190dd 100644 --- a/build/docker-images/HealthChecks.UI.Image/PushService/HealthChecksPushService.cs +++ b/build/docker-images/HealthChecks.UI.Image/PushService/HealthChecksPushService.cs @@ -16,16 +16,16 @@ public HealthChecksPushService(HealthChecksDb db, ILoggerLinux ..\.. $(HealthChecksUIK8sOperator) - $(WarningsNotAsErrors);RCS1090 + $(NoWarn);RCS1090 diff --git a/src/HealthChecks.UI/Core/Discovery/K8S/Extensions/IKubernetesExtensions.cs b/src/HealthChecks.UI/Core/Discovery/K8S/Extensions/IKubernetesExtensions.cs index d451458fd6..94dd59a1aa 100644 --- a/src/HealthChecks.UI/Core/Discovery/K8S/Extensions/IKubernetesExtensions.cs +++ b/src/HealthChecks.UI/Core/Discovery/K8S/Extensions/IKubernetesExtensions.cs @@ -10,11 +10,11 @@ internal static async Task GetServicesAsync(this IKubernetes clie { if (k8sNamespaces is null || k8sNamespaces.Count == 0) { - return await client.CoreV1.ListServiceForAllNamespacesAsync(labelSelector: label, cancellationToken: cancellationToken); + return await client.CoreV1.ListServiceForAllNamespacesAsync(labelSelector: label, cancellationToken: cancellationToken).ConfigureAwait(false); } else { - var responses = await Task.WhenAll(k8sNamespaces.Select(k8sNamespace => client.CoreV1.ListNamespacedServiceAsync(k8sNamespace, labelSelector: label, cancellationToken: cancellationToken))); + var responses = await Task.WhenAll(k8sNamespaces.Select(k8sNamespace => client.CoreV1.ListNamespacedServiceAsync(k8sNamespace, labelSelector: label, cancellationToken: cancellationToken))).ConfigureAwait(false); return new V1ServiceList() { diff --git a/src/HealthChecks.UI/Core/Discovery/K8S/KubernetesDiscoveryHostedService.cs b/src/HealthChecks.UI/Core/Discovery/K8S/KubernetesDiscoveryHostedService.cs index 2f00e3936f..9afdf5aed4 100644 --- a/src/HealthChecks.UI/Core/Discovery/K8S/KubernetesDiscoveryHostedService.cs +++ b/src/HealthChecks.UI/Core/Discovery/K8S/KubernetesDiscoveryHostedService.cs @@ -68,7 +68,7 @@ private Task ExecuteAsync(CancellationToken cancellationToken) #pragma warning disable IDISP003 // Dispose previous before re-assigning _discoveryClient = InitializeKubernetesClient(); #pragma warning restore IDISP003 // Dispose previous before re-assigning - await StartK8sServiceAsync(cancellationToken); + await StartK8sServiceAsync(cancellationToken).ConfigureAwait(false); } catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested) { @@ -84,7 +84,7 @@ private Task ExecuteAsync(CancellationToken cancellationToken) public async Task StopAsync(CancellationToken cancellationToken) { if (_executingTask != null) - await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken)); + await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken)).ConfigureAwait(false); } private async Task StartK8sServiceAsync(CancellationToken cancellationToken) @@ -99,7 +99,7 @@ private async Task StartK8sServiceAsync(CancellationToken cancellationToken) try { - var services = await _discoveryClient!.GetServicesAsync(_discoveryOptions.ServicesLabel, _discoveryOptions.Namespaces, cancellationToken); + var services = await _discoveryClient!.GetServicesAsync(_discoveryOptions.ServicesLabel, _discoveryOptions.Namespaces, cancellationToken).ConfigureAwait(false); if (services != null) { @@ -111,10 +111,10 @@ private async Task StartK8sServiceAsync(CancellationToken cancellationToken) if (serviceAddress != null && !IsLivenessRegistered(livenessDbContext, serviceAddress)) { - var statusCode = await CallClusterServiceAsync(serviceAddress); + var statusCode = await CallClusterServiceAsync(serviceAddress).ConfigureAwait(false); if (IsValidHealthChecksStatusCode(statusCode)) { - await RegisterDiscoveredLiveness(livenessDbContext, serviceAddress, item.Metadata.Name); + await RegisterDiscoveredLiveness(livenessDbContext, serviceAddress, item.Metadata.Name).ConfigureAwait(false); _logger.LogInformation($"Registered discovered liveness on {serviceAddress} with name {item.Metadata.Name}"); } } @@ -131,7 +131,7 @@ private async Task StartK8sServiceAsync(CancellationToken cancellationToken) _logger.LogError(ex, "An error occurred on kubernetes service discovery"); } - await Task.Delay(_discoveryOptions.RefreshTimeInSeconds * 1000); + await Task.Delay(_discoveryOptions.RefreshTimeInSeconds * 1000).ConfigureAwait(false); } } @@ -148,7 +148,7 @@ private static bool IsValidHealthChecksStatusCode(HttpStatusCode statusCode) private async Task CallClusterServiceAsync(string host) { - using var response = await _clusterServiceClient.GetAsync(host, HttpCompletionOption.ResponseHeadersRead); + using var response = await _clusterServiceClient.GetAsync(host, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); return response.StatusCode; } diff --git a/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs b/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs index 4d7a96d7d6..bd9a50c33b 100644 --- a/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs +++ b/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollector.cs @@ -54,7 +54,7 @@ public async Task Collect(CancellationToken cancellationToken) { using (_logger.BeginScope("HealthReportCollector is collecting health checks results.")) { - var healthChecks = await _db.Configurations.ToListAsync(cancellationToken); + var healthChecks = await _db.Configurations.ToListAsync(cancellationToken).ConfigureAwait(false); foreach (var item in healthChecks.OrderBy(h => h.Id)) { @@ -66,31 +66,31 @@ public async Task Collect(CancellationToken cancellationToken) foreach (var interceptor in _interceptors) { - await interceptor.OnCollectExecuting(item); + await interceptor.OnCollectExecuting(item).ConfigureAwait(false); } - var healthReport = await GetHealthReportAsync(item); + var healthReport = await GetHealthReportAsync(item).ConfigureAwait(false); if (healthReport.Status != UIHealthStatus.Healthy) { - if (!_settings.NotifyUnHealthyOneTimeUntilChange || await ShouldNotifyAsync(item.Name)) + if (!_settings.NotifyUnHealthyOneTimeUntilChange || await ShouldNotifyAsync(item.Name).ConfigureAwait(false)) { - await _healthCheckFailureNotifier.NotifyDown(item.Name, healthReport); + await _healthCheckFailureNotifier.NotifyDown(item.Name, healthReport).ConfigureAwait(false); } } else { - if (await HasLivenessRecoveredFromFailureAsync(item)) + if (await HasLivenessRecoveredFromFailureAsync(item).ConfigureAwait(false)) { - await _healthCheckFailureNotifier.NotifyWakeUp(item.Name); + await _healthCheckFailureNotifier.NotifyWakeUp(item.Name).ConfigureAwait(false); } } - await SaveExecutionHistoryAsync(item, healthReport); + await SaveExecutionHistoryAsync(item, healthReport).ConfigureAwait(false); foreach (var interceptor in _interceptors) { - await interceptor.OnCollectExecuted(healthReport); + await interceptor.OnCollectExecuted(healthReport).ConfigureAwait(false); } } @@ -135,18 +135,18 @@ private async Task GetHealthReportAsync(HealthCheckConfiguration using var requestMessage = new HttpRequestMessage(HttpMethod.Get, absoluteUri); requestMessage.Headers.Authorization = new BasicAuthenticationHeaderValue(userInfoArr[0], userInfoArr[1]); - response = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead); + response = await _httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); } } - response ??= await _httpClient.GetAsync(absoluteUri, HttpCompletionOption.ResponseHeadersRead); + response ??= await _httpClient.GetAsync(absoluteUri, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); using (response) { if (!response.IsSuccessStatusCode && response.Content.Headers.ContentType?.MediaType != "application/json") return UIHealthReport.CreateFrom(new InvalidOperationException($"HTTP response is not in valid state ({response.StatusCode}) when trying to get report from {uri} configured with name {name}.")); - return await response.Content.ReadFromJsonAsync(_options) + return await response.Content.ReadFromJsonAsync(_options).ConfigureAwait(false) ?? throw new InvalidOperationException($"{nameof(HttpContentJsonExtensions.ReadFromJsonAsync)} returned null"); } } @@ -182,7 +182,7 @@ private Uri GetEndpointUri(HealthCheckConfiguration configuration) private async Task HasLivenessRecoveredFromFailureAsync(HealthCheckConfiguration configuration) { - var previous = await GetHealthCheckExecutionAsync(configuration); + var previous = await GetHealthCheckExecutionAsync(configuration).ConfigureAwait(false); return previous != null && previous.Status != UIHealthStatus.Healthy; } @@ -193,7 +193,8 @@ private async Task HasLivenessRecoveredFromFailureAsync(HealthCheckConfigu .Include(le => le.History) .Include(le => le.Entries) .Where(le => le.Name == configuration.Name) - .SingleOrDefaultAsync(); + .SingleOrDefaultAsync() + .ConfigureAwait(false); } private async Task ShouldNotifyAsync(string healthCheckName) @@ -202,7 +203,7 @@ private async Task ShouldNotifyAsync(string healthCheckName) var lastNotifications = await _db.Failures .Where(lf => string.Equals(lf.HealthCheckName, healthCheckName)) .OrderByDescending(lf => lf.LastNotified) - .Take(2).ToListAsync(); + .Take(2).ToListAsync().ConfigureAwait(false); #pragma warning restore RCS1155 // Use StringComparison when comparing strings. if (lastNotifications?.Count == 2) @@ -222,7 +223,7 @@ private async Task SaveExecutionHistoryAsync(HealthCheckConfiguration configurat { _logger.LogDebug("HealthReportCollector - health report execution history saved."); - var execution = await GetHealthCheckExecutionAsync(configuration); + var execution = await GetHealthCheckExecutionAsync(configuration).ConfigureAwait(false); var lastExecutionTime = DateTime.UtcNow; @@ -288,10 +289,11 @@ private async Task SaveExecutionHistoryAsync(HealthCheckConfiguration configurat }; await _db.Executions - .AddAsync(execution); + .AddAsync(execution) + .ConfigureAwait(false); } - await _db.SaveChangesAsync(); + await _db.SaveChangesAsync().ConfigureAwait(false); } private static void UpdateUris(HealthCheckExecution execution, HealthCheckConfiguration configuration) diff --git a/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollectorHostedService.cs b/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollectorHostedService.cs index 6bae19c551..8abb78ead7 100644 --- a/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollectorHostedService.cs +++ b/src/HealthChecks.UI/Core/HostedService/HealthCheckReportCollectorHostedService.cs @@ -46,7 +46,7 @@ public async Task StopAsync(CancellationToken cancellationToken) _cancellationTokenSource.Cancel(); if (_executingTask != null) - await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken)); + await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken)).ConfigureAwait(false); } private Task ExecuteAsync(CancellationToken cancellationToken) @@ -55,7 +55,7 @@ private Task ExecuteAsync(CancellationToken cancellationToken) { try { - await CollectAsync(cancellationToken); + await CollectAsync(cancellationToken).ConfigureAwait(false); } catch (TaskCanceledException) when (cancellationToken.IsCancellationRequested) { @@ -81,7 +81,7 @@ private async Task CollectAsync(CancellationToken cancellationToken) try { var runner = scope.ServiceProvider.GetRequiredService(); - await runner.Collect(cancellationToken); + await runner.Collect(cancellationToken).ConfigureAwait(false); _logger.LogDebug("HealthCheck collector HostedService executed successfully."); } @@ -91,7 +91,7 @@ private async Task CollectAsync(CancellationToken cancellationToken) } } - await Task.Delay(_settings.EvaluationTimeInSeconds * 1000, cancellationToken); + await Task.Delay(_settings.EvaluationTimeInSeconds * 1000, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/HealthChecks.UI/Core/HostedService/UIInitializationHostedService.cs b/src/HealthChecks.UI/Core/HostedService/UIInitializationHostedService.cs index 0c241c43d8..a00c589415 100644 --- a/src/HealthChecks.UI/Core/HostedService/UIInitializationHostedService.cs +++ b/src/HealthChecks.UI/Core/HostedService/UIInitializationHostedService.cs @@ -31,7 +31,7 @@ public async Task StartAsync(CancellationToken cancellationToken) var scopeFactory = _provider.GetRequiredService(); using var scope = scopeFactory.CreateScope(); - await InitializeDatabaseAsync(scope.ServiceProvider); + await InitializeDatabaseAsync(scope.ServiceProvider).ConfigureAwait(false); } public Task StopAsync(CancellationToken cancellationToken) @@ -45,10 +45,10 @@ private async Task InitializeDatabaseAsync(IServiceProvider sp) var configuration = sp.GetRequiredService(); var settings = sp.GetRequiredService>(); - if (await ShouldMigrateDatabaseAsync(context)) + if (await ShouldMigrateDatabaseAsync(context).ConfigureAwait(false)) { _logger.LogInformation("Executing database migrations"); - await context.Database.MigrateAsync(); + await context.Database.MigrateAsync().ConfigureAwait(false); } var healthCheckConfigurations = settings.Value? @@ -59,19 +59,20 @@ private async Task InitializeDatabaseAsync(IServiceProvider sp) Uri = s.Uri }); - bool isInitialized = await context.Configurations.AnyAsync(); + bool isInitialized = await context.Configurations.AnyAsync().ConfigureAwait(false); if (!isInitialized && healthCheckConfigurations != null && healthCheckConfigurations.Any()) { _logger.LogInformation("Saving healthchecks configuration to database"); await context.Configurations - .AddRangeAsync(healthCheckConfigurations); + .AddRangeAsync(healthCheckConfigurations) + .ConfigureAwait(false); } else if (isInitialized && healthCheckConfigurations != null && healthCheckConfigurations.Any()) { - var dbConfigurations = await context.Configurations.ToListAsync(); + var dbConfigurations = await context.Configurations.ToListAsync().ConfigureAwait(false); var existingConfigurations = dbConfigurations .Where(hc => healthCheckConfigurations.Any(dbc => string.Equals(hc.Name, dbc.Name, StringComparison.InvariantCultureIgnoreCase))); @@ -94,18 +95,18 @@ await context.Configurations foreach (var item in newConfigurations) { _logger.LogInformation("Adding new service {service} to database", item.Name); - await context.AddAsync(item); + await context.AddAsync(item).ConfigureAwait(false); } } } - await context.SaveChangesAsync(); + await context.SaveChangesAsync().ConfigureAwait(false); } private async Task ShouldMigrateDatabaseAsync(HealthChecksDb context) { return !_settings.DisableMigrations && !context.Database.IsInMemory() && - (await context.Database.GetPendingMigrationsAsync()).Any(); + (await context.Database.GetPendingMigrationsAsync().ConfigureAwait(false)).Any(); } } diff --git a/src/HealthChecks.UI/Core/Notifications/WebHookFailureNotifier.cs b/src/HealthChecks.UI/Core/Notifications/WebHookFailureNotifier.cs index a0f43b78ec..a0f9d081b2 100644 --- a/src/HealthChecks.UI/Core/Notifications/WebHookFailureNotifier.cs +++ b/src/HealthChecks.UI/Core/Notifications/WebHookFailureNotifier.cs @@ -33,12 +33,12 @@ public WebHookFailureNotifier( public async Task NotifyDown(string name, UIHealthReport report) { - await NotifyAsync(name, report, isHealthy: false); + await NotifyAsync(name, report, isHealthy: false).ConfigureAwait(false); } public async Task NotifyWakeUp(string name) { - await NotifyAsync(name, null!, isHealthy: true); // TODO: why null! ? + await NotifyAsync(name, null!, isHealthy: true).ConfigureAwait(false); // TODO: why null! ? } internal async Task NotifyAsync(string name, UIHealthReport report, bool isHealthy = false) @@ -46,14 +46,14 @@ internal async Task NotifyAsync(string name, UIHealthReport report, bool isHealt string? failure = default; string? description = default; - if (!await IsNotifiedOnWindowTimeAsync(name, isHealthy)) + if (!await IsNotifiedOnWindowTimeAsync(name, isHealthy).ConfigureAwait(false)) { await SaveNotificationAsync(new HealthCheckFailureNotification() { LastNotified = DateTime.UtcNow, HealthCheckName = name, IsUpAndRunning = isHealthy - }); + }).ConfigureAwait(false); foreach (var webHook in _settings.Webhooks) { @@ -86,7 +86,7 @@ await SaveNotificationAsync(new HealthCheckFailureNotification() if (absoluteUri == null) throw new InvalidOperationException("Could not get absolute uri"); - await SendRequestAsync(absoluteUri, webHook.Name, payload); + await SendRequestAsync(absoluteUri, webHook.Name, payload).ConfigureAwait(false); } } else @@ -102,7 +102,8 @@ private async Task IsNotifiedOnWindowTimeAsync(string livenessName, bool r .Where(lf => lf.HealthCheckName.ToLower() == livenessName.ToLower()) .OrderByDescending(lf => lf.LastNotified) .Take(1) - .SingleOrDefaultAsync(); + .SingleOrDefaultAsync() + .ConfigureAwait(false); #pragma warning restore RCS1155 // Use StringComparison when comparing strings. return lastNotification != null @@ -117,9 +118,10 @@ private async Task SaveNotificationAsync(HealthCheckFailureNotification notifica if (notification != null) { await _db.Failures - .AddAsync(notification); + .AddAsync(notification) + .ConfigureAwait(false); - await _db.SaveChangesAsync(); + await _db.SaveChangesAsync().ConfigureAwait(false); } } @@ -131,7 +133,7 @@ private async Task SendRequestAsync(Uri uri, string name, string payloadContent) { Content = new StringContent(payloadContent, Encoding.UTF8, Keys.DEFAULT_RESPONSE_CONTENT_TYPE) }; - using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); + using var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { _logger.LogError("The webhook notification has not executed successfully for {name} webhook. The error code is {statuscode}.", name, response.StatusCode); diff --git a/src/HealthChecks.UI/Core/UIEndpointsResourceMapper.cs b/src/HealthChecks.UI/Core/UIEndpointsResourceMapper.cs index dfc1256af5..f13e263fd9 100644 --- a/src/HealthChecks.UI/Core/UIEndpointsResourceMapper.cs +++ b/src/HealthChecks.UI/Core/UIEndpointsResourceMapper.cs @@ -27,7 +27,7 @@ public IEnumerable Map(IEndpointRouteBuilder builder endpoints.Add(builder.MapGet($"{options.ResourcesPath}/{resource.FileName}", async context => { context.Response.ContentType = resource.ContentType; - await context.Response.WriteAsync(resource.Content); + await context.Response.WriteAsync(resource.Content).ConfigureAwait(false); })); } @@ -44,7 +44,7 @@ public IEnumerable Map(IEndpointRouteBuilder builder }); context.Response.ContentType = ui.ContentType; - await context.Response.WriteAsync(ui.Content); + await context.Response.WriteAsync(ui.Content).ConfigureAwait(false); })); foreach (var item in styleSheets) @@ -52,7 +52,7 @@ public IEnumerable Map(IEndpointRouteBuilder builder endpoints.Add(builder.MapGet(item.ResourcePath, async context => { context.Response.ContentType = "text/css"; - await context.Response.Body.WriteAsync(item.Content, 0, item.Content.Length); + await context.Response.Body.WriteAsync(item.Content, 0, item.Content.Length).ConfigureAwait(false); })); } diff --git a/src/HealthChecks.UI/Core/UIResourceMapper.cs b/src/HealthChecks.UI/Core/UIResourceMapper.cs index e9238b23f8..ceaf961664 100644 --- a/src/HealthChecks.UI/Core/UIResourceMapper.cs +++ b/src/HealthChecks.UI/Core/UIResourceMapper.cs @@ -26,7 +26,7 @@ public void Map(IApplicationBuilder app, Options options) appBuilder.Run(async context => { context.Response.ContentType = resource.ContentType; - await context.Response.WriteAsync(resource.Content); + await context.Response.WriteAsync(resource.Content).ConfigureAwait(false); }); }); } @@ -49,7 +49,7 @@ public void Map(IApplicationBuilder app, Options options) }); context.Response.ContentType = ui.ContentType; - await context.Response.WriteAsync(ui.Content); + await context.Response.WriteAsync(ui.Content).ConfigureAwait(false); }); }); @@ -60,7 +60,7 @@ public void Map(IApplicationBuilder app, Options options) appBuilder.Run(async context => { context.Response.ContentType = "text/css"; - await context.Response.Body.WriteAsync(item.Content, 0, item.Content.Length); + await context.Response.Body.WriteAsync(item.Content, 0, item.Content.Length).ConfigureAwait(false); }); }); }