cosmo icon indicating copy to clipboard operation
cosmo copied to clipboard

feat(router): hot config reloading

Open endigma opened this issue 7 months ago • 2 comments

Motivation and Context

As a user who deploys the router with a dynamic config from the filesystem, I'd like it such that when the file changes on disk, there is the option to have the router automatically reload itself when it detects this change.

Changes

  • Better responsibility boundary between main.go and config.go
  • The log level is now atomic and mutable at runtime if you hold a reference
  • The router is now capable of executing a full reload when either the config file changes or SIGHUP signal is sent to the process
  • Moved randomDuration utility out of controlplane package into internal/timex for reuse
  • Added configuration for watching the config file and triggering a reload when a change is detected (example below)
  • Introduces new package /router/pkg/supervisor which contains logic for handling setup/start/stop/teardown of router instances

Todo

  • I have observed panics when reloading during a k6 load test, pending investigation
  • Integration tests

Config responsibility change

As a side effect of drawing a clearer boundary between the responsibilities of main.go and config.go for determining the config file to read, direct calls to LoadConfig will no longer check CONFIG_FILE environment variable. This is intentional, as this responsibility now falls to the caller.

LoadConfig continues to default to config.DefaultConfigPath when the provided path is "".

Limitations

The config path loading and the file watcher are outside the reload loop, so:

  • Configuration hot-reloading will not detect changes to the config path
  • Configuration for the file watching behaviour itself will not be updated during reloads

Configuration Example

watch_config:
  enabled: true
  interval: "10s"

  startup_delay:
    enabled: false
    maximum: "10s"

Checklist

  • [x] I have discussed my proposed changes in an issue and have received approval to proceed.
  • [x] I have followed the coding standards of the project.
  • [x] Tests or benchmarks have been added or updated.
  • [ ] Documentation has been updated on https://github.com/wundergraph/cosmo-docs.

endigma avatar Apr 01 '25 18:04 endigma

Router image scan passed

:white_check_mark: No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-665fa6436a60b33e7252eb76891d029ebc54a9c6

github-actions[bot] avatar Apr 01 '25 20:04 github-actions[bot]

Current state has a more minimal callback, and implemented other feedback

endigma avatar Apr 30 '25 15:04 endigma