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 1/2] 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 } From 4aedc1763dcbe7cb5b1e65bfa7f3392ba9e9e410 Mon Sep 17 00:00:00 2001 From: Nate Gotz <775979+nlgotz@users.noreply.github.com> Date: Fri, 20 Dec 2024 09:24:54 -0600 Subject: [PATCH 2/2] docs: Update api_intro with new healthz-disable-logging option --- docs/user_guide/api/api_intro.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/user_guide/api/api_intro.md b/docs/user_guide/api/api_intro.md index 4f2db475..d57fec85 100644 --- a/docs/user_guide/api/api_intro.md +++ b/docs/user_guide/api/api_intro.md @@ -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