From 3adb4474ebb6370ee755f2c6b88fbd63bddb452a Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Mon, 4 Dec 2023 18:20:09 +0300 Subject: [PATCH] Add comments and fix build (#2114) --- README.md | 2 +- ...venessOptions.cs => DiskStorageOptions.cs} | 63 ++++++++++--------- src/HealthChecks.System/FileHealthCheck.cs | 4 ++ .../FileHealthCheckOptions.cs | 3 + src/HealthChecks.System/FolderHealthCheck.cs | 3 + .../Functional/FileHealthCheckTests.cs | 6 +- 6 files changed, 47 insertions(+), 34 deletions(-) rename src/HealthChecks.System/{DiskStorageLivenessOptions.cs => DiskStorageOptions.cs} (93%) diff --git a/README.md b/README.md index 19112a7243..d53c0e8e63 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ HealthChecks packages include health checks for: | Solr | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Solr)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Solr) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.Solr)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Solr) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/solr)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/solr) | Sqlite | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Sqlite)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Sqlite) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.Sqlite)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Sqlite) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/sqlite)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/sqlite) | Sql Server | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.SqlServer)](https://www.nuget.org/packages/AspNetCore.HealthChecks.SqlServer) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.SqlServer)](https://www.nuget.org/packages/AspNetCore.HealthChecks.SqlServer) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/sqlserver)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/sqlserver) -| System | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.System)](https://www.nuget.org/packages/AspNetCore.HealthChecks.System) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.System)](https://www.nuget.org/packages/AspNetCore.HealthChecks.System) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/system)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/system) | Disk Storage, Folder, Private Memory, Virtual Memory, Process, Windows Service | +| System | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.System)](https://www.nuget.org/packages/AspNetCore.HealthChecks.System) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.System)](https://www.nuget.org/packages/AspNetCore.HealthChecks.System) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/system)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/system) | Disk Storage, Folder, File, Private Memory, Virtual Memory, Process, Windows Service | | Uris | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Uris)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Uris) | [![Nuget](https://img.shields.io/nuget/v/AspNetCore.HealthChecks.Uris)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Uris) | [![view](https://img.shields.io/github/issues/Xabaril/AspNetCore.Diagnostics.HealthChecks/uris)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/labels/uris) | Single uri and uri groups | > We support netcoreapp 2.2, 3.0 and 3.1. Please use package versions 2.2.X, 3.0.X and 3.1.X to target different versions. diff --git a/src/HealthChecks.System/DiskStorageLivenessOptions.cs b/src/HealthChecks.System/DiskStorageOptions.cs similarity index 93% rename from src/HealthChecks.System/DiskStorageLivenessOptions.cs rename to src/HealthChecks.System/DiskStorageOptions.cs index 48e2e5e8e2..83ec405e4e 100644 --- a/src/HealthChecks.System/DiskStorageLivenessOptions.cs +++ b/src/HealthChecks.System/DiskStorageOptions.cs @@ -1,30 +1,33 @@ -namespace HealthChecks.System; - -public class DiskStorageOptions -{ - internal Dictionary ConfiguredDrives { get; } = new(); - - public DiskStorageOptions AddDrive(string driveName, long minimumFreeMegabytes = 1) - { - ConfiguredDrives.Add(driveName, (driveName, minimumFreeMegabytes)); - return this; - } - - public bool CheckAllDrives { get; set; } - - public DiskStorageOptions WithCheckAllDrives() - { - CheckAllDrives = true; - return this; - } - - /// - /// Allows to set custom description of the failed disk check. - /// - public ErrorDescription FailedDescription = (driveName, minimumFreeMegabytes, actualFreeMegabytes) - => actualFreeMegabytes == null - ? $"Configured drive {driveName} is not present on system" - : $"Minimum configured megabytes for disk {driveName} is {minimumFreeMegabytes} but actual free space are {actualFreeMegabytes} megabytes"; - - public delegate string ErrorDescription(string driveName, long minimumFreeMegabytes, long? actualFreeMegabytes); -} +namespace HealthChecks.System; + +/// +/// Options for . +/// +public class DiskStorageOptions +{ + internal Dictionary ConfiguredDrives { get; } = new(); + + public DiskStorageOptions AddDrive(string driveName, long minimumFreeMegabytes = 1) + { + ConfiguredDrives.Add(driveName, (driveName, minimumFreeMegabytes)); + return this; + } + + public bool CheckAllDrives { get; set; } + + public DiskStorageOptions WithCheckAllDrives() + { + CheckAllDrives = true; + return this; + } + + /// + /// Allows to set custom description of the failed disk check. + /// + public ErrorDescription FailedDescription = (driveName, minimumFreeMegabytes, actualFreeMegabytes) + => actualFreeMegabytes == null + ? $"Configured drive {driveName} is not present on system" + : $"Minimum configured megabytes for disk {driveName} is {minimumFreeMegabytes} but actual free space are {actualFreeMegabytes} megabytes"; + + public delegate string ErrorDescription(string driveName, long minimumFreeMegabytes, long? actualFreeMegabytes); +} diff --git a/src/HealthChecks.System/FileHealthCheck.cs b/src/HealthChecks.System/FileHealthCheck.cs index ff37a00822..29551a393f 100644 --- a/src/HealthChecks.System/FileHealthCheck.cs +++ b/src/HealthChecks.System/FileHealthCheck.cs @@ -6,11 +6,15 @@ public class FileHealthCheck : IHealthCheck { private readonly FileHealthCheckOptions _fileOptions; + /// + /// Creates an instance of with the specified options. + /// public FileHealthCheck(FileHealthCheckOptions fileOptions) { _fileOptions = fileOptions; } + /// public Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { try diff --git a/src/HealthChecks.System/FileHealthCheckOptions.cs b/src/HealthChecks.System/FileHealthCheckOptions.cs index d1c70ff7a6..da8284fedb 100644 --- a/src/HealthChecks.System/FileHealthCheckOptions.cs +++ b/src/HealthChecks.System/FileHealthCheckOptions.cs @@ -1,5 +1,8 @@ namespace HealthChecks.System; +/// +/// Options for . +/// public class FileHealthCheckOptions { public List Files { get; } = new(); diff --git a/src/HealthChecks.System/FolderHealthCheck.cs b/src/HealthChecks.System/FolderHealthCheck.cs index d9d8837ed1..92a8dc30ee 100644 --- a/src/HealthChecks.System/FolderHealthCheck.cs +++ b/src/HealthChecks.System/FolderHealthCheck.cs @@ -6,6 +6,9 @@ public class FolderHealthCheck : IHealthCheck { private readonly FolderHealthCheckOptions _folderOptions; + /// + /// Creates an instance of with the specified options. + /// public FolderHealthCheck(FolderHealthCheckOptions folderOptions) { _folderOptions = Guard.ThrowIfNull(folderOptions); diff --git a/test/HealthChecks.System.Tests/Functional/FileHealthCheckTests.cs b/test/HealthChecks.System.Tests/Functional/FileHealthCheckTests.cs index 423b9eb8e4..3aa7d5c3db 100644 --- a/test/HealthChecks.System.Tests/Functional/FileHealthCheckTests.cs +++ b/test/HealthChecks.System.Tests/Functional/FileHealthCheckTests.cs @@ -23,7 +23,7 @@ public async Task be_healthy_if_file_is_available() using var server = new TestServer(webHostBuilder); - using var response = await server.CreateRequest("/health").GetAsync().ConfigureAwait(false); + using var response = await server.CreateRequest("/health").GetAsync(); response.StatusCode.ShouldBe(HttpStatusCode.OK); } @@ -49,7 +49,7 @@ public async Task be_healthy_if_no_file_provided() using var server = new TestServer(webHostBuilder); - using var response = await server.CreateRequest("/health").GetAsync().ConfigureAwait(false); + using var response = await server.CreateRequest("/health").GetAsync(); response.StatusCode.ShouldBe(HttpStatusCode.OK); } @@ -73,7 +73,7 @@ public async Task be_unhealthy_if_file_is_not_available() using var server = new TestServer(webHostBuilder); - using var response = await server.CreateRequest("/health").GetAsync().ConfigureAwait(false); + using var response = await server.CreateRequest("/health").GetAsync(); response.StatusCode.ShouldBe(HttpStatusCode.ServiceUnavailable); }