Skip to content

Commit

Permalink
AWS SNS HealthCheck (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
zodraz authored Jul 4, 2022
1 parent 1482e93 commit 8431868
Show file tree
Hide file tree
Showing 15 changed files with 622 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/healthchecks_aws_sns_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: HealthChecks Aws Sns CD

on:
push:
tags:
- release-aws_sns-* # Push events to release-aws_sns*
jobs:
build:
env:
BUILD_CONFIG: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.202
include-prerelease: false
- name: Restore
run: dotnet restore ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj
- name: Build
run: dotnet build --no-restore ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj -c $BUILD_CONFIG
- name: Pack
run: dotnet pack --no-build ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj -c $BUILD_CONFIG -o ./artifacts
- name: Publish
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.Aws.Sns.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
27 changes: 27 additions & 0 deletions .github/workflows/healthchecks_aws_sns_cd_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: HealthChecks Aws Sns Preview CD

on:
push:
tags:
- preview-aws_sns-*
jobs:
build:
env:
BUILD_CONFIG: Release
VERSION_SUFFIX: -rc2.${{ github.run_number }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.202
include-prerelease: false
- name: Restore
run: dotnet restore ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj
- name: Build
run: dotnet build --no-restore ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj -c $BUILD_CONFIG
- name: Pack
run: dotnet pack --no-build ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts
- name: Publish
run: dotnet nuget push ./artifacts/AspNetCore.HealthChecks.Aws.Sns.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate
48 changes: 48 additions & 0 deletions .github/workflows/healthchecks_aws_sns_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: HealthChecks Aws Sns CI

on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- src/HealthChecks.Aws.Sns/**
- test/HealthChecks.Aws.Sns.Tests/**
- .github/workflows/healthchecks_aws_sns_ci.yml
- Directory.Build.props
- Directory.Build.targets
tags-ignore:
- release-*

pull_request:
branches: [ master ]
paths:
- src/HealthChecks.Aws.Sns/**
- test/HealthChecks.Aws.Sns.Tests/**
- .github/workflows/healthchecks_aws_sns_ci.yml
- Directory.Build.props
- Directory.Build.targets
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.202
include-prerelease: false
- name: Restore
run: |
dotnet restore ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj &&
dotnet restore ./test/HealthChecks.Aws.Sns.Tests/HealthChecks.Aws.Sns.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Aws.Sns.Tests/HealthChecks.Aws.Sns.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj &&
dotnet build --no-restore ./test/HealthChecks.Aws.Sns.Tests/HealthChecks.Aws.Sns.Tests.csproj
- name: Test
run: dotnet test --no-restore --no-build ./test/HealthChecks.Aws.Sns.Tests/HealthChecks.Aws.Sns.Tests.csproj

17 changes: 17 additions & 0 deletions AspNetCore.Diagnostics.HealthChecks.sln
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\healthchecks_aws_secretsmanager_cd.yml = .github\workflows\healthchecks_aws_secretsmanager_cd.yml
.github\workflows\healthchecks_aws_secretsmanager_cd_preview.yml = .github\workflows\healthchecks_aws_secretsmanager_cd_preview.yml
.github\workflows\healthchecks_aws_secretsmanager_ci.yml = .github\workflows\healthchecks_aws_secretsmanager_ci.yml
.github\workflows\healthchecks_aws_sns_cd.yml = .github\workflows\healthchecks_aws_sns_cd.yml
.github\workflows\healthchecks_aws_sns_cd_preview.yml = .github\workflows\healthchecks_aws_sns_cd_preview.yml
.github\workflows\healthchecks_aws_sns_ci.yml = .github\workflows\healthchecks_aws_sns_ci.yml
.github\workflows\healthchecks_aws_sqs_cd.yml = .github\workflows\healthchecks_aws_sqs_cd.yml
.github\workflows\healthchecks_aws_sqs_cd_preview.yml = .github\workflows\healthchecks_aws_sqs_cd_preview.yml
.github\workflows\healthchecks_aws_sqs_ci.yml = .github\workflows\healthchecks_aws_sqs_ci.yml
Expand Down Expand Up @@ -380,6 +383,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Aws.Sqs", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Aws.Sqs.Tests", "test\HealthChecks.Aws.Sqs.Tests\HealthChecks.Aws.Sqs.Tests.csproj", "{EFA76A2C-CA0E-42BC-8215-AEEB16414947}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Aws.Sns", "src\HealthChecks.Aws.Sns\HealthChecks.Aws.Sns.csproj", "{AE41DB38-93BC-48A7-8841-163E5E13CE8D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Aws.Sns.Tests", "test\HealthChecks.Aws.Sns.Tests\HealthChecks.Aws.Sns.Tests.csproj", "{CB1A7B68-E24A-4729-9401-606F3A914586}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -810,6 +817,14 @@ Global
{EFA76A2C-CA0E-42BC-8215-AEEB16414947}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFA76A2C-CA0E-42BC-8215-AEEB16414947}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFA76A2C-CA0E-42BC-8215-AEEB16414947}.Release|Any CPU.Build.0 = Release|Any CPU
{AE41DB38-93BC-48A7-8841-163E5E13CE8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE41DB38-93BC-48A7-8841-163E5E13CE8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE41DB38-93BC-48A7-8841-163E5E13CE8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE41DB38-93BC-48A7-8841-163E5E13CE8D}.Release|Any CPU.Build.0 = Release|Any CPU
{CB1A7B68-E24A-4729-9401-606F3A914586}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB1A7B68-E24A-4729-9401-606F3A914586}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB1A7B68-E24A-4729-9401-606F3A914586}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB1A7B68-E24A-4729-9401-606F3A914586}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -922,6 +937,8 @@ Global
{7052C706-4B1A-4167-A33A-DF3E9FBCFE6B} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
{3E28B63C-814E-46C9-ADBF-7357997148F5} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
{EFA76A2C-CA0E-42BC-8215-AEEB16414947} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
{AE41DB38-93BC-48A7-8841-163E5E13CE8D} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4}
{CB1A7B68-E24A-4729-9401-606F3A914586} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2B8C62A1-11B6-469F-874C-A02443256568}
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![ArangoDb Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_arangodb_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_arangodb_ci.yml)
[![Aws S3 Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_s3_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_s3_ci.yml)
[![Aws SecretsManager Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_secretsmanager_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_secretsmanager_ci.yml)
[![Aws Sns Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_sns_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_sns_ci.yml)
[![Aws Sqs Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_sqs_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_sqs_ci.yml)
[![Aws SystemsManager Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_systemsmanager_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_aws_systemsmanager_ci.yml)
[![Azure IoTHub Build status](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_azure_iothub_ci.yml/badge.svg)](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/actions/workflows/healthchecks_azure_iothub_ci.yml)
Expand Down Expand Up @@ -99,7 +100,8 @@ HealthChecks packages include health checks for:
| ArangoDB | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.ArangoDb)](https://www.nuget.org/packages/AspNetCore.HealthChecks.ArangoDb) |
| Amazon S3 | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Aws.S3)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Aws.S3) |
| Amazon Secrets Manager | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Aws.SecretsManager)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Aws.SecretsManager) |
| Amazon SQS | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Aws.Sqs)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Aws.Sqs) |
| Amazon SNS | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Aws.Sns)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Aws.Sns) |
| Amazon SQS | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Aws.Sqs)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Aws.Sqs) |
| Amazon Systems Manager | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Aws.SystemsManager)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Aws.SystemsManager) |
| Azure IoT Hub | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.Azure.IoTHub)](https://www.nuget.org/packages/AspNetCore.HealthChecks.Azure.IoTHub) |
| Azure DigitalTwin | [![Nuget](https://img.shields.io/nuget/dt/AspNetCore.HealthChecks.AzureDigitalTwin)](https://www.nuget.org/packages/AspNetCore.HealthChecks.AzureDigitalTwin) | Subscription status, models and instances |
Expand Down Expand Up @@ -142,6 +144,8 @@ HealthChecks packages include health checks for:
Install-Package AspNetCore.HealthChecks.ArangoDb
Install-Package AspNetCore.HealthChecks.Aws.S3
Install-Package AspNetCore.HealthChecks.Aws.SecretsManager
Install-Package AspNetCore.HealthChecks.Aws.Sns
Install-Package AspNetCore.HealthChecks.Aws.Sqs
Install-Package AspNetCore.HealthChecks.Aws.SystemsManager
Install-Package AspNetCore.HealthChecks.Azure.IoTHub
Install-Package AspNetCore.HealthChecks.AzureDigitalTwin
Expand Down
2 changes: 2 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ if ($suffix -eq "") {
exec { & dotnet pack .\src\HealthChecks.AzureDigitalTwin\HealthChecks.AzureDigitalTwin.csproj -c Release -o .\artifacts --include-symbols --no-build }
exec { & dotnet pack .\src\HealthChecks.Aws.SecretsManager\HealthChecks.Aws.SecretsManager.csproj -c Release -o .\artifacts --include-symbols --no-build }
exec { & dotnet pack .\src\HealthChecks.Aws.SystemsManager\HealthChecks.Aws.SystemsManager.csproj -c Release -o .\artifacts --include-symbols --no-build }
exec { & dotnet pack .\src\HealthChecks.Aws.Sns\HealthChecks.Aws.Sns.csproj -c Release -o .\artifacts --include-symbols --no-build }
exec { & dotnet pack .\src\HealthChecks.Aws.Sqs\HealthChecks.Aws.Sqs.csproj -c Release -o .\artifacts --include-symbols --no-build }
}

Expand Down Expand Up @@ -172,5 +173,6 @@ else {
exec { & dotnet pack .\src\HealthChecks.AzureDigitalTwin\HealthChecks.AzureDigitalTwin.csproj -c Release -o .\artifacts --include-symbols --no-build --version-suffix=$suffix }
exec { & dotnet pack .\src\HealthChecks.Aws.SecretsManager\HealthChecks.Aws.SecretsManager.csproj -c Release -o .\artifacts --include-symbols --no-build --version-suffix=$suffix }
exec { & dotnet pack .\src\HealthChecks.Aws.SystemsManager\HealthChecks.Aws.SystemsManager.csproj -c Release -o .\artifacts --include-symbols --no-build --version-suffix=$suffix }
exec { & dotnet pack .\src\HealthChecks.Aws.Sns\HealthChecks.Aws.Sns.csproj -c Release -o .\artifacts --include-symbols --no-build --version-suffix=$suffix }
exec { & dotnet pack .\src\HealthChecks.Aws.Sqs\HealthChecks.Aws.Sqs.csproj -c Release -o .\artifacts --include-symbols --no-build --version-suffix=$suffix }
}
1 change: 1 addition & 0 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<HealthCheckArangoDb>6.0.2</HealthCheckArangoDb>
<HealthCheckAWSS3>6.0.2</HealthCheckAWSS3>
<HealthCheckAWSSecretsManager>6.0.0</HealthCheckAWSSecretsManager>
<HealthCheckAWSSns>6.0.0</HealthCheckAWSSns>
<HealthCheckAWSSqs>6.0.0</HealthCheckAWSSqs>
<HealthCheckAWSSystemsManager>6.0.0</HealthCheckAWSSystemsManager>
<HealthCheckAzureDigitalTwin>6.0.0</HealthCheckAzureDigitalTwin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using HealthChecks.Aws.Sns;
using Microsoft.Extensions.Diagnostics.HealthChecks;

namespace Microsoft.Extensions.DependencyInjection;

/// <summary>
/// Extension methods to configure <see cref="SnsTopicAndSubscriptionHealthCheck"/>.
/// </summary>
public static class SnsHealthCheckBuilderExtensions
{
private const string AWS_NAME_SNS_SUBS = "aws sns subs";

/// <summary>
/// Add a health check for AWS SNS topics and optional subscriptions.
/// </summary>
/// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param>
/// <param name="setup">The action to configure the SNS connection parameters.</param>
/// <param name="name">The health check name. Optional. If <c>null</c> the type name 'aws sns subs' will be used for the name.</param>
/// <param name="failureStatus">
/// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then
/// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported.
/// </param>
/// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param>
/// <param name="timeout">An optional <see cref="TimeSpan"/> representing the timeout of the check.</param>
/// <returns>The specified <paramref name="builder"/>.</returns>
public static IHealthChecksBuilder AddSnsTopicsAndSubscriptions(
this IHealthChecksBuilder builder,
Action<SnsOptions>? setup,
string? name = default,
HealthStatus? failureStatus = default,
IEnumerable<string>? tags = default,
TimeSpan? timeout = default)
{
var options = new SnsOptions();
setup?.Invoke(options);

return builder.Add(new HealthCheckRegistration(
name ?? AWS_NAME_SNS_SUBS,
sp => new SnsTopicAndSubscriptionHealthCheck(options),
failureStatus,
tags,
timeout));
}
}
15 changes: 15 additions & 0 deletions src/HealthChecks.Aws.Sns/HealthChecks.Aws.Sns.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetFrameworkVersion);$(NetStandardVersion)</TargetFrameworks>
<PackageTags>$(PackageTags);AWS;SNS;Amazon Simple Notification Service</PackageTags>
<Description>HealthChecks.Aws.Sns is the health check package for Amazon Simple Notification Service.</Description>
<Version>$(HealthCheckAWSSns)</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.3.50" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.6" />
</ItemGroup>

</Project>
Loading

0 comments on commit 8431868

Please sign in to comment.