78 lines
1.8 KiB
Markdown
78 lines
1.8 KiB
Markdown
# Task 7: Create Health Check Endpoint
|
|
|
|
## Task Description
|
|
|
|
**Files:**
|
|
- Modify: `src/Fengling.AuthService/Program.cs`
|
|
- Modify: `src/Fengling.AuthService/Fengling.AuthService.csproj`
|
|
|
|
## Implementation Steps
|
|
|
|
### Step 1: Add health check package
|
|
|
|
Edit: `src/Fengling.AuthService/Fengling.AuthService.csproj`
|
|
|
|
Add package reference:
|
|
```xml
|
|
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.2" />
|
|
<PackageReference Include="Npgsql.HealthChecks" Version="10.0.0" />
|
|
```
|
|
|
|
### Step 2: Add health check configuration
|
|
|
|
Edit: `src/Fengling.AuthService/Program.cs` (add after builder services)
|
|
|
|
```csharp
|
|
builder.Services.AddHealthChecks()
|
|
.AddNpgSql(builder.Configuration.GetConnectionString("DefaultConnection")!);
|
|
```
|
|
|
|
### Step 3: Add health check endpoint
|
|
|
|
Edit: `src/Fengling.AuthService/Program.cs` (before app.Run())
|
|
|
|
```csharp
|
|
app.MapHealthChecks("/health");
|
|
```
|
|
|
|
### Step 4: Test health check
|
|
|
|
Run:
|
|
```bash
|
|
dotnet run
|
|
```
|
|
|
|
Test:
|
|
```bash
|
|
curl http://localhost:5000/health
|
|
```
|
|
Expected: "Healthy"
|
|
|
|
### Step 5: Commit
|
|
|
|
```bash
|
|
git add src/Fengling.AuthService/Program.cs src/Fengling.AuthService/Fengling.AuthService.csproj
|
|
git commit -m "feat(auth): add health check endpoint"
|
|
```
|
|
|
|
## Context
|
|
|
|
This task adds a health check endpoint to monitor service and database connectivity. Health checks are essential for container orchestration and monitoring.
|
|
|
|
**Tech Stack**: ASP.NET Core Health Checks, PostgreSQL
|
|
|
|
## Verification
|
|
|
|
- [ ] Health check packages added
|
|
- [ ] Health check configuration added
|
|
- [ ] Health check endpoint mapped
|
|
- [ ] Endpoint returns "Healthy"
|
|
- [ ] Build succeeds
|
|
- [ ] Committed to git
|
|
|
|
## Notes
|
|
|
|
- Health check endpoint: /health
|
|
- Monitors PostgreSQL connection
|
|
- Ready for Kubernetes liveness/readiness probes
|