From ed014ccc2a86da427a3465ba1c657c2a0bdbc72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 11 Nov 2024 11:48:50 +0100 Subject: [PATCH] Worker: log which config paths are used at startup To aid in debugging configuration loading issues, log the paths to config files at startup. --- CHANGELOG.md | 1 + cmd/flamenco-worker/main.go | 5 +++++ internal/worker/config.go | 42 ++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e6c13a..accfcb84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ bugs in actually-released versions. - [GO-2024-3106: Stack exhaustion in Decoder.Decode in encoding/gob](https://pkg.go.dev/vuln/GO-2024-3106) - Fix bug where database foreign key constraints could be deactivated ([#104305](https://projects.blender.org/studio/flamenco/issues/104305)). - Fix bug when submitting a file with a non-ASCII name via Shaman ([#104338](https://projects.blender.org/studio/flamenco/issues/104338)). +- Worker: log the configuration file locations at startup. ## 3.5 - released 2024-04-16 diff --git a/cmd/flamenco-worker/main.go b/cmd/flamenco-worker/main.go index b4d1ee46..f44a7705 100644 --- a/cmd/flamenco-worker/main.go +++ b/cmd/flamenco-worker/main.go @@ -95,6 +95,11 @@ func main() { // Load configuration, and override things from the CLI arguments if necessary. configWrangler := worker.NewConfigWrangler() + configPaths := configWrangler.ConfigPaths() + log.Info(). + Str("main", configPaths.Main). + Str("credentials", configPaths.Credentials). + Msg("will load configuration from these paths") // Before the config can be overridden, it has to be loaded. if _, err := configWrangler.WorkerConfig(); err != nil { diff --git a/internal/worker/config.go b/internal/worker/config.go index e786cbb8..6caeb95b 100644 --- a/internal/worker/config.go +++ b/internal/worker/config.go @@ -89,6 +89,41 @@ func NewConfigWrangler() FileConfigWrangler { return FileConfigWrangler{} } +type WorkerConfigPaths struct { + Main string + Credentials string +} + +// ConfigPaths returns the absolute file paths Flamenco Worker will use to load +// its configuration. If the path cannot be made absolute, an error will be +// logged and a relative path will be returned instead. +func (fcw *FileConfigWrangler) ConfigPaths() WorkerConfigPaths { + var err error + paths := WorkerConfigPaths{} + + // configFilename is used as-is. + paths.Main, err = filepath.Abs(configFilename) + if err != nil { + log.Error(). + AnErr("cause", err). + Str("filepath", configFilename). + Msg("could not make the main configuration file path an absolute path") + paths.Main = configFilename + } + + // credentialsFilename is always looked up somewhere in the user's home dir. + paths.Credentials, err = fcw.credentialsAbsPath() + if err != nil { + log.Error(). + AnErr("cause", err). + Str("filepath", credentialsFilename). + Msg("could not make the credentials configuration file path an absolute path") + paths.Credentials = credentialsFilename + } + + return paths +} + // WorkerConfig returns the worker configuration, or the default config if // there is no config file. Configuration is only loaded from disk once; // subsequent calls return the same config. @@ -150,7 +185,7 @@ func (fcw *FileConfigWrangler) WorkerCredentials() (WorkerCredentials, error) { func (fcw *FileConfigWrangler) SaveCredentials(creds WorkerCredentials) error { fcw.creds = &creds - filepath, err := appinfo.InFlamencoHome(credentialsFilename) + filepath, err := fcw.credentialsAbsPath() if err != nil { return err } @@ -162,6 +197,11 @@ func (fcw *FileConfigWrangler) SaveCredentials(creds WorkerCredentials) error { return nil } +func (fcw *FileConfigWrangler) credentialsAbsPath() (string, error) { + filepath, err := appinfo.InFlamencoHome(credentialsFilename) + return filepath, err +} + // SetManagerURL overwrites the Manager URL in the cached configuration. // This is an in-memory change only, and will not be written to the config file. func (fcw *FileConfigWrangler) SetManagerURL(managerURL string) {