-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## What kind of change does this PR introduce? File based configuration reloading using fsnotify. ## What is the current behavior? Currently the Auth config is loaded once from the environment or file (-c flag) and persists until the service is restarted. ## What is the new behavior? A new optional flag (long: `--watch-dir`, short: `-w`) has been added. When present any files with a ".env" suffix will be loaded into the environment before the `*GlobalConfiguration` is created, otherwise existing behavior is preserved. In addition when the watch-dir flag is present a goroutine will be started in serve_cmd.go and begin blocking on a call to `(*Reloader).Watch` with a callback function that accepts a `*conf.GlobalConfiguration object`. Each time this function is called we create a new `*api.API` object and store it within our `AtomicHandler`, previously given as the root handler to the `*http.Server`. The Reloader uses some simple heuristics to deal with a few edge cases, an overview: - At most 1 configuration reload may happen per 10 seconds with a +-1s margin of error. - After a file within `--watch-dir` has changed the 10 second grace period begins. After that it will reload the config. - Config reloads first sort each file by name then processes them in sequence. - Directories within `--watch-dir` are ignored during config reloading. - Implementation quirk: directory changes can trigger a config reload, as I don't stat fsnotify events. This and similar superfulous reloads could be easily fixed by storing a snapshot of `os.Environ()` after successful reloads to compare with the latest via `slices.Equal()` before reloading. - Files that do not end with a `.env` suffix are ignored. - It handles the removal or renaming of the `-watch-dir` during runtime, but an error message will be printed every 10 seconds as long as it's missing. - The config file passed with -c is only loaded once. Live reloads only read the config dir. Meaning it would be possible to create a config dir change that results in a new final configuration on the next reload due to the persistence of `os.Environ()`. --------- Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
- Loading branch information
Showing
15 changed files
with
880 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.