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

Provides ability to use different ctors for AmazonCloudWatchClient #1473

Merged
merged 2 commits into from
Oct 3, 2022
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
11 changes: 11 additions & 0 deletions src/HealthChecks.Publisher.CloudWatch/CloudWatchOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Amazon;
using Amazon.CloudWatch;

namespace HealthChecks.Publisher.CloudWatch;

Expand All @@ -19,4 +20,14 @@ public class CloudWatchOptions
/// The namespace for the metric data.
/// </summary>
public string Namespace { get; set; } = "Xabaril/AspNetCoreDiagnosticsHealthChecks";

/// <summary>
/// Delegate to build <see cref="AmazonCloudWatchClient"/> used by AWS CloudWatch publisher.
/// </summary>
public Func<CloudWatchOptions, AmazonCloudWatchClient> ClientBuilder { get; set; } = options =>
{
return options.AwsAccessKeyId is null && options.AwsSecretAccessKey is null && options.Region is null
? new AmazonCloudWatchClient()
: new AmazonCloudWatchClient(options.AwsAccessKeyId, options.AwsSecretAccessKey, options.Region);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public CloudWatchPublisher(CloudWatchOptions options)
{
_options = options ?? throw new ArgumentNullException(nameof(options));

_amazonCloudWatchClient = new AmazonCloudWatchClient(options.AwsAccessKeyId, options.AwsSecretAccessKey, options.Region);
_amazonCloudWatchClient = options.ClientBuilder(options);

string serviceCheckName = options.ServiceCheckName ?? Assembly.GetEntryAssembly()?.GetName()?.Name ?? "undefined";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class CloudWatchHealthCheckBuilderExtensions
/// Add a health check publisher for AWS CloudWatch.
/// </summary>
/// <remarks>
/// For each <see cref="HealthReport"/> published a new metric is sent to AWS CloudWatch indicating
/// For each <see cref="HealthReport"/> published a new metric is sent to AWS CloudWatch indicating
/// the health check status (2 - Healthy, 1 - Degraded, 0 - Unhealthy)
/// </remarks>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace HealthChecks.Publisher.CloudWatch
public CloudWatchOptions() { }
public string? AwsAccessKeyId { get; set; }
public string? AwsSecretAccessKey { get; set; }
public System.Func<HealthChecks.Publisher.CloudWatch.CloudWatchOptions, Amazon.CloudWatch.AmazonCloudWatchClient> ClientBuilder { get; set; }
public string Namespace { get; set; }
public Amazon.RegionEndpoint? Region { get; set; }
public string? ServiceCheckName { get; set; }
Expand Down