diff options
| author | bndw <ben@bdw.to> | 2026-02-15 08:22:03 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-15 08:22:03 -0800 |
| commit | 71f7a444398275923246e1bc8283938a63a8267a (patch) | |
| tree | e4e3a0721ae5c697f6592daacf28f79fd442dc0c /internal/handler/websocket | |
| parent | 77bb5b2469e6813bed3ffc0be5ed4933a437a969 (diff) | |
feat: add metrics for blocked events
Track and display blocked event counts with per-kind breakdown.
- Add events_blocked_total counter with kind label
- Add RecordBlockedEvent method to metrics
- Display blocked count in dashboard Storage section
- Call metric when rejecting non-core protocol kinds
Allows monitoring spam patterns and verifying kind filter effectiveness.
Raw metrics show breakdown by kind (e.g., kind=20001, kind=30311).
Diffstat (limited to 'internal/handler/websocket')
| -rw-r--r-- | internal/handler/websocket/handler.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index 8daa89f..35d0aea 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go | |||
| @@ -33,6 +33,7 @@ type MetricsRecorder interface { | |||
| 33 | DecrementSubscriptions() | 33 | DecrementSubscriptions() |
| 34 | SetActiveSubscriptions(count int) | 34 | SetActiveSubscriptions(count int) |
| 35 | RecordRequest(method, status string, duration float64) | 35 | RecordRequest(method, status string, duration float64) |
| 36 | RecordBlockedEvent(kind int32) | ||
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | type RateLimiter interface { | 39 | type RateLimiter interface { |
| @@ -302,6 +303,9 @@ func (h *Handler) handleEvent(ctx context.Context, conn *websocket.Conn, raw []j | |||
| 302 | // Reject non-core protocol kinds (spam, ephemeral, chat) | 303 | // Reject non-core protocol kinds (spam, ephemeral, chat) |
| 303 | if !isAllowedKind(pbEvent.Kind) { | 304 | if !isAllowedKind(pbEvent.Kind) { |
| 304 | status = "ok" | 305 | status = "ok" |
| 306 | if h.metrics != nil { | ||
| 307 | h.metrics.RecordBlockedEvent(pbEvent.Kind) | ||
| 308 | } | ||
| 305 | h.sendOK(ctx, conn, event.ID, true, "rejected: kind not supported") | 309 | h.sendOK(ctx, conn, event.ID, true, "rejected: kind not supported") |
| 306 | return nil | 310 | return nil |
| 307 | } | 311 | } |
