Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 18, 2025

This PR adds a comprehensive health check package for Azure Cosmos DB, following the established patterns used by other Azure health check implementations in the repository.

Features

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

Multiple Authentication Modes

  • Connection String: Direct connection using Cosmos DB connection string
  • Account Key: Authentication using service endpoint and account key
  • Default Azure Credentials: Uses Azure SDK's default credential chain
  • Service Principal: Token-based authentication for service principals

Hierarchical Health Checking

The health check performs verification at multiple levels:

  1. Service Availability: Verifies Cosmos DB account is accessible
  2. Database Check: Optional verification of specific database (if DatabaseName configured)
  3. Container Check: Optional verification of specific container (if ContainerName configured)

Configuration Approaches

Supports both configuration-based and programmatic setup:

// Configuration-based approach
builder.AddCosmosDb("MyCosmosDb");

// Programmatic approach
builder.AddCosmosDb("MyCosmosDb", options =>
{
    options.ConnectionString = "AccountEndpoint=https://...;AccountKey=...";
    options.DatabaseName = "MyDatabase";
    options.ContainerName = "MyContainer";
    options.Timeout = 200;
});

Configuration Structure

{
  "HealthChecks": {
    "CosmosDb": {
      "MyCosmosDb": {
        "ConnectionString": "AccountEndpoint=https://test.documents.azure.com:443/;AccountKey=...",
        "DatabaseName": "TestDatabase",
        "ContainerName": "TestContainer",
        "Mode": "ConnectionString",
        "Timeout": 100
      }
    }
  }
}

Implementation Details

The package includes:

  • Client Creation Factory: Thread-safe client caching with support for all authentication modes
  • Comprehensive Validation: Mode-specific validation ensuring required properties are configured
  • Proper Error Handling: Clear error messages for missing databases/containers
  • Performance Optimized: Uses WithTimeoutAsync extension for timeout handling
  • Consistent API: Follows same patterns as existing Azure health checks

Testing

Added comprehensive unit tests covering:

  • Dependency injection validation
  • Options configuration and validation
  • Configuration binding scenarios
  • Mode-specific validation rules

Integration test structure is provided for future CosmosDB emulator testing.

Fixes #35.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] NetEvolve.HealthChecks.Azure.CosmosDB Implement NetEvolve.HealthChecks.Azure.CosmosDB package Aug 18, 2025
@Copilot Copilot AI requested a review from samtrion August 18, 2025 20:52
Copilot finished work on behalf of samtrion August 18, 2025 20:52
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.CosmosDB
2 participants