Skip to content

Commit 47a4cce

Browse files
author
Nate McMaster
committed
Merge HealthChecks API source code from aspnet/Diagnostics
2 parents db6dfae + a038612 commit 47a4cce

37 files changed

+3142
-0
lines changed

Extensions.sln

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenericHostSample", "src\Ho
265265
EndProject
266266
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleMsmqHost", "src\Hosting\samples\SampleMsmqHost\SampleMsmqHost.csproj", "{1A203DA9-D706-4094-B549-2611C6DA38F4}"
267267
EndProject
268+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HealthChecks", "HealthChecks", "{D9252E02-D807-43DA-BBAF-AD739A8D385A}"
269+
EndProject
270+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Extensions.Diagnostics.HealthChecks", "src\HealthChecks\HealthChecks\src\Microsoft.Extensions.Diagnostics.HealthChecks.csproj", "{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}"
271+
EndProject
272+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Extensions.Diagnostics.HealthChecks.Tests", "src\HealthChecks\HealthChecks\test\Microsoft.Extensions.Diagnostics.HealthChecks.Tests.csproj", "{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}"
273+
EndProject
274+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions", "src\HealthChecks\Abstractions\src\Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.csproj", "{5D56AD97-9819-4A65-ADD3-18728FE81D95}"
275+
EndProject
268276
Global
269277
GlobalSection(SharedMSBuildProjectFiles) = preSolution
270278
src\Shared\src\CommandLineUtils\Microsoft.Extensions.CommandLineUtils.Sources.projitems*{00947d4a-c20e-46e3-90c3-6cd6bc87ee72}*SharedItemsImports = 13
@@ -1514,6 +1522,42 @@ Global
15141522
{F047546D-EABA-4E60-AAB3-739C7C2407B1}.Release|x64.Build.0 = Release|Any CPU
15151523
{F047546D-EABA-4E60-AAB3-739C7C2407B1}.Release|x86.ActiveCfg = Release|Any CPU
15161524
{F047546D-EABA-4E60-AAB3-739C7C2407B1}.Release|x86.Build.0 = Release|Any CPU
1525+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1526+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
1527+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Debug|x64.ActiveCfg = Debug|Any CPU
1528+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Debug|x64.Build.0 = Debug|Any CPU
1529+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Debug|x86.ActiveCfg = Debug|Any CPU
1530+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Debug|x86.Build.0 = Debug|Any CPU
1531+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
1532+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Release|Any CPU.Build.0 = Release|Any CPU
1533+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Release|x64.ActiveCfg = Release|Any CPU
1534+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Release|x64.Build.0 = Release|Any CPU
1535+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Release|x86.ActiveCfg = Release|Any CPU
1536+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF}.Release|x86.Build.0 = Release|Any CPU
1537+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1538+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Debug|Any CPU.Build.0 = Debug|Any CPU
1539+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Debug|x64.ActiveCfg = Debug|Any CPU
1540+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Debug|x64.Build.0 = Debug|Any CPU
1541+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Debug|x86.ActiveCfg = Debug|Any CPU
1542+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Debug|x86.Build.0 = Debug|Any CPU
1543+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Release|Any CPU.ActiveCfg = Release|Any CPU
1544+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Release|Any CPU.Build.0 = Release|Any CPU
1545+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Release|x64.ActiveCfg = Release|Any CPU
1546+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Release|x64.Build.0 = Release|Any CPU
1547+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Release|x86.ActiveCfg = Release|Any CPU
1548+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F}.Release|x86.Build.0 = Release|Any CPU
1549+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1550+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Debug|Any CPU.Build.0 = Debug|Any CPU
1551+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Debug|x64.ActiveCfg = Debug|Any CPU
1552+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Debug|x64.Build.0 = Debug|Any CPU
1553+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Debug|x86.ActiveCfg = Debug|Any CPU
1554+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Debug|x86.Build.0 = Debug|Any CPU
1555+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Release|Any CPU.ActiveCfg = Release|Any CPU
1556+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Release|Any CPU.Build.0 = Release|Any CPU
1557+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Release|x64.ActiveCfg = Release|Any CPU
1558+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Release|x64.Build.0 = Release|Any CPU
1559+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Release|x86.ActiveCfg = Release|Any CPU
1560+
{5D56AD97-9819-4A65-ADD3-18728FE81D95}.Release|x86.Build.0 = Release|Any CPU
15171561
{FC9D173D-8F61-40AF-BFC3-A95A47F75A38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15181562
{FC9D173D-8F61-40AF-BFC3-A95A47F75A38}.Debug|Any CPU.Build.0 = Debug|Any CPU
15191563
{FC9D173D-8F61-40AF-BFC3-A95A47F75A38}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -1688,6 +1732,9 @@ Global
16881732
{BE74CE89-456C-44E4-9C27-10755372C17D} = {2930377F-5CDC-4826-A885-B5AE5CAF9EB3}
16891733
{89B8541F-FEC6-4D5E-9557-DD8C566CF536} = {2930377F-5CDC-4826-A885-B5AE5CAF9EB3}
16901734
{F047546D-EABA-4E60-AAB3-739C7C2407B1} = {89B8541F-FEC6-4D5E-9557-DD8C566CF536}
1735+
{D7757C5F-D9BA-4049-A956-EA1E5BEDE4CF} = {D9252E02-D807-43DA-BBAF-AD739A8D385A}
1736+
{A14AC3AC-3BAD-450A-957F-2F3B45E2412F} = {D9252E02-D807-43DA-BBAF-AD739A8D385A}
1737+
{5D56AD97-9819-4A65-ADD3-18728FE81D95} = {D9252E02-D807-43DA-BBAF-AD739A8D385A}
16911738
{FC9D173D-8F61-40AF-BFC3-A95A47F75A38} = {6868A014-43FD-4047-B536-30D5D159D9D4}
16921739
{4FA34264-8FAA-4C96-85E1-3212BB385FB0} = {6868A014-43FD-4047-B536-30D5D159D9D4}
16931740
{270CD057-32B2-4F16-A76A-9C074B4F35D5} = {6868A014-43FD-4047-B536-30D5D159D9D4}

eng/Baseline.props

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,20 @@
181181
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.DiagnosticAdapter' AND '$(TargetFramework)' == 'netstandard2.0' ">
182182
<BaselinePackageReference Include="System.Diagnostics.DiagnosticSource" Version="[4.5.0, )" />
183183
</ItemGroup>
184+
<!-- Package: Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions-->
185+
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions' ">
186+
<BaselinePackageVersion>2.2.0</BaselinePackageVersion>
187+
</PropertyGroup>
188+
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions' AND '$(TargetFramework)' == 'netstandard2.0' " />
189+
<!-- Package: Microsoft.Extensions.Diagnostics.HealthChecks-->
190+
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Diagnostics.HealthChecks' ">
191+
<BaselinePackageVersion>2.2.0</BaselinePackageVersion>
192+
</PropertyGroup>
193+
<ItemGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.Diagnostics.HealthChecks' AND '$(TargetFramework)' == 'netstandard2.0' ">
194+
<BaselinePackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="[2.2.0, )" />
195+
<BaselinePackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="[2.2.0, )" />
196+
<BaselinePackageReference Include="Microsoft.Extensions.Options" Version="[2.2.0, )" />
197+
</ItemGroup>
184198
<!-- Package: Microsoft.Extensions.FileProviders.Abstractions-->
185199
<PropertyGroup Condition=" '$(PackageId)' == 'Microsoft.Extensions.FileProviders.Abstractions' ">
186200
<BaselinePackageVersion>2.2.0</BaselinePackageVersion>

eng/ProjectReferences.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<ProjectReferenceProvider Include="Microsoft.Extensions.FileProviders.Embedded" ProjectPath="$(RepositoryRoot)src\FileProviders\Embedded\src\Microsoft.Extensions.FileProviders.Embedded.csproj" />
2929
<ProjectReferenceProvider Include="Microsoft.Extensions.FileProviders.Physical" ProjectPath="$(RepositoryRoot)src\FileProviders\Physical\src\Microsoft.Extensions.FileProviders.Physical.csproj" />
3030
<ProjectReferenceProvider Include="Microsoft.Extensions.FileSystemGlobbing" ProjectPath="$(RepositoryRoot)src\FileSystemGlobbing\src\Microsoft.Extensions.FileSystemGlobbing.csproj" />
31+
<ProjectReferenceProvider Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" ProjectPath="$(RepositoryRoot)src\HealthChecks\Abstractions\src\Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.csproj" />
32+
<ProjectReferenceProvider Include="Microsoft.Extensions.Diagnostics.HealthChecks" ProjectPath="$(RepositoryRoot)src\HealthChecks\HealthChecks\src\Microsoft.Extensions.Diagnostics.HealthChecks.csproj" />
3133
<ProjectReferenceProvider Include="Microsoft.Extensions.Hosting.Abstractions" ProjectPath="$(RepositoryRoot)src\Hosting\Abstractions\src\Microsoft.Extensions.Hosting.Abstractions.csproj" />
3234
<ProjectReferenceProvider Include="Microsoft.Extensions.Hosting" ProjectPath="$(RepositoryRoot)src\Hosting\Hosting\src\Microsoft.Extensions.Hosting.csproj" />
3335
<ProjectReferenceProvider Include="Microsoft.Extensions.Http" ProjectPath="$(RepositoryRoot)src\HttpClientFactory\Http\src\Microsoft.Extensions.Http.csproj" />

eng/tools/BaselineGenerator/baseline.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<Package Id="Microsoft.Extensions.DependencyInjection.Specification.Tests" Version="2.2.0" />
2121
<Package Id="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
2222
<Package Id="Microsoft.Extensions.DiagnosticAdapter" Version="2.2.0" />
23+
<Package Id="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="2.2.0" />
24+
<Package Id="Microsoft.Extensions.Diagnostics.HealthChecks" Version="2.2.0" />
2325
<Package Id="Microsoft.Extensions.FileProviders.Abstractions" Version="2.2.0" />
2426
<Package Id="Microsoft.Extensions.FileProviders.Composite" Version="2.2.0" />
2527
<Package Id="Microsoft.Extensions.FileProviders.Embedded" Version="2.2.0" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
3+
4+
<PropertyGroup>
5+
<IsProductComponent>true</IsProductComponent>
6+
</PropertyGroup>
7+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.Extensions.Diagnostics.HealthChecks
5+
{
6+
public sealed class HealthCheckContext
7+
{
8+
/// <summary>
9+
/// Gets or sets the <see cref="HealthCheckRegistration"/> of the currently executing <see cref="IHealthCheck"/>.
10+
/// </summary>
11+
public HealthCheckRegistration Registration { get; set; }
12+
}
13+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
namespace Microsoft.Extensions.Diagnostics.HealthChecks
8+
{
9+
/// <summary>
10+
/// Represent the registration information associated with an <see cref="IHealthCheck"/> implementation.
11+
/// </summary>
12+
/// <remarks>
13+
/// <para>
14+
/// The health check registration is provided as a separate object so that application developers can customize
15+
/// how health check implementations are configured.
16+
/// </para>
17+
/// <para>
18+
/// The registration is provided to an <see cref="IHealthCheck"/> implementation during execution through
19+
/// <see cref="HealthCheckContext.Registration"/>. This allows a health check implementation to access named
20+
/// options or perform other operations based on the registered name.
21+
/// </para>
22+
/// </remarks>
23+
public sealed class HealthCheckRegistration
24+
{
25+
private Func<IServiceProvider, IHealthCheck> _factory;
26+
private string _name;
27+
28+
/// <summary>
29+
/// Creates a new <see cref="HealthCheckRegistration"/> for an existing <see cref="IHealthCheck"/> instance.
30+
/// </summary>
31+
/// <param name="name">The health check name.</param>
32+
/// <param name="instance">The <see cref="IHealthCheck"/> instance.</param>
33+
/// <param name="failureStatus">
34+
/// The <see cref="HealthStatus"/> that should be reported upon failure of the health check. If the provided value
35+
/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
36+
/// </param>
37+
/// <param name="tags">A list of tags that can be used for filtering health checks.</param>
38+
public HealthCheckRegistration(string name, IHealthCheck instance, HealthStatus? failureStatus, IEnumerable<string> tags)
39+
{
40+
if (name == null)
41+
{
42+
throw new ArgumentNullException(nameof(name));
43+
}
44+
45+
if (instance == null)
46+
{
47+
throw new ArgumentNullException(nameof(instance));
48+
}
49+
50+
Name = name;
51+
FailureStatus = failureStatus ?? HealthStatus.Unhealthy;
52+
Tags = new HashSet<string>(tags ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
53+
Factory = (_) => instance;
54+
}
55+
56+
/// <summary>
57+
/// Creates a new <see cref="HealthCheckRegistration"/> for an existing <see cref="IHealthCheck"/> instance.
58+
/// </summary>
59+
/// <param name="name">The health check name.</param>
60+
/// <param name="factory">A delegate used to create the <see cref="IHealthCheck"/> instance.</param>
61+
/// <param name="failureStatus">
62+
/// The <see cref="HealthStatus"/> that should be reported when the health check reports a failure. If the provided value
63+
/// is <c>null</c>, then <see cref="HealthStatus.Unhealthy"/> will be reported.
64+
/// </param>
65+
/// <param name="tags">A list of tags that can be used for filtering health checks.</param>
66+
public HealthCheckRegistration(
67+
string name,
68+
Func<IServiceProvider, IHealthCheck> factory,
69+
HealthStatus? failureStatus,
70+
IEnumerable<string> tags)
71+
{
72+
if (name == null)
73+
{
74+
throw new ArgumentNullException(nameof(name));
75+
}
76+
77+
if (factory == null)
78+
{
79+
throw new ArgumentNullException(nameof(factory));
80+
}
81+
82+
Name = name;
83+
FailureStatus = failureStatus ?? HealthStatus.Unhealthy;
84+
Tags = new HashSet<string>(tags ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
85+
Factory = factory;
86+
}
87+
88+
/// <summary>
89+
/// Gets or sets a delegate used to create the <see cref="IHealthCheck"/> instance.
90+
/// </summary>
91+
public Func<IServiceProvider, IHealthCheck> Factory
92+
{
93+
get => _factory;
94+
set
95+
{
96+
if (value == null)
97+
{
98+
throw new ArgumentNullException(nameof(value));
99+
}
100+
101+
_factory = value;
102+
}
103+
}
104+
105+
/// <summary>
106+
/// Gets or sets the <see cref="HealthStatus"/> that should be reported upon failure of the health check.
107+
/// </summary>
108+
public HealthStatus FailureStatus { get; set; }
109+
110+
/// <summary>
111+
/// Gets or sets the health check name.
112+
/// </summary>
113+
public string Name
114+
{
115+
get => _name;
116+
set
117+
{
118+
if (value == null)
119+
{
120+
throw new ArgumentNullException(nameof(value));
121+
}
122+
123+
_name = value;
124+
}
125+
}
126+
127+
/// <summary>
128+
/// Gets a list of tags that can be used for filtering health checks.
129+
/// </summary>
130+
public ISet<string> Tags { get; }
131+
}
132+
}

0 commit comments

Comments
 (0)