spacecloud-io / space-cloud

Open source Firebase + Heroku to develop, scale and secure serverless apps on Kubernetes
https://space-cloud.io
Apache License 2.0
3.94k stars 222 forks source link

[Feature] Add support for out-of-caddy config loader #1631

Closed YourTechBud closed 1 year ago

YourTechBud commented 1 year ago

The problem faced currently?

  1. Config loader in caddy is interval based.
  2. It cannot be used to trigger a config reload whenever a there is a file change
  3. This can screw up developer experience in dev environments where changes in config will be expected to reflect immediately

How can we solve it?

  1. Create a new ConfigLoader manager which will run outside the scope of caddy in a separate goroutine.
  2. The configloader's operation will be started before caddy.
  3. The config loader can have multiple adapters Adapters will watch for config changes in a specific env. For e.g: File / K8s adapters.
  4. Each adapter, upon successful initialization which return a channel of []byte which is nothing but the caddy config in JSON. The ConfigLoader will watch this channel in a for-range loop and call caddy.Load after a debounce.
  5. Debounce Logic:
    • Wait for 500 milliseconds whenever a change is received on the channel before running `caddy.Load'
    • The interval restarts if another config was received before the interval elapses.
    • The debounce interval is configurable via the --config.debouce-interval flag

We will start with migrating the existing file configloader to this new mechanism.

If you want this feature to be implemented, give it a thumbs up reaction, so that we can determine which features are important to you. 👍

YourTechBud commented 1 year ago

Fixed