-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
Description
Parent Issue
Part of #119 - Implement Custom Health Probes and Dependency Health Checks
Overview
Establish the health check pattern by implementing comprehensive health probes for the Weight API service. This is the foundation issue that will establish the pattern for all other services.
Scope
src/Biotrackr.Weight.Api/infra/apps/weight-api/main.bicep
Tasks
1. Install Health Check Packages
Add to Biotrackr.Weight.Api.csproj:
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.CosmosDb" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.AzureKeyVault" Version="8.0.1" />2. Implement Health Check Endpoints
Update Program.cs:
- Add health checks for self, Cosmos DB (lightweight connectivity check), Key Vault
- Implement custom authenticated Fitbit API health check
- Configure
/health/live,/health/ready,/health/startupendpoints
Health Check Configuration:
builder.Services.AddHealthChecks()
.AddCheck("self", () => HealthCheckResult.Healthy("Service is running"))
.AddAzureCosmosDB(
sp => sp.GetRequiredService<CosmosClient>(),
name: "cosmosdb",
failureStatus: HealthStatus.Degraded,
tags: new[] { "ready", "database" })
.AddAzureKeyVault(
sp => sp.GetRequiredService<SecretClient>(),
name: "keyvault",
failureStatus: HealthStatus.Degraded,
tags: new[] { "ready", "secrets" })
.AddCheck<FitbitApiHealthCheck>("fitbit-api",
failureStatus: HealthStatus.Degraded,
tags: new[] { "ready", "external" });3. Create Custom Fitbit API Health Check
Create Services/FitbitApiHealthCheck.cs:
- Use authenticated lightweight endpoint (e.g.,
/1/user/-/profile.json) - 5-second timeout
- Return
Degraded(notUnhealthy) if API is unreachable - Log warnings for failures
4. Update Bicep Configuration
Update infra/apps/weight-api/main.bicep:
probes: [
{
type: 'Liveness'
httpGet: {
path: '/health/live'
port: 8080
}
initialDelaySeconds: 10
periodSeconds: 30
failureThreshold: 3
timeoutSeconds: 5
}
{
type: 'Readiness'
httpGet: {
path: '/health/ready'
port: 8080
}
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3
timeoutSeconds: 5
}
{
type: 'Startup'
httpGet: {
path: '/health/startup'
port: 8080
}
initialDelaySeconds: 0
periodSeconds: 5
failureThreshold: 30 // 150 seconds total
timeoutSeconds: 5
}
]5. Add Integration Tests
Create health endpoint tests:
- Verify
/health/livereturns 200 when service is running - Verify
/health/readyreturns 200 when all dependencies are healthy - Verify
/health/readyreturns 503 when Cosmos DB is unavailable - Verify
/health/startupchecks all dependencies
6. Document Pattern
Create documentation for:
- Health check implementation steps
- Probe configuration rationale
- Testing approach
- Lessons learned for replication to other services
Acceptance Criteria
- Health check packages installed
-
/health/live,/health/ready,/health/startupendpoints implemented - Cosmos DB health check validates connectivity (lightweight, minimal RU consumption)
- Key Vault health check validates secret client connectivity
- Fitbit API health check uses authenticated endpoint
- Bicep probe configuration updated with 150s startup timeout
- Health endpoints return JSON response with detailed status
- Integration tests validate health endpoints
- Documentation created for pattern replication
- Deployed to dev environment and validated with cold start scenarios
Dependencies
- None (this is the foundation issue)
References
Notes
This is the pattern-establishing issue. Lessons learned here will simplify implementation for the remaining 7 services. Focus on creating reusable code and clear documentation.
Design Decisions:
- Cosmos DB health check: Lightweight client connectivity only (minimal RU cost)
- Fitbit health check: Authenticated endpoint (validates OAuth flow)
- Health endpoints: Public (no auth required for Container Apps probes)
- Startup timeout: 150 seconds (generous for cold starts)
- Probe intervals: Liveness 30s, Readiness 10s, Startup 5s
Reactions are currently unavailable