Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DynamoDBOptions.Limit and DynamoDBOptions.LastEvaluatedTableName #1945

Merged
merged 2 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IHealthChecksBuilder AddDynamoDb(

return builder.Add(new HealthCheckRegistration(
name ?? NAME,
sp => new DynamoDbHealthCheck(options),
_ => new DynamoDbHealthCheck(options),
failureStatus,
tags,
timeout));
Expand Down
14 changes: 13 additions & 1 deletion src/HealthChecks.DynamoDb/DynamoDbHealthCheck.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.Runtime;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace HealthChecks.DynamoDb;

/// <summary>
/// Health check for AWS DynamoDb database.
/// </summary>
public class DynamoDbHealthCheck : IHealthCheck
{
private readonly DynamoDBOptions _options;

/// <summary>
/// Creates health check for AWS DynamoDb database with the specified options.
/// </summary>
/// <param name="options"></param>
public DynamoDbHealthCheck(DynamoDBOptions options)
{
_options = Guard.ThrowIfNull(options);
Expand Down Expand Up @@ -36,7 +44,11 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
? CreateClientWithCredentials(credentials)
: CreateClientWithoutCredentials();

_ = await client.ListTablesAsync(cancellationToken).ConfigureAwait(false);
var request = new ListTablesRequest { ExclusiveStartTableName = _options.LastEvaluatedTableName };
if (_options.Limit != null)
request.Limit = _options.Limit.Value;

var response = await client.ListTablesAsync(request, cancellationToken).ConfigureAwait(false);

return HealthCheckResult.Healthy();
}
Expand Down
10 changes: 10 additions & 0 deletions src/HealthChecks.DynamoDb/DynamoDbOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ public class DynamoDBOptions
public string? SecretKey { get; set; }

public RegionEndpoint RegionEndpoint { get; set; } = null!;

/// <summary>
/// A maximum number of table names to read.
/// </summary>
public int? Limit { get; set; }

/// <summary>
/// The first table name to read.
/// </summary>
public string? LastEvaluatedTableName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace HealthChecks.DynamoDb
"d")]
public string? AccessKey { get; set; }
public Amazon.Runtime.AWSCredentials? Credentials { get; set; }
public string? LastEvaluatedTableName { get; set; }
public int? Limit { get; set; }
public Amazon.RegionEndpoint RegionEndpoint { get; set; }
[System.Obsolete("Specify access key and secret as a BasicCredential to Credentials property instea" +
"d")]
Expand Down