Skip to content

Commit

Permalink
MongoDB.Driver version 3 made a major breaking change by removing the…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
eerhardt committed Nov 25, 2024
1 parent 508123e commit d23edfd
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 3 deletions.
14 changes: 14 additions & 0 deletions AspNetCore.Diagnostics.HealthChecks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,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
Expand Down Expand Up @@ -868,6 +872,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
Expand Down Expand Up @@ -1011,6 +1023,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}
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);1591;IDISP013;AD0001;</NoWarn> <!--TODO: temporary solution, remove AD0001 after https://github.com/dotnet/aspnetcore/issues/50836 fixed-->
<NoWarn>$(NoWarn);1591;IDISP013;AD0001;NU1901;NU1902;NU1903;</NoWarn> <!--TODO: temporary solution, remove AD0001 after https://github.com/dotnet/aspnetcore/issues/50836 fixed-->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/CallerArgumentExpressionAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CallerArgumentExpressionAttribute(string parameterName)

#endif

#if NETSTANDARD2_0
#if NETSTANDARD2_0 || NETFRAMEWORK

namespace System.Diagnostics.CodeAnalysis
{
Expand Down
20 changes: 20 additions & 0 deletions src/HealthChecks.MongoDb.v3/HealthChecks.MongoDb.v3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Match the TFMs of MongoDB.Driver -->
<TargetFrameworks>$(DefaultNetCoreApp);netstandard2.1;net472</TargetFrameworks>
<PackageTags>$(PackageTags);MongoDb</PackageTags>
<Description>HealthChecks.MongoDb is the health check package for MongoDb (version 3+).</Description>
<VersionPrefix>$(HealthCheckMongoDB)</VersionPrefix>
<AssemblyName>HealthChecks.MongoDb</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />

<Compile Include="../HealthChecks.MongoDb/DependencyInjection/MongoDbHealthCheckBuilderExtensions.cs" Link="DependencyInjection/MongoDbHealthCheckBuilderExtensions.cs" />
<Compile Include="../HealthChecks.MongoDb/MongoDbHealthCheck.cs" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/HealthChecks.MongoDb/HealthChecks.MongoDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.28.0" />
<PackageReference Include="MongoDB.Driver" Version="[2.28.0,3.0.0)" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckResult> 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<string>? tags = null, System.TimeSpan? timeout = default) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func<System.IServiceProvider, MongoDB.Driver.IMongoClient> mongoClientFactory, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable<string>? tags = null, System.TimeSpan? timeout = default) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func<System.IServiceProvider, string> mongodbConnectionStringFactory, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable<string>? 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<string>? 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<string>? tags = null, System.TimeSpan? timeout = default) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func<System.IServiceProvider, MongoDB.Driver.IMongoClient> mongoClientFactory, string mongoDatabaseName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable<string>? tags = null, System.TimeSpan? timeout = default) { }
public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddMongoDb(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func<System.IServiceProvider, string> mongodbConnectionStringFactory, string mongoDatabaseName, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable<string>? 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<string>? tags = null, System.TimeSpan? timeout = default) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>HealthChecks.MongoDb.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\HealthChecks.MongoDb.v3\HealthChecks.MongoDb.v3.csproj" />

<Compile Include="../HealthChecks.MongoDb.Tests/DependencyInjection/RegistrationTests.cs" Link="DependencyInjection/RegistrationTests.cs" />
<Compile Include="../HealthChecks.MongoDb.Tests/Functional/MongoDbHealthCheckTests.cs" Link="Functional/MongoDbHealthCheckTests.cs" />
</ItemGroup>

</Project>

0 comments on commit d23edfd

Please sign in to comment.