diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index c6066b72f..d7342499f 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -278,6 +278,12 @@ func main() { os.Exit(2) } + // Throw error for invalid config before starting other components. + if _, err := config.LoadFile(cfg.configFile); err != nil { + level.Error(logger).Log("msg", fmt.Sprintf("Error loading config (--config.file=%s)", cfg.configFile), "err", err) + os.Exit(2) + } + cfg.web.ReadTimeout = time.Duration(cfg.webTimeout) // Default -web.route-prefix to path of -web.external-url. if cfg.web.RoutePrefix == "" { diff --git a/cmd/prometheus/main_test.go b/cmd/prometheus/main_test.go index 3a56d0c14..f556437b2 100644 --- a/cmd/prometheus/main_test.go +++ b/cmd/prometheus/main_test.go @@ -111,7 +111,7 @@ func TestFailedStartupExitCode(t *testing.T) { } fakeInputFile := "fake-input-file" - expectedExitStatus := 1 + expectedExitStatus := 2 prom := exec.Command(promPath, "-test.main", "--config.file="+fakeInputFile) err := prom.Run()