return error exit status in prometheus cli (#4296)

Signed-off-by: mikeykhalil <mikeyfkhalil@gmail.com>
This commit is contained in:
Michael Khalil 2018-06-21 00:32:26 -07:00 committed by Brian Brazil
parent 630f42fcf1
commit 78e0784d04
2 changed files with 19 additions and 0 deletions

View File

@ -595,6 +595,7 @@ func main() {
}
if err := g.Run(); err != nil {
level.Error(logger).Log("err", err)
os.Exit(1)
}
level.Info(logger).Log("msg", "See you next time!")
}

View File

@ -20,6 +20,7 @@ import (
"os"
"os/exec"
"path/filepath"
"syscall"
"testing"
"time"
@ -155,3 +156,20 @@ func TestComputeExternalURL(t *testing.T) {
}
}
}
// Let's provide an invalid configuration file and verify the exit status indicates the error.
func TestFailedStartupExitCode(t *testing.T) {
fakeInputFile := "fake-input-file"
expectedExitStatus := 1
prom := exec.Command(promPath, "--config.file="+fakeInputFile)
err := prom.Run()
testutil.NotOk(t, err, "")
if exitError, ok := err.(*exec.ExitError); ok {
status := exitError.Sys().(syscall.WaitStatus)
testutil.Equals(t, expectedExitStatus, status.ExitStatus())
} else {
t.Errorf("unable to retrieve the exit status for prometheus: %v", err)
}
}