Skip to content

Commit

Permalink
move HealthChecks.Azure.Data.Tables out of CosmosDb package
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Sep 14, 2023
1 parent 964ad22 commit 6f03c77
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 73 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/healthchecks_cosmosdb_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ jobs:
run: dotnet restore ./src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj
- name: Build
run: dotnet build --no-restore ./src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj -c $BUILD_CONFIG
- name: Pack Tables
run: dotnet pack --no-build ./src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj -c $BUILD_CONFIG -o ./artifacts
- name: Pack
run: dotnet pack --no-build ./src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj -c $BUILD_CONFIG -o ./artifacts
- name: Publish Tables
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.Azure.Data.Tables.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Publish
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.CosmosDb.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
4 changes: 4 additions & 0 deletions .github/workflows/healthchecks_cosmosdb_cd_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ jobs:
run: dotnet restore ./src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj
- name: Build
run: dotnet build --no-restore ./src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj -c $BUILD_CONFIG
- name: Pack Tables
run: dotnet pack --no-build ./src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts
- name: Pack
run: dotnet pack --no-build ./src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts
- name: Publish Tables
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.Azure.Data.Tables.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Publish
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.CosmosDb.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
2 changes: 2 additions & 0 deletions .github/workflows/healthchecks_cosmosdb_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches: [ master ]
paths:
- src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables/**
- src/HealthChecks.CosmosDb/**
- test/HealthChecks.CosmosDb.Tests/**
- test/_SHARED/**
Expand All @@ -18,6 +19,7 @@ on:
pull_request:
branches: [ master ]
paths:
- src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables/**
- src/HealthChecks.CosmosDb/**
- test/HealthChecks.CosmosDb.Tests/**
- test/_SHARED/**
Expand Down
7 changes: 7 additions & 0 deletions AspNetCore.Diagnostics.HealthChecks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.Azure.Messagin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.Azure.Messaging.EventHubs", "src\HealthChecks.Azure.Messaging.EventHubs\HealthChecks.Azure.Messaging.EventHubs.csproj", "{87F760F2-C265-4898-8B9F-2C78532BC321}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.Azure.Data.Tables", "src\HealthChecks.Azure.Data.Tables\HealthChecks.Azure.Data.Tables.csproj", "{B58D3765-3BB8-4FB4-9F0D-CC9A5EF07DF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -837,6 +839,10 @@ Global
{87F760F2-C265-4898-8B9F-2C78532BC321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87F760F2-C265-4898-8B9F-2C78532BC321}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87F760F2-C265-4898-8B9F-2C78532BC321}.Release|Any CPU.Build.0 = Release|Any CPU
{B58D3765-3BB8-4FB4-9F0D-CC9A5EF07DF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B58D3765-3BB8-4FB4-9F0D-CC9A5EF07DF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B58D3765-3BB8-4FB4-9F0D-CC9A5EF07DF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B58D3765-3BB8-4FB4-9F0D-CC9A5EF07DF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -975,6 +981,7 @@ Global
{94031EF0-8262-46BE-9CF0-4E357CAE27AE} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
{C84C0A78-B520-4B21-95D1-9113A6B46611} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
{87F760F2-C265-4898-8B9F-2C78532BC321} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
{B58D3765-3BB8-4FB4-9F0D-CC9A5EF07DF1} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2B8C62A1-11B6-469F-874C-A02443256568}
Expand Down
4 changes: 0 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
<WarningsNotAsErrors>$(WarningsNotAsErrors);IDE0053;IDE0060</WarningsNotAsErrors>
</PropertyGroup>

<ItemGroup Condition="$(MSBuildProjectName) == 'HealthChecks.CosmosDb'">
<Compile Include="../ClientCache.cs" Link="ClientCache.cs" />
</ItemGroup>

<ItemGroup Condition="!$(MSBuildProjectName.EndsWith('.Tests'))">
<InternalsVisibleTo Include="$(MSBuildProjectName).Tests" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageTags>$(PackageTags);Azure;Tables</PackageTags>
<Description>HealthChecks.CosmosDb is the health check package for Azure Tables.</Description>
<VersionPrefix>$(HealthCheckCosmosDb)</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<Compile Include="../ClientCache.cs" Link="ClientCache.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.9" />
<PackageReference Include="Azure.Data.Tables" Version="12.8.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
using Azure.Core;
using Azure.Data.Tables;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.CosmosDb;

public class TableServiceHealthCheck : IHealthCheck
{
private readonly TableServiceClient _tableServiceClient;
private readonly TableServiceHealthCheckOptions _options;

public TableServiceHealthCheck(string connectionString, string? tableName)
: this(
ClientCache.GetOrAdd(connectionString, k => new TableServiceClient(k)),
new TableServiceHealthCheckOptions { TableName = tableName })
{ }

public TableServiceHealthCheck(Uri endpoint, TableSharedKeyCredential credentials, string? tableName)
: this(
ClientCache.GetOrAdd(endpoint?.ToString()!, _ => new TableServiceClient(endpoint, credentials)),
new TableServiceHealthCheckOptions { TableName = tableName })
{ }

public TableServiceHealthCheck(Uri endpoint, TokenCredential tokenCredential, string? tableName)
: this(
ClientCache.GetOrAdd(endpoint?.ToString()!, _ => new TableServiceClient(endpoint, tokenCredential)),
new TableServiceHealthCheckOptions { TableName = tableName })
{ }

public TableServiceHealthCheck(TableServiceClient tableServiceClient, TableServiceHealthCheckOptions options)
{
_tableServiceClient = Guard.ThrowIfNull(tableServiceClient);
_options = Guard.ThrowIfNull(options);
}

/// <inheritdoc />
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
// Note: TableServiceClient.GetPropertiesAsync() cannot be used with only the role assignment
// "Storage Table Data Contributor," so TableServiceClient.QueryAsync() and
// TableClient.QueryAsync<T>() are used instead to probe service health.
await _tableServiceClient
.QueryAsync(filter: "false", cancellationToken: cancellationToken)
.GetAsyncEnumerator(cancellationToken)
.MoveNextAsync()
.ConfigureAwait(false);

if (!string.IsNullOrEmpty(_options.TableName))
{
var tableClient = _tableServiceClient.GetTableClient(_options.TableName);
await tableClient
.QueryAsync<TableEntity>(filter: "false", cancellationToken: cancellationToken)
.GetAsyncEnumerator(cancellationToken)
.MoveNextAsync()
.ConfigureAwait(false);
}

return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}
using Azure.Core;
using Azure.Data.Tables;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.CosmosDb;

public class TableServiceHealthCheck : IHealthCheck
{
private readonly TableServiceClient _tableServiceClient;
private readonly TableServiceHealthCheckOptions _options;

public TableServiceHealthCheck(string connectionString, string? tableName)
: this(
ClientCache.GetOrAdd(connectionString, k => new TableServiceClient(k)),
new TableServiceHealthCheckOptions { TableName = tableName })
{ }

public TableServiceHealthCheck(Uri endpoint, TableSharedKeyCredential credentials, string? tableName)
: this(
ClientCache.GetOrAdd(endpoint?.ToString()!, _ => new TableServiceClient(endpoint, credentials)),
new TableServiceHealthCheckOptions { TableName = tableName })
{ }

public TableServiceHealthCheck(Uri endpoint, TokenCredential tokenCredential, string? tableName)
: this(
ClientCache.GetOrAdd(endpoint?.ToString()!, _ => new TableServiceClient(endpoint, tokenCredential)),
new TableServiceHealthCheckOptions { TableName = tableName })
{ }

public TableServiceHealthCheck(TableServiceClient tableServiceClient, TableServiceHealthCheckOptions options)
{
_tableServiceClient = Guard.ThrowIfNull(tableServiceClient);
_options = Guard.ThrowIfNull(options);
}

/// <inheritdoc />
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
// Note: TableServiceClient.GetPropertiesAsync() cannot be used with only the role assignment
// "Storage Table Data Contributor," so TableServiceClient.QueryAsync() and
// TableClient.QueryAsync<T>() are used instead to probe service health.
await _tableServiceClient
.QueryAsync(filter: "false", cancellationToken: cancellationToken)
.GetAsyncEnumerator(cancellationToken)
.MoveNextAsync()
.ConfigureAwait(false);

if (!string.IsNullOrEmpty(_options.TableName))
{
var tableClient = _tableServiceClient.GetTableClient(_options.TableName);
await tableClient
.QueryAsync<TableEntity>(filter: "false", cancellationToken: cancellationToken)
.GetAsyncEnumerator(cancellationToken)
.MoveNextAsync()
.ConfigureAwait(false);
}

return HealthCheckResult.Healthy();
}
catch (Exception ex)
{
return new HealthCheckResult(context.Registration.FailureStatus, exception: ex);
}
}
}
10 changes: 8 additions & 2 deletions src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
<VersionPrefix>$(HealthCheckCosmosDb)</VersionPrefix>
</PropertyGroup>

<ItemGroup>
<Compile Include="../ClientCache.cs" Link="ClientCache.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="7.0.9" />
<PackageReference Include="Azure.Data.Tables" Version="12.8.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\HealthChecks.Azure.Data.Tables\HealthChecks.Azure.Data.Tables.csproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/HealthChecks.CosmosDb/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Runtime.CompilerServices;
using HealthChecks.CosmosDb;

[assembly: TypeForwardedTo(typeof(TableServiceHealthCheck))]
[assembly: TypeForwardedTo(typeof(TableServiceHealthCheckOptions))]

0 comments on commit 6f03c77

Please sign in to comment.