Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for exit zero on sigterm #1870

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var (
Code: 143,
}

errSigTermZero = &exitError{
Err: errors.New("SIGTERM signal received"),
Code: 0,
}

errQuitQuitQuit = &exitError{
Err: errors.New("/quitquitquit received request"),
Code: 0, // This error guarantees a clean exit.
Expand Down
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ the Proxy will then pick-up automatically.`)
"Disable Cloud Monitoring integration (used with --telemetry-project)")
pflags.StringVar(&c.conf.TelemetryPrefix, "telemetry-prefix", "",
"Prefix for Cloud Monitoring metrics.")
pflags.BoolVar(&c.conf.ExitZeroOnSigterm, "exit-zero-on-sigterm", false,
"Exit with 0 exit code when Sigterm received (default is 143)")
pflags.BoolVar(&c.conf.Prometheus, "prometheus", false,
"Enable Prometheus HTTP endpoint /metrics on localhost")
pflags.StringVar(&c.conf.PrometheusNamespace, "prometheus-namespace", "",
Expand Down Expand Up @@ -772,7 +774,11 @@ func runSignalWrapper(cmd *Command) (err error) {
case syscall.SIGINT:
shutdownCh <- errSigInt
case syscall.SIGTERM:
shutdownCh <- errSigTerm
if cmd.conf.ExitZeroOnSigterm {
shutdownCh <- errSigTermZero
} else {
shutdownCh <- errSigTerm
}
}
}()

Expand Down
2 changes: 2 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ type Config struct {
// TelemetryTracingSampleRate sets the rate at which traces are
// samples. A higher value means fewer traces.
TelemetryTracingSampleRate int
// ExitZeroOnSigterm exits with 0 exit code when Sigterm received
ExitZeroOnSigterm bool
// DisableTraces disables tracing when TelemetryProject is set.
DisableTraces bool
// DisableMetrics disables metrics when TelemetryProject is set.
Expand Down
Loading