Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 18, 2025

This PR implements a complete health check package for Azure IoT Hub, following the established patterns used throughout the repository for other Azure services.

Features

The new NetEvolve.HealthChecks.Azure.IotHub package provides:

  • IoT Hub Availability Health Check: Verifies connectivity to Azure IoT Hub by calling GetServiceStatisticsAsync()
  • Multiple Authentication Modes:
    • ServiceProvider - Uses pre-registered client from DI container
    • DefaultAzureCredentials - Uses Azure AD authentication
    • ConnectionString - Uses IoT Hub connection string
  • Configuration Support: Both configuration-based and options-based setup
  • Proper Validation: Comprehensive options validation with meaningful error messages
  • Timeout Control: Configurable timeout (default 100ms) with degraded status on timeout

Usage Examples

Configuration-based approach:

builder.Services.AddHealthChecks()
    .AddAzureIotHubAvailability("my-iothub");

With appsettings.json:

{
  "HealthChecks": {
    "AzureIotHubAvailability": {
      "my-iothub": {
        "ConnectionString": "HostName=my-hub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=...",
        "Mode": "ConnectionString"
      }
    }
  }
}

Options-based approach:

builder.Services.AddHealthChecks()
    .AddAzureIotHubAvailability("my-iothub", options =>
    {
        options.ConnectionString = "HostName=my-hub.azure-devices.net;...";
        options.Mode = ClientCreationMode.ConnectionString;
        options.Timeout = 1000;
    });

Implementation Details

The implementation follows the same architectural patterns as other Azure health checks in the repository:

  • IotHubOptionsBase - Abstract base class for configuration options
  • IotHubAvailabilityOptions - Specific options for availability check
  • IotHubClientFactory - Manages IoT Hub client instances with caching
  • IotHubAvailabilityHealthCheck - Main health check implementation
  • DependencyInjectionExtensions - Extension methods for service registration
  • Comprehensive unit tests covering all scenarios including health check execution, client factory behavior, configuration validation, and error handling
  • Testcontainers-based integration tests using WireMock to simulate Azure IoT Hub REST API endpoints
  • Complete README documentation with usage examples

The health check uses the Azure IoT Hub SDK's ServiceClient.GetServiceStatisticsAsync() method as a lightweight operation to verify connectivity and service availability.

Testing

  • Unit Tests: Complete test coverage for all components including IotHubAvailabilityHealthCheck, IotHubClientFactory, configuration options, and dependency injection extensions
  • Integration Tests: Testcontainers-based implementation using WireMock to simulate Azure IoT Hub REST API endpoints, providing coverage for configuration validation, timeout scenarios, and error handling
  • Package Management: Properly configured with central package version management for Microsoft.Azure.Devices v1.40.0

Integration Test Implementation

The integration tests use a IoTHubMockContainer that runs WireMock in a Docker container to simulate Azure IoT Hub REST API endpoints. This testcontainers approach allows testing of:

  • Health check infrastructure and dependency injection
  • Configuration validation with invalid connection strings
  • Timeout behavior resulting in degraded health status
  • Error handling and status reporting

Due to Azure IoT Hub SDK limitations (hostname validation and certificate requirements), one test is appropriately skipped with clear documentation explaining the technical constraints.

Fixes #38.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] NetEvolve.HealthChecks.Azure.IotHub Add NetEvolve.HealthChecks.Azure.IotHub package Aug 18, 2025
Copilot finished work on behalf of samtrion August 18, 2025 20:45
@Copilot Copilot AI requested a review from samtrion August 18, 2025 20:45
@samtrion
Copy link
Member

@copilot rebase and start implementing the tests

samtrion and others added 20 commits September 27, 2025 17:00
* chore: Conventional commits copilot-instructions.md

Signed-off-by: Martin Stühmer <[email protected]>

* fix: Wording

Signed-off-by: Martin Stühmer <[email protected]>

---------

Signed-off-by: Martin Stühmer <[email protected]>
Bumps [dailydevops/pipelines](https://github.com/dailydevops/pipelines) from 1.0.8 to 1.0.32.
- [Release notes](https://github.com/dailydevops/pipelines/releases)
- [Commits](dailydevops/pipelines@1.0.8...1.0.32)

---
updated-dependencies:
- dependency-name: dailydevops/pipelines
  dependency-version: 1.0.32
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps): Bump the tunit group with 1 update

Bumps TUnit from 0.25.21 to 0.56.44

---
updated-dependencies:
- dependency-name: TUnit
  dependency-version: 0.56.44
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: tunit
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore(deps): Also updated `NetEvolve.Extensions.TUnit`

* fix(deps): Updated `Verify.TUnit`

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Martin Stühmer <[email protected]>
Bumps xunit.runner.visualstudio from 3.1.3 to 3.1.4

---
updated-dependencies:
- dependency-name: xunit.runner.visualstudio
  dependency-version: 3.1.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: xunit
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
)

* feat: Implement core NetEvolve.HealthChecks.Azure.ApplicationInsights package

Co-authored-by: samtrion <[email protected]>

* feat: Add comprehensive unit and integration tests for ApplicationInsights health checks

Co-authored-by: samtrion <[email protected]>

* feat: Complete NetEvolve.HealthChecks.Azure.ApplicationInsights implementation with README integration

Co-authored-by: samtrion <[email protected]>

* fix(build): add NetEvolve.HealthChecks.Azure.ApplicationInsights to solution file

Co-authored-by: samtrion <[email protected]>

* style(format): Reformatted code

* fix(deps): Added PackageVersion for `Microsoft.ApplicationInsights` and `Microsoft.ApplicationInsights.AspNetCore`

* fix(CA2000): Disabled warning

* fix: Added missing project reference

* fix: Added missing project reference

* fix(test): resolve ApplicationInsights test errors and InstrumentationKey bug

Co-authored-by: samtrion <[email protected]>

* fix: Use Invariant Culture for formatting

* fix(test): Updated tests for missing async support

* fix(test): More async test cases

* fix: Do not cache ServiceProvider Clients

* test: Updated the integration tests

* fix: Usage of internal method `CreateTelemetryClient`  updated

* fix: Removed S1186 Warning

* chore: Updated Public API Defnition

* chore: Simplified of Event creation

* chore: Even more simplification of the execution

* style(format): Reformatted code

* fix: Removed false positve ArangoDB Test

* chore: Removed old verify files

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: samtrion <[email protected]>
Co-authored-by: Martin Stühmer <[email protected]>
* fix: Changes before error encountered

Co-authored-by: samtrion <[email protected]>

* fix: Additional spelling mistakes: yo need → you need in README files

Co-authored-by: samtrion <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: samtrion <[email protected]>
…oring (#887)

* feat: Initial analysis and plan for NetEvolve.HealthChecks.Http package

Co-authored-by: samtrion <[email protected]>

* feat: Implement NetEvolve.HealthChecks.Http core functionality and unit tests

Co-authored-by: samtrion <[email protected]>

* fix: Complete NetEvolve.HealthChecks.Http implementation with tests and verification

Co-authored-by: samtrion <[email protected]>

* fix: Complete NetEvolve.HealthChecks.Http implementation by adding missing package reference and solution entries

Co-authored-by: samtrion <[email protected]>

* fix: Remove nested .editorconfig files and dotnet-install.sh script

Co-authored-by: samtrion <[email protected]>

* style(format): Reformatted code

* fix: Removed warnings

* chore: Simplified `HttpConfigure`

* fix: Removed unnecessary using

* fix(test): Fixed tests

* test: Updated integration tests

* fix: Removed open warnings

* fix: Use ProcessCount

* fix(test): Wrong timeout for test

* fix: Special handling for `Win32Exceptions`

* fix(verify): Updated verify files

* fix: Further Win32 Exception handling

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: samtrion <[email protected]>
Co-authored-by: Martin Stühmer <[email protected]>
Bumps [dailydevops/pipelines](https://github.com/dailydevops/pipelines) from 1.0.32 to 1.0.38.
- [Release notes](https://github.com/dailydevops/pipelines/releases)
- [Commits](dailydevops/pipelines@1.0.32...1.0.38)

---
updated-dependencies:
- dependency-name: dailydevops/pipelines
  dependency-version: 1.0.38
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* fix: Set Timeout for Test execution to 10000 ms

* fix: Missing updates
Copy link
Contributor Author

Copilot AI commented Sep 27, 2025

@copilot rebase and start implementing the tests

Branch has been rebased and comprehensive unit tests have been implemented. Added tests for IotHubAvailabilityHealthCheck and IotHubClientFactory classes, following the established patterns used throughout the repository. Integration tests are not implemented as Azure IoT Hub doesn't have a local emulator like Azurite. Commit: ae7e8b0

Copilot finished work on behalf of samtrion September 27, 2025 17:01
@samtrion
Copy link
Member

@copilot add integration tests based on testcontainers

Copy link
Contributor Author

Copilot AI commented Sep 27, 2025

@copilot add integration tests based on testcontainers

Integration tests based on testcontainers have been implemented. Created IoTHubMockContainer using WireMock in a generic testcontainer to simulate Azure IoT Hub REST API endpoints. The tests cover configuration validation, timeout scenarios, and error handling. One test is skipped due to Azure SDK hostname validation limitations (documented with explanation). Commit: 8a0d6b5

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dotnet.testcontainers.org
    • Triggering command: curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of samtrion September 27, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NetEvolve.HealthChecks.Azure.IotHub
2 participants