From 3043c6f42660e5259d4c12a6677d56d040003731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Thu, 31 Jan 2019 08:40:55 +0100 Subject: [PATCH 01/12] Add RavenDB HealthCheck. --- AspNetCore.Diagnostics.HealthChecks.sln | 7 ++ build/dependencies.props | 6 +- .../RavenDBHealthCheckBuilderExtensions.cs | 39 ++++++++++ .../HealthChecks.RavenDB.csproj | 25 +++++++ .../RavenDBHealthCheck.cs | 71 +++++++++++++++++++ 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs create mode 100644 src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj create mode 100644 src/HealthChecks.RavenDB/RavenDBHealthCheck.cs diff --git a/AspNetCore.Diagnostics.HealthChecks.sln b/AspNetCore.Diagnostics.HealthChecks.sln index 80397b9061..046ae3c437 100644 --- a/AspNetCore.Diagnostics.HealthChecks.sln +++ b/AspNetCore.Diagnostics.HealthChecks.sln @@ -87,6 +87,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Consul", "src\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Hangfire", "src\HealthChecks.Hangfire\HealthChecks.Hangfire.csproj", "{439DF9B7-5D0F-4531-BA19-F1BD01B244DB}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.RavenDB", "src\HealthChecks.RavenDB\HealthChecks.RavenDB.csproj", "{E91924B0-BE65-4CF8-A43A-2F22EEFE53F2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -229,6 +231,10 @@ Global {439DF9B7-5D0F-4531-BA19-F1BD01B244DB}.Debug|Any CPU.Build.0 = Debug|Any CPU {439DF9B7-5D0F-4531-BA19-F1BD01B244DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {439DF9B7-5D0F-4531-BA19-F1BD01B244DB}.Release|Any CPU.Build.0 = Release|Any CPU + {E91924B0-BE65-4CF8-A43A-2F22EEFE53F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E91924B0-BE65-4CF8-A43A-2F22EEFE53F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E91924B0-BE65-4CF8-A43A-2F22EEFE53F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E91924B0-BE65-4CF8-A43A-2F22EEFE53F2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -268,6 +274,7 @@ Global {B7C5C213-677D-4B03-ADA9-101299BCA047} = {092533AB-7505-4EDC-8932-D40BF575D0D2} {6F2F1445-01C9-4CFD-9F41-BD95E4F96BA6} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {439DF9B7-5D0F-4531-BA19-F1BD01B244DB} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} + {E91924B0-BE65-4CF8-A43A-2F22EEFE53F2} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2B8C62A1-11B6-469F-874C-A02443256568} diff --git a/build/dependencies.props b/build/dependencies.props index 5284c4b4e5..fa4ae3d3cd 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -29,13 +29,14 @@ 2.0.1 2.0.513 5.0.1 + 4.1.3 2.18.3 3.2.6 2.5.0 0.40.4 0.11.4 2016.1.0 - 6.1.0 + 6.1.0 4.5.0 1.9.1 1.6.21 @@ -72,7 +73,7 @@ 2.2.2 2.2.0 2.2.0 - 2.2.1 + 2.2.1 2.2.0 2.2.0 2.2.1 @@ -93,5 +94,6 @@ 2.2.0 2.2.2 2.2.0 + 2.2.0 \ No newline at end of file diff --git a/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs b/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs new file mode 100644 index 0000000000..4c73aa32b9 --- /dev/null +++ b/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs @@ -0,0 +1,39 @@ +using HealthChecks.RavenDB; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using System.Collections.Generic; + +namespace Microsoft.Extensions.DependencyInjection +{ + public static class HealthCheckBuilderExtensions + { + const string NAME = "ravendb"; + + /// + /// Add a health check for RabbitMQ services. + /// + /// The . + /// The RabbitMQ connection string to be used. + /// Urls to RavenDB. + /// + /// The health check name. Optional. If the type name 'ravendb' will be used for the name. + /// + /// + /// The that should be reported when the health check fails. Optional. If then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// The . + public static IHealthChecksBuilder AddRavenDB( + this IHealthChecksBuilder builder, + string[] ravenUrls, + string databaseName = default, + string name = default, + HealthStatus? failureStatus = default, + IEnumerable tags = default) + => builder.Add(new HealthCheckRegistration( + name ?? NAME, + sp => new RavenDBHealthCheck(ravenUrls, databaseName), + failureStatus, + tags)); + } +} diff --git a/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj b/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj new file mode 100644 index 0000000000..926c7ec157 --- /dev/null +++ b/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj @@ -0,0 +1,25 @@ + + + $(NetStandardTargetVersion) + $(PackageLicenseUrl) + $(PackageProjectUrl) + HealthCheck;Health;MongoDb + HealthChecks.RavenDB is the health check package for RavenDB. + $(HealthCheckRavenDB) + $(RepositoryUrl) + $(Company) + $(Authors) + latest + AspNetCore.HealthChecks.RavenDB + $(PublishRepositoryUrl) + $(AllowedOutputExtensionsInPackageBuildOutputFolder) + + + + + all + runtime; build; native; contentfiles; analyzers + + + + diff --git a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs new file mode 100644 index 0000000000..bb9abe490a --- /dev/null +++ b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs @@ -0,0 +1,71 @@ +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Raven.Client.Documents; +using Raven.Client.ServerWide.Operations; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace HealthChecks.RavenDB +{ + /// + /// Health check for RavenDB. + /// + /// + public class RavenDBHealthCheck : IHealthCheck + { + private readonly string[] _ravenUrls; + private readonly string _specifiedDatabase; + + /// + /// Initializes a new instance of the class. + /// + public RavenDBHealthCheck(string[] ravenUrls, string databaseName = default) + { + _ravenUrls = ravenUrls ?? throw new ArgumentNullException(nameof(ravenUrls)); + _specifiedDatabase = databaseName; + } + + /// + /// Runs the health check, returning the status of the RavenDB. + /// + /// + /// A context object associated with the current execution. + /// + /// + /// A that can be used to cancel the health check. + /// + /// + /// A that completes when the health check has finished, + /// yielding the status of the component being checked. + /// + public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) + { + try + { + using (var store = new DocumentStore + { + Urls = _ravenUrls + }) + { + store.Initialize(); + var databases = await store.Maintenance.Server.SendAsync(new GetDatabaseNamesOperation(0, 1)); + + if (!string.IsNullOrWhiteSpace(_specifiedDatabase) + && !databases.Contains(_specifiedDatabase, StringComparer.OrdinalIgnoreCase)) + { + return HealthCheckResult.Unhealthy($"RavenDB doesn't contains '{_specifiedDatabase}' database."); + } + else + { + return HealthCheckResult.Healthy(); + } + } + } + catch (Exception ex) + { + return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); + } + } + } +} From 4475d11c358fdcff7815ed075a580399efae077c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Thu, 31 Jan 2019 09:13:14 +0100 Subject: [PATCH 02/12] Remove URLs array and replace with one connectionstring. --- src/HealthChecks.RavenDB/RavenDBHealthCheck.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs index bb9abe490a..a3f5533109 100644 --- a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs +++ b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs @@ -14,15 +14,18 @@ namespace HealthChecks.RavenDB /// public class RavenDBHealthCheck : IHealthCheck { - private readonly string[] _ravenUrls; + private readonly string _connectionString; private readonly string _specifiedDatabase; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public RavenDBHealthCheck(string[] ravenUrls, string databaseName = default) + /// The connection string to RavenDB. + /// Name of the database. + /// connectionString + public RavenDBHealthCheck(string connectionString, string databaseName = default) { - _ravenUrls = ravenUrls ?? throw new ArgumentNullException(nameof(ravenUrls)); + _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)); _specifiedDatabase = databaseName; } @@ -45,7 +48,7 @@ public async Task CheckHealthAsync(HealthCheckContext context { using (var store = new DocumentStore { - Urls = _ravenUrls + Urls = new string[] { _connectionString } }) { store.Initialize(); From 0c21612ee8f21512efd8b7f90a4608cfc3bcde85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Thu, 31 Jan 2019 10:27:22 +0100 Subject: [PATCH 03/12] Change urls to connections string --- .../RavenDBHealthCheckBuilderExtensions.cs | 6 +++--- src/HealthChecks.RavenDB/RavenDBHealthCheck.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs b/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs index 4c73aa32b9..b281293e38 100644 --- a/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs +++ b/src/HealthChecks.RavenDB/DependencyInjection/RavenDBHealthCheckBuilderExtensions.cs @@ -13,7 +13,7 @@ public static class HealthCheckBuilderExtensions /// /// The . /// The RabbitMQ connection string to be used. - /// Urls to RavenDB. + /// Connection string to RavenDB. /// /// The health check name. Optional. If the type name 'ravendb' will be used for the name. /// @@ -25,14 +25,14 @@ public static class HealthCheckBuilderExtensions /// The . public static IHealthChecksBuilder AddRavenDB( this IHealthChecksBuilder builder, - string[] ravenUrls, + string connectionString, string databaseName = default, string name = default, HealthStatus? failureStatus = default, IEnumerable tags = default) => builder.Add(new HealthCheckRegistration( name ?? NAME, - sp => new RavenDBHealthCheck(ravenUrls, databaseName), + sp => new RavenDBHealthCheck(connectionString, databaseName), failureStatus, tags)); } diff --git a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs index a3f5533109..dd76afa489 100644 --- a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs +++ b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs @@ -52,7 +52,7 @@ public async Task CheckHealthAsync(HealthCheckContext context }) { store.Initialize(); - var databases = await store.Maintenance.Server.SendAsync(new GetDatabaseNamesOperation(0, 1)); + var databases = await store.Maintenance.Server.SendAsync(new GetDatabaseNamesOperation(0, 100)); if (!string.IsNullOrWhiteSpace(_specifiedDatabase) && !databases.Contains(_specifiedDatabase, StringComparer.OrdinalIgnoreCase)) From 71f8c54dedb483c55ddeef9e57f1a71537fb2020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Thu, 31 Jan 2019 10:36:07 +0100 Subject: [PATCH 04/12] Add tests for RavenDBHealthCheck --- test/FunctionalTests/FunctionalTests.csproj | 1 + .../RavenDBHealthCheckTests.cs | 141 ++++++++++++++++++ .../RavenDB/RavenUnitTests.cs | 47 ++++++ test/UnitTests/UnitTests.csproj | 1 + 4 files changed, 190 insertions(+) create mode 100644 test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs create mode 100644 test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs diff --git a/test/FunctionalTests/FunctionalTests.csproj b/test/FunctionalTests/FunctionalTests.csproj index 27b7bfddc4..4ec8692f26 100644 --- a/test/FunctionalTests/FunctionalTests.csproj +++ b/test/FunctionalTests/FunctionalTests.csproj @@ -30,6 +30,7 @@ + diff --git a/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs b/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs new file mode 100644 index 0000000000..d36dc4645d --- /dev/null +++ b/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs @@ -0,0 +1,141 @@ +using FluentAssertions; +using FunctionalTests.Base; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Net; +using System.Threading.Tasks; +using Xunit; + +namespace FunctionalTests.HealthChecks.RavenDB +{ + [Collection("execution")] + public class ravendb_healthcheck_should + { + private readonly ExecutionFixture _fixture; + private const string ConnectionString = "http://live-test.ravendb.net:80"; + + public ravendb_healthcheck_should(ExecutionFixture fixture) + { + _fixture = fixture ?? throw new ArgumentNullException(nameof(fixture)); + } + + [SkipOnAppVeyor] + public async Task be_healthy_if_ravendb_is_available() + { + + var webHostBuilder = new WebHostBuilder() + .UseStartup() + .ConfigureServices(services => + { + services + .AddHealthChecks() + .AddRavenDB(ConnectionString, tags: new string[] { "ravendb" }); + }) + .Configure(app => + { + app.UseHealthChecks("/health", new HealthCheckOptions() + { + Predicate = r => r.Tags.Contains("ravendb") + }); + }); + + var server = new TestServer(webHostBuilder); + + var response = await server.CreateRequest($"/health") + .GetAsync(); + + response.StatusCode + .Should().Be(HttpStatusCode.OK); + } + + [SkipOnAppVeyor] + public async Task be_healthy_if_ravendb_is_available_and_contains_specific_database() + { + var webHostBuilder = new WebHostBuilder() + .UseStartup() + .ConfigureServices(services => + { + services + .AddHealthChecks() + .AddRavenDB(ConnectionString, "Demo", tags: new string[] { "ravendb" }); + }) + .Configure(app => + { + app.UseHealthChecks("/health", new HealthCheckOptions() + { + Predicate = r => r.Tags.Contains("ravendb") + }); + }); + + var server = new TestServer(webHostBuilder); + + var response = await server.CreateRequest($"/health") + .GetAsync(); + + response.StatusCode + .Should().Be(HttpStatusCode.OK); + } + + [SkipOnAppVeyor] + public async Task be_healthy_if_ravendb_isnot_available() + { + var connectionString = "http://localhost:9999"; + + var webHostBuilder = new WebHostBuilder() + .UseStartup() + .ConfigureServices(services => + { + services + .AddHealthChecks() + .AddRavenDB(connectionString, tags: new string[] { "ravendb" }); + }) + .Configure(app => + { + app.UseHealthChecks("/health", new HealthCheckOptions() + { + Predicate = r => r.Tags.Contains("ravendb") + }); + }); + + var server = new TestServer(webHostBuilder); + + var response = await server.CreateRequest($"/health") + .GetAsync(); + + response.StatusCode + .Should().Be(HttpStatusCode.ServiceUnavailable); + } + + [SkipOnAppVeyor] + public async Task be_healthy_if_ravendb_is_available_but_database_doesnot_exist() + { + var webHostBuilder = new WebHostBuilder() + .UseStartup() + .ConfigureServices(services => + { + services + .AddHealthChecks() + .AddRavenDB(ConnectionString, "ThisDatabaseReallyDoesnExist", tags: new string[] { "ravendb" }); + }) + .Configure(app => + { + app.UseHealthChecks("/health", new HealthCheckOptions() + { + Predicate = r => r.Tags.Contains("ravendb") + }); + }); + + var server = new TestServer(webHostBuilder); + + var response = await server.CreateRequest($"/health") + .GetAsync(); + + response.StatusCode + .Should().Be(HttpStatusCode.ServiceUnavailable); + } + } +} diff --git a/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs b/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs new file mode 100644 index 0000000000..3c42e4c916 --- /dev/null +++ b/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs @@ -0,0 +1,47 @@ +using FluentAssertions; +using HealthChecks.RavenDB; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.Extensions.Options; +using System.Linq; +using Xunit; + +namespace UnitTests.DependencyInjection.RavenDB +{ + public class ravendb_registration_should + { + [Fact] + public void add_health_check_when_properly_configured() + { + var services = new ServiceCollection(); + services.AddHealthChecks() + .AddRavenDB(new string[] { "http://localhost:8080" }); + + var serviceProvider = services.BuildServiceProvider(); + var options = serviceProvider.GetService>(); + + var registration = options.Value.Registrations.First(); + var check = registration.Factory(serviceProvider); + + registration.Name.Should().Be("ravendb"); + check.GetType().Should().Be(typeof(RavenDBHealthCheck)); + } + + [Fact] + public void add_named_health_check_when_properly_configured() + { + var services = new ServiceCollection(); + services.AddHealthChecks() + .AddRavenDB(new string[] { "http://localhost:8080" }, name: "my-ravendb"); + + var serviceProvider = services.BuildServiceProvider(); + var options = serviceProvider.GetService>(); + + var registration = options.Value.Registrations.First(); + var check = registration.Factory(serviceProvider); + + registration.Name.Should().Be("my-ravendb"); + check.GetType().Should().Be(typeof(RavenDBHealthCheck)); + } + } +} diff --git a/test/UnitTests/UnitTests.csproj b/test/UnitTests/UnitTests.csproj index 706c1986ff..f8bec84eb2 100644 --- a/test/UnitTests/UnitTests.csproj +++ b/test/UnitTests/UnitTests.csproj @@ -29,6 +29,7 @@ + From cb0b4f068e4b94750776a2ab1b7f01b5c8955bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Thu, 31 Jan 2019 10:39:23 +0100 Subject: [PATCH 05/12] Add info about RavenDB package into README --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 980970623f..86448b6cc7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Build status](https://ci.appveyor.com/api/projects/status/ldk031dvcn2no51g/branch/master?svg=true)](https://ci.appveyor.com/project/Xabaril/aspnetcore-diagnostics-healthchecks) +[![Build status](https://ci.appveyor.com/api/projects/status/ldk031dvcn2no51g/branch/master?svg=true)](https://ci.appveyor.com/project/Xabaril/aspnetcore-diagnostics-healthchecks) [![Build history](https://buildstats.info/appveyor/chart/xabaril/aspnetcore-diagnostics-healthchecks)](https://ci.appveyor.com/project/xabaril/aspnetcore-diagnostics-healthchecks/history) @@ -16,11 +16,11 @@ HealthChecks packages include health checks for: - MySql - Oracle - Sqlite -- Postgres +- Postgres - EventStore - RabbitMQ - Elasticsearch -- Redis +- Redis - System: Disk Storage, Private Memory, Virtual Memory - Azure Service Bus: EventHub, Queue and Topics - Azure Storage: Blob, Queue and Table @@ -35,6 +35,7 @@ HealthChecks packages include health checks for: - Uri: single uri and uri groups - Consul - Hangfire +- RavenDB ``` PowerShell @@ -61,6 +62,7 @@ Install-Package AspNetCore.HealthChecks.Uris Install-Package AspNetCore.HealthChecks.Aws.S3 Install-Package AspNetCore.HealthChecks.Consul Install-Package AspNetCore.HealthChecks.Hangfire +Install-Package AspNetCore.HealthChecks.RavenDB ``` Once the package is installed you can add the HealthCheck using the **AddXXX** IServiceCollection extension methods. @@ -85,7 +87,7 @@ public void ConfigureServices(IServiceCollection services) .AddSqlServer( connectionString: Configuration["Data:ConnectionStrings:Sql"], healthQuery: "SELECT 1;", - name: "sql", + name: "sql", failureStatus: HealthStatus.Degraded, tags: new string[] { "db", "sql", "sqlserver" }); } @@ -121,7 +123,7 @@ To integrate HealthChecks.UI in your project you just need to add the HealthChec ```csharp public class Startup -{ +{ public void ConfigureServices(IServiceCollection services) { services.AddHealthChecksUI(); @@ -134,7 +136,7 @@ public class Startup } ``` -This automatically registers a new interface on **/healthchecks-ui** where the spa will be served. +This automatically registers a new interface on **/healthchecks-ui** where the spa will be served. > Optionally, *UseHealthChecksUI* can be configured to serve it's health api, webhooks api and the front-end resources in different endpoints using the UseHealthChecksUI(setup =>) method overload. Default configured urls for this endpoints can be found [here](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/blob/master/src/HealthChecks.UI/Configuration/Options.cs) @@ -163,7 +165,7 @@ By default HealthChecks returns a simple Status Code (200 or 503) without the He > *WriteHealthCheckUIResponse* is defined on HealthChecks.UI.Client nuget package. -To show these HealthChecks in HealthCheck-UI they have to be configured through the **HealthCheck-UI** settings. +To show these HealthChecks in HealthCheck-UI they have to be configured through the **HealthCheck-UI** settings. ```json { From 7b5b3b609a4cc05cb4940e08a167b2f8f0c3fe47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Thu, 31 Jan 2019 11:53:41 +0100 Subject: [PATCH 06/12] Add 'Fact' attribute for RavenDB tests --- .../HealthChecks.RavenDB/RavenDBHealthCheckTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs b/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs index d36dc4645d..91878aeef3 100644 --- a/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs +++ b/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs @@ -23,7 +23,7 @@ public ravendb_healthcheck_should(ExecutionFixture fixture) _fixture = fixture ?? throw new ArgumentNullException(nameof(fixture)); } - [SkipOnAppVeyor] + [Fact] public async Task be_healthy_if_ravendb_is_available() { @@ -52,7 +52,7 @@ public async Task be_healthy_if_ravendb_is_available() .Should().Be(HttpStatusCode.OK); } - [SkipOnAppVeyor] + [Fact] public async Task be_healthy_if_ravendb_is_available_and_contains_specific_database() { var webHostBuilder = new WebHostBuilder() @@ -80,7 +80,7 @@ public async Task be_healthy_if_ravendb_is_available_and_contains_specific_datab .Should().Be(HttpStatusCode.OK); } - [SkipOnAppVeyor] + [Fact] public async Task be_healthy_if_ravendb_isnot_available() { var connectionString = "http://localhost:9999"; @@ -110,7 +110,7 @@ public async Task be_healthy_if_ravendb_isnot_available() .Should().Be(HttpStatusCode.ServiceUnavailable); } - [SkipOnAppVeyor] + [Fact] public async Task be_healthy_if_ravendb_is_available_but_database_doesnot_exist() { var webHostBuilder = new WebHostBuilder() From a910837f3f101d1c927c67d5cf9649332f95c681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Fri, 1 Feb 2019 06:16:15 +0100 Subject: [PATCH 07/12] Fixed build failed. --- build.ps1 | 16 +++++++++------- .../HealthChecks.RavenDB.csproj | 2 +- .../RavenDB/RavenUnitTests.cs | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/build.ps1 b/build.ps1 index 845e1d469b..380945291f 100644 --- a/build.ps1 +++ b/build.ps1 @@ -34,14 +34,14 @@ $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($c echo "build: Tag is $tag" echo "build: Package version suffix is $suffix" -echo "build: Build version suffix is $buildSuffix" +echo "build: Build version suffix is $buildSuffix" exec { & dotnet build AspNetCore.Diagnostics.HealthChecks.sln -c Release --version-suffix=$buildSuffix -v q /nologo } -echo "Running unit tests" +echo "Running unit tests" try { - + Push-Location -Path .\test\UnitTests exec { & dotnet test} } finally { @@ -58,7 +58,7 @@ echo "compose up done" echo "Running functional tests" try { - + Push-Location -Path .\test\FunctionalTests exec { & dotnet test} } finally { @@ -93,8 +93,9 @@ if ($suffix -eq "") { exec { & dotnet pack .\src\HealthChecks.UI.Client\HealthChecks.UI.Client.csproj -c Release -o ..\..\artifacts --include-symbols --no-build } exec { & dotnet pack .\src\HealthChecks.Publisher.ApplicationInsights\HealthChecks.Publisher.ApplicationInsights.csproj -c Release -o ..\..\artifacts --include-symbols --no-build } exec { & dotnet pack .\src\HealthChecks.Publisher.Prometheus\HealthChecks.Publisher.Prometheus.csproj -c Release -o ..\..\artifacts --include-symbols --no-build } - exec { & dotnet pack .\src\HealthChecks.Consul\HealthChecks.Consul.csproj -c Release -o ..\..\artifacts --include-symbols --no-build } -} + exec { & dotnet pack .\src\HealthChecks.Consul\HealthChecks.Consul.csproj -c Release -o ..\..\artifacts --include-symbols --no-build } + exec { & dotnet pack .\src\HealthChecks.RavenDB\HealthChecks.RavenDB.csproj -c Release -o ..\..\artifacts --include-symbols --no-build } +} else { exec { & dotnet pack .\src\HealthChecks.SqlServer\HealthChecks.SqlServer.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } @@ -123,6 +124,7 @@ else { exec { & dotnet pack .\src\HealthChecks.UI.Client\HealthChecks.UI.Client.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } exec { & dotnet pack .\src\HealthChecks.Publisher.ApplicationInsights\HealthChecks.Publisher.ApplicationInsights.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } exec { & dotnet pack .\src\HealthChecks.Publisher.Prometheus\HealthChecks.Publisher.Prometheus.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } - exec { & dotnet pack .\src\HealthChecks.Consul\HealthChecks.Consul.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } + exec { & dotnet pack .\src\HealthChecks.Consul\HealthChecks.Consul.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } + exec { & dotnet pack .\src\HealthChecks.RavenDB\HealthChecks.RavenDB.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix } } diff --git a/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj b/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj index 926c7ec157..b23a26722b 100644 --- a/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj +++ b/src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj @@ -20,6 +20,6 @@ all runtime; build; native; contentfiles; analyzers - + diff --git a/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs b/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs index 3c42e4c916..3b4084b27a 100644 --- a/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs +++ b/test/UnitTests/DependencyInjection/RavenDB/RavenUnitTests.cs @@ -15,7 +15,7 @@ public void add_health_check_when_properly_configured() { var services = new ServiceCollection(); services.AddHealthChecks() - .AddRavenDB(new string[] { "http://localhost:8080" }); + .AddRavenDB("http://localhost:8080"); var serviceProvider = services.BuildServiceProvider(); var options = serviceProvider.GetService>(); @@ -32,7 +32,7 @@ public void add_named_health_check_when_properly_configured() { var services = new ServiceCollection(); services.AddHealthChecks() - .AddRavenDB(new string[] { "http://localhost:8080" }, name: "my-ravendb"); + .AddRavenDB("http://localhost:8080", name: "my-ravendb"); var serviceProvider = services.BuildServiceProvider(); var options = serviceProvider.GetService>(); From 20cf1aecb98bd0369158f201e78b92ae85eb0fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Fri, 1 Feb 2019 08:54:48 +0100 Subject: [PATCH 08/12] Rename test by convention. --- .../HealthChecks.RavenDB/RavenDBHealthCheckTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs b/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs index 91878aeef3..40a9542927 100644 --- a/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs +++ b/test/FunctionalTests/HealthChecks.RavenDB/RavenDBHealthCheckTests.cs @@ -81,7 +81,7 @@ public async Task be_healthy_if_ravendb_is_available_and_contains_specific_datab } [Fact] - public async Task be_healthy_if_ravendb_isnot_available() + public async Task be_healthy_if_ravendb_is_not_available() { var connectionString = "http://localhost:9999"; From 9740d9db938a83b3f615eed16cd6f49bb69ffe3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Fri, 1 Feb 2019 08:59:37 +0100 Subject: [PATCH 09/12] Adding RavenBD info close to the other database healthchecks. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86448b6cc7..cad6cde894 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ HealthChecks packages include health checks for: - MySql - Oracle - Sqlite +- RavenDB - Postgres - EventStore - RabbitMQ @@ -35,7 +36,6 @@ HealthChecks packages include health checks for: - Uri: single uri and uri groups - Consul - Hangfire -- RavenDB ``` PowerShell @@ -53,6 +53,7 @@ Install-Package AspNetCore.HealthChecks.AzureKeyVault Install-Package AspNetCore.HealthChecks.MySql Install-Package AspNetCore.HealthChecks.DocumentDb Install-Package AspNetCore.HealthChecks.SqLite +Install-Package AspNetCore.HealthChecks.RavenDB Install-Package AspNetCore.HealthChecks.Kafka Install-Package AspNetCore.HealthChecks.RabbitMQ Install-Package AspNetCore.HealthChecks.OpenIdConnectServer @@ -62,7 +63,6 @@ Install-Package AspNetCore.HealthChecks.Uris Install-Package AspNetCore.HealthChecks.Aws.S3 Install-Package AspNetCore.HealthChecks.Consul Install-Package AspNetCore.HealthChecks.Hangfire -Install-Package AspNetCore.HealthChecks.RavenDB ``` Once the package is installed you can add the HealthCheck using the **AddXXX** IServiceCollection extension methods. From 522979ee58f4322c4e35feeb5a4ca6fb66509c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Fri, 1 Feb 2019 09:30:03 +0100 Subject: [PATCH 10/12] Remove unnecessary comment --- src/HealthChecks.RavenDB/RavenDBHealthCheck.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs index dd76afa489..dcdab8c4ff 100644 --- a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs +++ b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs @@ -29,19 +29,6 @@ public RavenDBHealthCheck(string connectionString, string databaseName = default _specifiedDatabase = databaseName; } - /// - /// Runs the health check, returning the status of the RavenDB. - /// - /// - /// A context object associated with the current execution. - /// - /// - /// A that can be used to cancel the health check. - /// - /// - /// A that completes when the health check has finished, - /// yielding the status of the component being checked. - /// public async Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { try From a3f8f11b000784f912e4a5caa250477b39740c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Fri, 1 Feb 2019 09:38:33 +0100 Subject: [PATCH 11/12] Return new instance of `HealthCheckResult` with `FailureStatus`. --- src/HealthChecks.RavenDB/RavenDBHealthCheck.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs index dcdab8c4ff..b6dfa23ce1 100644 --- a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs +++ b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs @@ -44,7 +44,9 @@ public async Task CheckHealthAsync(HealthCheckContext context if (!string.IsNullOrWhiteSpace(_specifiedDatabase) && !databases.Contains(_specifiedDatabase, StringComparer.OrdinalIgnoreCase)) { - return HealthCheckResult.Unhealthy($"RavenDB doesn't contains '{_specifiedDatabase}' database."); + return new HealthCheckResult( + context.Registration.FailureStatus, + $"RavenDB doesn't contains '{_specifiedDatabase}' database."); } else { From 814e6292df30a73ecc54cd7085ed2d08a223145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=88o=20Martiniak?= Date: Fri, 1 Feb 2019 09:44:46 +0100 Subject: [PATCH 12/12] Remove comment --- src/HealthChecks.RavenDB/RavenDBHealthCheck.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs index b6dfa23ce1..937f2abae4 100644 --- a/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs +++ b/src/HealthChecks.RavenDB/RavenDBHealthCheck.cs @@ -17,12 +17,6 @@ public class RavenDBHealthCheck : IHealthCheck private readonly string _connectionString; private readonly string _specifiedDatabase; - /// - /// Initializes a new instance of the class. - /// - /// The connection string to RavenDB. - /// Name of the database. - /// connectionString public RavenDBHealthCheck(string connectionString, string databaseName = default) { _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));