Skip to content

feat: extend Traefik healthcheck to validate file routers and config errors, fixes #6463, fixes #6553 - #7442

Merged
rfay merged 5 commits into
mainfrom
20250710_stasadev_traefik_healthcheck
Aug 1, 2025
Merged

rfay merged 5 commits into
mainfrom
20250710_stasadev_traefik_healthcheck

Conversation

@stasadev

@stasadev stasadev commented Jul 10, 2025 •

Copy link
Copy Markdown
Member

The Issue

How This PR Solves The Issue

Uses more endpoints from https://doc.traefik.io/traefik/operations/api/#endpoints to determine if the router is healthy.

The only drawback is that if you already have a working project, and start a broken one, you won't see an error on ddev start (because /healthcheck.sh runs once a minute, not a second, and I'm not going to change it). In the end, the router will become unhealthy after a few minutes.

Manual Testing Instructions

Review https://ddev--7442.org.readthedocs.build/en/7442/users/extend/traefik-router/#troubleshooting-traefik-routing

Test broken file provider on Linux (low fs.inotify.max_user_watches):

$ sysctl fs.inotify.max_user_watches
fs.inotify.max_user_watches = 524288

# temporary set to 10 (it's reset automatically after reboot)
$ sudo sysctl -w fs.inotify.max_user_watches=10
fs.inotify.max_user_watches = 10

$ ddev poweroff && ddev start
...
Failed to start d11: ddev-router failed to become ready; log=, err=health check timed out after 1m0s: labels map[com.docker.compose.oneoff:False com.docker.compose.service:ddev-router] timed out without becoming healthy, status=, detail= ddev-router:starting
Troubleshoot this with these commands:

  - docker logs ddev-router
  - docker inspect --format "{{ json .State.Health }}" ddev-router | docker run -i --rm ddev/ddev-utilities jq -r

$ docker logs ddev-router
2025-07-10T20:17:39+03:00 ERR Cannot start the provider *file.Provider error="error adding file watcher: no space left on device"

$ docker inspect --format "{{ json .State.Health }}" ddev-router | docker run -i --rm ddev/ddev-utilities jq -r
{
  "Status": "starting",
  "FailingStreak": 0,
  "Log": [
    {
      "Start": "2025-07-10T20:18:51.320899781+03:00",
      "End": "2025-07-10T20:18:51.492648671+03:00",
      "ExitCode": 1,
      "Output": "Traefik healthcheck failed: No file-based routers found"
    },
    {
      "Start": "2025-07-10T20:18:56.49417706+03:00",
      "End": "2025-07-10T20:18:56.664399121+03:00",
      "ExitCode": 1,
      "Output": "Traefik healthcheck failed: No file-based routers found"
    },
    {
      "Start": "2025-07-10T20:19:01.665447916+03:00",
      "End": "2025-07-10T20:19:01.833593676+03:00",
      "ExitCode": 1,
      "Output": "Traefik healthcheck failed: No file-based routers found"
    },
    {
      "Start": "2025-07-10T20:19:06.834065761+03:00",
      "End": "2025-07-10T20:19:07.01302342+03:00",
      "ExitCode": 1,
      "Output": "Traefik healthcheck failed: No file-based routers found"
    },
    {
      "Start": "2025-07-10T20:19:12.014656106+03:00",
      "End": "2025-07-10T20:19:12.168240404+03:00",
      "ExitCode": 1,
      "Output": "Traefik healthcheck failed: No file-based routers found"
    }
  ]
}

# after several minutes:

$ ddev list --active-only
┌────────┬───────────┬─────────────────────────────────────┬────────────────────────┬──────────┐
│ NAME   │ STATUS    │ LOCATION                            │ URL                    │ TYPE     │
├────────┼───────────┼─────────────────────────────────────┼────────────────────────┼──────────┤
│ d11    │ OK        │ ~/code/ddev-quickstarts/d11         │ https://d11.ddev.site  │ drupal11 │
├────────┼───────────┼─────────────────────────────────────┼────────────────────────┼──────────┤
│ Router │ unhealthy │ The router is not healthy, your     │ http://127.0.0.1:10999 │          │
│        │           │ projects may not be accessible, if  │                        │          │
│        │           │ it doesn't become healthy, run      │                        │          │
│        │           │ 'ddev poweroff && ddev start' on a  │                        │          │
│        │           │ project to recreate it. Traefik     │                        │          │
│        │           │ healthcheck failed: No file-based   │                        │          │
│        │           │ routers found                       │                        │          │
└────────┴───────────┴─────────────────────────────────────┴────────────────────────┴──────────┘

# revert back without reboot
$ sudo sysctl -w fs.inotify.max_user_watches=524288

Test broken file provider on Linux (low fs.inotify.max_user_instances):

$ sysctl fs.inotify.max_user_instances
fs.inotify.max_user_instances = 1024

# temporary set to 1 (it's reset automatically after reboot)
$ sudo sysctl -w fs.inotify.max_user_instances=1
fs.inotify.max_user_instances = 1

$ ddev poweroff && ddev start
...
Failed to start d11: ddev-router failed to become ready; log=, err=health check timed out after 1m0s: labels map[com.docker.compose.oneoff:False com.docker.compose.service:ddev-router] timed out without becoming healthy, status=, detail= ddev-router:starting
Troubleshoot this with these commands:

  - docker logs ddev-router
  - docker inspect --format "{{ json .State.Health }}" ddev-router | docker run -i --rm ddev/ddev-utilities jq -r

$ docker logs ddev-router
2025-07-16T14:29:37+03:00 ERR Cannot start the provider *file.Provider error="error creating file watcher: too many open files"

Test broken Traefik config inside the project:

$ cat <<'EOF' > .ddev/traefik/config/broken.yaml
http:
  routers:
    broken-web-80-http:
      entrypoints:
        - http-80
      rule: HostRegexp(`^broken.ddev.site$`)
      
      service: "broken-web-80"
      ruleSyntax: v3
      tls: false
  services:
    broken-web-80:
      loadbalancer:
        servers:
          - url: ht!tp://broken-url
EOF

$ ddev poweroff && ddev start
...
Failed to start d11: ddev-router failed to become ready; log=, err=health check timed out after 1m0s: labels map[com.docker.compose.oneoff:False com.docker.compose.service:ddev-router] timed out without becoming healthy, status=, detail= ddev-router:starting
Troubleshoot this with these commands:

  - docker logs ddev-router
  - docker inspect --format "{{ json .State.Health }}" ddev-router | docker run -i --rm ddev/ddev-utilities jq -r

$ docker logs ddev-router
2025-07-10T20:32:04+03:00 ERR Error while creating certificate store error="failed to load X509 key pair: tls: failed to find any PEM data in certificate input" tlsStoreName=default
2025-07-10T20:32:04+03:00 ERR error="error parsing server URL ht!tp://broken-url: parse \"ht!tp://broken-url\": first path segment in URL cannot contain colon" entryPointName=http-80 routerName=broken-web-80-http@file

$ docker inspect --format "{{ json .State.Health }}" ddev-router | docker run -i --rm ddev/ddev-utilities jq -r
{
  "Status": "starting",
  "FailingStreak": 0,
  "Log": [
    {
      "Start": "2025-07-10T20:33:32.283310893+03:00",
      "End": "2025-07-10T20:33:32.405053894+03:00",
      "ExitCode": 2,
      "Output": "Traefik healthcheck failed: Detected 2 configuration error(s) in project"
    },
    {
      "Start": "2025-07-10T20:33:37.406443023+03:00",
      "End": "2025-07-10T20:33:37.581668479+03:00",
      "ExitCode": 2,
      "Output": "Traefik healthcheck failed: Detected 2 configuration error(s) in project"
    },
    {
      "Start": "2025-07-10T20:33:42.583379521+03:00",
      "End": "2025-07-10T20:33:42.749632219+03:00",
      "ExitCode": 2,
      "Output": "Traefik healthcheck failed: Detected 2 configuration error(s) in project"
    },
    {
      "Start": "2025-07-10T20:33:47.750587633+03:00",
      "End": "2025-07-10T20:33:47.928696402+03:00",
      "ExitCode": 2,
      "Output": "Traefik healthcheck failed: Detected 2 configuration error(s) in project"
    },
    {
      "Start": "2025-07-10T20:33:52.929707298+03:00",
      "End": "2025-07-10T20:33:53.115709872+03:00",
      "ExitCode": 2,
      "Output": "Traefik healthcheck failed: Detected 2 configuration error(s) in project"
    }
  ]
}

$ rm -f .ddev/traefik/config/broken.yaml

Automated Testing Overview

Release/Deployment Notes

@stasadev
stasadev requested a review from a team as a code owner July 10, 2025 17:45
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file enhancement labels Jul 10, 2025
@github-actions

github-actions Bot commented Jul 10, 2025 •

Copy link
Copy Markdown

@rfay
rfay force-pushed the 20250710_stasadev_traefik_healthcheck branch from d06061a to 5b1d2a8 Compare July 14, 2025 12:20
@rfay

rfay commented Jul 14, 2025

Copy link
Copy Markdown
Member

Rebased, but I guess it's irrelevant without a push

@rfay
rfay marked this pull request as draft July 15, 2025 12:52
@stasadev stasadev changed the title feat: extend Traefik healthcheck to validate file routers and config errors, fixes #6463 feat: extend Traefik healthcheck to validate file routers and config errors, fixes #6463, fixes #6553 Jul 16, 2025
@stasadev

stasadev commented Jul 16, 2025 •

Copy link
Copy Markdown
Member Author

TODO: update our documentation with examples for:

  • error adding file watcher: no space left on device - increase fs.inotify.max_user_watches
  • error creating file watcher: too many open files - increase fs.inotify.max_user_instances

@stasadev
stasadev force-pushed the 20250710_stasadev_traefik_healthcheck branch from 5b1d2a8 to 211d4a0 Compare July 29, 2025 14:04
@stasadev
stasadev marked this pull request as ready for review July 30, 2025 12:32
@stasadev
stasadev requested a review from a team as a code owner July 30, 2025 12:32

@rfay rfay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great approach and will lead to much more robust handling of the obscure traefik situations. Thanks for taking this on and for the elegant implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants