Skip to content

feat(health): honor debug logging param #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,47 @@ func (pc *ProviderChecker) Check(_ context.Context) Check {

// HTTPHandler creates HTTP handlers for health endpoints.
type HTTPHandler struct {
checker *Manager
checker *Manager
debugHealthChecks bool
}

// HTTPHandlerOptions holds configuration for the HTTP handler.
type HTTPHandlerOptions struct {
DebugHealthChecks bool
}

// WithDebugHealthChecks enables or disables debug logging for health check endpoints.
func WithDebugHealthChecks(enabled bool) func(*HTTPHandlerOptions) {
return func(opts *HTTPHandlerOptions) {
opts.DebugHealthChecks = enabled
}
}

// NewHTTPHandler creates a new HTTP handler for health checks.
func NewHTTPHandler(checker *Manager) *HTTPHandler {
return &HTTPHandler{checker: checker}
func NewHTTPHandler(checker *Manager, opts ...func(*HTTPHandlerOptions)) *HTTPHandler {
// Apply default options
options := &HTTPHandlerOptions{
DebugHealthChecks: true, // Default to true for backwards compatibility
}

// Apply provided options
for _, opt := range opts {
opt(options)
}

return &HTTPHandler{
checker: checker,
debugHealthChecks: options.DebugHealthChecks,
}
}

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

log.Debug(ctx, "Liveness check requested")
if h.debugHealthChecks {
log.Debug(ctx, "Liveness check requested")
}

response := h.checker.CheckLiveness(ctx)

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

log.Debug(ctx, "Liveness check completed", "status", string(response.Status))
if h.debugHealthChecks {
log.Debug(ctx, "Liveness check completed", "status", string(response.Status))
}
}

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

log.Debug(ctx, "Readiness check requested")
if h.debugHealthChecks {
log.Debug(ctx, "Readiness check requested")
}

response := h.checker.CheckReadiness(ctx)

Expand Down Expand Up @@ -335,11 +367,13 @@ func (h *HTTPHandler) ReadinessHandler(writer http.ResponseWriter, request *http
return
}

log.Debug(ctx, "Readiness check completed",
"status", string(response.Status),
"status_code", statusCode,
"healthy_checks", response.Summary["healthy"],
"unhealthy_checks", response.Summary["unhealthy"],
"degraded_checks", response.Summary["degraded"],
)
if h.debugHealthChecks {
log.Debug(ctx, "Readiness check completed",
"status", string(response.Status),
"status_code", statusCode,
"healthy_checks", response.Summary["healthy"],
"unhealthy_checks", response.Summary["unhealthy"],
"degraded_checks", response.Summary["degraded"],
)
}
}
8 changes: 7 additions & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,19 @@ func NewAPIProxy(
return nil, fmt.Errorf("failed to create OAuth2 server: %w", err)
}

// Configure health handler options
healthOpts := []func(*health.HTTPHandlerOptions){}
if !cfg.DebugHealthChecks {
healthOpts = append(healthOpts, health.WithDebugHealthChecks(false))
}

proxy := &APIProxy{
mux: http.NewServeMux(),
cfg: cfg,
schwabClient: schwabClient,
tokenService: tokenService,
clientService: clientService,
healthHandler: health.NewHTTPHandler(healthChecker),
healthHandler: health.NewHTTPHandler(healthChecker, healthOpts...),
otelProviders: otelProviders,
server: server,
storage: store,
Expand Down
Loading