From 26e0636f4548387f902d7642192321e87633df64 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Mon, 25 Nov 2024 16:24:05 -0600 Subject: [PATCH] MongoDB.Driver version 3 made a major breaking change by removing the MongoDB.Driver.Core assembly. Handle this breaking change by splitting our package into 2, one for each major version. 1. For the current HealthChecks.MongoDb package, we put a NuGet version limit on our dependency: [2.28.0,3.0.0). This way people won't be able to update to the 3.0.0 version, which will break their app. 2. We add a new, forked component named HealthChecks.MongoDb.v3 which will have a dependency on 3.0.0 and contains updates so the health checks will work with v3. People who explicitly want to use version 3 can opt into using this package. 3. When the next major version of HealthChecks ships, we can "swap" the dependencies around. The HealthChecks.MongoDb package will be updated to depend on version 3 of MongoDB.Driver. If MongoDB.Driver v2.x is still in support, we can create HeatlhChecks.MongoDb.v2 which has the dependency limit [2.28.0,3.0.0) and works with the version 2 of MongoDB.Driver. HealthChecks.MongoDb.v3 will be dead-ended. Fix #2322 --- AspNetCore.Diagnostics.HealthChecks.sln | 14 +++++++++++ src/CallerArgumentExpressionAttribute.cs | 2 +- .../HealthChecks.MongoDb.v3.csproj | 20 ++++++++++++++++ .../HealthChecks.MongoDb.approved.txt | 24 +++++++++++++++++++ .../HealthChecks.MongoDb.v3.Tests.csproj | 14 +++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/HealthChecks.MongoDb.v3/HealthChecks.MongoDb.v3.csproj create mode 100644 test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.approved.txt create mode 100644 test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.v3.Tests.csproj diff --git a/AspNetCore.Diagnostics.HealthChecks.sln b/AspNetCore.Diagnostics.HealthChecks.sln index 0beabeb600..e14af80e68 100644 --- a/AspNetCore.Diagnostics.HealthChecks.sln +++ b/AspNetCore.Diagnostics.HealthChecks.sln @@ -311,6 +311,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Milvus", "src\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Milvus.Tests", "test\HealthChecks.Milvus.Tests\HealthChecks.Milvus.Tests.csproj", "{D49CF52C-9D21-4D98-8A15-A2B259E9C003}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.MongoDb.v3", "src\HealthChecks.MongoDb.v3\HealthChecks.MongoDb.v3.csproj", "{DF23B881-B607-9ACE-051E-6463E677E675}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.MongoDb.v3.Tests", "test\HealthChecks.MongoDb.v3.Tests\HealthChecks.MongoDb.v3.Tests.csproj", "{465DB8CE-3D18-4191-8692-BC1C8BED491C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -869,6 +873,14 @@ Global {D49CF52C-9D21-4D98-8A15-A2B259E9C003}.Debug|Any CPU.Build.0 = Debug|Any CPU {D49CF52C-9D21-4D98-8A15-A2B259E9C003}.Release|Any CPU.ActiveCfg = Release|Any CPU {D49CF52C-9D21-4D98-8A15-A2B259E9C003}.Release|Any CPU.Build.0 = Release|Any CPU + {DF23B881-B607-9ACE-051E-6463E677E675}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF23B881-B607-9ACE-051E-6463E677E675}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF23B881-B607-9ACE-051E-6463E677E675}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF23B881-B607-9ACE-051E-6463E677E675}.Release|Any CPU.Build.0 = Release|Any CPU + {465DB8CE-3D18-4191-8692-BC1C8BED491C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {465DB8CE-3D18-4191-8692-BC1C8BED491C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {465DB8CE-3D18-4191-8692-BC1C8BED491C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {465DB8CE-3D18-4191-8692-BC1C8BED491C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1012,6 +1024,8 @@ Global {3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {17913EAF-3B12-495B-80EA-9EB975FBE6BA} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {D49CF52C-9D21-4D98-8A15-A2B259E9C003} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} + {DF23B881-B607-9ACE-051E-6463E677E675} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} + {465DB8CE-3D18-4191-8692-BC1C8BED491C} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2B8C62A1-11B6-469F-874C-A02443256568} diff --git a/src/CallerArgumentExpressionAttribute.cs b/src/CallerArgumentExpressionAttribute.cs index 81ccffaebb..929fef68e0 100644 --- a/src/CallerArgumentExpressionAttribute.cs +++ b/src/CallerArgumentExpressionAttribute.cs @@ -21,7 +21,7 @@ public CallerArgumentExpressionAttribute(string parameterName) #endif -#if NETSTANDARD2_0 +#if NETSTANDARD2_0 || NETFRAMEWORK namespace System.Diagnostics.CodeAnalysis { diff --git a/src/HealthChecks.MongoDb.v3/HealthChecks.MongoDb.v3.csproj b/src/HealthChecks.MongoDb.v3/HealthChecks.MongoDb.v3.csproj new file mode 100644 index 0000000000..1d77045286 --- /dev/null +++ b/src/HealthChecks.MongoDb.v3/HealthChecks.MongoDb.v3.csproj @@ -0,0 +1,20 @@ + + + + + $(DefaultNetCoreApp);netstandard2.1;net472 + $(PackageTags);MongoDb + HealthChecks.MongoDb is the health check package for MongoDb (version 3+). + $(HealthCheckMongoDB) + HealthChecks.MongoDb + + + + + + + + + + + diff --git a/test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.approved.txt b/test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.approved.txt new file mode 100644 index 0000000000..88613ac36a --- /dev/null +++ b/test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.approved.txt @@ -0,0 +1,24 @@ +namespace HealthChecks.MongoDb +{ + public class MongoDbHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck + { + public MongoDbHealthCheck(MongoDB.Driver.IMongoClient client, string? databaseName = null) { } + public MongoDbHealthCheck(MongoDB.Driver.MongoClientSettings clientSettings, string? databaseName = null) { } + public MongoDbHealthCheck(string connectionString, string? databaseName = null) { } + public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } + } +} +namespace Microsoft.Extensions.DependencyInjection +{ + public static class MongoDbHealthCheckBuilderExtensions + { + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, MongoDB.Driver.MongoClientSettings mongoClientSettings, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func mongoClientFactory, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func mongodbConnectionStringFactory, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string mongodbConnectionString, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, MongoDB.Driver.MongoClientSettings mongoClientSettings, string mongoDatabaseName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func mongoClientFactory, string mongoDatabaseName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func mongodbConnectionStringFactory, string mongoDatabaseName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string mongodbConnectionString, string mongoDatabaseName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + } +} \ No newline at end of file diff --git a/test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.v3.Tests.csproj b/test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.v3.Tests.csproj new file mode 100644 index 0000000000..7b6589506d --- /dev/null +++ b/test/HealthChecks.MongoDb.v3.Tests/HealthChecks.MongoDb.v3.Tests.csproj @@ -0,0 +1,14 @@ + + + + HealthChecks.MongoDb.Tests + + + + + + + + + +