From 044ca2ac892d61bf526c8e3722b2e0b4f19c84d7 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Fri, 2 Mar 2018 16:47:29 -0700 Subject: [PATCH] ensure ENV overrides are applied when configuring logging Additionally, the config file is only parsed once. --- cmd/influxd/run/command.go | 51 +++++++++++++------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/cmd/influxd/run/command.go b/cmd/influxd/run/command.go index 575356546f..15ef5ba7ad 100644 --- a/cmd/influxd/run/command.go +++ b/cmd/influxd/run/command.go @@ -71,30 +71,29 @@ func (cmd *Command) Run(args ...string) error { return err } - // Attempt to parse the config once in advance. If this fails, use the - // default logging configuration. - var ( - suppressLogo bool - logErr error - ) - if config, err := cmd.ParseConfig(options.GetConfigPath()); err == nil { - suppressLogo = config.Logging.SuppressLogo - if l, err := config.Logging.New(cmd.Stderr); err == nil { - cmd.Logger = l - } else { - logErr = err - } - } else { - logErr = err + config, err := cmd.ParseConfig(options.GetConfigPath()) + if err != nil { + return fmt.Errorf("parse config: %s", err) } - // We were unable to read the configuration file. Use the default logging format. - if logErr != nil { + // Apply any environment variables on top of the parsed config + if err := config.ApplyEnvOverrides(cmd.Getenv); err != nil { + return fmt.Errorf("apply env config: %v", err) + } + + // Validate the configuration. + if err := config.Validate(); err != nil { + return fmt.Errorf("%s. To generate a valid configuration file run `influxd config > influxdb.generated.conf`", err) + } + + var logErr error + if cmd.Logger, logErr = config.Logging.New(cmd.Stderr); logErr != nil { + // assign the default logger cmd.Logger = logger.New(cmd.Stderr) } // Print sweet InfluxDB logo. - if !suppressLogo && logger.IsTerminal(cmd.Stdout) { + if !config.Logging.SuppressLogo && logger.IsTerminal(cmd.Stdout) { fmt.Fprint(cmd.Stdout, logo) } @@ -118,22 +117,6 @@ func (cmd *Command) Run(args ...string) error { } cmd.pidfile = options.PIDFile - // Parse config - config, err := cmd.ParseConfig(options.GetConfigPath()) - if err != nil { - return fmt.Errorf("parse config: %s", err) - } - - // Apply any environment variables on top of the parsed config - if err := config.ApplyEnvOverrides(cmd.Getenv); err != nil { - return fmt.Errorf("apply env config: %v", err) - } - - // Validate the configuration. - if err := config.Validate(); err != nil { - return fmt.Errorf("%s. To generate a valid configuration file run `influxd config > influxdb.generated.conf`", err) - } - if config.HTTPD.PprofEnabled { // Turn on block and mutex profiling. runtime.SetBlockProfileRate(int(1 * time.Second))