Skip to content

Commit

Permalink
add "verify-config" flag that load and verify configuration and exits…
Browse files Browse the repository at this point in the history
… with proper exit code (grafana#2737)

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
dlemel8 authored and cyriltovena committed Oct 21, 2020
1 parent 4f8f4ce commit 37b3e40
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ var lineReplacer = strings.NewReplacer("\n", "\\n ")
type Config struct {
loki.Config `yaml:",inline"`
printVersion bool
verifyConfig bool
printConfig bool
logConfig bool
configFile string
}

func (c *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&c.printVersion, "version", false, "Print this builds version information")
f.BoolVar(&c.verifyConfig, "verify-config", false, "Verify config file and exits")
f.BoolVar(&c.printConfig, "print-config-stderr", false, "Dump the entire Loki config object to stderr")
f.BoolVar(&c.logConfig, "log-config-reverse-order", false, "Dump the entire Loki config object at Info log "+
"level with the order reversed, reversing the order makes viewing the entries easier in Grafana.")
Expand Down Expand Up @@ -87,6 +89,11 @@ func main() {
os.Exit(1)
}

if config.verifyConfig {
level.Info(util.Logger).Log("msg", "config is valid")
os.Exit(0)
}

if config.printConfig {
err := logutil.PrintConfig(os.Stderr, &config)
if err != nil {
Expand Down

0 comments on commit 37b3e40

Please sign in to comment.