Skip to content

Commit

Permalink
Merge pull request #568 from nlgotz/ng/disable-healthz-logs
Browse files Browse the repository at this point in the history
fix: Make logging healthz route optional
  • Loading branch information
karimra authored Jan 20, 2025
2 parents 2e290ab + 4aedc17 commit 90be036
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/user_guide/api/api_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ api-server:
enable-metrics: false
# boolean, enables extra debug log printing
debug: false
# boolean, disables creating log messages when accessing the `healthz` path
healthz-disable-logging: false
```
## API Endpoints
Expand Down
4 changes: 3 additions & 1 deletion pkg/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ func headersMiddleware(next http.Handler) http.Handler {
}

func (a *App) loggingMiddleware(next http.Handler) http.Handler {
next = handlers.LoggingHandler(a.Logger.Writer(), next)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if (!a.Config.APIServer.HealthzDisableLogging && r.URL.Path == "/api/v1/healthz") || r.URL.Path != "/api/v1/healthz" {
next = handlers.LoggingHandler(a.Logger.Writer(), next)
}
next.ServeHTTP(w, r)
})
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type APIServer struct {
TLS *types.TLSConfig `mapstructure:"tls,omitempty" json:"tls,omitempty"`
EnableMetrics bool `mapstructure:"enable-metrics,omitempty" json:"enable-metrics,omitempty"`
Debug bool `mapstructure:"debug,omitempty" json:"debug,omitempty"`
HealthzDisableLogging bool `mapstructure:"healthz-disable-logging,omitempty" json:"healthz-disable-logging,omitempty"`
}

func (c *Config) GetAPIServer() error {
Expand All @@ -53,6 +54,7 @@ func (c *Config) GetAPIServer() error {

c.APIServer.EnableMetrics = os.ExpandEnv(c.FileConfig.GetString("api-server/enable-metrics")) == trueString
c.APIServer.Debug = os.ExpandEnv(c.FileConfig.GetString("api-server/debug")) == trueString
c.APIServer.HealthzDisableLogging = os.ExpandEnv(c.FileConfig.GetString("api-server/healthz-disable-logging")) == trueString
c.setAPIServerDefaults()
return nil
}
Expand Down

0 comments on commit 90be036

Please sign in to comment.