From 57bc300fe26812aad568c8119f04d92e94c9ab14 Mon Sep 17 00:00:00 2001 From: bndw Date: Sun, 15 Feb 2026 10:26:10 -0800 Subject: fix: record AUTH attempt metrics in WebSocket handler Add RecordAuthAttempt calls to handleAuth so successful and failed AUTH attempts are tracked in metrics. This fixes the dashboard 'Challenges' counter which was always showing 0. The deferred call ensures both success and failure cases are recorded: - success=true when AUTH completes successfully - success=false when AUTH fails (invalid signature, wrong challenge, etc.) Updated MetricsRecorder interface and mock to include RecordAuthAttempt. --- internal/handler/websocket/handler.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'internal/handler/websocket/handler.go') diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index de71926..dfe7b9e 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go @@ -33,6 +33,7 @@ type MetricsRecorder interface { DecrementSubscriptions() SetActiveSubscriptions(count int) RecordRequest(method, status string, duration float64) + RecordAuthAttempt(success bool) RecordBlockedEvent(kind int32) } @@ -522,6 +523,13 @@ func (h *Handler) sendAuthChallenge(ctx context.Context, conn *websocket.Conn, c } func (h *Handler) handleAuth(ctx context.Context, conn *websocket.Conn, raw []json.RawMessage, state *connState) error { + success := false + defer func() { + if h.metrics != nil { + h.metrics.RecordAuthAttempt(success) + } + }() + if len(raw) != 2 { return fmt.Errorf("AUTH expects 2 elements") } @@ -560,6 +568,7 @@ func (h *Handler) handleAuth(ctx context.Context, conn *websocket.Conn, raw []js state.authenticatedPubkey = authEvent.PubKey log.Printf("WebSocket client authenticated: %s", authEvent.PubKey[:16]) + success = true // Don't send OK for AUTH - it's not an EVENT return nil } -- cgit v1.2.3