Skip to content

Commit

Permalink
fix: Make logging healthz route optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nlgotz committed Dec 20, 2024
1 parent 2e290ab commit a0efa4b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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 a0efa4b

Please sign in to comment.