Skip to content

Commit

Permalink
Merge branch 'master' into issue-116
Browse files Browse the repository at this point in the history
  • Loading branch information
jnovick authored Apr 24, 2019
2 parents 3f99d3c + 6b1c4ba commit 2a2e259
Show file tree
Hide file tree
Showing 116 changed files with 383 additions and 573 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ Check this [README](./AzureDevOpsTasks/README.md) on how to configure it.

AspNetCore.Diagnostics.HealthChecks wouldn't be possible without the time and effort of its contributors. The team is made up of Unai Zorrilla Castro [@unaizorrilla](https://github.com/unaizorrilla), Luis Ruiz Pavón [@lurumad](https://github.com/lurumad), Carlos Landeras [@carloslanderas](https://github.com/carloslanderas) and Eduard Tomás [@eiximenis](https://github.com/eiximenis).

*Our valued committers are*: Hugo Biarge @hbiarge, Matt Channer @mattchanner, Luis Fraile @lfraile, Bradley Grainger @bgrainger, Simon Birrer @SbiCA, Mahamadou Camara @poumup,Jonathan Berube @joncloud, Daniel Edwards @dantheman999301, Mike McFarland @roketworks, Matteo @Franklin89, Miňo Martiniak @Burgyn, Peter Winkler @pajzo, @mikevanoo,Alexandru Rus @AlexandruRus23,Volker Thiel @riker09, Ahmad Magdy @Ahmad-Magdy, Marcel Lambacher @Marcel-Lambacher.
*Our valued committers are*: Hugo Biarge @hbiarge, Matt Channer @mattchanner, Luis Fraile @lfraile, Bradley Grainger @bgrainger, Simon Birrer @SbiCA, Mahamadou Camara @poumup,Jonathan Berube @joncloud, Daniel Edwards @dantheman999301, Mike McFarland @roketworks, Matteo @Franklin89, Miňo Martiniak @Burgyn, Peter Winkler @pajzo, @mikevanoo,Alexandru Rus @AlexandruRus23,Volker Thiel @riker09, Ahmad Magdy @Ahmad-Magdy, Marcel Lambacher @Marcel-Lambacher,Ivan Maximov @sungam3r.

If you want to contribute to the project and make it better, your help is very welcome. You can contribute with helpful bug reports, features requests and also submitting new features with pull requests.

Expand Down
6 changes: 4 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<#
.SYNOPSIS
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
to see if an error occured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
.EXAMPLE
Expand All @@ -22,7 +22,7 @@ function Exec
}
}

if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
if (Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }

exec { & dotnet restore }

Expand Down Expand Up @@ -94,6 +94,7 @@ 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.Publisher.Seq\HealthChecks.Publisher.Seq.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 }
exec { & dotnet pack .\src\HealthChecks.Kubernetes\HealthChecks.Kubernetes.csproj -c Release -o ..\..\artifacts --include-symbols --no-build }
Expand Down Expand Up @@ -128,6 +129,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.Publisher.Seq\HealthChecks.Publisher.Seq.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 }
exec { & dotnet pack .\src\HealthChecks.Kubernetes\HealthChecks.Kubernetes.csproj -c Release -o ..\..\artifacts --include-symbols --no-build --version-suffix=$suffix }
Expand Down
4 changes: 2 additions & 2 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<HealthCheckSqlServer>2.2.0</HealthCheckSqlServer>
<HealthCheckSqlite>2.2.0</HealthCheckSqlite>
<HealthCheckUri>2.2.3</HealthCheckUri>
<HealthCheckRedis>2.2.2</HealthCheckRedis>
<HealthCheckRedis>2.2.3</HealthCheckRedis>
<HealthCheckRabbitMQ>2.2.1</HealthCheckRabbitMQ>
<HealthCheckEventStore>2.2.1</HealthCheckEventStore>
<HealthCheckElasticsearch>2.2.1</HealthCheckElasticsearch>
Expand All @@ -99,7 +99,7 @@
<HealthCheckPublisherPrometheus>2.2.0</HealthCheckPublisherPrometheus>
<HealthCheckAWSS3>2.2.0</HealthCheckAWSS3>
<HealthCheckKeyVault>2.2.2</HealthCheckKeyVault>
<HealthCheckPublisherSeq>2.2.0</HealthCheckPublisherSeq>
<HealthCheckPublisherSeq>2.2.1</HealthCheckPublisherSeq>
<HealthCheckRavenDB>2.2.2</HealthCheckRavenDB>
<HealthCheckKubernetes>2.2.1</HealthCheckKubernetes>
<HealthCheckSignalR>2.2.0</HealthCheckSignalR>
Expand Down
8 changes: 4 additions & 4 deletions dotnet-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
.PARAMETER DryRun
If set it will not perform installation but instead display what command line to use to consistently install
currently requested version of dotnet cli. In example if you specify version 'latest' it will display a link
with specific version so that this command can be used deterministicly in a build script.
with specific version so that this command can be used deterministically in a build script.
It also displays binaries location if you prefer to install or download it yourself.
.PARAMETER NoPath
By default this script will set environment variable PATH for the current process to the binaries folder inside installation folder.
Expand Down Expand Up @@ -199,11 +199,11 @@ function GetHTTPResponse([Uri] $Uri)
# HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet.
Load-Assembly -Assembly System.Net.Http

if(-not $ProxyAddress) {
if (-not $ProxyAddress) {
try {
# Despite no proxy being explicitly specified, we may still be behind a default proxy
$DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy;
if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))) {
if ($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))) {
$ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString
$ProxyUseDefaultCredentials = $true
}
Expand All @@ -215,7 +215,7 @@ function GetHTTPResponse([Uri] $Uri)
}
}

if($ProxyAddress) {
if ($ProxyAddress) {
$HttpClientHandler = New-Object System.Net.Http.HttpClientHandler
$HttpClientHandler.Proxy = New-Object System.Net.WebProxy -Property @{Address=$ProxyAddress;UseDefaultCredentials=$ProxyUseDefaultCredentials}
$HttpClient = New-Object System.Net.Http.HttpClient -ArgumentList $HttpClientHandler
Expand Down
5 changes: 1 addition & 4 deletions samples/HealthChecks.Sample/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace HealthChecks.Sample.Controllers
{
Expand Down
9 changes: 1 addition & 8 deletions samples/HealthChecks.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace HealthChecks.Sample
{
Expand Down
4 changes: 2 additions & 2 deletions samples/HealthChecks.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthChecks("/health", new HealthCheckOptions()
app.UseHealthChecks("/health", new HealthCheckOptions
{
Predicate = _ => true
});

app.UseHealthChecks("/healthz", new HealthCheckOptions()
app.UseHealthChecks("/healthz", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
Expand Down
9 changes: 1 addition & 8 deletions samples/HealthChecks.UI.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace HealthChecks.UI.Sample
{
Expand Down
7 changes: 1 addition & 6 deletions samples/HealthChecks.UI.Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace HealthChecks.UI.Sample
Expand Down
9 changes: 1 addition & 8 deletions samples/HealthChecks.UIAndApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace HealthChecks.UIAndApi
{
Expand Down
4 changes: 2 additions & 2 deletions samples/HealthChecks.UIAndApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthChecks("/healthz",new HealthCheckOptions()
app.UseHealthChecks("/healthz",new HealthCheckOptions
{
Predicate = _=>true,
Predicate = _=> true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
})
.UseHealthChecksUI()
Expand Down
9 changes: 1 addition & 8 deletions samples/HealthChecks.UIAndApiCustomization/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace HealthChecks.UIAndApi
{
Expand Down
2 changes: 1 addition & 1 deletion samples/HealthChecks.UIAndApiCustomization/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void ConfigureServices(IServiceCollection services)
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthChecks("/healthz", new HealthCheckOptions()
app.UseHealthChecks("/healthz", new HealthCheckOptions
{
Predicate = _ => true,
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
Expand Down
27 changes: 14 additions & 13 deletions src/HealthChecks.Aws.S3/S3HealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@ public class S3HealthCheck : IHealthCheck
private readonly S3BucketOptions _bucketOptions;
public S3HealthCheck(S3BucketOptions bucketOptions)
{
if (bucketOptions == null)
{
throw new ArgumentNullException(nameof(bucketOptions));
}
if (string.IsNullOrEmpty(bucketOptions.AccessKey))
{
throw new ArgumentNullException(nameof(S3BucketOptions.AccessKey));
}

if (string.IsNullOrEmpty(bucketOptions.SecretKey))
{
throw new ArgumentNullException(nameof(S3BucketOptions.SecretKey));
}

if (bucketOptions.S3Config == null)
{
throw new ArgumentNullException(nameof(S3BucketOptions.S3Config));
}

_bucketOptions = bucketOptions;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
var credentials = new BasicAWSCredentials(_bucketOptions.AccessKey, _bucketOptions.SecretKey);
var client = new AmazonS3Client(credentials, _bucketOptions.S3Config);

var response = await client.ListObjectsAsync(_bucketOptions.BucketName, cancellationToken);

if (_bucketOptions.CustomResponseCheck != null)
{
return _bucketOptions.CustomResponseCheck.Invoke(response)
? HealthCheckResult.Healthy()
: new HealthCheckResult(context.Registration.FailureStatus, description:"Custom response check is not satisfied.");
using (var client = new AmazonS3Client(credentials, _bucketOptions.S3Config))
{
var response = await client.ListObjectsAsync(_bucketOptions.BucketName, cancellationToken);

if (_bucketOptions.CustomResponseCheck != null)
{
return _bucketOptions.CustomResponseCheck.Invoke(response)
? HealthCheckResult.Healthy()
: new HealthCheckResult(context.Registration.FailureStatus, description: "Custom response check is not satisfied.");
}
}

return HealthCheckResult.Healthy();
}
catch (Exception ex)
Expand Down
16 changes: 6 additions & 10 deletions src/HealthChecks.AzureKeyVault/AzureKeyVaultHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,29 @@ namespace HealthChecks.AzureKeyVault
public class AzureKeyVaultHealthCheck : IHealthCheck
{
private readonly AzureKeyVaultOptions _options;

public AzureKeyVaultHealthCheck(AzureKeyVaultOptions options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
var currentSecret = string.Empty;

try
{
var client = CreateClient();
foreach (var item in _options.Secrets)
{
await client.GetSecretAsync(_options.KeyVaultUrlBase, item, cancellationToken);
using (var client = CreateClient())
{
foreach (var item in _options.Secrets)
{
await client.GetSecretAsync(_options.KeyVaultUrlBase, item, cancellationToken);
}
}

return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}

private KeyVaultClient CreateClient()
{
if (_options.UseManagedServiceIdentity)
Expand All @@ -48,7 +46,6 @@ private KeyVaultClient CreateClient()
return new KeyVaultClient(GetToken);
}
}

private async Task<string> GetToken(string authority, string resource, string scope)
{
var authContext = new AuthenticationContext(authority);
Expand All @@ -59,7 +56,6 @@ private async Task<string> GetToken(string authority, string resource, string sc
{
throw new InvalidOperationException($"[{nameof(AzureKeyVaultHealthCheck)}] - Failed to obtain the JWT token");
}

return result.AccessToken;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public static IHealthChecksBuilder AddAzureEventHub(this IHealthChecksBuilder bu
failureStatus,
tags));
}

/// <summary>
/// Add a health check for specified Azure Service Bus Queue.
/// </summary>
Expand All @@ -48,12 +47,11 @@ public static IHealthChecksBuilder AddAzureEventHub(this IHealthChecksBuilder bu
public static IHealthChecksBuilder AddAzureServiceBusQueue(this IHealthChecksBuilder builder, string connectionString, string queueName, string name = default, HealthStatus? failureStatus = default, IEnumerable<string> tags = default)
{
return builder.Add(new HealthCheckRegistration(
name ?? AZUREQUEUE_NAME,
name ?? AZUREQUEUE_NAME,
sp => new AzureServiceBusQueueHealthCheck(connectionString, queueName),
failureStatus,
tags));
}

/// <summary>
/// Add a health check for Azure Service Bus Topic.
/// </summary>
Expand All @@ -70,7 +68,7 @@ public static IHealthChecksBuilder AddAzureServiceBusQueue(this IHealthChecksBui
public static IHealthChecksBuilder AddAzureServiceBusTopic(this IHealthChecksBuilder builder, string connectionString, string topicName, string name = default, HealthStatus? failureStatus = default, IEnumerable<string> tags = default)
{
return builder.Add(new HealthCheckRegistration(
name ?? AZURETOPIC_NAME,
name ?? AZURETOPIC_NAME,
sp => new AzureServiceBusTopicHealthCheck(connectionString, topicName),
failureStatus,
tags));
Expand Down
6 changes: 5 additions & 1 deletion src/HealthChecks.AzureStorage/AzureBlobStorageHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

namespace HealthChecks.AzureStorage
{
public class AzureBlobStorageHealthCheck
public class AzureBlobStorageHealthCheck
: IHealthCheck
{
private readonly string _connectionString;
public AzureBlobStorageHealthCheck(string connectionString)
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
_connectionString = connectionString;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

namespace HealthChecks.AzureStorage
{
public class AzureQueueStorageHealthCheck
public class AzureQueueStorageHealthCheck
: IHealthCheck
{
private readonly string _connectionString;
public AzureQueueStorageHealthCheck(string connectionString)
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
_connectionString = connectionString;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
Expand Down
4 changes: 4 additions & 0 deletions src/HealthChecks.AzureStorage/AzureTableStorageHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class AzureTableStorageHealthCheck
private readonly string _connectionString;
public AzureTableStorageHealthCheck(string connectionString)
{
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentNullException(nameof(connectionString));
}
_connectionString = connectionString;
}
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
Expand Down
Loading

0 comments on commit 2a2e259

Please sign in to comment.