Browse Source

Exit early on invalid config file (#7399)

* Reload config file at start

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* relocated config checking

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* change log lever

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>

* add helpful comment

Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
pull/7433/head
Harkishen Singh 4 years ago committed by GitHub
parent
commit
70b0a34616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      cmd/prometheus/main.go
  2. 2
      cmd/prometheus/main_test.go

6
cmd/prometheus/main.go

@ -278,6 +278,12 @@ func main() {
os.Exit(2) 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) cfg.web.ReadTimeout = time.Duration(cfg.webTimeout)
// Default -web.route-prefix to path of -web.external-url. // Default -web.route-prefix to path of -web.external-url.
if cfg.web.RoutePrefix == "" { if cfg.web.RoutePrefix == "" {

2
cmd/prometheus/main_test.go

@ -111,7 +111,7 @@ func TestFailedStartupExitCode(t *testing.T) {
} }
fakeInputFile := "fake-input-file" fakeInputFile := "fake-input-file"
expectedExitStatus := 1 expectedExitStatus := 2
prom := exec.Command(promPath, "-test.main", "--config.file="+fakeInputFile) prom := exec.Command(promPath, "-test.main", "--config.file="+fakeInputFile)
err := prom.Run() err := prom.Run()

Loading…
Cancel
Save