Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #5 from AppMetrics/dev
Browse files Browse the repository at this point in the history
1.0.0 release
  • Loading branch information
alhardy authored Dec 2, 2018
2 parents 3ea60df + a467c20 commit 19a8443
Show file tree
Hide file tree
Showing 20 changed files with 631 additions and 29 deletions.
14 changes: 14 additions & 0 deletions HealthAzure.sln
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthAzureSandbox", "sandb
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.Metrics.Health.Checks.AzureDocumentDB", "src\App.Metrics.Health.Checks.AzureDocumentDB\App.Metrics.Health.Checks.AzureDocumentDB.csproj", "{FDA9F929-C56D-424F-A4B5-8B551931C39C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.Metrics.Health.Checks.AzureServiceBus", "src\App.Metrics.Health.Checks.AzureServiceBus\App.Metrics.Health.Checks.AzureServiceBus.csproj", "{452F4D94-36E8-4AB0-BD5D-01E5C160E465}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.Metrics.Health.Checks.AzureEventHubs", "src\App.Metrics.Health.Checks.AzureEventHubs\App.Metrics.Health.Checks.AzureEventHubs.csproj", "{1AC63139-9B03-4936-9ABF-300523E4522F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -67,6 +71,14 @@ Global
{FDA9F929-C56D-424F-A4B5-8B551931C39C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FDA9F929-C56D-424F-A4B5-8B551931C39C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FDA9F929-C56D-424F-A4B5-8B551931C39C}.Release|Any CPU.Build.0 = Release|Any CPU
{452F4D94-36E8-4AB0-BD5D-01E5C160E465}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{452F4D94-36E8-4AB0-BD5D-01E5C160E465}.Debug|Any CPU.Build.0 = Debug|Any CPU
{452F4D94-36E8-4AB0-BD5D-01E5C160E465}.Release|Any CPU.ActiveCfg = Release|Any CPU
{452F4D94-36E8-4AB0-BD5D-01E5C160E465}.Release|Any CPU.Build.0 = Release|Any CPU
{1AC63139-9B03-4936-9ABF-300523E4522F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1AC63139-9B03-4936-9ABF-300523E4522F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1AC63139-9B03-4936-9ABF-300523E4522F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1AC63139-9B03-4936-9ABF-300523E4522F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -78,6 +90,8 @@ Global
{38E7AD0C-9792-4D2D-8C2C-9D9CE6BA210B} = {2D805782-756E-4C98-B22E-F502BEE95318}
{6CEA2D2A-FCDD-4C5C-98F8-6C69DFB3F8F9} = {C0BC96C5-46E1-4323-9C5D-58D9A96549CD}
{FDA9F929-C56D-424F-A4B5-8B551931C39C} = {2D805782-756E-4C98-B22E-F502BEE95318}
{452F4D94-36E8-4AB0-BD5D-01E5C160E465} = {2D805782-756E-4C98-B22E-F502BEE95318}
{1AC63139-9B03-4936-9ABF-300523E4522F} = {2D805782-756E-4C98-B22E-F502BEE95318}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8699A1D-0BA1-403C-86E9-C789CD2645EB}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ App Metrics is an open-source and cross-platform .NET library used to record met
|------|:--------:|:--------:|:--------:|
|App.Metrics.Health.Checks.AzureDocumentDB|[![MyGet Status](https://img.shields.io/myget/appmetrics/v/App.Metrics.Health.Checks.AzureDocumentDB.svg?style=flat-square)](https://www.myget.org/feed/appmetrics/package/nuget/App.Metrics.Health.Checks.AzureDocumentDB)|[![NuGet Status](https://img.shields.io/nuget/vpre/App.Metrics.Health.Checks.AzureDocumentDB.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureDocumentDB/)|[![NuGet Status](https://img.shields.io/nuget/v/App.Metrics.Health.Checks.AzureDocumentDB.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureDocumentDB/)
|App.Metrics.Health.Checks.AzureStorage|[![MyGet Status](https://img.shields.io/myget/appmetrics/v/App.Metrics.Health.Checks.AzureStorage.svg?style=flat-square)](https://www.myget.org/feed/appmetrics/package/nuget/App.Metrics.Health.Checks.AzureStorage)|[![NuGet Status](https://img.shields.io/nuget/vpre/App.Metrics.Health.Checks.AzureStorage.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureStorage/)|[![NuGet Status](https://img.shields.io/nuget/v/App.Metrics.Health.Checks.AzureStorage.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureStorage/)|
|App.Metrics.Health.Checks.AzureServiceBus|[![MyGet Status](https://img.shields.io/myget/appmetrics/v/App.Metrics.Health.Checks.AzureServiceBus.svg?style=flat-square)](https://www.myget.org/feed/appmetrics/package/nuget/App.Metrics.Health.Checks.AzureServiceBus)|[![NuGet Status](https://img.shields.io/nuget/vpre/App.Metrics.Health.Checks.AzureServiceBus.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureServiceBus/)|[![NuGet Status](https://img.shields.io/nuget/v/App.Metrics.Health.Checks.AzureServiceBus.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureServiceBus/)|
|App.Metrics.Health.Checks.AzureEventHubs|[![MyGet Status](https://img.shields.io/myget/appmetrics/v/App.Metrics.Health.Checks.AzureEventHubs.svg?style=flat-square)](https://www.myget.org/feed/appmetrics/package/nuget/App.Metrics.Health.Checks.AzureEventHubs)|[![NuGet Status](https://img.shields.io/nuget/vpre/App.Metrics.Health.Checks.AzureEventHubs.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureEventHubs/)|[![NuGet Status](https://img.shields.io/nuget/v/App.Metrics.Health.Checks.AzureEventHubs.svg?style=flat-square)](https://www.nuget.org/packages/App.Metrics.Health.Checks.AzureEventHubs/)|

## How to build

Expand Down
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ deploy:
secure: gIAiACgNj+JzXyLLTe3rLxZyrAB9RpC8Lw81xEjdOLXqotprqEwGiFWRipEqkpps
skip_symbols: true
symbol_server: https://www.myget.org/F/appmetrics/symbol
install:
- cmd: curl -O https://download.microsoft.com/download/8/8/5/88544F33-836A-49A5-8B67-451C24709A8F/dotnet-sdk-2.1.300-win-x64.exe
- cmd: dotnet-sdk-2.1.300-win-x64.exe /install /quiet /norestart /log install.log
skip_commits:
files:
- '**/*.md'
4 changes: 3 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ var linkSources = HasArgument("LinkSources") ? Argument<bool>("LinkSources")
//////////////////////////////////////////////////////////////////////
var packDirs = new [] {
Directory("./src/App.Metrics.Health.Checks.AzureStorage"),
Directory("./src/App.Metrics.Health.Checks.AzureDocumentDB")
Directory("./src/App.Metrics.Health.Checks.AzureDocumentDB"),
Directory("./src/App.Metrics.Health.Checks.AzureServiceBus"),
Directory("./src/App.Metrics.Health.Checks.AzureEventHubs")
};
var artifactsDir = (DirectoryPath) Directory("./artifacts");
var testResultsDir = (DirectoryPath) artifactsDir.Combine("test-results");
Expand Down
13 changes: 7 additions & 6 deletions build/dependencies.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Project>
<PropertyGroup>
<MicrosoftExtensionsVersion>2.1.0</MicrosoftExtensionsVersion>
<AppMetricsHealthVersion>2.1.0-*</AppMetricsHealthVersion>
<MicrosoftExtensionsVersion>2.1.1</MicrosoftExtensionsVersion>
<BenchmarkDotNetVersion>0.10.14</BenchmarkDotNetVersion>
<CoreFxVersion>4.5.0</CoreFxVersion>
<DependencyModelVersion>2.1.0-*</DependencyModelVersion>
<LibLogVersion>5.0.0</LibLogVersion>
<MicrosoftCSharpVersion>4.5.0</MicrosoftCSharpVersion>
<MoqVersion>4.8.2</MoqVersion>
<NewtonsoftVersion>11.0.2</NewtonsoftVersion>
<TestSdkVersion>15.8.0-preview-20180510-03</TestSdkVersion>
<XunitVersion>2.4.0-beta.2.build4010</XunitVersion>
<FluentAssertionsVersion>5.3.2</FluentAssertionsVersion>
<MoqVersion>4.10.0</MoqVersion>
<NewtonsoftVersion>12.0.1</NewtonsoftVersion>
<TestSdkVersion>15.9.0</TestSdkVersion>
<XunitVersion>2.4.1</XunitVersion>
<FluentAssertionsVersion>5.5.3</FluentAssertionsVersion>
<FluentAssertionsJsonVersion>5.0.0</FluentAssertionsJsonVersion>
<StyleCopAnalyzersVersion>1.0.0</StyleCopAnalyzersVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "test", "benchmarks", "sandbox" ],
"sdk": {
"version": "2.1.300"
"version": "2.1.301"
}
}
2 changes: 2 additions & 0 deletions sandbox/HealthAzureSandbox/HealthAzureSandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

<ItemGroup>
<ProjectReference Include="..\..\src\App.Metrics.Health.Checks.AzureDocumentDB\App.Metrics.Health.Checks.AzureDocumentDB.csproj" />
<ProjectReference Include="..\..\src\App.Metrics.Health.Checks.AzureEventHubs\App.Metrics.Health.Checks.AzureEventHubs.csproj" />
<ProjectReference Include="..\..\src\App.Metrics.Health.Checks.AzureServiceBus\App.Metrics.Health.Checks.AzureServiceBus.csproj" />
<ProjectReference Include="..\..\src\App.Metrics.Health.Checks.AzureStorage\App.Metrics.Health.Checks.AzureStorage.csproj" />
</ItemGroup>

Expand Down
22 changes: 14 additions & 8 deletions sandbox/HealthAzureSandbox/Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using System.Threading;
using System.Threading.Tasks;
using App.Metrics.Health;
using App.Metrics.Health.Checks.AzureDocumentDB;
using App.Metrics.Health.Checks.AzureStorage;
using Microsoft.Azure.Documents.Client;
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage;
Expand Down Expand Up @@ -72,20 +70,28 @@ private static void Init()
var containerName = "test";
var documentDbDatabaseUri = UriFactory.CreateDatabaseUri("test");
var collectionUri = UriFactory.CreateDocumentCollectionUri("test", "testcollection");
var documentDbClient = new DocumentClient(
new Uri("https://localhost:8081"),
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
var doucmentDbKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
var documentDbUri = "https://localhost:8081";
var storageAccount = CloudStorageAccount.Parse(@"UseDevelopmentStorage=true");

var eventHubConnectionString = "todo event hub connection string";
var eventHubName = "todo event hub name";
var serviceBusConnectionString = "todo sb connection string";
var queueName = "todo queue name";
var topicName = "todo topic name";

Health = AppMetricsHealth.CreateDefaultBuilder()
.HealthChecks.AddAzureBlobStorageConnectivityCheck("Blob Storage Conectivity Check", storageAccount)
.HealthChecks.AddAzureBlobStorageConnectivityCheck("Blob Storage Connectivity Check", storageAccount)
.HealthChecks.AddAzureBlobStorageContainerCheck("Blob Storage Container Check", storageAccount, containerName)
.HealthChecks.AddAzureQueueStorageConnectivityCheck("Queue Storage Connectivity Check", storageAccount)
.HealthChecks.AddAzureQueueStorageCheck("Queue Storage Check", storageAccount, "test")
.HealthChecks.AddAzureDocumentDBDatabaseCheck("DocumentDB Database Check", documentDbDatabaseUri, documentDbClient)
.HealthChecks.AddAzureDocumentDBCollectionCheck("DocumentDB Collection Check", collectionUri, documentDbClient)
.HealthChecks.AddAzureDocumentDBDatabaseCheck("DocumentDB Database Check", documentDbDatabaseUri, documentDbUri, doucmentDbKey)
.HealthChecks.AddAzureDocumentDBCollectionCheck("DocumentDB Collection Check", collectionUri, documentDbUri, doucmentDbKey)
.HealthChecks.AddAzureTableStorageConnectivityCheck("Table Storage Connectivity Check", storageAccount)
.HealthChecks.AddAzureTableStorageTableCheck("Table Storage Table Exists Check", storageAccount, "test")
.HealthChecks.AddAzureEventHubConnectivityCheck("Service EventHub Connectivity Check", eventHubConnectionString, eventHubName)
.HealthChecks.AddAzureServiceBusQueueConnectivityCheck("Service Bus Queue Connectivity Check", serviceBusConnectionString, queueName)
.HealthChecks.AddAzureServiceBusTopicConnectivityCheck("Service Bus Topic Connectivity Check", serviceBusConnectionString, topicName)
.Build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.Health.Abstractions" Version="2.1.0-*" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="1.9.1" />
<PackageReference Include="App.Metrics.Health.Abstractions" Version="$(AppMetricsHealthVersion)" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.1.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using App.Metrics.Health.Logging;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;

namespace App.Metrics.Health.Checks.AzureDocumentDB
// ReSharper disable CheckNamespace
namespace App.Metrics.Health
// ReSharper restore CheckNamespace
{
public static class AzureDocumentDBHealthCheckBuilderExtensions
{
Expand All @@ -30,6 +33,22 @@ public static IHealthBuilder AddAzureDocumentDBCollectionCheck(
return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBCollectionCheck(
this IHealthCheckBuilder builder,
string name,
Uri collectionUri,
string endpointUri,
string key,
TimeSpan cacheDuration)
{
builder.AddCachedCheck(
name,
CheckDocumentDbCollectionExists(collectionUri, endpointUri, key),
cacheDuration);

return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBCollectionCheck(
this IHealthCheckBuilder builder,
string name,
Expand All @@ -41,6 +60,18 @@ public static IHealthBuilder AddAzureDocumentDBCollectionCheck(
return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBCollectionCheck(
this IHealthCheckBuilder builder,
string name,
Uri collectionUri,
string endpointUri,
string key)
{
builder.AddCheck(name, CheckDocumentDbCollectionExists(collectionUri, endpointUri, key));

return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBDatabaseCheck(
this IHealthCheckBuilder builder,
string name,
Expand All @@ -56,6 +87,22 @@ public static IHealthBuilder AddAzureDocumentDBDatabaseCheck(
return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBDatabaseCheck(
this IHealthCheckBuilder builder,
string name,
Uri databaseUri,
string endpointUri,
string key,
TimeSpan cacheDuration)
{
builder.AddCachedCheck(
name,
CheckDocumentDBDatabaseConnectivity(databaseUri, endpointUri, key),
cacheDuration);

return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBDatabaseCheck(
this IHealthCheckBuilder builder,
string name,
Expand All @@ -67,6 +114,52 @@ public static IHealthBuilder AddAzureDocumentDBDatabaseCheck(
return builder.Builder;
}

public static IHealthBuilder AddAzureDocumentDBDatabaseCheck(
this IHealthCheckBuilder builder,
string name,
Uri databaseUri,
string endpointUri,
string key)
{
builder.AddCheck(name, CheckDocumentDBDatabaseConnectivity(databaseUri, endpointUri, key));

return builder.Builder;
}

private static Func<ValueTask<HealthCheckResult>> CheckDocumentDbCollectionExists(Uri collectionUri, string endpointUri, string key)
{
return async () =>
{
bool result;

try
{
using (var documentClient = new DocumentClient(new Uri(endpointUri), key))
{
var database = await documentClient.ReadDocumentCollectionAsync(collectionUri);

result = database?.StatusCode == HttpStatusCode.OK;
}
}
catch (DocumentClientException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Logger.ErrorException($"{collectionUri} was not found.", ex);

result = false;
}
catch (Exception ex)
{
Logger.ErrorException($"{collectionUri} failed.", ex);

result = false;
}

return result
? HealthCheckResult.Healthy($"OK. '{collectionUri}' is available.")
: HealthCheckResult.Unhealthy($"Failed. '{collectionUri}' is unavailable.");
};
}

private static Func<ValueTask<HealthCheckResult>> CheckDocumentDbCollectionExists(Uri collectionUri, DocumentClient documentClient)
{
return async () =>
Expand Down Expand Up @@ -128,5 +221,44 @@ private static Func<ValueTask<HealthCheckResult>> CheckDocumentDBDatabaseConnect
: HealthCheckResult.Unhealthy($"Failed. '{databaseUri}' is unavailable.");
};
}

private static Func<ValueTask<HealthCheckResult>> CheckDocumentDBDatabaseConnectivity(Uri databaseUri, string endpointUri, string key)
{
return async () =>
{
bool result;

try
{
using (var documentClient = new DocumentClient(new Uri(endpointUri), key))
{
var token = new CancellationTokenSource();
token.CancelAfter(TimeSpan.FromSeconds(10));

await documentClient.OpenAsync(token.Token).ConfigureAwait(false);

var database = await documentClient.ReadDatabaseAsync(databaseUri);

result = database?.StatusCode == HttpStatusCode.OK;
}
}
catch (DocumentClientException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Logger.ErrorException($"{databaseUri} was not found.", ex);

result = false;
}
catch (Exception ex)
{
Logger.ErrorException($"{databaseUri} failed.", ex);

result = false;
}

return result
? HealthCheckResult.Healthy($"OK. '{databaseUri}' is available.")
: HealthCheckResult.Unhealthy($"Failed. '{databaseUri}' is unavailable.");
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>App Metrics Azure EventHubs health checks.</Description>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>appmetrics;healthchecks;azure;eventhubs</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.Health.Abstractions" Version="$(AppMetricsHealthVersion)" />
<PackageReference Include="Microsoft.Azure.EventHubs" Version="2.2.1" />
</ItemGroup>

</Project>
Loading

0 comments on commit 19a8443

Please sign in to comment.