From a0efa4b21af43e38ca85c97bb90d6bdc8401063e Mon Sep 17 00:00:00 2001 From: Nate Gotz <775979+nlgotz@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:21:39 -0600 Subject: [PATCH] fix: Make logging healthz route optional --- pkg/app/api.go | 4 +++- pkg/config/api_server.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/app/api.go b/pkg/app/api.go index 3aaabf52..9e825767 100644 --- a/pkg/app/api.go +++ b/pkg/app/api.go @@ -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) }) } diff --git a/pkg/config/api_server.go b/pkg/config/api_server.go index 541adb0d..bca02021 100644 --- a/pkg/config/api_server.go +++ b/pkg/config/api_server.go @@ -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 { @@ -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 }