Repository navigation
fix(router): Improve Traefik healthcheck for better router verification - #7981
Conversation
|
@copilot this fails in casual testing with healthcheck.sh reporting "Traefik healthcheck failed: Detected 6 service(s) not yet UP" Here's the API response for examination: api/http/services output0bf81c1d7ffb:/mnt/ddev-global-cache/traefik$ curl -sf "http://127.0.0.1:${TRAEFIK_MONITOR_PORT}/api/http/services" |jq
[
{
"loadBalancer": {
"servers": [
{
"url": "http://ddev-TestCmdWordpress-web:8025"
}
],
"strategy": "wrr",
"passHostHeader": true,
"responseForwarding": {
"flushInterval": "100ms"
}
},
"status": "enabled",
"usedBy": [
"TestCmdWordpress-web-8025-http@file",
"TestCmdWordpress-web-8025-https@file"
],
"name": "TestCmdWordpress-web-8025@file",
"provider": "file",
"type": "loadbalancer",
"serverStatus": {
"http://ddev-TestCmdWordpress-web:8025": "UP"
}
},
{
"loadBalancer": {
"servers": [
{
"url": "http://ddev-TestCmdWordpress-web:80"
}
],
"strategy": "wrr",
"passHostHeader": true,
"responseForwarding": {
"flushInterval": "100ms"
}
},
"status": "enabled",
"usedBy": [
"TestCmdWordpress-web-80-http@file",
"TestCmdWordpress-web-80-https@file"
],
"name": "TestCmdWordpress-web-80@file",
"provider": "file",
"type": "loadbalancer",
"serverStatus": {
"http://ddev-TestCmdWordpress-web:80": "UP"
}
},
{
"loadBalancer": {
"servers": [
{
"url": "http://ddev-TestCmdWordpress-xhgui:80"
}
],
"strategy": "wrr",
"passHostHeader": true,
"responseForwarding": {
"flushInterval": "100ms"
}
},
"status": "enabled",
"usedBy": [
"TestCmdWordpress-xhgui-80-http@file",
"TestCmdWordpress-xhgui-80-https@file"
],
"name": "TestCmdWordpress-xhgui-80@file",
"provider": "file",
"type": "loadbalancer",
"serverStatus": {
"http://ddev-TestCmdWordpress-xhgui:80": "UP"
}
},
{
"loadBalancer": {
"servers": [
{
"url": "http://ddev-TestPkgWordpress-web:8025"
}
],
"strategy": "wrr",
"passHostHeader": true,
"responseForwarding": {
"flushInterval": "100ms"
}
},
"status": "enabled",
"usedBy": [
"TestPkgWordpress-web-8025-http@file",
"TestPkgWordpress-web-8025-https@file"
],
"name": "TestPkgWordpress-web-8025@file",
"provider": "file",
"type": "loadbalancer",
"serverStatus": {
"http://ddev-TestPkgWordpress-web:8025": "UP"
}
},
{
"loadBalancer": {
"servers": [
{
"url": "http://ddev-TestPkgWordpress-web:80"
}
],
"strategy": "wrr",
"passHostHeader": true,
"responseForwarding": {
"flushInterval": "100ms"
}
},
"status": "enabled",
"usedBy": [
"TestPkgWordpress-web-80-http@file",
"TestPkgWordpress-web-80-https@file"
],
"name": "TestPkgWordpress-web-80@file",
"provider": "file",
"type": "loadbalancer",
"serverStatus": {
"http://ddev-TestPkgWordpress-web:80": "UP"
}
},
{
"loadBalancer": {
"servers": [
{
"url": "http://ddev-TestPkgWordpress-xhgui:80"
}
],
"strategy": "wrr",
"passHostHeader": true,
"responseForwarding": {
"flushInterval": "100ms"
}
},
"status": "enabled",
"usedBy": [
"TestPkgWordpress-xhgui-80-http@file",
"TestPkgWordpress-xhgui-80-https@file"
],
"name": "TestPkgWordpress-xhgui-80@file",
"provider": "file",
"type": "loadbalancer",
"serverStatus": {
"http://ddev-TestPkgWordpress-xhgui:80": "UP"
}
},
{
"status": "enabled",
"usedBy": [
"api@internal"
],
"name": "api@internal",
"provider": "internal"
},
{
"status": "enabled",
"usedBy": [
"dashboard@internal"
],
"name": "dashboard@internal",
"provider": "internal"
},
{
"status": "enabled",
"name": "noop@internal",
"provider": "internal"
},
{
"status": "enabled",
"usedBy": [
"ping@internal"
],
"name": "ping@internal",
"provider": "internal"
}
] |
Fixed in commit 21e38a3. The service status check was using an incorrect field path ( |
|
@copilot this is testing now. Update the OP to use the format in .github/PULL_REQUEST_TEMPLATE.md. Mention that this will almost certainly conflict with |
Updated the PR description to follow the template format and added notes about expected merge conflicts with #7967 and #7961. The description now includes all required sections: The Issue, How This PR Solves The Issue, Manual Testing Instructions, Automated Testing Overview, and Release/Deployment Notes. |
|
Download the artifacts for this pull request:
See Testing a PR. |
|
@copilot when starting all of the other containers, we show the result and give a hint as to how long we're waiting. But for startDdevRouter() we don't show that. In the other places (see app.Start() in ddevapp.go) we use |
|
|
@copilot Make the router wait output look like the other container waits. |
Done in commit 7a60324. The router wait now displays "Waiting %ds for ddev-router to become ready..." matching the format used for other containers (line 2023 in ddevapp.go). This shows the wait timeout (60s normally, 180s with Let's Encrypt) so users can see the impact of the stricter healthcheck. |
rfay
left a comment
There was a problem hiding this comment.
This looks like a decent continuation of the journey to appropriate traefik healthcheck. Many more stops along the road remain.
|
@copilot this is failing TestGetApps() with Traefik healthcheck failed: Router count mismatch: 97 loaded, 108 expected This is probably a good piece of information. I think the api we're using only provides 100 results and has to be called again for more. |
…lures Co-authored-by: rfay <[email protected]>
Co-authored-by: rfay <[email protected]>
… call Co-authored-by: rfay <[email protected]>
Fixes broken merge from PR #7967 conflict. The script now: - Calculates expected router count from config files (yq) - Verifies actual loaded routers match expected count - Uses per_page=10000 to handle >100 routers - Reports mismatches as WARNING but still returns healthy (exit 0) This maintains the philosophy from #7967: detect and report router issues but do not inconvenience users by refusing to run. Generated with Claude Code Co-Authored-By: Claude Opus 4.5 <[email protected]>
The healthcheck now writes router configuration warnings (count mismatches, config errors) to /tmp/ddev-traefik-errors.txt so GetRouterConfigErrors() can read and display them during ddev start. Warnings are automatically cleared when the underlying issues are resolved. Also captures WRN level logs in addition to ERR logs from traefik, and uses a separate test volume to avoid conflicts with running DDEV instances. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add tests to verify the API correctly detects and reports: - Missing service references - Missing middleware references - Invalid entrypoints - Invalid rule syntax - Config errors detected via API overview Each test clears the error file at start and asserts on specific identifiers to prevent cross-pollution between tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
When traefik first starts, configs may not be loaded yet. The healthcheck now waits up to 10 seconds if 0 routers are loaded but some are expected. This avoids false warnings during initial startup while still detecting genuine config issues immediately. Also increased sleep times in tests for traefik file watcher reload. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
…bility Refactor the healthcheck script to improve readability and maintainability by extracting repeated patterns into reusable functions: - clear_warnings(): Remove healthcheck warnings from error file - get_file_router_count(): Query Traefik API for loaded router count - get_error_count(): Query Traefik API for config error count - get_expected_router_count(): Parse config files to count expected routers - mark_healthy(): Mark container healthy and exit - write_warning(): Write warning to error file (avoids duplicates) - wait_for_routers(): Retry loop for initial router loading - generate_warning_message(): Create appropriate warning message No functional changes - all existing tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Print "Waiting for containers..." without newline, append elapsed time when ready - Show elapsed time in seconds with one decimal place (e.g., "ready in 3.0s") - Apply to all container wait locations: web/db, router, additional containers, profiles - Add debug logging to ContainerWait/ContainersWait showing status changes - Debug output shows status transitions and periodic updates every 5 seconds Example output: Waiting for containers to become ready: [web db]... ready in 3.0s Waiting for ddev-router to become ready... ready in 5.5s 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add output.StartWait() and WaitTimer.Complete() to reduce repetitive
code for container wait operations with inline elapsed time display.
Before (repeated 4+ times):
if !output.JSONOutput {
fmt.Fprintf(os.Stdout, "Waiting for X...")
}
startTime := time.Now()
err := doWait()
elapsed := time.Since(startTime)
if !output.JSONOutput {
if err != nil {
fmt.Fprintf(os.Stdout, "\n")
} else {
fmt.Fprintf(os.Stdout, " ready in %.1fs\n", elapsed.Seconds())
}
}
After:
wait := output.StartWait("Waiting for X")
err := doWait()
wait.Complete(err, "")
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-authored-by: Stanislav Zhuk <[email protected]>
- Strip timestamps from ERR/WRN messages when saving to error file - Only append error if message isn't already in the file (deduplication) - Remove redundant healthcheck test for API overview config errors This prevents duplicate error messages from appearing in ddev start output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
…ip ci] The extra parameter was no longer being used in the output, so remove it from the signature and all call sites. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
4a87ad8 to
4fd8b8a
Compare
Co-authored-by: Stanislav Zhuk <[email protected]>
The Issue
app.Start()completes, even though the router reports healthyfile_router_count > 0, which passes as soon as the first router is loaded, not when all expected routers are readyHow This PR Solves The Issue
This PR enhances the Traefik router healthcheck to be more robust by:
file_router_count > 0, parse config files to calculate expected router count and verify all routers are loadedper_pageparameter to API callsChanges Made
containers/ddev-traefik-router/Dockerfile:
yqpackage to enable YAML parsing of config filescontainers/ddev-traefik-router/traefik_healthcheck.sh:
/mnt/ddev-global-cache/traefik/config/*.yamlfiles?per_page=10000parameter to/api/http/routersendpoint to handle large numbers of routers (fixes pagination issue)pkg/ddevapp/router.go:
Manual Testing Instructions
Start a DDEV project and verify router becomes healthy:
Test router count verification - temporarily remove a router config:
Verify multiple projects work correctly:
Verify router wait output is displayed:
ddev start # Should show "Waiting 60s for ddev-router to become ready..." in outputTest with many routers (100+ routers):
Automated Testing Overview
The existing container tests in
containers/ddev-traefik-router/test/containertest.shalready verify:These tests will continue to pass and now benefit from more robust healthcheck logic. No new tests are needed as the change is internal to the healthcheck implementation.
Release/Deployment Notes
Merge Conflicts Expected:
This PR will almost certainly conflict with:
Original prompt
This pull request was created from Copilot chat.
💡 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.