diff --git a/.github/workflows/healthchecks_cosmosdb_cd.yml b/.github/workflows/healthchecks_cosmosdb_cd.yml index f8552a1601..dd5416da23 100644 --- a/.github/workflows/healthchecks_cosmosdb_cd.yml +++ b/.github/workflows/healthchecks_cosmosdb_cd.yml @@ -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 diff --git a/.github/workflows/healthchecks_cosmosdb_cd_preview.yml b/.github/workflows/healthchecks_cosmosdb_cd_preview.yml index de3feca56f..f3490be96e 100644 --- a/.github/workflows/healthchecks_cosmosdb_cd_preview.yml +++ b/.github/workflows/healthchecks_cosmosdb_cd_preview.yml @@ -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 diff --git a/.github/workflows/healthchecks_cosmosdb_ci.yml b/.github/workflows/healthchecks_cosmosdb_ci.yml index 95c2e8e4ad..da8c589a2e 100644 --- a/.github/workflows/healthchecks_cosmosdb_ci.yml +++ b/.github/workflows/healthchecks_cosmosdb_ci.yml @@ -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/** @@ -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/** diff --git a/AspNetCore.Diagnostics.HealthChecks.sln b/AspNetCore.Diagnostics.HealthChecks.sln index 0a5d4203f7..3d805ee52a 100644 --- a/AspNetCore.Diagnostics.HealthChecks.sln +++ b/AspNetCore.Diagnostics.HealthChecks.sln @@ -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 @@ -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 @@ -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} diff --git a/Directory.Build.props b/Directory.Build.props index 302831abc8..d0562a4f5a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -32,10 +32,6 @@ $(WarningsNotAsErrors);IDE0053;IDE0060 - - - - diff --git a/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj b/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj new file mode 100644 index 0000000000..d79412186f --- /dev/null +++ b/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.0 + $(PackageTags);Azure;Tables + HealthChecks.CosmosDb is the health check package for Azure Tables. + $(HealthCheckCosmosDb) + + + + + + + + + + + + diff --git a/src/HealthChecks.CosmosDb/TableServiceHealthCheck.cs b/src/HealthChecks.Azure.Data.Tables/TableServiceHealthCheck.cs similarity index 97% rename from src/HealthChecks.CosmosDb/TableServiceHealthCheck.cs rename to src/HealthChecks.Azure.Data.Tables/TableServiceHealthCheck.cs index 69c4cb3620..073a3a3ce0 100644 --- a/src/HealthChecks.CosmosDb/TableServiceHealthCheck.cs +++ b/src/HealthChecks.Azure.Data.Tables/TableServiceHealthCheck.cs @@ -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); - } - - /// - public async Task 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() 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(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); + } + + /// + public async Task 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() 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(filter: "false", cancellationToken: cancellationToken) + .GetAsyncEnumerator(cancellationToken) + .MoveNextAsync() + .ConfigureAwait(false); + } + + return HealthCheckResult.Healthy(); + } + catch (Exception ex) + { + return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); + } + } +} diff --git a/src/HealthChecks.CosmosDb/TableServiceHealthCheckOptions.cs b/src/HealthChecks.Azure.Data.Tables/TableServiceHealthCheckOptions.cs similarity index 100% rename from src/HealthChecks.CosmosDb/TableServiceHealthCheckOptions.cs rename to src/HealthChecks.Azure.Data.Tables/TableServiceHealthCheckOptions.cs diff --git a/src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj b/src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj index a22f793141..5de7413068 100644 --- a/src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj +++ b/src/HealthChecks.CosmosDb/HealthChecks.CosmosDb.csproj @@ -7,10 +7,16 @@ $(HealthCheckCosmosDb) + + + + - - + + + + diff --git a/src/HealthChecks.CosmosDb/Properties/AssemblyInfo.cs b/src/HealthChecks.CosmosDb/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..bcce031767 --- /dev/null +++ b/src/HealthChecks.CosmosDb/Properties/AssemblyInfo.cs @@ -0,0 +1,5 @@ +using System.Runtime.CompilerServices; +using HealthChecks.CosmosDb; + +[assembly: TypeForwardedTo(typeof(TableServiceHealthCheck))] +[assembly: TypeForwardedTo(typeof(TableServiceHealthCheckOptions))]