Skip to content

Commit

Permalink
Deprecate -no-exit and add -exit-on-errors. This essentially flips th…
Browse files Browse the repository at this point in the history
…e default behavior as it always should have been for a long running HTTP server.

If you pass -no-exit a deprecation warning is printed and the app behaves as before.
  • Loading branch information
jonnenauha committed Jun 24, 2019
1 parent 3a368bc commit 5859c3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
1.5
===
* Deprecate `-no-exit`. Default behavior is not to exit on scrape errors as it should be for a long running HTTP server.
* This was design misstep. You will not get a deprecation warning if you pass `-no-exit` but the process behaves as before.
* New explicit `-exit-on-errors` has been added for users who want the old default behavior back.
* Correctly export gauge and counter types from `varnishstat` output `type` property.
* Add go module support.
* Use `github.com/prometheus/client_golang` v1.0.0
Expand Down
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ type startParams struct {
Params *varnishstatParams

Verbose bool
NoExit bool
ExitOnErrors bool
Test bool
Raw bool
WithGoMetrics bool

noExit bool // deprecated
}

type varnishstatParams struct {
Expand Down Expand Up @@ -86,12 +88,15 @@ func init() {
// modes
version := false
flag.BoolVar(&version, "version", version, "Print version and exit")
flag.BoolVar(&StartParams.NoExit, "no-exit", StartParams.NoExit, "Do not exit server on Varnish scrape errors.")
flag.BoolVar(&StartParams.ExitOnErrors, "exit-on-errors", StartParams.ExitOnErrors, "Exit process on scrape errors.")
flag.BoolVar(&StartParams.Verbose, "verbose", StartParams.Verbose, "Verbose logging.")
flag.BoolVar(&StartParams.Test, "test", StartParams.Test, "Test varnishstat availability, prints available metrics and exits.")
flag.BoolVar(&StartParams.Raw, "raw", StartParams.Test, "Raw stdout logging without timestamps.")
flag.BoolVar(&StartParams.WithGoMetrics, "with-go-metrics", StartParams.WithGoMetrics, "Export go runtime and http handler metrics")

// deprecated
flag.BoolVar(&StartParams.noExit, "no-exit", StartParams.noExit, "Deprecated: see -exit-on-errors")

flag.Parse()

if version {
Expand All @@ -111,10 +116,13 @@ func init() {
logFatal("-web.telemetry-path and -web.health-path cannot have same value")
}

// This looks weird, but we want the start param to have default value
// of the old behavior, not flip it with e.g. -exit. You have to
// explicitly turn on the changed behavior.
ExitHandler.exitOnError = StartParams.Test == true || StartParams.NoExit == false
// Don't log warning on !noExit as that would spam for the formed default value.
if StartParams.noExit {
logWarn("-no-exit is deprecated. As of v1.5 it is the default behavior not to exit process on scrape errors. You can remove this parameter.")
}

// Test run or user explicitly wants to exit on any scrape errors during runtime.
ExitHandler.exitOnError = StartParams.Test == true || StartParams.ExitOnErrors == true
}

func main() {
Expand Down

0 comments on commit 5859c3d

Please sign in to comment.