HTTP Probe
Shows using the built‑in HTTP probe to call an internal route and fold its success/failure into the health aggregate.
Full source
File: pwsh/tutorial/examples/16.3-Health-Http-Probe.ps1
<#
HTTP Probe Example
Demonstrates adding an HTTP health probe calling a local route.
#>
param(
[int]$Port = 5000,
[IPAddress]$IPAddress = [IPAddress]::Loopback
)
## 1. Logging
New-KrLogger | Add-KrSinkConsole | Register-KrLogger -Name 'console' -SetAsDefault
## 2. Server
New-KrServer -Name 'Health HTTP Probe'
## 3. Listener (port 5000)
Add-KrEndpoint -Port $Port -IPAddress $IPAddress
#
## 5. Enable configuration
Enable-KrConfiguration
## 6. Supporting /status route simulating downstream component
Add-KrMapRoute -Verbs Get -Pattern '/status' -ScriptBlock {
Write-KrJsonResponse @{ status = 'Healthy'; description = 'Component OK'; version = '1.0.3' }
}
## 7. HTTP probe referencing /status
# The listener above is on port 5000, so target that; adjust if you intentionally host /status elsewhere.
Add-KrHealthHttpProbe -Name 'ComponentStatus' -Url 'http://127.0.0.1:5000/status' -Tags 'remote', 'self' -Timeout '00:00:02'
## 8. Health endpoint
Add-KrHealthEndpoint -Pattern '/healthz' -DefaultTags 'self', 'remote' -ResponseContentType Xml
## 9. Start server
Start-KrServer
Step-by-step
- Register an HTTP probe with
-Kind Httpand a loopback-Url. - Configure optional handling:
-TreatRedirectAsSuccess,-TreatNotFoundAsSuccess. - Tag the probe as needed for filtering.
- Start the server and query
/healthz.
Try it
Invoke-RestMethod http://127.0.0.1:5002/healthz | ConvertTo-Json -Depth 4
Break the /status route (rename or stop server) and observe the probe become Unhealthy.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Probe timeout | Remote route slow | Increase endpoint timeout or optimize route |
| 404 recorded as failure | Endpoint removed/renamed | Adjust probe URL or treat not found as success (only if expected) |
References
Previous / Next
Previous: Script Probe Next: Process Probe