Add runtime flag to allow disabling config hot-reload (#5079) (#5112)

* Add runtime flag to allow disabling config hot-reload (#5079)

* Add unit tests

* Log at info level instead of warning
This commit is contained in:
Joe Kralicky 2024-06-12 23:20:30 -04:00 committed by GitHub
parent 114f730dba
commit c3534df885
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 189 additions and 52 deletions

View file

@ -134,7 +134,12 @@ func NewFileOrEnvironmentSource(
config: cfg,
}
if configFile != "" {
src.watcher.Watch(ctx, []string{configFile})
if cfg.Options.IsRuntimeFlagSet(RuntimeFlagConfigHotReload) {
src.watcher.Watch(ctx, []string{configFile})
} else {
log.Info(ctx).Msg("hot reload disabled")
src.watcher.Watch(ctx, nil)
}
}
ch := src.watcher.Bind()
go func() {
@ -223,7 +228,11 @@ func (src *FileWatcherSource) GetConfig() *Config {
func (src *FileWatcherSource) onConfigChange(ctx context.Context, cfg *Config) {
// update the file watcher with paths from the config
src.watcher.Watch(ctx, getAllConfigFilePaths(cfg))
if cfg.Options.IsRuntimeFlagSet(RuntimeFlagConfigHotReload) {
src.watcher.Watch(ctx, getAllConfigFilePaths(cfg))
} else {
src.watcher.Watch(ctx, nil)
}
src.mu.Lock()
defer src.mu.Unlock()