Skip to content

Commit

Permalink
Add CLI flag to verify config and exit (#187)
Browse files Browse the repository at this point in the history
* Add CLI flag to verify config and exit

* Add verify-config usage to readme
  • Loading branch information
zswanson committed Mar 1, 2021
1 parent 2870493 commit eb8b9f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ Use the configuration file:
$ ./prometheus-nginxlog-exporter -config-file /path/to/config.hcl
----

You can verify your config file before deployment, which will exit with shell status indicating success:

[source]
----
$ ./prometheus-nginxlog-exporter -config-file /path/to/config.hcl -verify-config
----

Installation
------------
Expand Down Expand Up @@ -526,7 +533,7 @@ If your regular expression contains groups, you can also use the matched values
relabel "request_uri" {
from = "request"
split = 2
match "^/(users|profiles)/[0-9]+" {
replacement = "/$1/:id"
}
Expand Down
1 change: 1 addition & 0 deletions config/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type StartupFlags struct {
ListenPort int
EnableExperimentalFeatures bool
MetricsEndpoint string
VerifyConfig bool

CPUProfile string
MemProfile string
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func main() {
flag.StringVar(&opts.CPUProfile, "cpuprofile", "", "write cpu profile to `file`")
flag.StringVar(&opts.MemProfile, "memprofile", "", "write memory profile to `file`")
flag.StringVar(&opts.MetricsEndpoint, "metrics-endpoint", cfg.Listen.MetricsEndpoint, "URL path at which to serve metrics")
flag.BoolVar(&opts.VerifyConfig, "verify-config", false, "Enable this flag to check config file loads, then exit")
flag.Parse()

opts.Filenames = flag.Args()
Expand Down Expand Up @@ -267,6 +268,10 @@ func loadConfig(opts *config.StartupFlags, cfg *config.Config) {
} else if err := config.LoadConfigFromFlags(cfg, opts); err != nil {
panic(err)
}
if opts.VerifyConfig {
fmt.Printf("Configuration is valid")
os.Exit(0)
}
}

func setupConsul(cfg *config.Config, stopChan <-chan bool, stopHandlers *sync.WaitGroup) {
Expand Down

0 comments on commit eb8b9f3

Please sign in to comment.