@@ -269,19 +269,47 @@ func (pc *ProviderChecker) Check(_ context.Context) Check {
269
269
270
270
// HTTPHandler creates HTTP handlers for health endpoints.
271
271
type HTTPHandler struct {
272
- checker * Manager
272
+ checker * Manager
273
+ debugHealthChecks bool
274
+ }
275
+
276
+ // HTTPHandlerOptions holds configuration for the HTTP handler.
277
+ type HTTPHandlerOptions struct {
278
+ DebugHealthChecks bool
279
+ }
280
+
281
+ // WithDebugHealthChecks enables or disables debug logging for health check endpoints.
282
+ func WithDebugHealthChecks (enabled bool ) func (* HTTPHandlerOptions ) {
283
+ return func (opts * HTTPHandlerOptions ) {
284
+ opts .DebugHealthChecks = enabled
285
+ }
273
286
}
274
287
275
288
// NewHTTPHandler creates a new HTTP handler for health checks.
276
- func NewHTTPHandler (checker * Manager ) * HTTPHandler {
277
- return & HTTPHandler {checker : checker }
289
+ func NewHTTPHandler (checker * Manager , opts ... func (* HTTPHandlerOptions )) * HTTPHandler {
290
+ // Apply default options
291
+ options := & HTTPHandlerOptions {
292
+ DebugHealthChecks : true , // Default to true for backwards compatibility
293
+ }
294
+
295
+ // Apply provided options
296
+ for _ , opt := range opts {
297
+ opt (options )
298
+ }
299
+
300
+ return & HTTPHandler {
301
+ checker : checker ,
302
+ debugHealthChecks : options .DebugHealthChecks ,
303
+ }
278
304
}
279
305
280
306
// LivenessHandler handles liveness probe requests.
281
307
func (h * HTTPHandler ) LivenessHandler (writer http.ResponseWriter , request * http.Request ) {
282
308
ctx := request .Context ()
283
309
284
- log .Debug (ctx , "Liveness check requested" )
310
+ if h .debugHealthChecks {
311
+ log .Debug (ctx , "Liveness check requested" )
312
+ }
285
313
286
314
response := h .checker .CheckLiveness (ctx )
287
315
@@ -296,14 +324,18 @@ func (h *HTTPHandler) LivenessHandler(writer http.ResponseWriter, request *http.
296
324
return
297
325
}
298
326
299
- log .Debug (ctx , "Liveness check completed" , "status" , string (response .Status ))
327
+ if h .debugHealthChecks {
328
+ log .Debug (ctx , "Liveness check completed" , "status" , string (response .Status ))
329
+ }
300
330
}
301
331
302
332
// ReadinessHandler handles readiness probe requests.
303
333
func (h * HTTPHandler ) ReadinessHandler (writer http.ResponseWriter , request * http.Request ) {
304
334
ctx := request .Context ()
305
335
306
- log .Debug (ctx , "Readiness check requested" )
336
+ if h .debugHealthChecks {
337
+ log .Debug (ctx , "Readiness check requested" )
338
+ }
307
339
308
340
response := h .checker .CheckReadiness (ctx )
309
341
@@ -335,11 +367,13 @@ func (h *HTTPHandler) ReadinessHandler(writer http.ResponseWriter, request *http
335
367
return
336
368
}
337
369
338
- log .Debug (ctx , "Readiness check completed" ,
339
- "status" , string (response .Status ),
340
- "status_code" , statusCode ,
341
- "healthy_checks" , response .Summary ["healthy" ],
342
- "unhealthy_checks" , response .Summary ["unhealthy" ],
343
- "degraded_checks" , response .Summary ["degraded" ],
344
- )
370
+ if h .debugHealthChecks {
371
+ log .Debug (ctx , "Readiness check completed" ,
372
+ "status" , string (response .Status ),
373
+ "status_code" , statusCode ,
374
+ "healthy_checks" , response .Summary ["healthy" ],
375
+ "unhealthy_checks" , response .Summary ["unhealthy" ],
376
+ "degraded_checks" , response .Summary ["degraded" ],
377
+ )
378
+ }
345
379
}
0 commit comments