Skip to content

Commit

Permalink
Add comments and fix build (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Dec 4, 2023
1 parent 2aad15f commit 3adb447
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
namespace HealthChecks.System;

public class DiskStorageOptions
{
internal Dictionary<string, (string DriveName, long MinimumFreeMegabytes)> 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;
}

/// <summary>
/// Allows to set custom description of the failed disk check.
/// </summary>
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;

/// <summary>
/// Options for <see cref="DiskStorageHealthCheck"/>.
/// </summary>
public class DiskStorageOptions
{
internal Dictionary<string, (string DriveName, long MinimumFreeMegabytes)> 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;
}

/// <summary>
/// Allows to set custom description of the failed disk check.
/// </summary>
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);
}
4 changes: 4 additions & 0 deletions src/HealthChecks.System/FileHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ public class FileHealthCheck : IHealthCheck
{
private readonly FileHealthCheckOptions _fileOptions;

/// <summary>
/// Creates an instance of <see cref="FileHealthCheck"/> with the specified options.
/// </summary>
public FileHealthCheck(FileHealthCheckOptions fileOptions)
{
_fileOptions = fileOptions;
}

/// <inheritdoc />
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
Expand Down
3 changes: 3 additions & 0 deletions src/HealthChecks.System/FileHealthCheckOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace HealthChecks.System;

/// <summary>
/// Options for <see cref="FileHealthCheck"/>.
/// </summary>
public class FileHealthCheckOptions
{
public List<string> Files { get; } = new();
Expand Down
3 changes: 3 additions & 0 deletions src/HealthChecks.System/FolderHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public class FolderHealthCheck : IHealthCheck
{
private readonly FolderHealthCheckOptions _folderOptions;

/// <summary>
/// Creates an instance of <see cref="FolderHealthCheck"/> with the specified options.
/// </summary>
public FolderHealthCheck(FolderHealthCheckOptions folderOptions)
{
_folderOptions = Guard.ThrowIfNull(folderOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 3adb447

Please sign in to comment.