-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move HealthChecks.Azure.Data.Tables out of CosmosDb package
- Loading branch information
1 parent
964ad22
commit 6f03c77
Showing
10 changed files
with
116 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
134 changes: 67 additions & 67 deletions
134
...hecks.CosmosDb/TableServiceHealthCheck.cs → ...re.Data.Tables/TableServiceHealthCheck.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))] |