From 7b660dc40969bee3072c1d300bff11d463952110 Mon Sep 17 00:00:00 2001 From: Adam Sitnik Date: Mon, 18 Sep 2023 13:30:21 +0200 Subject: [PATCH] adjust remaining projects --- .../healthchecks_azure_blobstorage_cd.yml | 2 +- ...lthchecks_azure_blobstorage_cd_preview.yml | 2 +- .../healthchecks_azureeventhubs_cd.yml | 16 + ...healthchecks_azureeventhubs_cd_preview.yml | 17 + .../healthchecks_azureeventhubs_ci.yml | 37 + .../healthchecks_azureservicebus_cd.yml | 31 +- ...ealthchecks_azureservicebus_cd_preview.yml | 33 +- .../healthchecks_azureservicebus_ci.yml | 62 +- AspNetCore.Diagnostics.HealthChecks.sln | 30 +- build/versions.props | 9 +- .../HealthChecks.Sample.csproj | 1 - .../AzureTableServiceHealthCheck.cs | 2 +- .../AzureTableServiceHealthCheckOptions.cs | 2 +- ...lesServiceHealthChecksBuilderExtensions.cs | 2 +- .../HealthChecks.Azure.Data.Tables.csproj | 2 +- src/HealthChecks.Azure.Data.Tables/README.md | 9 +- ...HealthChecks.Azure.KeyVault.Secrets.csproj | 2 +- .../README.md | 4 +- .../AzureEventHubHealthCheck.cs | 84 +- .../AzureEventHubHealthCheckOptions.cs | 41 - ...reEventHubHealthChecksBuilderExtensions.cs | 45 + ...lthChecks.Azure.Messaging.EventHubs.csproj | 8 +- .../README.md | 42 + .../ClientCache.cs | 0 ...eServiceBusHealthCheckBuilderExtensions.cs | 1423 +++++++---------- ...thChecks.Azure.Messaging.ServiceBus.csproj | 6 +- .../AzureBlobStorageHealthCheck.cs | 2 +- .../AzureBlobStorageHealthCheckOptions.cs | 2 +- ...lobStorageHealthChecksBuilderExtensions.cs | 2 +- .../HealthChecks.Azure.Storage.Blobs.csproj | 2 +- .../README.md | 9 +- .../AzureFileShareHealthCheck.cs | 2 +- .../AzureFileShareHealthCheckOptions.cs | 2 +- ...eueStorageHealthChecksBuilderExtensions.cs | 2 +- ...thChecks.Azure.Storage.Files.Shares.csproj | 2 +- .../README.md | 8 +- .../AzureQueueStorageHealthCheck.cs | 2 +- .../AzureQueueStorageHealthCheckOptions.cs | 2 +- ...eueStorageHealthChecksBuilderExtensions.cs | 2 +- .../HealthChecks.Azure.Storage.Queues.csproj | 2 +- .../README.md | 9 +- .../HealthChecks.AzureServiceBus.csproj | 15 - .../Properties/AssemblyInfo.cs | 17 - src/HealthChecks.CosmosDb/README.md | 10 +- ...ealthChecks.Azure.Data.Tables.approved.txt | 6 +- .../TableServiceHealthCheckTests.cs | 2 +- .../TablesConformanceTests.cs | 1 - .../EventHubsConformanceTests.cs | 24 + ...ks.Azure.Messaging.EventHubs.Tests.csproj} | 2 +- ...cks.Azure.Messaging.EventHubs.approved.txt | 15 + .../AzureServiceBusQueueHealthCheckTests.cs | 0 ...ueMessageCountThresholdHealthCheckTests.cs | 0 ...eServiceBusSubscriptionHealthCheckTests.cs | 0 .../AzureServiceBusTopicHealthCheckTests.cs | 0 ...eBusQueueMessageThresholdCountUnitTests.cs | 0 ...ageThresholdCountUnitWithTokenUnitTests.cs | 0 .../AzureServiceBusQueueRegistrationTests.cs | 0 ...eBusQueueUnitWithTokenRegistrationTests.cs | 0 ...ServiceBusSubscriptionRegistrationTests.cs | 0 ...sSubscriptionWithTokenRegistrationTests.cs | 0 .../AzureServiceBusTopicRegistrationTests.cs | 0 ...rviceBusTopicWithTokenRegistrationTests.cs | 0 ...ks.Azure.Messaging.ServiceBus.Tests.csproj | 15 + ...s.Azure.Messaging.ServiceBus.approved.txt} | 19 - .../AzureBlobStorageHealthCheckTests.cs | 2 +- .../BlobStorageConformanceTests.cs | 1 - ...lthChecks.Azure.Storage.Blobs.approved.txt | 6 +- .../AzureFileShareHealthCheckTests.cs | 2 +- .../FileConformanceTests.cs | 3 +- ...ks.Azure.Storage.Files.Shares.approved.txt | 6 +- .../AzureQueueStorageHealthCheckTests.cs | 2 +- ...thChecks.Azure.Storage.Queues.approved.txt | 6 +- .../QueueStorageConformanceTests.cs | 1 - .../AzureEventHubRegistrationTests.cs | 134 -- ...eEventHubUnitWithTokenRegistrationTests.cs | 129 -- test/_SHARED/ConformanceTests.cs | 4 +- 76 files changed, 950 insertions(+), 1434 deletions(-) create mode 100644 .github/workflows/healthchecks_azureeventhubs_cd.yml create mode 100644 .github/workflows/healthchecks_azureeventhubs_cd_preview.yml create mode 100644 .github/workflows/healthchecks_azureeventhubs_ci.yml delete mode 100644 src/HealthChecks.Azure.Messaging.EventHubs/Configuration/AzureEventHubHealthCheckOptions.cs create mode 100644 src/HealthChecks.Azure.Messaging.EventHubs/DependencyInjection/AzureEventHubHealthChecksBuilderExtensions.cs create mode 100644 src/HealthChecks.Azure.Messaging.EventHubs/README.md rename src/{ => HealthChecks.Azure.Messaging.ServiceBus}/ClientCache.cs (100%) rename src/{HealthChecks.AzureServiceBus => HealthChecks.Azure.Messaging.ServiceBus}/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs (73%) delete mode 100644 src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj delete mode 100644 src/HealthChecks.AzureServiceBus/Properties/AssemblyInfo.cs create mode 100644 test/HealthChecks.Azure.Messaging.EventHubs.Tests/EventHubsConformanceTests.cs rename test/{HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj => HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.Tests.csproj} (67%) create mode 100644 test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.approved.txt rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/AzureServiceBusQueueHealthCheckTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/AzureServiceBusQueueMessageCountThresholdHealthCheckTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/AzureServiceBusSubscriptionHealthCheckTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/AzureServiceBusTopicHealthCheckTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitWithTokenUnitTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusQueueRegistrationTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusQueueUnitWithTokenRegistrationTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusSubscriptionRegistrationTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusSubscriptionWithTokenRegistrationTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusTopicRegistrationTests.cs (100%) rename test/{HealthChecks.AzureServiceBus.Tests => HealthChecks.Azure.Messaging.ServiceBus.Tests}/DependencyInjection/AzureServiceBusTopicWithTokenRegistrationTests.cs (100%) create mode 100644 test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.Tests.csproj rename test/{HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.approved.txt => HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.approved.txt} (80%) delete mode 100644 test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubRegistrationTests.cs delete mode 100644 test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubUnitWithTokenRegistrationTests.cs diff --git a/.github/workflows/healthchecks_azure_blobstorage_cd.yml b/.github/workflows/healthchecks_azure_blobstorage_cd.yml index 027e50d74a..4c8e1bfe5d 100644 --- a/.github/workflows/healthchecks_azure_blobstorage_cd.yml +++ b/.github/workflows/healthchecks_azure_blobstorage_cd.yml @@ -3,7 +3,7 @@ name: HealthChecks Azure Blob Storage CD on: push: tags: - - release-azurequeuestorage-* + - release-azureblobstorage-* - release-all-* jobs: diff --git a/.github/workflows/healthchecks_azure_blobstorage_cd_preview.yml b/.github/workflows/healthchecks_azure_blobstorage_cd_preview.yml index 92fbeb51b3..23bf3f914a 100644 --- a/.github/workflows/healthchecks_azure_blobstorage_cd_preview.yml +++ b/.github/workflows/healthchecks_azure_blobstorage_cd_preview.yml @@ -3,7 +3,7 @@ name: HealthChecks Azure Blob Storage Preview CD on: push: tags: - - preview-azurequeuestorage-* + - preview-azureblobstorage-* - preview-all-* jobs: diff --git a/.github/workflows/healthchecks_azureeventhubs_cd.yml b/.github/workflows/healthchecks_azureeventhubs_cd.yml new file mode 100644 index 0000000000..658375c5c7 --- /dev/null +++ b/.github/workflows/healthchecks_azureeventhubs_cd.yml @@ -0,0 +1,16 @@ +name: HealthChecks Azure EventHubs CD + +on: + push: + tags: + - release-azureeventhubs-* + - release-all-* + +jobs: + build: + uses: ./.github/workflows/reusable_cd_workflow.yml + secrets: inherit + with: + BUILD_CONFIG: Release + PROJECT_PATH: ./src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj + PACKAGE_NAME: HealthChecks.Azure.Messaging.EventHubs \ No newline at end of file diff --git a/.github/workflows/healthchecks_azureeventhubs_cd_preview.yml b/.github/workflows/healthchecks_azureeventhubs_cd_preview.yml new file mode 100644 index 0000000000..9f4e67f0d6 --- /dev/null +++ b/.github/workflows/healthchecks_azureeventhubs_cd_preview.yml @@ -0,0 +1,17 @@ +name: HealthChecks Azure EventHubs Preview CD + +on: + push: + tags: + - preview-azureeventhubs-* + - preview-all-* + +jobs: + build: + uses: ./.github/workflows/reusable_cd_preview_workflow.yml + secrets: inherit + with: + BUILD_CONFIG: Release + VERSION_SUFFIX_PREFIX: rc1 + PROJECT_PATH: ./src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj + PACKAGE_NAME: AspNetCore.HealthChecks.Azure.Messaging.EventHubs \ No newline at end of file diff --git a/.github/workflows/healthchecks_azureeventhubs_ci.yml b/.github/workflows/healthchecks_azureeventhubs_ci.yml new file mode 100644 index 0000000000..bbfbcd6708 --- /dev/null +++ b/.github/workflows/healthchecks_azureeventhubs_ci.yml @@ -0,0 +1,37 @@ +name: HealthChecks Azure EventHubs CI + +on: + workflow_dispatch: + push: + branches: [ master ] + paths: + - src/HealthChecks.Azure.Messaging.EventHubs/** + - test/HealthChecks.Azure.Messaging.EventHubs.Tests/** + - test/_SHARED/** + - .github/workflows/healthchecks_azureeventhubs_ci.yml + - .github/workflows/reusable_ci_workflow.yml + - Directory.Build.props + - Directory.Build.targets + tags-ignore: + - release-* + - preview-* + + pull_request: + branches: [ master ] + paths: + - src/HealthChecks.Azure.Messaging.EventHubs/** + - test/HealthChecks.Azure.Messaging.EventHubs.Tests/** + - test/_SHARED/** + - .github/workflows/healthchecks_azureeventhubs_ci.yml + - .github/workflows/reusable_ci_workflow.yml + - Directory.Build.props + - Directory.Build.targets + +jobs: + build: + uses: ./.github/workflows/reusable_ci_workflow.yml + with: + PROJECT_PATH: ./src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj + TEST_PROJECT_PATH: ./test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.Tests.csproj + CODECOV_FLAGS: AzureEventHubs + diff --git a/.github/workflows/healthchecks_azureservicebus_cd.yml b/.github/workflows/healthchecks_azureservicebus_cd.yml index 69f6da5257..b1adf30f47 100644 --- a/.github/workflows/healthchecks_azureservicebus_cd.yml +++ b/.github/workflows/healthchecks_azureservicebus_cd.yml @@ -8,30 +8,9 @@ on: jobs: build: - env: + uses: ./.github/workflows/reusable_cd_workflow.yml + secrets: inherit + with: BUILD_CONFIG: Release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: dotnet restore ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj - - name: Build - run: dotnet build --no-restore ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj -c $BUILD_CONFIG - - name: Pack EventHubs - run: dotnet pack --no-build ./src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj -c $BUILD_CONFIG -o ./artifacts - - name: Pack ServiceBus - run: dotnet pack --no-build ./src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj -c $BUILD_CONFIG -o ./artifacts - - name: Pack - run: dotnet pack --no-build ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj -c $BUILD_CONFIG -o ./artifacts - - name: Publish EventHubs - run: dotnet nuget push ./artifacts/HealthChecks.Azure.Messaging.EventHubs.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate - - name: Publish ServiceBus - run: dotnet nuget push ./artifacts/HealthChecks.Azure.Messaging.ServiceBus.*.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.AzureServiceBus.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate + PROJECT_PATH: ./src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj + PACKAGE_NAME: HealthChecks.Azure.Messaging.ServiceBus \ No newline at end of file diff --git a/.github/workflows/healthchecks_azureservicebus_cd_preview.yml b/.github/workflows/healthchecks_azureservicebus_cd_preview.yml index a47bbdf566..3ae2373347 100644 --- a/.github/workflows/healthchecks_azureservicebus_cd_preview.yml +++ b/.github/workflows/healthchecks_azureservicebus_cd_preview.yml @@ -8,31 +8,10 @@ on: jobs: build: - env: + uses: ./.github/workflows/reusable_cd_preview_workflow.yml + secrets: inherit + with: 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@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: dotnet restore ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj - - name: Build - run: dotnet build --no-restore ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj -c $BUILD_CONFIG - - name: Pack EventHubs - run: dotnet pack --no-build ./src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts - - name: Pack ServiceBus - run: dotnet pack --no-build ./src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts - - name: Pack - run: dotnet pack --no-build ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj --version-suffix $VERSION_SUFFIX -c $BUILD_CONFIG -o ./artifacts - - name: Publish EventHubs - run: dotnet nuget push ./artifacts/HealthChecks.Azure.Messaging.EventHubs.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate - - name: Publish ServiceBus - run: dotnet nuget push ./artifacts/HealthChecks.Azure.Messaging.ServiceBus.*.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.AzureServiceBus.*.nupkg -k ${{secrets.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --skip-duplicate \ No newline at end of file + VERSION_SUFFIX_PREFIX: rc2 + PROJECT_PATH: ./src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj + PACKAGE_NAME: AspNetCore.HealthChecks.Azure.Messaging.ServiceBus \ No newline at end of file diff --git a/.github/workflows/healthchecks_azureservicebus_ci.yml b/.github/workflows/healthchecks_azureservicebus_ci.yml index 80761f0c7b..38e0d26d45 100644 --- a/.github/workflows/healthchecks_azureservicebus_ci.yml +++ b/.github/workflows/healthchecks_azureservicebus_ci.yml @@ -5,11 +5,11 @@ on: push: branches: [ master ] paths: - - src/HealthChecks.Azure.Messaging.*/** - - src/HealthChecks.AzureServiceBus/** - - test/HealthChecks.AzureServiceBus.Tests/** + - src/HealthChecks.Azure.Messaging.ServiceBus/** + - test/HealthChecks.Azure.Messaging.ServiceBus.Tests/** - test/_SHARED/** - .github/workflows/healthchecks_azureservicebus_ci.yml + - .github/workflows/reusable_ci_workflow.yml - Directory.Build.props - Directory.Build.targets tags-ignore: @@ -19,49 +19,19 @@ on: pull_request: branches: [ master ] paths: - - src/HealthChecks.Azure.Messaging.*/** - - src/HealthChecks.AzureServiceBus/** - - test/HealthChecks.AzureServiceBus.Tests/** - - test/_SHARED/** - - .github/workflows/healthchecks_azureservicebus_ci.yml - - Directory.Build.props - - Directory.Build.targets + - src/HealthChecks.Azure.Messaging.ServiceBus/** + - test/HealthChecks.Azure.Messaging.ServiceBus.Tests/** + - test/_SHARED/** + - .github/workflows/healthchecks_azureservicebus_ci.yml + - .github/workflows/reusable_ci_workflow.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@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - - name: Restore - run: | - dotnet restore ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj && - dotnet restore ./test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj - - name: Check formatting - run: | - dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) && - dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) - - name: Build - run: | - dotnet build --no-restore ./src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj && - dotnet build --no-restore ./test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj - - name: Test - run: > - dotnet test - ./test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj - --no-restore - --no-build - --collect "XPlat Code Coverage" - --results-directory .coverage - -- - DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover - - name: Upload Coverage - uses: codecov/codecov-action@v3 - with: - flags: AzureServiceBus - directory: .coverage + uses: ./.github/workflows/reusable_ci_workflow.yml + with: + PROJECT_PATH: ./src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj + TEST_PROJECT_PATH: ./test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.Tests.csproj + CODECOV_FLAGS: AzureServiceBus + diff --git a/AspNetCore.Diagnostics.HealthChecks.sln b/AspNetCore.Diagnostics.HealthChecks.sln index b8f06fa942..a603d58d93 100644 --- a/AspNetCore.Diagnostics.HealthChecks.sln +++ b/AspNetCore.Diagnostics.HealthChecks.sln @@ -42,8 +42,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Network", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.DocumentDb", "src\HealthChecks.DocumentDb\HealthChecks.DocumentDb.csproj", "{F42DB8D6-65CE-4C7B-A1CB-560DDA468F93}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.AzureServiceBus", "src\HealthChecks.AzureServiceBus\HealthChecks.AzureServiceBus.csproj", "{4F45BB95-CB91-406D-B8A4-01E2830CC451}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.UI", "src\HealthChecks.UI\HealthChecks.UI.csproj", "{6AE01EB5-86D4-4603-B798-26C7DB63AEB3}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{092533AB-7505-4EDC-8932-D40BF575D0D2}" @@ -197,8 +195,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".Solution Items", ".Solutio README.md = README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.AzureServiceBus.Tests", "test\HealthChecks.AzureServiceBus.Tests\HealthChecks.AzureServiceBus.Tests.csproj", "{80835FF3-C984-4BCE-B047-7985B42F6B0E}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.AzureKeyVault.Tests", "test\HealthChecks.AzureKeyVault.Tests\HealthChecks.AzureKeyVault.Tests.csproj", "{CAA0DB8F-9759-436D-A4E7-2061C0125B06}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.IoTHub.Tests", "test\HealthChecks.Azure.IoTHub.Tests\HealthChecks.Azure.IoTHub.Tests.csproj", "{C825E756-F1E0-4AE9-9814-B8A112B1CAA9}" @@ -303,7 +299,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.Storage. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.Storage.Files.Shares.Tests", "test\HealthChecks.Azure.Storage.Files.Shares.Tests\HealthChecks.Azure.Storage.Files.Shares.Tests.csproj", "{A6BD9977-E12E-4309-B0AA-A755C04E525B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecks.Azure.Data.Tables.Tests", "test\HealthChecks.Azure.Data.Tables.Tests\HealthChecks.Azure.Data.Tables.Tests.csproj", "{2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.Data.Tables.Tests", "test\HealthChecks.Azure.Data.Tables.Tests\HealthChecks.Azure.Data.Tables.Tests.csproj", "{2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.Messaging.EventHubs.Tests", "test\HealthChecks.Azure.Messaging.EventHubs.Tests\HealthChecks.Azure.Messaging.EventHubs.Tests.csproj", "{09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecks.Azure.Messaging.ServiceBus.Tests", "test\HealthChecks.Azure.Messaging.ServiceBus.Tests\HealthChecks.Azure.Messaging.ServiceBus.Tests.csproj", "{3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -359,10 +359,6 @@ Global {F42DB8D6-65CE-4C7B-A1CB-560DDA468F93}.Debug|Any CPU.Build.0 = Debug|Any CPU {F42DB8D6-65CE-4C7B-A1CB-560DDA468F93}.Release|Any CPU.ActiveCfg = Release|Any CPU {F42DB8D6-65CE-4C7B-A1CB-560DDA468F93}.Release|Any CPU.Build.0 = Release|Any CPU - {4F45BB95-CB91-406D-B8A4-01E2830CC451}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F45BB95-CB91-406D-B8A4-01E2830CC451}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F45BB95-CB91-406D-B8A4-01E2830CC451}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F45BB95-CB91-406D-B8A4-01E2830CC451}.Release|Any CPU.Build.0 = Release|Any CPU {6AE01EB5-86D4-4603-B798-26C7DB63AEB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6AE01EB5-86D4-4603-B798-26C7DB63AEB3}.Debug|Any CPU.Build.0 = Debug|Any CPU {6AE01EB5-86D4-4603-B798-26C7DB63AEB3}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -639,10 +635,6 @@ Global {4E8DA856-FC10-4A18-BDFB-7C604F17D1EE}.Debug|Any CPU.Build.0 = Debug|Any CPU {4E8DA856-FC10-4A18-BDFB-7C604F17D1EE}.Release|Any CPU.ActiveCfg = Release|Any CPU {4E8DA856-FC10-4A18-BDFB-7C604F17D1EE}.Release|Any CPU.Build.0 = Release|Any CPU - {80835FF3-C984-4BCE-B047-7985B42F6B0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {80835FF3-C984-4BCE-B047-7985B42F6B0E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {80835FF3-C984-4BCE-B047-7985B42F6B0E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {80835FF3-C984-4BCE-B047-7985B42F6B0E}.Release|Any CPU.Build.0 = Release|Any CPU {CAA0DB8F-9759-436D-A4E7-2061C0125B06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CAA0DB8F-9759-436D-A4E7-2061C0125B06}.Debug|Any CPU.Build.0 = Debug|Any CPU {CAA0DB8F-9759-436D-A4E7-2061C0125B06}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -855,6 +847,14 @@ Global {2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A}.Release|Any CPU.Build.0 = Release|Any CPU + {09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD}.Release|Any CPU.Build.0 = Release|Any CPU + {3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -872,7 +872,6 @@ Global {E6AF5AD6-618A-491D-B8BB-F8EF56C6B403} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {46A58C98-B38F-486C-83BA-3772A217A24E} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {F42DB8D6-65CE-4C7B-A1CB-560DDA468F93} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} - {4F45BB95-CB91-406D-B8A4-01E2830CC451} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {6AE01EB5-86D4-4603-B798-26C7DB63AEB3} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {7C8F7A48-2FF9-4CF4-AAAC-142053E34FC0} = {092533AB-7505-4EDC-8932-D40BF575D0D2} {EEF1E206-DEE3-45F2-A753-73D2FFFF8EDA} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} @@ -942,7 +941,6 @@ Global {74921A32-8C36-4E74-B593-887FFEC1AF19} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} {8B853DD2-0B83-4898-906C-F34D1AD844F9} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {4E8DA856-FC10-4A18-BDFB-7C604F17D1EE} = {2A3FD988-2BB8-43CF-B3A2-B70E648259D4} - {80835FF3-C984-4BCE-B047-7985B42F6B0E} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {CAA0DB8F-9759-436D-A4E7-2061C0125B06} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {C825E756-F1E0-4AE9-9814-B8A112B1CAA9} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {62B73D6A-076D-414B-9B4E-D6C3FF38E786} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} @@ -996,6 +994,8 @@ Global {5265E8E8-92B7-4123-BAF3-7B9A0E893785} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {A6BD9977-E12E-4309-B0AA-A755C04E525B} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} {2C02BEDF-FFFA-4747-920A-A1ED6CFFC21A} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} + {09160C0F-BB5E-4DF2-AF44-E859E8EDE6BD} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} + {3B812989-2C4E-4FCE-B3A0-EF9C00A9B3A5} = {FF4414C2-8863-4ADA-8A1D-4B9F25C361FE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2B8C62A1-11B6-469F-874C-A02443256568} diff --git a/build/versions.props b/build/versions.props index 87d70a1496..c891568e4f 100644 --- a/build/versions.props +++ b/build/versions.props @@ -11,8 +11,13 @@ 7.0.0 7.0.0 7.0.0 - 7.2.1 - 7.0.1 + 7.0.0 + 7.0.1 + 7.0.0 + 7.2.1 + 7.0.0 + 7.0.0 + 7.0.0 7.0.0 7.0.0 7.0.1 diff --git a/samples/HealthChecks.Sample/HealthChecks.Sample.csproj b/samples/HealthChecks.Sample/HealthChecks.Sample.csproj index 0e310522d1..a483e8c2bd 100644 --- a/samples/HealthChecks.Sample/HealthChecks.Sample.csproj +++ b/samples/HealthChecks.Sample/HealthChecks.Sample.csproj @@ -13,7 +13,6 @@ - diff --git a/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheck.cs b/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheck.cs index b61006d072..0df08e046a 100644 --- a/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheck.cs +++ b/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheck.cs @@ -1,7 +1,7 @@ using Azure.Data.Tables; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace HealthChecks.CosmosDb; +namespace HealthChecks.Azure.Data.Tables; /// /// Azure Tables health check. diff --git a/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheckOptions.cs b/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheckOptions.cs index 31c9113da9..f9c64ec2f7 100644 --- a/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheckOptions.cs +++ b/src/HealthChecks.Azure.Data.Tables/AzureTableServiceHealthCheckOptions.cs @@ -1,4 +1,4 @@ -namespace HealthChecks.CosmosDb; +namespace HealthChecks.Azure.Data.Tables; /// /// Represents a collection of settings that configure an diff --git a/src/HealthChecks.Azure.Data.Tables/DependencyInjection/AzureTablesServiceHealthChecksBuilderExtensions.cs b/src/HealthChecks.Azure.Data.Tables/DependencyInjection/AzureTablesServiceHealthChecksBuilderExtensions.cs index f242546d65..1e6c17cab5 100644 --- a/src/HealthChecks.Azure.Data.Tables/DependencyInjection/AzureTablesServiceHealthChecksBuilderExtensions.cs +++ b/src/HealthChecks.Azure.Data.Tables/DependencyInjection/AzureTablesServiceHealthChecksBuilderExtensions.cs @@ -1,5 +1,5 @@ using Azure.Data.Tables; -using HealthChecks.CosmosDb; +using HealthChecks.Azure.Data.Tables; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj b/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj index 55f63d0d7c..af2440ca2c 100644 --- a/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj +++ b/src/HealthChecks.Azure.Data.Tables/HealthChecks.Azure.Data.Tables.csproj @@ -4,7 +4,7 @@ netstandard2.0 $(PackageTags);Azure;Tables HealthChecks.Azure.Data.Tables is the health check package for Azure Tables. - $(HealthCheckCosmosDb) + $(HealthCheckAzureDataTables) diff --git a/src/HealthChecks.Azure.Data.Tables/README.md b/src/HealthChecks.Azure.Data.Tables/README.md index eabfb899b2..79607c831f 100644 --- a/src/HealthChecks.Azure.Data.Tables/README.md +++ b/src/HealthChecks.Azure.Data.Tables/README.md @@ -7,7 +7,7 @@ This health check verifies the ability to communicate with [Azure Tables](https: By default, the `TableServiceClient` instance is resolved from service provider. `AzureTableServiceHealthCheckOptions` does not provide any specific container name, so the health check fetches just first container. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new TableServiceClient(new Uri("azure-table-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureTable(); @@ -26,7 +26,7 @@ You can additionally add the following parameters: - `timeout`: A `System.TimeSpan` representing the timeout of the check. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new TableServiceClient(new Uri("azure-table-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureTable( @@ -37,4 +37,7 @@ public void Configure(IHealthChecksBuilder builder) } ``` -For more information about credentials types please see [Azure TokenCredentials](https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme) +### Breaking changes + +In the prior releases, `TableServiceHealthCheck` was a part of `HealthChecks.CosmosDb` package. It had a dependency on not just `Azure.Data.Tables`, but also `Microsoft.Azure.Cosmos`. The packages have been split to avoid bringing unnecessary dependencies. Moreover, `TableServiceHealthCheck` was letting the users specify how `TableServiceClient` should be created (from raw connection string or from endpoint and managed identity credentials), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and **it's the caller responsibility to provide the instance of `TableServiceClient`** (please see [#2040](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2040) for more details). Since Azure SDK recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for Azure SDK clients. So the clients are created only when needed and once per whole application lifetime. + diff --git a/src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj b/src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj index fd4f77bce2..d8aa0bdd46 100644 --- a/src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj +++ b/src/HealthChecks.Azure.KeyVault.Secrets/HealthChecks.Azure.KeyVault.Secrets.csproj @@ -4,7 +4,7 @@ netstandard2.0 $(PackageTags);Azure Key Vault;Secrets HealthChecks.Azure.KeyVault.Secrets is the health check package for Azure Key Vault secrets - $(HealthCheckKeyVault) + $(HealthCheckKeyVaultSecrets) diff --git a/src/HealthChecks.Azure.KeyVault.Secrets/README.md b/src/HealthChecks.Azure.KeyVault.Secrets/README.md index 411fc7e0a4..94dd53c4ca 100644 --- a/src/HealthChecks.Azure.KeyVault.Secrets/README.md +++ b/src/HealthChecks.Azure.KeyVault.Secrets/README.md @@ -7,7 +7,7 @@ This health check verifies the ability to communicate with [Azure Key Vault Secr By default, the `SecretClient` instance is resolved from service provider. `AzureKeyVaultSecretsHealthCheckOptions` by default uses "AzureKeyVaultSecretsHealthCheck" secret name and does not try to create the secret when it's not found. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new SecretClient(new Uri("azure-key-vault-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureKeyVaultSecrets(); @@ -26,7 +26,7 @@ You can additionally add the following parameters: - `timeout`: A `System.TimeSpan` representing the timeout of the check. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new SecretClient(new Uri("azure-key-vault-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureKeyVaultSecrets( diff --git a/src/HealthChecks.Azure.Messaging.EventHubs/AzureEventHubHealthCheck.cs b/src/HealthChecks.Azure.Messaging.EventHubs/AzureEventHubHealthCheck.cs index 004bd2d8d2..44f4fce334 100644 --- a/src/HealthChecks.Azure.Messaging.EventHubs/AzureEventHubHealthCheck.cs +++ b/src/HealthChecks.Azure.Messaging.EventHubs/AzureEventHubHealthCheck.cs @@ -1,46 +1,15 @@ -using Azure.Messaging.EventHubs; using Azure.Messaging.EventHubs.Producer; -using HealthChecks.AzureServiceBus.Configuration; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace HealthChecks.AzureServiceBus; +namespace HealthChecks.Azure.Messaging.EventHubs; -public class AzureEventHubHealthCheck : IHealthCheck +public sealed class AzureEventHubHealthCheck : IHealthCheck { - private const string ENTITY_PATH_SEGMENT = "EntityPath="; - private readonly AzureEventHubHealthCheckOptions _options; + private readonly EventHubProducerClient _client; - private string? _connectionKey; - - private string ConnectionKey => _connectionKey ??= _options.ConnectionString is null - ? $"{_options.FullyQualifiedNamespace}_{_options.EventHubName}" - : GetFullConnectionString(); - - public AzureEventHubHealthCheck(AzureEventHubHealthCheckOptions options) + public AzureEventHubHealthCheck(EventHubProducerClient client) { - _options = options; - - if (!string.IsNullOrWhiteSpace(options.ConnectionString)) - { - Guard.ThrowIfNull(options.EventHubName, true); - return; - } - - if (options.Credential is not null) - { - Guard.ThrowIfNull(options.FullyQualifiedNamespace, true); - Guard.ThrowIfNull(options.EventHubName, true); - return; - } - - if (options.Connection is not null) - { - _connectionKey = $"{options.Connection.FullyQualifiedNamespace}_{options.Connection.EventHubName}"; - return; - } - - throw new ArgumentException("A connection string, TokenCredential or EventHubConnection must be set!", - nameof(options)); + _client = Guard.ThrowIfNull(client); } /// @@ -48,9 +17,7 @@ public async Task CheckHealthAsync(HealthCheckContext context { try { - var client = await ClientCache.GetOrAddAsyncDisposableAsync(ConnectionKey, _ => CreateClient(context)).ConfigureAwait(false); - - _ = await client.GetEventHubPropertiesAsync(cancellationToken).ConfigureAwait(false); + _ = await _client.GetEventHubPropertiesAsync(cancellationToken).ConfigureAwait(false); return HealthCheckResult.Healthy(); } @@ -59,43 +26,4 @@ public async Task CheckHealthAsync(HealthCheckContext context return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); } } - - private EventHubProducerClient CreateClient(HealthCheckContext context) - { - var clientOptions = CreateClientOptions(context); - - if (_options.ConnectionString is not null) - return new EventHubProducerClient(GetFullConnectionString(), clientOptions); - - if (_options.Connection is not null) - return new EventHubProducerClient(_options.Connection, clientOptions); - - return new EventHubProducerClient(_options.FullyQualifiedNamespace, _options.EventHubName, _options.Credential, clientOptions); - } - - private string GetFullConnectionString() - { - string connectionString = _options.ConnectionString!; - - if (!connectionString.Contains(ENTITY_PATH_SEGMENT)) - connectionString = $"{connectionString};{ENTITY_PATH_SEGMENT}{_options.EventHubName}"; - return connectionString; - } - - private static EventHubProducerClientOptions CreateClientOptions(HealthCheckContext context) => new() - { - ConnectionOptions = CreateConnectionOptions(context) - }; - - private static EventHubConnectionOptions CreateConnectionOptions(HealthCheckContext context) - { - EventHubConnectionOptions options = new(); - - if (context.Registration.Timeout.TotalMilliseconds > 0) - { - options.ConnectionIdleTimeout = context.Registration.Timeout; - } - - return options; - } } diff --git a/src/HealthChecks.Azure.Messaging.EventHubs/Configuration/AzureEventHubHealthCheckOptions.cs b/src/HealthChecks.Azure.Messaging.EventHubs/Configuration/AzureEventHubHealthCheckOptions.cs deleted file mode 100644 index e99f28d002..0000000000 --- a/src/HealthChecks.Azure.Messaging.EventHubs/Configuration/AzureEventHubHealthCheckOptions.cs +++ /dev/null @@ -1,41 +0,0 @@ -using Azure.Core; -using Azure.Messaging.EventHubs; - -namespace HealthChecks.AzureServiceBus.Configuration; - -/// -/// Configuration options for . -/// -public class AzureEventHubHealthCheckOptions -{ - /// - /// The azure event hub connection string. - /// - public string? ConnectionString { get; set; } - - /// - /// The azure event hub name. - /// - public string? EventHubName { get; set; } - - /// - /// The azure event hub fully qualified namespace. - /// - /// - /// Must be used in conjunction with the property. - /// - public string? FullyQualifiedNamespace { get; set; } - - /// - /// The token credential for authentication. - /// - /// - /// Must be used in conjunction with the property. - /// - public TokenCredential? Credential { get; set; } - - /// - /// The event hub connection to use for authenticating and connecting. - /// - public EventHubConnection? Connection { get; set; } -} diff --git a/src/HealthChecks.Azure.Messaging.EventHubs/DependencyInjection/AzureEventHubHealthChecksBuilderExtensions.cs b/src/HealthChecks.Azure.Messaging.EventHubs/DependencyInjection/AzureEventHubHealthChecksBuilderExtensions.cs new file mode 100644 index 0000000000..96fbc34900 --- /dev/null +++ b/src/HealthChecks.Azure.Messaging.EventHubs/DependencyInjection/AzureEventHubHealthChecksBuilderExtensions.cs @@ -0,0 +1,45 @@ +using Azure.Messaging.EventHubs.Producer; +using HealthChecks.Azure.Messaging.EventHubs; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace Microsoft.Extensions.DependencyInjection; + +/// +/// Extension methods to configure . +/// +public static class AzureEventHubHealthChecksBuilderExtensions +{ + private const string HEALTH_CHECK_NAME = "azure_event_hub"; + + /// + /// Add a health check for Azure Event Hub by registering for given . + /// + /// The to add to. + /// + /// An optional factory to obtain instance. + /// When not provided, is simply resolved from . + /// + /// The health check name. Optional. If null the name 'azure_event_hub' will be used. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureEventHub( + this IHealthChecksBuilder builder, + Func? clientFactory = default, + string? healthCheckName = HEALTH_CHECK_NAME, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + return builder.Add(new HealthCheckRegistration( + string.IsNullOrEmpty(healthCheckName) ? HEALTH_CHECK_NAME : healthCheckName!, + sp => new AzureEventHubHealthCheck(clientFactory?.Invoke(sp) ?? sp.GetRequiredService()), + failureStatus, + tags, + timeout)); + } +} diff --git a/src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj b/src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj index 83a779f1f6..3950bb925b 100644 --- a/src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj +++ b/src/HealthChecks.Azure.Messaging.EventHubs/HealthChecks.Azure.Messaging.EventHubs.csproj @@ -3,14 +3,10 @@ netstandard2.0 $(PackageTags);Azure;EventHub - HealthChecks.Azure.Messaging.EventHubs is the health check package for Azure EventHub. - $(HealthCheckAzureServiceBus) + HealthChecks.Azure.Messaging.EventHubs is the health check package for Azure Event Hubs. + $(HealthCheckAzureMessagingEventsHubs) - - - - diff --git a/src/HealthChecks.Azure.Messaging.EventHubs/README.md b/src/HealthChecks.Azure.Messaging.EventHubs/README.md new file mode 100644 index 0000000000..1b2ad0d055 --- /dev/null +++ b/src/HealthChecks.Azure.Messaging.EventHubs/README.md @@ -0,0 +1,42 @@ +## Azure Event Hubs Health Check + +This health check verifies the ability to communicate with [Azure Event Hubs](https://azure.microsoft.com/services/event-hubs/). It uses the provided [EventHubProducerClient](https://learn.microsoft.com/dotnet/api/azure.messaging.eventhubs.producer.eventhubproducerclient) to get event hub properties. + +### Defaults + +By default, the `EventHubProducerClient` instance is resolved from service provider. + +```csharp +void Configure(IHealthChecksBuilder builder) +{ + builder.Services.AddSingleton(sp => new EventHubProducerClient("fullyQualifiedNamespace", "eventHubName", new DefaultAzureCredential())); + builder.AddHealthChecks().AddAzureEventHub(); +} +``` + +### Customization + +You can additionally add the following parameters: + +- `clientFactory`: A factory method to provide `EventHubProducerClient` instance. This can be very useful when you need more than one `EventHubProducerClient` instance in your app (please see the example below that uses keyed DI introduced in .NET 8). +- `failureStatus`: The `HealthStatus` that should be reported when the health check fails. Default is `HealthStatus.Unhealthy`. +- `tags`: A list of tags that can be used to filter sets of health checks. +- `timeout`: A `System.TimeSpan` representing the timeout of the check. + +```csharp +void Configure(IHealthChecksBuilder builder) +{ + builder.Services + .AddKeyedSingleton(serviceKey: "eventHubName1", (serviceProvider, serviceKey) => new EventHubProducerClient("fullyQualifiedNamespace", "eventHubName1", new DefaultAzureCredential())) + .AddKeyedSingleton(serviceKey: "eventHubName2", (serviceProvider, serviceKey) => new EventHubProducerClient("fullyQualifiedNamespace", "eventHubName2", new DefaultAzureCredential())) + .AddHealthChecks() + .AddAzureKeyVaultSecrets(clientFactory: serviceProvider => serviceProvider.GetRequiredKeyedService("eventHubName1"), healthCheckName: "event_hub_1") + .AddAzureKeyVaultSecrets(clientFactory: serviceProvider => serviceProvider.GetRequiredKeyedService("eventHubName2"), healthCheckName: "event_hub_2"); + +} +``` + + +### Breaking changes + +In the prior releases, `AzureEventHubHealthCheck` was a part of `HealthChecks.AzureServiceBus` package. It had a dependency on not just `Azure.Messaging.EventHubs`, but also `Azure.Messaging.ServiceBus`. The packages have been split to avoid bringing unnecessary dependencies. Moreover, `AzureEventHubHealthCheck` was letting the users specify how `EventHubProducerClient` should be created (from raw connection string or from fully qualified namespace and managed identity credentials), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and **it's the caller responsibility to provide the instance of `EventHubProducerClient`** (please see [#2040](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2040) for more details). Since Azure SDK recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for Azure SDK clients. So the clients are created only when needed and once per whole application lifetime. diff --git a/src/ClientCache.cs b/src/HealthChecks.Azure.Messaging.ServiceBus/ClientCache.cs similarity index 100% rename from src/ClientCache.cs rename to src/HealthChecks.Azure.Messaging.ServiceBus/ClientCache.cs diff --git a/src/HealthChecks.AzureServiceBus/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs b/src/HealthChecks.Azure.Messaging.ServiceBus/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs similarity index 73% rename from src/HealthChecks.AzureServiceBus/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs rename to src/HealthChecks.Azure.Messaging.ServiceBus/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs index 6a05ce25bc..3654757160 100644 --- a/src/HealthChecks.AzureServiceBus/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs +++ b/src/HealthChecks.Azure.Messaging.ServiceBus/DependencyInjection/AzureServiceBusHealthCheckBuilderExtensions.cs @@ -1,814 +1,609 @@ -using Azure.Core; -using Azure.Messaging.EventHubs; -using HealthChecks.AzureServiceBus; -using HealthChecks.AzureServiceBus.Configuration; -using Microsoft.Extensions.Diagnostics.HealthChecks; - -namespace Microsoft.Extensions.DependencyInjection; - -/// -/// Extension methods to configure , -/// , , -/// , , -/// . -/// -public static class AzureServiceBusHealthCheckBuilderExtensions -{ - private const string AZUREEVENTHUB_NAME = "azureeventhub"; - private const string AZUREQUEUE_NAME = "azurequeue"; - private const string AZURETOPIC_NAME = "azuretopic"; - private const string AZURESUBSCRIPTION_NAME = "azuresubscription"; - private const string AZUREQUEUETHRESHOLD_NAME = "azurequeuethreshold"; - - /// - /// Add a health check for specified Azure Event Hub. - /// - /// The . - /// The azure event hub connection string. - /// The azure event hub name. - /// An optional action to allow additional Azure Event Hub configuration. - /// The health check name. Optional. If null the type name 'azureeventhub' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureEventHub( - this IHealthChecksBuilder builder, - string connectionString, - string eventHubName, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureEventHub( - _ => connectionString, - _ => eventHubName, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for specified Azure Event Hub. - /// - /// The . - /// A factory to build the azure event hub connection string. - /// A factory to build the azure event hub name. - /// An optional action to allow additional Azure Event Hub configuration. - /// The health check name. Optional. If null the type name 'azureeventhub' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureEventHub( - this IHealthChecksBuilder builder, - Func connectionStringFactory, - Func eventHubNameFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(connectionStringFactory); - Guard.ThrowIfNull(eventHubNameFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREEVENTHUB_NAME, - sp => - { - var options = new AzureEventHubHealthCheckOptions - { - ConnectionString = connectionStringFactory(sp), - EventHubName = eventHubNameFactory(sp) - }; - - configure?.Invoke(options); - return new AzureEventHubHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for specified Azure Event Hub. - /// - /// The . - /// The azure event hub fully qualified namespace. - /// The azure event hub name. - /// The token credential for authentication. - /// An optional action to allow additional Azure Event Hub configuration. - /// The health check name. Optional. If null the type name 'azureeventhub' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureEventHub( - this IHealthChecksBuilder builder, - string fullyQualifiedNamespace, - string eventHubName, - TokenCredential tokenCredential, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureEventHub( - _ => fullyQualifiedNamespace, - _ => eventHubName, - _ => tokenCredential, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for specified Azure Event Hub. - /// - /// The . - /// A factory to build the azure event hub fully qualified namespace. - /// A factory to build the azure event hub name. - /// A factory to build the token credential for authentication. - /// An optional action to allow additional Azure Event Hub configuration. - /// The health check name. Optional. If null the type name 'azureeventhub' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureEventHub( - this IHealthChecksBuilder builder, - Func fullyQualifiedNamespaceFactory, - Func eventHubNameFactory, - Func tokenCredentialFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); - Guard.ThrowIfNull(eventHubNameFactory); - Guard.ThrowIfNull(tokenCredentialFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREEVENTHUB_NAME, - sp => - { - var options = new AzureEventHubHealthCheckOptions - { - FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), - EventHubName = eventHubNameFactory(sp), - Credential = tokenCredentialFactory(sp) - }; - - configure?.Invoke(options); - return new AzureEventHubHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for specified Azure Event Hub. - /// - /// The . - /// The event hub connection factory used to create a event hub connection for this health check. - /// An optional action to allow additional Azure Event Hub configuration. - /// The health check name. Optional. If null the type name 'azureeventhub' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureEventHub( - this IHealthChecksBuilder builder, - Func eventHubConnectionFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(eventHubConnectionFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREEVENTHUB_NAME, - sp => - { - var options = new AzureEventHubHealthCheckOptions { Connection = eventHubConnectionFactory(sp) }; - configure?.Invoke(options); - return new AzureEventHubHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for specified Azure Service Bus Queue. - /// - /// The . - /// The azure service bus connection string to be used. - /// The name of the queue to check. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusQueue( - this IHealthChecksBuilder builder, - string connectionString, - string queueName, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureServiceBusQueue( - _ => connectionString, - _ => queueName, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for specified Azure Service Bus Queue. - /// - /// The . - /// A factory to build the azure service bus connection string to be used. - /// A factory to build the queue name to check. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusQueue( - this IHealthChecksBuilder builder, - Func connectionStringFactory, - Func queueNameFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(connectionStringFactory); - Guard.ThrowIfNull(queueNameFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREQUEUE_NAME, - sp => - { - var options = new AzureServiceBusQueueHealthCheckOptions(queueNameFactory(sp)) - { - ConnectionString = connectionStringFactory(sp) - }; - - configure?.Invoke(options); - return new AzureServiceBusQueueHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for specified Azure Service Bus Queue. - /// - /// The . - /// The azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. - /// The name of the queue to check. - /// The token credential for authentication. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusQueue( - this IHealthChecksBuilder builder, - string fullyQualifiedNamespace, - string queueName, - TokenCredential tokenCredential, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureServiceBusQueue( - _ => fullyQualifiedNamespace, - _ => queueName, - _ => tokenCredential, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for specified Azure Service Bus Queue. - /// - /// The . - /// A factory to build the azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. - /// A factory to build the name of the queue to check. - /// A factory to build the token credential for authentication. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusQueue( - this IHealthChecksBuilder builder, - Func fullyQualifiedNamespaceFactory, - Func queueNameFactory, - Func tokenCredentialFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); - Guard.ThrowIfNull(queueNameFactory); - Guard.ThrowIfNull(tokenCredentialFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREQUEUE_NAME, - sp => - { - var options = new AzureServiceBusQueueHealthCheckOptions(queueNameFactory(sp)) - { - FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), - Credential = tokenCredentialFactory(sp) - }; - - configure?.Invoke(options); - return new AzureServiceBusQueueHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for specified Azure Service Bus Queue active or dead letter messages threshold. - /// - /// The . - /// The azure service bus connection string to be used. - /// The name of the queue to check. - /// The health check name. Optional. If null the type name 'azurequeuethreshold' will be used for the name. - /// An optional action to allow additional Azure Service Bus configuration. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The . - public static IHealthChecksBuilder AddAzureServiceBusQueueMessageCountThreshold( - this IHealthChecksBuilder builder, - string connectionString, - string queueName, - string? name = default, - Action? configure = null, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(connectionString); - Guard.ThrowIfNull(queueName); - - var options = new AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions(queueName) - { - ConnectionString = connectionString, - }; - - configure?.Invoke(options); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREQUEUETHRESHOLD_NAME, - sp => new AzureServiceBusQueueMessageCountThresholdHealthCheck(options), - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for specified Azure Service Bus Queue active or dead letter messages threshold. - /// - /// The . - /// The azure service bus endpoint to be used, format sb://myservicebus.servicebus.windows.net/. - /// The name of the queue to check. - /// The token credential for authentication. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azurequeuethreshold' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The . - public static IHealthChecksBuilder AddAzureServiceBusQueueMessageCountThreshold( - this IHealthChecksBuilder builder, - string endpoint, - string queueName, - TokenCredential tokenCredential, - Action? configure = null, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(endpoint); - Guard.ThrowIfNull(queueName); - Guard.ThrowIfNull(tokenCredential); - - var options = new AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions(queueName) - { - FullyQualifiedNamespace = endpoint, - Credential = tokenCredential, - }; - - configure?.Invoke(options); - - return builder.Add(new HealthCheckRegistration( - name ?? AZUREQUEUETHRESHOLD_NAME, - sp => new AzureServiceBusQueueMessageCountThresholdHealthCheck(options), - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for Azure Service Bus Topic. - /// - /// The . - /// The Azure ServiceBus connection string to be used. - /// The name of the topic to check. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusTopic( - this IHealthChecksBuilder builder, - string connectionString, - string topicName, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureServiceBusTopic( - _ => connectionString, - _ => topicName, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for Azure Service Bus Topic. - /// - /// The . - /// A factory to build the Azure ServiceBus connection string to be used. - /// A factory to build the name of the topic to check. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusTopic( - this IHealthChecksBuilder builder, - Func connectionStringFactory, - Func topicNameFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(connectionStringFactory); - Guard.ThrowIfNull(topicNameFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZURETOPIC_NAME, - sp => - { - var options = new AzureServiceBusTopicHealthCheckOptions(topicNameFactory(sp)) - { - ConnectionString = connectionStringFactory(sp) - }; - - configure?.Invoke(options); - return new AzureServiceBusTopicHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for Azure Service Bus Topic. - /// - /// The . - /// The azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. - /// The name of the topic to check. - /// The token credential for authentication. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusTopic( - this IHealthChecksBuilder builder, - string fullyQualifiedNamespace, - string topicName, - TokenCredential tokenCredential, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureServiceBusTopic( - _ => fullyQualifiedNamespace, - _ => topicName, - _ => tokenCredential, - configure: null, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for Azure Service Bus Topic. - /// - /// The . - /// A factory to build the azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. - /// A factory to build the name of the topic to check. - /// A factory to build the token credential for authentication. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusTopic( - this IHealthChecksBuilder builder, - Func fullyQualifiedNamespaceFactory, - Func topicNameFactory, - Func tokenCredentialFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); - Guard.ThrowIfNull(topicNameFactory); - Guard.ThrowIfNull(tokenCredentialFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZURETOPIC_NAME, - sp => - { - var options = new AzureServiceBusTopicHealthCheckOptions(topicNameFactory(sp)) - { - FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), - Credential = tokenCredentialFactory(sp) - }; - - configure?.Invoke(options); - return new AzureServiceBusTopicHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for Azure Service Bus Subscription. - /// - /// The . - /// The Azure ServiceBus connection string to be used. - /// The name of the topic to check. - /// The subscription name of the topic subscription to check. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusSubscription( - this IHealthChecksBuilder builder, - string connectionString, - string topicName, - string subscriptionName, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureServiceBusSubscription( - _ => connectionString, - _ => topicName, - _ => subscriptionName, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for Azure Service Bus Subscription. - /// - /// The . - /// A factory to build the Azure ServiceBus connection string to be used. - /// A factory to build the name of the topic to check. - /// A factory to build the subscription name of the topic subscription to check. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusSubscription( - this IHealthChecksBuilder builder, - Func connectionStringFactory, - Func topicNameFactory, - Func subscriptionNameFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(connectionStringFactory); - Guard.ThrowIfNull(topicNameFactory); - Guard.ThrowIfNull(subscriptionNameFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZURESUBSCRIPTION_NAME, - sp => - { - var options = new AzureServiceBusSubscriptionHealthCheckHealthCheckOptions(topicNameFactory(sp), subscriptionNameFactory(sp)) - { - ConnectionString = connectionStringFactory(sp) - }; - - configure?.Invoke(options); - return new AzureServiceBusSubscriptionHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } - - /// - /// Add a health check for Azure Service Bus Subscription. - /// - /// The . - /// The azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. - /// The name of the topic to check. - /// The subscription name of the topic subscription to check. - /// The token credential for authentication. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusSubscription( - this IHealthChecksBuilder builder, - string fullyQualifiedNamespace, - string topicName, - string subscriptionName, - TokenCredential tokenCredential, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) => - builder.AddAzureServiceBusSubscription( - _ => fullyQualifiedNamespace, - _ => topicName, - _ => subscriptionName, - _ => tokenCredential, - configure, - name, - failureStatus, - tags, - timeout); - - /// - /// Add a health check for Azure Service Bus Subscription. - /// - /// The . - /// A factory to build the azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. - /// A factory to build the name of the topic to check. - /// A factory to build the subscription name of the topic subscription to check. - /// A factory to build the token credential for authentication. - /// An optional action to allow additional Azure Service Bus configuration. - /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. - /// - /// The that should be reported when the health check fails. Optional. If null then - /// the default status of will be reported. - /// - /// A list of tags that can be used to filter sets of health checks. Optional. - /// An optional representing the timeout of the check. - /// The specified . - public static IHealthChecksBuilder AddAzureServiceBusSubscription( - this IHealthChecksBuilder builder, - Func fullyQualifiedNamespaceFactory, - Func topicNameFactory, - Func subscriptionNameFactory, - Func tokenCredentialFactory, - Action? configure = default, - string? name = default, - HealthStatus? failureStatus = default, - IEnumerable? tags = default, - TimeSpan? timeout = default) - { - Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); - Guard.ThrowIfNull(topicNameFactory); - Guard.ThrowIfNull(subscriptionNameFactory); - Guard.ThrowIfNull(tokenCredentialFactory); - - return builder.Add(new HealthCheckRegistration( - name ?? AZURESUBSCRIPTION_NAME, - sp => - { - var options = new AzureServiceBusSubscriptionHealthCheckHealthCheckOptions(topicNameFactory(sp), subscriptionNameFactory(sp)) - { - FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), - Credential = tokenCredentialFactory(sp) - }; - - configure?.Invoke(options); - return new AzureServiceBusSubscriptionHealthCheck(options); - }, - failureStatus, - tags, - timeout)); - } -} +using Azure.Core; +using HealthChecks.AzureServiceBus; +using HealthChecks.AzureServiceBus.Configuration; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace Microsoft.Extensions.DependencyInjection; + +/// +/// Extension methods to configure +/// , , +/// , , +/// . +/// +public static class AzureServiceBusHealthCheckBuilderExtensions +{ + private const string AZUREQUEUE_NAME = "azurequeue"; + private const string AZURETOPIC_NAME = "azuretopic"; + private const string AZURESUBSCRIPTION_NAME = "azuresubscription"; + private const string AZUREQUEUETHRESHOLD_NAME = "azurequeuethreshold"; + + /// + /// Add a health check for specified Azure Service Bus Queue. + /// + /// The . + /// The azure service bus connection string to be used. + /// The name of the queue to check. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusQueue( + this IHealthChecksBuilder builder, + string connectionString, + string queueName, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) => + builder.AddAzureServiceBusQueue( + _ => connectionString, + _ => queueName, + configure, + name, + failureStatus, + tags, + timeout); + + /// + /// Add a health check for specified Azure Service Bus Queue. + /// + /// The . + /// A factory to build the azure service bus connection string to be used. + /// A factory to build the queue name to check. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusQueue( + this IHealthChecksBuilder builder, + Func connectionStringFactory, + Func queueNameFactory, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(connectionStringFactory); + Guard.ThrowIfNull(queueNameFactory); + + return builder.Add(new HealthCheckRegistration( + name ?? AZUREQUEUE_NAME, + sp => + { + var options = new AzureServiceBusQueueHealthCheckOptions(queueNameFactory(sp)) + { + ConnectionString = connectionStringFactory(sp) + }; + + configure?.Invoke(options); + return new AzureServiceBusQueueHealthCheck(options); + }, + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for specified Azure Service Bus Queue. + /// + /// The . + /// The azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. + /// The name of the queue to check. + /// The token credential for authentication. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusQueue( + this IHealthChecksBuilder builder, + string fullyQualifiedNamespace, + string queueName, + TokenCredential tokenCredential, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) => + builder.AddAzureServiceBusQueue( + _ => fullyQualifiedNamespace, + _ => queueName, + _ => tokenCredential, + configure, + name, + failureStatus, + tags, + timeout); + + /// + /// Add a health check for specified Azure Service Bus Queue. + /// + /// The . + /// A factory to build the azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. + /// A factory to build the name of the queue to check. + /// A factory to build the token credential for authentication. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azurequeue' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusQueue( + this IHealthChecksBuilder builder, + Func fullyQualifiedNamespaceFactory, + Func queueNameFactory, + Func tokenCredentialFactory, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); + Guard.ThrowIfNull(queueNameFactory); + Guard.ThrowIfNull(tokenCredentialFactory); + + return builder.Add(new HealthCheckRegistration( + name ?? AZUREQUEUE_NAME, + sp => + { + var options = new AzureServiceBusQueueHealthCheckOptions(queueNameFactory(sp)) + { + FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), + Credential = tokenCredentialFactory(sp) + }; + + configure?.Invoke(options); + return new AzureServiceBusQueueHealthCheck(options); + }, + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for specified Azure Service Bus Queue active or dead letter messages threshold. + /// + /// The . + /// The azure service bus connection string to be used. + /// The name of the queue to check. + /// The health check name. Optional. If null the type name 'azurequeuethreshold' will be used for the name. + /// An optional action to allow additional Azure Service Bus configuration. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The . + public static IHealthChecksBuilder AddAzureServiceBusQueueMessageCountThreshold( + this IHealthChecksBuilder builder, + string connectionString, + string queueName, + string? name = default, + Action? configure = null, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(connectionString); + Guard.ThrowIfNull(queueName); + + var options = new AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions(queueName) + { + ConnectionString = connectionString, + }; + + configure?.Invoke(options); + + return builder.Add(new HealthCheckRegistration( + name ?? AZUREQUEUETHRESHOLD_NAME, + sp => new AzureServiceBusQueueMessageCountThresholdHealthCheck(options), + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for specified Azure Service Bus Queue active or dead letter messages threshold. + /// + /// The . + /// The azure service bus endpoint to be used, format sb://myservicebus.servicebus.windows.net/. + /// The name of the queue to check. + /// The token credential for authentication. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azurequeuethreshold' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The . + public static IHealthChecksBuilder AddAzureServiceBusQueueMessageCountThreshold( + this IHealthChecksBuilder builder, + string endpoint, + string queueName, + TokenCredential tokenCredential, + Action? configure = null, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(endpoint); + Guard.ThrowIfNull(queueName); + Guard.ThrowIfNull(tokenCredential); + + var options = new AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions(queueName) + { + FullyQualifiedNamespace = endpoint, + Credential = tokenCredential, + }; + + configure?.Invoke(options); + + return builder.Add(new HealthCheckRegistration( + name ?? AZUREQUEUETHRESHOLD_NAME, + sp => new AzureServiceBusQueueMessageCountThresholdHealthCheck(options), + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for Azure Service Bus Topic. + /// + /// The . + /// The Azure ServiceBus connection string to be used. + /// The name of the topic to check. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusTopic( + this IHealthChecksBuilder builder, + string connectionString, + string topicName, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) => + builder.AddAzureServiceBusTopic( + _ => connectionString, + _ => topicName, + configure, + name, + failureStatus, + tags, + timeout); + + /// + /// Add a health check for Azure Service Bus Topic. + /// + /// The . + /// A factory to build the Azure ServiceBus connection string to be used. + /// A factory to build the name of the topic to check. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusTopic( + this IHealthChecksBuilder builder, + Func connectionStringFactory, + Func topicNameFactory, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(connectionStringFactory); + Guard.ThrowIfNull(topicNameFactory); + + return builder.Add(new HealthCheckRegistration( + name ?? AZURETOPIC_NAME, + sp => + { + var options = new AzureServiceBusTopicHealthCheckOptions(topicNameFactory(sp)) + { + ConnectionString = connectionStringFactory(sp) + }; + + configure?.Invoke(options); + return new AzureServiceBusTopicHealthCheck(options); + }, + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for Azure Service Bus Topic. + /// + /// The . + /// The azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. + /// The name of the topic to check. + /// The token credential for authentication. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusTopic( + this IHealthChecksBuilder builder, + string fullyQualifiedNamespace, + string topicName, + TokenCredential tokenCredential, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) => + builder.AddAzureServiceBusTopic( + _ => fullyQualifiedNamespace, + _ => topicName, + _ => tokenCredential, + configure: null, + name, + failureStatus, + tags, + timeout); + + /// + /// Add a health check for Azure Service Bus Topic. + /// + /// The . + /// A factory to build the azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. + /// A factory to build the name of the topic to check. + /// A factory to build the token credential for authentication. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusTopic( + this IHealthChecksBuilder builder, + Func fullyQualifiedNamespaceFactory, + Func topicNameFactory, + Func tokenCredentialFactory, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); + Guard.ThrowIfNull(topicNameFactory); + Guard.ThrowIfNull(tokenCredentialFactory); + + return builder.Add(new HealthCheckRegistration( + name ?? AZURETOPIC_NAME, + sp => + { + var options = new AzureServiceBusTopicHealthCheckOptions(topicNameFactory(sp)) + { + FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), + Credential = tokenCredentialFactory(sp) + }; + + configure?.Invoke(options); + return new AzureServiceBusTopicHealthCheck(options); + }, + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for Azure Service Bus Subscription. + /// + /// The . + /// The Azure ServiceBus connection string to be used. + /// The name of the topic to check. + /// The subscription name of the topic subscription to check. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusSubscription( + this IHealthChecksBuilder builder, + string connectionString, + string topicName, + string subscriptionName, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) => + builder.AddAzureServiceBusSubscription( + _ => connectionString, + _ => topicName, + _ => subscriptionName, + configure, + name, + failureStatus, + tags, + timeout); + + /// + /// Add a health check for Azure Service Bus Subscription. + /// + /// The . + /// A factory to build the Azure ServiceBus connection string to be used. + /// A factory to build the name of the topic to check. + /// A factory to build the subscription name of the topic subscription to check. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusSubscription( + this IHealthChecksBuilder builder, + Func connectionStringFactory, + Func topicNameFactory, + Func subscriptionNameFactory, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(connectionStringFactory); + Guard.ThrowIfNull(topicNameFactory); + Guard.ThrowIfNull(subscriptionNameFactory); + + return builder.Add(new HealthCheckRegistration( + name ?? AZURESUBSCRIPTION_NAME, + sp => + { + var options = new AzureServiceBusSubscriptionHealthCheckHealthCheckOptions(topicNameFactory(sp), subscriptionNameFactory(sp)) + { + ConnectionString = connectionStringFactory(sp) + }; + + configure?.Invoke(options); + return new AzureServiceBusSubscriptionHealthCheck(options); + }, + failureStatus, + tags, + timeout)); + } + + /// + /// Add a health check for Azure Service Bus Subscription. + /// + /// The . + /// The azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. + /// The name of the topic to check. + /// The subscription name of the topic subscription to check. + /// The token credential for authentication. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusSubscription( + this IHealthChecksBuilder builder, + string fullyQualifiedNamespace, + string topicName, + string subscriptionName, + TokenCredential tokenCredential, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) => + builder.AddAzureServiceBusSubscription( + _ => fullyQualifiedNamespace, + _ => topicName, + _ => subscriptionName, + _ => tokenCredential, + configure, + name, + failureStatus, + tags, + timeout); + + /// + /// Add a health check for Azure Service Bus Subscription. + /// + /// The . + /// A factory to build the azure service bus fully qualified namespace to be used, format sb://myservicebus.servicebus.windows.net/. + /// A factory to build the name of the topic to check. + /// A factory to build the subscription name of the topic subscription to check. + /// A factory to build the token credential for authentication. + /// An optional action to allow additional Azure Service Bus configuration. + /// The health check name. Optional. If null the type name 'azuretopic' will be used for the name. + /// + /// The that should be reported when the health check fails. Optional. If null then + /// the default status of will be reported. + /// + /// A list of tags that can be used to filter sets of health checks. Optional. + /// An optional representing the timeout of the check. + /// The specified . + public static IHealthChecksBuilder AddAzureServiceBusSubscription( + this IHealthChecksBuilder builder, + Func fullyQualifiedNamespaceFactory, + Func topicNameFactory, + Func subscriptionNameFactory, + Func tokenCredentialFactory, + Action? configure = default, + string? name = default, + HealthStatus? failureStatus = default, + IEnumerable? tags = default, + TimeSpan? timeout = default) + { + Guard.ThrowIfNull(fullyQualifiedNamespaceFactory); + Guard.ThrowIfNull(topicNameFactory); + Guard.ThrowIfNull(subscriptionNameFactory); + Guard.ThrowIfNull(tokenCredentialFactory); + + return builder.Add(new HealthCheckRegistration( + name ?? AZURESUBSCRIPTION_NAME, + sp => + { + var options = new AzureServiceBusSubscriptionHealthCheckHealthCheckOptions(topicNameFactory(sp), subscriptionNameFactory(sp)) + { + FullyQualifiedNamespace = fullyQualifiedNamespaceFactory(sp), + Credential = tokenCredentialFactory(sp) + }; + + configure?.Invoke(options); + return new AzureServiceBusSubscriptionHealthCheck(options); + }, + failureStatus, + tags, + timeout)); + } +} diff --git a/src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj b/src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj index 5019becce8..6561ba8497 100644 --- a/src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj +++ b/src/HealthChecks.Azure.Messaging.ServiceBus/HealthChecks.Azure.Messaging.ServiceBus.csproj @@ -4,13 +4,9 @@ netstandard2.0 $(PackageTags);Azure;ServiceBus HealthChecks.Azure.Messaging.ServiceBus is the health check package for Azure Service Bus Queues and Topics. - $(HealthCheckAzureServiceBus) + $(HealthCheckAzureMessagingServiceBus) - - - - diff --git a/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheck.cs b/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheck.cs index ed70c3641b..e84cee0668 100644 --- a/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheck.cs +++ b/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheck.cs @@ -1,7 +1,7 @@ using Azure.Storage.Blobs; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace HealthChecks.AzureStorage; +namespace HealthChecks.Azure.Storage.Blobs; /// /// Azure Blob Storage health check. diff --git a/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheckOptions.cs b/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheckOptions.cs index 8875f07621..612189821a 100644 --- a/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheckOptions.cs +++ b/src/HealthChecks.Azure.Storage.Blobs/AzureBlobStorageHealthCheckOptions.cs @@ -1,4 +1,4 @@ -namespace HealthChecks.AzureStorage; +namespace HealthChecks.Azure.Storage.Blobs; /// /// Represents a collection of settings that configure an diff --git a/src/HealthChecks.Azure.Storage.Blobs/DependencyInjection/AzureBlobStorageHealthChecksBuilderExtensions.cs b/src/HealthChecks.Azure.Storage.Blobs/DependencyInjection/AzureBlobStorageHealthChecksBuilderExtensions.cs index 92abdac425..2ef2fffe4c 100644 --- a/src/HealthChecks.Azure.Storage.Blobs/DependencyInjection/AzureBlobStorageHealthChecksBuilderExtensions.cs +++ b/src/HealthChecks.Azure.Storage.Blobs/DependencyInjection/AzureBlobStorageHealthChecksBuilderExtensions.cs @@ -1,5 +1,5 @@ using Azure.Storage.Blobs; -using HealthChecks.AzureStorage; +using HealthChecks.Azure.Storage.Blobs; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/HealthChecks.Azure.Storage.Blobs/HealthChecks.Azure.Storage.Blobs.csproj b/src/HealthChecks.Azure.Storage.Blobs/HealthChecks.Azure.Storage.Blobs.csproj index 2f109ff9ab..97cf7cf611 100644 --- a/src/HealthChecks.Azure.Storage.Blobs/HealthChecks.Azure.Storage.Blobs.csproj +++ b/src/HealthChecks.Azure.Storage.Blobs/HealthChecks.Azure.Storage.Blobs.csproj @@ -4,7 +4,7 @@ netstandard2.0 $(PackageTags);Azure;AzureStorage HealthChecks.Azure.Storage.Blobs is the health check package for Blobs. - $(HealthCheckAzureStorage) + $(HealthCheckAzureStorageBlobs) diff --git a/src/HealthChecks.Azure.Storage.Blobs/README.md b/src/HealthChecks.Azure.Storage.Blobs/README.md index c71c13bdae..0dfde59389 100644 --- a/src/HealthChecks.Azure.Storage.Blobs/README.md +++ b/src/HealthChecks.Azure.Storage.Blobs/README.md @@ -7,7 +7,7 @@ This health check verifies the ability to communicate with [Azure Blob Storage]( By default, the `BlobServiceClient` instance is resolved from service provider. `AzureBlobStorageHealthCheckOptions` does not provide any specific container name, so the health check fetches just first container. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new BlobServiceClient(new Uri("azure-blob-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureBlobStorage(); @@ -26,7 +26,7 @@ You can additionally add the following parameters: - `timeout`: A `System.TimeSpan` representing the timeout of the check. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new BlobServiceClient(new Uri("azure-blob-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureBlobStorage( @@ -37,4 +37,7 @@ public void Configure(IHealthChecksBuilder builder) } ``` -For more information about credentials types please see [Azure TokenCredentials](https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme) +### Breaking changes + +In the prior releases, `AzureBlobStorageHealthCheck` was a part of `HealthChecks.AzureStorage` package. It had a dependency on not just `Azure.Storage.Blobs`, but also `Azure.Storage.Queues` and `Azure.Storage.Files.Shares`. The packages have been split to avoid bringing unnecessary dependencies. Moreover, `AzureBlobStorageHealthCheck` was letting the users specify how `BlobServiceClient` should be created (from raw connection string or from endpoint uri and managed identity credentials), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and **it's the caller responsibility to provide the instance of `BlobServiceClient`** (please see [#2040](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2040) for more details). Since Azure SDK recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for Azure SDK clients. So the clients are created only when needed and once per whole application lifetime. + diff --git a/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheck.cs b/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheck.cs index 3e74be77d4..cb8472322d 100644 --- a/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheck.cs +++ b/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheck.cs @@ -1,7 +1,7 @@ using Azure.Storage.Files.Shares; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace HealthChecks.AzureStorage; +namespace HealthChecks.Azure.Storage.Files.Shares; /// /// Azure Files health check. diff --git a/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheckOptions.cs b/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheckOptions.cs index d8fc138eb3..22fc703848 100644 --- a/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheckOptions.cs +++ b/src/HealthChecks.Azure.Storage.Files.Shares/AzureFileShareHealthCheckOptions.cs @@ -1,4 +1,4 @@ -namespace HealthChecks.AzureStorage; +namespace HealthChecks.Azure.Storage.Files.Shares; /// /// Represents a collection of settings that configure an diff --git a/src/HealthChecks.Azure.Storage.Files.Shares/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs b/src/HealthChecks.Azure.Storage.Files.Shares/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs index 47406c820f..dabdd56481 100644 --- a/src/HealthChecks.Azure.Storage.Files.Shares/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs +++ b/src/HealthChecks.Azure.Storage.Files.Shares/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs @@ -1,5 +1,5 @@ using Azure.Storage.Files.Shares; -using HealthChecks.AzureStorage; +using HealthChecks.Azure.Storage.Files.Shares; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/HealthChecks.Azure.Storage.Files.Shares/HealthChecks.Azure.Storage.Files.Shares.csproj b/src/HealthChecks.Azure.Storage.Files.Shares/HealthChecks.Azure.Storage.Files.Shares.csproj index 28b180ed62..9cab99a4be 100644 --- a/src/HealthChecks.Azure.Storage.Files.Shares/HealthChecks.Azure.Storage.Files.Shares.csproj +++ b/src/HealthChecks.Azure.Storage.Files.Shares/HealthChecks.Azure.Storage.Files.Shares.csproj @@ -4,7 +4,7 @@ netstandard2.0 $(PackageTags);Azure;AzureStorage HealthChecks.Azure.Storage.Files.Shares is the health check package for Azure File Shares. - $(HealthCheckAzureStorage) + $(HealthCheckAzureStorageFilesShares) diff --git a/src/HealthChecks.Azure.Storage.Files.Shares/README.md b/src/HealthChecks.Azure.Storage.Files.Shares/README.md index a092f4edcf..771c223304 100644 --- a/src/HealthChecks.Azure.Storage.Files.Shares/README.md +++ b/src/HealthChecks.Azure.Storage.Files.Shares/README.md @@ -7,7 +7,7 @@ This health check verifies the ability to communicate with [Azure File Storage]( By default, the `ShareServiceClient` instance is resolved from service provider. `AzureFileShareHealthCheckOptions` does not provide any specific share name, so the health check fetches just first share. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new ShareServiceClient(new Uri("azure-file-share-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureFileShare(); @@ -26,7 +26,7 @@ You can additionally add the following parameters: - `timeout`: A `System.TimeSpan` representing the timeout of the check. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new ShareServiceClient(new Uri("azure-file-share-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureFileShare( @@ -37,4 +37,6 @@ public void Configure(IHealthChecksBuilder builder) } ``` -For more information about credentials types please see [Azure TokenCredentials](https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme) +### Breaking changes + +In the prior releases, `AzureFileShareHealthCheck` was a part of `HealthChecks.AzureStorage` package. It had a dependency on not just `Azure.Storage.Files.Shares`, but also `Azure.Storage.Queues` and `Azure.Storage.Blobs`. The packages have been split to avoid bringing unnecessary dependencies. Moreover, `AzureFileShareHealthCheck` was letting the users specify how `ShareServiceClient` should be created (from raw connection string), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and **it's the caller responsibility to provide the instance of `ShareServiceClient`** (please see [#2040](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2040) for more details). Since Azure SDK recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for Azure SDK clients. So the clients are created only when needed and once per whole application lifetime. diff --git a/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheck.cs b/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheck.cs index d85425b7c5..3201cd6c5d 100644 --- a/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheck.cs +++ b/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheck.cs @@ -1,7 +1,7 @@ using Azure.Storage.Queues; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace HealthChecks.AzureStorage; +namespace HealthChecks.Azure.Storage.Queues; /// /// Azure Queue Storage health check. diff --git a/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheckOptions.cs b/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheckOptions.cs index 08d91cd115..5a97230105 100644 --- a/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheckOptions.cs +++ b/src/HealthChecks.Azure.Storage.Queues/AzureQueueStorageHealthCheckOptions.cs @@ -1,4 +1,4 @@ -namespace HealthChecks.AzureStorage; +namespace HealthChecks.Azure.Storage.Queues; /// /// Represents a collection of settings that configure an diff --git a/src/HealthChecks.Azure.Storage.Queues/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs b/src/HealthChecks.Azure.Storage.Queues/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs index ebd488d1f5..76fcf4c417 100644 --- a/src/HealthChecks.Azure.Storage.Queues/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs +++ b/src/HealthChecks.Azure.Storage.Queues/DependencyInjection/AzureQueueStorageHealthChecksBuilderExtensions.cs @@ -1,5 +1,5 @@ using Azure.Storage.Queues; -using HealthChecks.AzureStorage; +using HealthChecks.Azure.Storage.Queues; using Microsoft.Extensions.Diagnostics.HealthChecks; namespace Microsoft.Extensions.DependencyInjection; diff --git a/src/HealthChecks.Azure.Storage.Queues/HealthChecks.Azure.Storage.Queues.csproj b/src/HealthChecks.Azure.Storage.Queues/HealthChecks.Azure.Storage.Queues.csproj index ff985f25f0..7c94ee5ca6 100644 --- a/src/HealthChecks.Azure.Storage.Queues/HealthChecks.Azure.Storage.Queues.csproj +++ b/src/HealthChecks.Azure.Storage.Queues/HealthChecks.Azure.Storage.Queues.csproj @@ -4,7 +4,7 @@ netstandard2.0 $(PackageTags);Azure;AzureStorage HealthChecks.Azure.Storage.Queues is the health check package for Azure Storage Queues. - $(HealthCheckAzureStorage) + $(HealthCheckAzureStorageQueues) diff --git a/src/HealthChecks.Azure.Storage.Queues/README.md b/src/HealthChecks.Azure.Storage.Queues/README.md index b08b66f93f..48ecbe1c0b 100644 --- a/src/HealthChecks.Azure.Storage.Queues/README.md +++ b/src/HealthChecks.Azure.Storage.Queues/README.md @@ -7,7 +7,7 @@ This health check verifies the ability to communicate with [Azure Queue Storage] By default, the `QueueServiceClient` instance is resolved from service provider. `AzureQueueStorageHealthCheckOptions` does not provide any specific queue name, so the health check fetches just first queue. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new QueueServiceClient(new Uri("azure-queue-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureQueueStorage(); @@ -26,7 +26,7 @@ You can additionally add the following parameters: - `timeout`: A `System.TimeSpan` representing the timeout of the check. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new QueueServiceClient(new Uri("azure-queue-storage-uri"), new DefaultAzureCredential())); builder.AddHealthChecks().AddAzureQueueStorage( @@ -37,4 +37,7 @@ public void Configure(IHealthChecksBuilder builder) } ``` -For more information about credentials types please see [Azure TokenCredentials](https://docs.microsoft.com/dotnet/api/overview/azure/identity-readme) +### Breaking changes + +In the prior releases, `AzureQueueStorageHealthCheck` was a part of `HealthChecks.AzureStorage` package. It had a dependency on not just `Azure.Storage.Queues`, but also `Azure.Storage.Files.Shares` and `Azure.Storage.Blobs`. The packages have been split to avoid bringing unnecessary dependencies. Moreover, `AzureQueueStorageHealthCheck` was letting the users specify how `QueueServiceClient` should be created (from raw connection string or an endpoint with managed identity credentials), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and **it's the caller responsibility to provide the instance of `ShareServiceClient`** (please see [#2040](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2040) for more details). Since Azure SDK recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for Azure SDK clients. So the clients are created only when needed and once per whole application lifetime. + diff --git a/src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj b/src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj deleted file mode 100644 index 663724b4e4..0000000000 --- a/src/HealthChecks.AzureServiceBus/HealthChecks.AzureServiceBus.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - netstandard2.0 - $(PackageTags);Azure;ServiceBus;EventHub - HealthChecks.AzureServiceBus is the health check package for Azure EventHub, and Azure Service Bus Queues and Topics. - $(HealthCheckAzureServiceBus) - - - - - - - - diff --git a/src/HealthChecks.AzureServiceBus/Properties/AssemblyInfo.cs b/src/HealthChecks.AzureServiceBus/Properties/AssemblyInfo.cs deleted file mode 100644 index 636c8c0c83..0000000000 --- a/src/HealthChecks.AzureServiceBus/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Runtime.CompilerServices; -using HealthChecks.AzureServiceBus; -using HealthChecks.AzureServiceBus.Configuration; - -[assembly: TypeForwardedTo(typeof(AzureServiceBusHealthCheck<>))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusHealthCheckOptions))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusQueueHealthCheck))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusQueueHealthCheckOptions))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusQueueMessageCountThresholdHealthCheck))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusQueueMessagesCountThresholdHealthCheckOptions))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusSubscriptionHealthCheck))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusSubscriptionHealthCheckHealthCheckOptions))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusTopicHealthCheck))] -[assembly: TypeForwardedTo(typeof(AzureServiceBusTopicHealthCheckOptions))] -[assembly: TypeForwardedTo(typeof(ServiceBusClientProvider))] -[assembly: TypeForwardedTo(typeof(AzureEventHubHealthCheck))] -[assembly: TypeForwardedTo(typeof(AzureEventHubHealthCheckOptions))] diff --git a/src/HealthChecks.CosmosDb/README.md b/src/HealthChecks.CosmosDb/README.md index 9ef40ad331..5ec99ffc14 100644 --- a/src/HealthChecks.CosmosDb/README.md +++ b/src/HealthChecks.CosmosDb/README.md @@ -7,7 +7,7 @@ This health check verifies the ability to communicate with [Azure Cosmos DB](htt By default, the `CosmosClient` instance is resolved from service provider. `AzureCosmosDbHealthCheckOptions` does not provide any specific containers or database ids, the health check just calls [CosmosClient.ReadAccountAsync](https://learn.microsoft.com/dotnet/api/microsoft.azure.cosmos.cosmosclient.readaccountasync). ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new CosmosClient( "endpoint-from-portal", @@ -32,7 +32,7 @@ You can additionally add the following parameters: - `timeout`: A `System.TimeSpan` representing the timeout of the check. ```csharp -public void Configure(IHealthChecksBuilder builder) +void Configure(IHealthChecksBuilder builder) { builder.Services.AddSingleton(sp => new CosmosClient( "endpoint-from-portal", @@ -48,3 +48,9 @@ public void Configure(IHealthChecksBuilder builder) }); } ``` + +### Breaking changes + +In the prior releases, `CosmosDbHealthCheck` was a part of `HealthChecks.CosmosDb` package. It had a dependency on not just `Microsoft.Azure.Cosmos`, but also `Azure.Data.Tables`. The packages have been split to avoid bringing unnecessary dependencies. Moreover, `CosmosDbHealthCheck` was letting the users specify how `CosmosClient` should be created (from raw connection string or from endpoint and managed identity credentials), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and **it's the caller responsibility to provide the instance of `CosmosClient`** (please see [#2040](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/2040) for more details). Since Azure SDK recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for Azure SDK clients. So the clients are created only when needed and once per whole application lifetime. + + diff --git a/test/HealthChecks.Azure.Data.Tables.Tests/HealthChecks.Azure.Data.Tables.approved.txt b/test/HealthChecks.Azure.Data.Tables.Tests/HealthChecks.Azure.Data.Tables.approved.txt index 450df022aa..5c42ac762f 100644 --- a/test/HealthChecks.Azure.Data.Tables.Tests/HealthChecks.Azure.Data.Tables.approved.txt +++ b/test/HealthChecks.Azure.Data.Tables.Tests/HealthChecks.Azure.Data.Tables.approved.txt @@ -1,8 +1,8 @@ -namespace HealthChecks.CosmosDb +namespace HealthChecks.Azure.Data.Tables { public sealed class AzureTableServiceHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck { - public AzureTableServiceHealthCheck(Azure.Data.Tables.TableServiceClient tableServiceClient, HealthChecks.CosmosDb.AzureTableServiceHealthCheckOptions? options) { } + public AzureTableServiceHealthCheck(Azure.Data.Tables.TableServiceClient tableServiceClient, HealthChecks.Azure.Data.Tables.AzureTableServiceHealthCheckOptions? options) { } public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } } public sealed class AzureTableServiceHealthCheckOptions @@ -15,6 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection { public static class AzureTablesServiceHealthChecksBuilderExtensions { - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_tables", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureTable(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_tables", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } \ No newline at end of file diff --git a/test/HealthChecks.Azure.Data.Tables.Tests/TableServiceHealthCheckTests.cs b/test/HealthChecks.Azure.Data.Tables.Tests/TableServiceHealthCheckTests.cs index eff4185bda..4e2c51c835 100644 --- a/test/HealthChecks.Azure.Data.Tables.Tests/TableServiceHealthCheckTests.cs +++ b/test/HealthChecks.Azure.Data.Tables.Tests/TableServiceHealthCheckTests.cs @@ -5,7 +5,7 @@ using NSubstitute; using NSubstitute.ExceptionExtensions; -namespace HealthChecks.CosmosDb.Tests; +namespace HealthChecks.Azure.Data.Tables.Tests; public class tableservicehealthcheck_should { diff --git a/test/HealthChecks.Azure.Data.Tables.Tests/TablesConformanceTests.cs b/test/HealthChecks.Azure.Data.Tables.Tests/TablesConformanceTests.cs index 80b923db17..18fcb120ad 100644 --- a/test/HealthChecks.Azure.Data.Tables.Tests/TablesConformanceTests.cs +++ b/test/HealthChecks.Azure.Data.Tables.Tests/TablesConformanceTests.cs @@ -1,6 +1,5 @@ using Azure.Data.Tables; using Azure.Identity; -using HealthChecks.CosmosDb; namespace HealthChecks.Azure.Data.Tables.Tests; diff --git a/test/HealthChecks.Azure.Messaging.EventHubs.Tests/EventHubsConformanceTests.cs b/test/HealthChecks.Azure.Messaging.EventHubs.Tests/EventHubsConformanceTests.cs new file mode 100644 index 0000000000..d09e71c45f --- /dev/null +++ b/test/HealthChecks.Azure.Messaging.EventHubs.Tests/EventHubsConformanceTests.cs @@ -0,0 +1,24 @@ +using Azure.Identity; +using Azure.Messaging.EventHubs.Producer; + +namespace HealthChecks.Azure.Messaging.EventHubs.Tests; + +public class EventHubsConformanceTests : ConformanceTests +{ + protected override IHealthChecksBuilder AddHealthCheck(IHealthChecksBuilder builder, Func? clientFactory = null, Func? optionsFactory = null, string? healthCheckName = null, HealthStatus? failureStatus = null, IEnumerable? tags = null, TimeSpan? timeout = null) + => builder.AddAzureEventHub(clientFactory, healthCheckName, failureStatus, tags, timeout); + + protected override EventHubProducerClient CreateClientForNonExistingEndpoint() + => new("fullyQualifiedNamespace", "eventHubName", new AzureCliCredential()); + + protected override AzureEventHubHealthCheck CreateHealthCheck(EventHubProducerClient client, UnusedOptions? options) + => new(client); + + protected override UnusedOptions CreateHealthCheckOptions() + => new(); +} + +// AzureEventHubHealthCheck does not use any options, the type exists only to meet ConformanceTests<,,> criteria +public sealed class UnusedOptions +{ +} diff --git a/test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj b/test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.Tests.csproj similarity index 67% rename from test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj rename to test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.Tests.csproj index 2f24db41c4..c9ea759210 100644 --- a/test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.Tests.csproj +++ b/test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.approved.txt b/test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.approved.txt new file mode 100644 index 0000000000..6eb8437244 --- /dev/null +++ b/test/HealthChecks.Azure.Messaging.EventHubs.Tests/HealthChecks.Azure.Messaging.EventHubs.approved.txt @@ -0,0 +1,15 @@ +namespace HealthChecks.Azure.Messaging.EventHubs +{ + public sealed class AzureEventHubHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck + { + public AzureEventHubHealthCheck(Azure.Messaging.EventHubs.Producer.EventHubProducerClient client) { } + public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } + } +} +namespace Microsoft.Extensions.DependencyInjection +{ + public static class AzureEventHubHealthChecksBuilderExtensions + { + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureEventHub(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, string? healthCheckName = "azure_event_hub", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + } +} \ No newline at end of file diff --git a/test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusQueueHealthCheckTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusQueueHealthCheckTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusQueueHealthCheckTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusQueueHealthCheckTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusQueueMessageCountThresholdHealthCheckTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusQueueMessageCountThresholdHealthCheckTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusQueueMessageCountThresholdHealthCheckTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusQueueMessageCountThresholdHealthCheckTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusSubscriptionHealthCheckTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusSubscriptionHealthCheckTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusSubscriptionHealthCheckTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusSubscriptionHealthCheckTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusTopicHealthCheckTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusTopicHealthCheckTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/AzureServiceBusTopicHealthCheckTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/AzureServiceBusTopicHealthCheckTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitWithTokenUnitTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitWithTokenUnitTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitWithTokenUnitTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueMessageThresholdCountUnitWithTokenUnitTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueRegistrationTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueRegistrationTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueRegistrationTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueRegistrationTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueUnitWithTokenRegistrationTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueUnitWithTokenRegistrationTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusQueueUnitWithTokenRegistrationTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusQueueUnitWithTokenRegistrationTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionRegistrationTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionRegistrationTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionRegistrationTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionRegistrationTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionWithTokenRegistrationTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionWithTokenRegistrationTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionWithTokenRegistrationTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusSubscriptionWithTokenRegistrationTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusTopicRegistrationTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusTopicRegistrationTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusTopicRegistrationTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusTopicRegistrationTests.cs diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusTopicWithTokenRegistrationTests.cs b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusTopicWithTokenRegistrationTests.cs similarity index 100% rename from test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureServiceBusTopicWithTokenRegistrationTests.cs rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/DependencyInjection/AzureServiceBusTopicWithTokenRegistrationTests.cs diff --git a/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.Tests.csproj b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.Tests.csproj new file mode 100644 index 0000000000..eec2835edd --- /dev/null +++ b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.Tests.csproj @@ -0,0 +1,15 @@ + + + + net6.0;net7.0 + + + + + + + + + + + diff --git a/test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.approved.txt b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.approved.txt similarity index 80% rename from test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.approved.txt rename to test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.approved.txt index e99ed17a40..d879b56adc 100644 --- a/test/HealthChecks.AzureServiceBus.Tests/HealthChecks.AzureServiceBus.approved.txt +++ b/test/HealthChecks.Azure.Messaging.ServiceBus.Tests/HealthChecks.Azure.Messaging.ServiceBus.approved.txt @@ -1,10 +1,5 @@ namespace HealthChecks.AzureServiceBus { - public class AzureEventHubHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck - { - public AzureEventHubHealthCheck(HealthChecks.AzureServiceBus.Configuration.AzureEventHubHealthCheckOptions options) { } - public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } - } public abstract class AzureServiceBusHealthCheck where TOptions : HealthChecks.AzureServiceBus.Configuration.AzureServiceBusHealthCheckOptions { @@ -51,15 +46,6 @@ namespace HealthChecks.AzureServiceBus } namespace HealthChecks.AzureServiceBus.Configuration { - public class AzureEventHubHealthCheckOptions - { - public AzureEventHubHealthCheckOptions() { } - public Azure.Messaging.EventHubs.EventHubConnection? Connection { get; set; } - public string? ConnectionString { get; set; } - public Azure.Core.TokenCredential? Credential { get; set; } - public string? EventHubName { get; set; } - public string? FullyQualifiedNamespace { get; set; } - } public abstract class AzureServiceBusHealthCheckOptions { protected AzureServiceBusHealthCheckOptions() { } @@ -101,11 +87,6 @@ namespace Microsoft.Extensions.DependencyInjection { public static class AzureServiceBusHealthCheckBuilderExtensions { - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureEventHub(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func eventHubConnectionFactory, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureEventHub(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func connectionStringFactory, System.Func eventHubNameFactory, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureEventHub(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string connectionString, string eventHubName, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureEventHub(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func fullyQualifiedNamespaceFactory, System.Func eventHubNameFactory, System.Func tokenCredentialFactory, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureEventHub(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string fullyQualifiedNamespace, string eventHubName, Azure.Core.TokenCredential tokenCredential, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureServiceBusQueue(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func connectionStringFactory, System.Func queueNameFactory, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureServiceBusQueue(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, string connectionString, string queueName, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureServiceBusQueue(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func fullyQualifiedNamespaceFactory, System.Func queueNameFactory, System.Func tokenCredentialFactory, System.Action? configure = null, string? name = null, Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } diff --git a/test/HealthChecks.Azure.Storage.Blobs.Tests/AzureBlobStorageHealthCheckTests.cs b/test/HealthChecks.Azure.Storage.Blobs.Tests/AzureBlobStorageHealthCheckTests.cs index b2aaed6cf4..c6063aab53 100644 --- a/test/HealthChecks.Azure.Storage.Blobs.Tests/AzureBlobStorageHealthCheckTests.cs +++ b/test/HealthChecks.Azure.Storage.Blobs.Tests/AzureBlobStorageHealthCheckTests.cs @@ -5,7 +5,7 @@ using NSubstitute; using NSubstitute.ExceptionExtensions; -namespace HealthChecks.AzureStorage.Tests; +namespace HealthChecks.Azure.Storage.Blobs.Tests; public class azureblobstoragehealthcheck_should { diff --git a/test/HealthChecks.Azure.Storage.Blobs.Tests/BlobStorageConformanceTests.cs b/test/HealthChecks.Azure.Storage.Blobs.Tests/BlobStorageConformanceTests.cs index c9470712e5..9deea73350 100644 --- a/test/HealthChecks.Azure.Storage.Blobs.Tests/BlobStorageConformanceTests.cs +++ b/test/HealthChecks.Azure.Storage.Blobs.Tests/BlobStorageConformanceTests.cs @@ -1,6 +1,5 @@ using Azure.Identity; using Azure.Storage.Blobs; -using HealthChecks.AzureStorage; namespace HealthChecks.Azure.Storage.Blobs.Tests; diff --git a/test/HealthChecks.Azure.Storage.Blobs.Tests/HealthChecks.Azure.Storage.Blobs.approved.txt b/test/HealthChecks.Azure.Storage.Blobs.Tests/HealthChecks.Azure.Storage.Blobs.approved.txt index 9a18ae882b..35f55fee35 100644 --- a/test/HealthChecks.Azure.Storage.Blobs.Tests/HealthChecks.Azure.Storage.Blobs.approved.txt +++ b/test/HealthChecks.Azure.Storage.Blobs.Tests/HealthChecks.Azure.Storage.Blobs.approved.txt @@ -1,8 +1,8 @@ -namespace HealthChecks.AzureStorage +namespace HealthChecks.Azure.Storage.Blobs { public sealed class AzureBlobStorageHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck { - public AzureBlobStorageHealthCheck(Azure.Storage.Blobs.BlobServiceClient blobServiceClient, HealthChecks.AzureStorage.AzureBlobStorageHealthCheckOptions? options = null) { } + public AzureBlobStorageHealthCheck(Azure.Storage.Blobs.BlobServiceClient blobServiceClient, HealthChecks.Azure.Storage.Blobs.AzureBlobStorageHealthCheckOptions? options = null) { } public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } } public sealed class AzureBlobStorageHealthCheckOptions @@ -15,6 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection { public static class AzureBlobStorageHealthChecksBuilderExtensions { - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureBlobStorage(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_blob_storage", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureBlobStorage(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_blob_storage", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } \ No newline at end of file diff --git a/test/HealthChecks.Azure.Storage.Files.Shares.Tests/AzureFileShareHealthCheckTests.cs b/test/HealthChecks.Azure.Storage.Files.Shares.Tests/AzureFileShareHealthCheckTests.cs index 6865f920ac..6d860fcaa6 100644 --- a/test/HealthChecks.Azure.Storage.Files.Shares.Tests/AzureFileShareHealthCheckTests.cs +++ b/test/HealthChecks.Azure.Storage.Files.Shares.Tests/AzureFileShareHealthCheckTests.cs @@ -5,7 +5,7 @@ using NSubstitute; using NSubstitute.ExceptionExtensions; -namespace HealthChecks.AzureStorage.Tests; +namespace HealthChecks.Azure.Storage.Files.Shares.Tests; public class azurefilesharehealthcheck_should { diff --git a/test/HealthChecks.Azure.Storage.Files.Shares.Tests/FileConformanceTests.cs b/test/HealthChecks.Azure.Storage.Files.Shares.Tests/FileConformanceTests.cs index 1a2c2a1234..84034b9495 100644 --- a/test/HealthChecks.Azure.Storage.Files.Shares.Tests/FileConformanceTests.cs +++ b/test/HealthChecks.Azure.Storage.Files.Shares.Tests/FileConformanceTests.cs @@ -1,8 +1,7 @@ using Azure.Identity; using Azure.Storage.Files.Shares; -using HealthChecks.AzureStorage; -namespace HealthChecks.Azure.Storage.Queues.Tests; +namespace HealthChecks.Azure.Storage.Files.Shares.Tests; public class FileConformanceTests : ConformanceTests { diff --git a/test/HealthChecks.Azure.Storage.Files.Shares.Tests/HealthChecks.Azure.Storage.Files.Shares.approved.txt b/test/HealthChecks.Azure.Storage.Files.Shares.Tests/HealthChecks.Azure.Storage.Files.Shares.approved.txt index bd2e2494a5..37ad8f1f4a 100644 --- a/test/HealthChecks.Azure.Storage.Files.Shares.Tests/HealthChecks.Azure.Storage.Files.Shares.approved.txt +++ b/test/HealthChecks.Azure.Storage.Files.Shares.Tests/HealthChecks.Azure.Storage.Files.Shares.approved.txt @@ -1,8 +1,8 @@ -namespace HealthChecks.AzureStorage +namespace HealthChecks.Azure.Storage.Files.Shares { public sealed class AzureFileShareHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck { - public AzureFileShareHealthCheck(Azure.Storage.Files.Shares.ShareServiceClient shareServiceClient, HealthChecks.AzureStorage.AzureFileShareHealthCheckOptions? options) { } + public AzureFileShareHealthCheck(Azure.Storage.Files.Shares.ShareServiceClient shareServiceClient, HealthChecks.Azure.Storage.Files.Shares.AzureFileShareHealthCheckOptions? options) { } public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } } public sealed class AzureFileShareHealthCheckOptions @@ -15,6 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection { public static class AzureFileShareStorageHealthChecksBuilderExtensions { - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureFileShare(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_file_share", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureFileShare(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_file_share", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } \ No newline at end of file diff --git a/test/HealthChecks.Azure.Storage.Queues.Tests/AzureQueueStorageHealthCheckTests.cs b/test/HealthChecks.Azure.Storage.Queues.Tests/AzureQueueStorageHealthCheckTests.cs index ba5f04cd16..62fc92fd4e 100644 --- a/test/HealthChecks.Azure.Storage.Queues.Tests/AzureQueueStorageHealthCheckTests.cs +++ b/test/HealthChecks.Azure.Storage.Queues.Tests/AzureQueueStorageHealthCheckTests.cs @@ -5,7 +5,7 @@ using NSubstitute; using NSubstitute.ExceptionExtensions; -namespace HealthChecks.AzureStorage.Tests; +namespace HealthChecks.Azure.Storage.Queues.Tests; public class azurequeuestoragehealthcheck_should { diff --git a/test/HealthChecks.Azure.Storage.Queues.Tests/HealthChecks.Azure.Storage.Queues.approved.txt b/test/HealthChecks.Azure.Storage.Queues.Tests/HealthChecks.Azure.Storage.Queues.approved.txt index ca21c3d296..3cdad33a89 100644 --- a/test/HealthChecks.Azure.Storage.Queues.Tests/HealthChecks.Azure.Storage.Queues.approved.txt +++ b/test/HealthChecks.Azure.Storage.Queues.Tests/HealthChecks.Azure.Storage.Queues.approved.txt @@ -1,8 +1,8 @@ -namespace HealthChecks.AzureStorage +namespace HealthChecks.Azure.Storage.Queues { public sealed class AzureQueueStorageHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck { - public AzureQueueStorageHealthCheck(Azure.Storage.Queues.QueueServiceClient queueServiceClient, HealthChecks.AzureStorage.AzureQueueStorageHealthCheckOptions? options = null) { } + public AzureQueueStorageHealthCheck(Azure.Storage.Queues.QueueServiceClient queueServiceClient, HealthChecks.Azure.Storage.Queues.AzureQueueStorageHealthCheckOptions? options = null) { } public System.Threading.Tasks.Task CheckHealthAsync(Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckContext context, System.Threading.CancellationToken cancellationToken = default) { } } public sealed class AzureQueueStorageHealthCheckOptions @@ -15,6 +15,6 @@ namespace Microsoft.Extensions.DependencyInjection { public static class AzureQueueStorageHealthChecksBuilderExtensions { - public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureQueueStorage(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_queue_storage", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } + public static Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder AddAzureQueueStorage(this Microsoft.Extensions.DependencyInjection.IHealthChecksBuilder builder, System.Func? clientFactory = null, System.Func? optionsFactory = null, string? healthCheckName = "azure_queue_storage", Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus? failureStatus = default, System.Collections.Generic.IEnumerable? tags = null, System.TimeSpan? timeout = default) { } } } \ No newline at end of file diff --git a/test/HealthChecks.Azure.Storage.Queues.Tests/QueueStorageConformanceTests.cs b/test/HealthChecks.Azure.Storage.Queues.Tests/QueueStorageConformanceTests.cs index f1aa557e20..3bd161e063 100644 --- a/test/HealthChecks.Azure.Storage.Queues.Tests/QueueStorageConformanceTests.cs +++ b/test/HealthChecks.Azure.Storage.Queues.Tests/QueueStorageConformanceTests.cs @@ -1,6 +1,5 @@ using Azure.Identity; using Azure.Storage.Queues; -using HealthChecks.AzureStorage; namespace HealthChecks.Azure.Storage.Queues.Tests; diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubRegistrationTests.cs b/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubRegistrationTests.cs deleted file mode 100644 index 87ad0681ff..0000000000 --- a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubRegistrationTests.cs +++ /dev/null @@ -1,134 +0,0 @@ -using Azure.Messaging.EventHubs; - -namespace HealthChecks.AzureServiceBus.Tests; - -public class azure_event_hub_registration_should -{ - [Fact] - public void add_health_check_when_properly_configured_using_connectionstring_and_eventhubname() - { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub( - "Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=", - "hubName"); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhub"); - check.ShouldBeOfType(); - } - - [Fact] - public void add_health_check_when_properly_configured_using_eventhubconnectionfactory() - { - Func factory = - _ => new EventHubConnection( - "Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=", - "hubnameconnection"); - - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(factory); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhub"); - check.ShouldBeOfType(); - } - - [Fact] - public void add_named_health_check_when_properly_configured_using_connectionstring_and_eventhubname() - { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub( - "Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=", - "hubName", name: "azureeventhubcheck"); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhubcheck"); - check.ShouldBeOfType(); - } - - [Fact] - public void add_named_health_check_when_properly_configured_using_connectionfactory() - { - Func factory = - _ => new EventHubConnection( - "Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly=", - "hubname"); - - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(factory, name: "azureeventhubcheck"); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhubcheck"); - check.ShouldBeOfType(); - } - - [Fact] - public void fail_when_no_health_check_configuration_provided() - { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(string.Empty, string.Empty); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - - var exception = Should.Throw(() => registration.Factory(serviceProvider)); - exception.ParamName.ShouldBe("options"); - } - - [Fact] - public void add_health_check_using_connection_string_factory_and_event_hub_name_factory_when_properly_configured() - { - bool connectionStringFactoryCalled = false, eventHubNameFactoryCalled = false; - - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(_ => - { - connectionStringFactoryCalled = true; - return "Endpoint=sb://dummynamespace.servicebus.windows.net/;SharedAccessKeyName=DummyAccessKeyName;SharedAccessKey=5dOntTRytoC24opYThisAsit3is2B+OGY1US/fuL3ly="; - }, - _ => - { - eventHubNameFactoryCalled = true; - return "hubName"; - }); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhub"); - check.ShouldBeOfType(); - connectionStringFactoryCalled.ShouldBeTrue(); - eventHubNameFactoryCalled.ShouldBeTrue(); - } -} diff --git a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubUnitWithTokenRegistrationTests.cs b/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubUnitWithTokenRegistrationTests.cs deleted file mode 100644 index f30f978462..0000000000 --- a/test/HealthChecks.AzureServiceBus.Tests/DependencyInjection/AzureEventHubUnitWithTokenRegistrationTests.cs +++ /dev/null @@ -1,129 +0,0 @@ -using Azure.Identity; - -namespace HealthChecks.AzureServiceBus.Tests; - -public class azure_event_hub_registration_with_token_should -{ - [Fact] - public void add_health_check_when_properly_configured() - { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub("cnn", "eventHubName", new AzureCliCredential()); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhub"); - check.ShouldBeOfType(); - } - - [Fact] - public void add_health_check_using_factories_when_properly_configured() - { - bool endpointFactoryCalled = false, eventHubNameFactoryCalled = false, tokenCredentialFactoryCalled = false; - - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(_ => - { - endpointFactoryCalled = true; - return "cnn"; - }, - _ => - { - eventHubNameFactoryCalled = true; - return "eventHubName"; - }, - _ => - { - tokenCredentialFactoryCalled = true; - return new AzureCliCredential(); - }); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhub"); - check.ShouldBeOfType(); - endpointFactoryCalled.ShouldBeTrue(); - eventHubNameFactoryCalled.ShouldBeTrue(); - tokenCredentialFactoryCalled.ShouldBeTrue(); - } - - [Fact] - public void add_named_health_check_when_properly_configured() - { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub("cnn", "eventHubName", new AzureCliCredential(), name: "azureeventhubcheck"); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhubcheck"); - check.ShouldBeOfType(); - } - - [Fact] - public void add_named_health_check_using_factories_when_properly_configured() - { - bool endpointFactoryCalled = false, eventHubNameFactoryCalled = false, tokenCredentialFactoryCalled = false; - - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(_ => - { - endpointFactoryCalled = true; - return "cnn"; - }, - _ => - { - eventHubNameFactoryCalled = true; - return "eventHubName"; - }, - _ => - { - tokenCredentialFactoryCalled = true; - return new AzureCliCredential(); - }, - name: "azureeventhubcheck"); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - var check = registration.Factory(serviceProvider); - - registration.Name.ShouldBe("azureeventhubcheck"); - check.ShouldBeOfType(); - endpointFactoryCalled.ShouldBeTrue(); - eventHubNameFactoryCalled.ShouldBeTrue(); - tokenCredentialFactoryCalled.ShouldBeTrue(); - } - - [Fact] - public void fail_when_no_health_check_configuration_provided() - { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddAzureEventHub(string.Empty, string.Empty, new AzureCliCredential()); - - using var serviceProvider = services.BuildServiceProvider(); - var options = serviceProvider.GetRequiredService>(); - - var registration = options.Value.Registrations.First(); - - var exception = Should.Throw(() => registration.Factory(serviceProvider)); - exception.ParamName.ShouldBe("options.FullyQualifiedNamespace"); - } -} diff --git a/test/_SHARED/ConformanceTests.cs b/test/_SHARED/ConformanceTests.cs index 7c05ed8c78..b0da7f08a7 100644 --- a/test/_SHARED/ConformanceTests.cs +++ b/test/_SHARED/ConformanceTests.cs @@ -90,7 +90,7 @@ public async Task ReturnsProvidedFailureStatusWhenConnectionCanNotBeMade(HealthS [Theory] [InlineData(HealthStatus.Unhealthy)] [InlineData(HealthStatus.Healthy)] - public void DependencyInjectionRegistrationWorksAsExpected(HealthStatus failureStatus) + public async Task DependencyInjectionRegistrationWorksAsExpected(HealthStatus failureStatus) { const string healthCheckName = "random_name"; var timeout = TimeSpan.FromSeconds(5); @@ -112,7 +112,7 @@ public void DependencyInjectionRegistrationWorksAsExpected(HealthStatus failureS tags: tags, timeout: timeout); - using ServiceProvider serviceProvider = services.BuildServiceProvider(); + await using ServiceProvider serviceProvider = services.BuildServiceProvider(); IOptions options = serviceProvider.GetRequiredService>(); HealthCheckRegistration registration = options.Value.Registrations.Single();