Skip to content

Commit 649c08e

Browse files
authored
Merge pull request #17 from jkoelker/jk/streaming
feat(health): honor debug logging param
2 parents 4db1b65 + a584379 commit 649c08e

File tree

2 files changed

+54
-14
lines changed

2 files changed

+54
-14
lines changed

health/health.go

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,47 @@ func (pc *ProviderChecker) Check(_ context.Context) Check {
269269

270270
// HTTPHandler creates HTTP handlers for health endpoints.
271271
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+
}
273286
}
274287

275288
// 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+
}
278304
}
279305

280306
// LivenessHandler handles liveness probe requests.
281307
func (h *HTTPHandler) LivenessHandler(writer http.ResponseWriter, request *http.Request) {
282308
ctx := request.Context()
283309

284-
log.Debug(ctx, "Liveness check requested")
310+
if h.debugHealthChecks {
311+
log.Debug(ctx, "Liveness check requested")
312+
}
285313

286314
response := h.checker.CheckLiveness(ctx)
287315

@@ -296,14 +324,18 @@ func (h *HTTPHandler) LivenessHandler(writer http.ResponseWriter, request *http.
296324
return
297325
}
298326

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+
}
300330
}
301331

302332
// ReadinessHandler handles readiness probe requests.
303333
func (h *HTTPHandler) ReadinessHandler(writer http.ResponseWriter, request *http.Request) {
304334
ctx := request.Context()
305335

306-
log.Debug(ctx, "Readiness check requested")
336+
if h.debugHealthChecks {
337+
log.Debug(ctx, "Readiness check requested")
338+
}
307339

308340
response := h.checker.CheckReadiness(ctx)
309341

@@ -335,11 +367,13 @@ func (h *HTTPHandler) ReadinessHandler(writer http.ResponseWriter, request *http
335367
return
336368
}
337369

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+
}
345379
}

proxy/proxy.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,19 @@ func NewAPIProxy(
101101
return nil, fmt.Errorf("failed to create OAuth2 server: %w", err)
102102
}
103103

104+
// Configure health handler options
105+
healthOpts := []func(*health.HTTPHandlerOptions){}
106+
if !cfg.DebugHealthChecks {
107+
healthOpts = append(healthOpts, health.WithDebugHealthChecks(false))
108+
}
109+
104110
proxy := &APIProxy{
105111
mux: http.NewServeMux(),
106112
cfg: cfg,
107113
schwabClient: schwabClient,
108114
tokenService: tokenService,
109115
clientService: clientService,
110-
healthHandler: health.NewHTTPHandler(healthChecker),
116+
healthHandler: health.NewHTTPHandler(healthChecker, healthOpts...),
111117
otelProviders: otelProviders,
112118
server: server,
113119
storage: store,

0 commit comments

Comments
 (0)