fix: suppress deadline rate limit logs - #22
Conversation
|
| Filename | Overview |
|---|---|
| internal/middleware/ratelimit.go | Introduces isContextEnded helper to handle both context.Canceled and context.DeadlineExceeded; both errors are tagged with RateLimitOutcomeCanceled in telemetry, which conflates two distinct failure modes. |
| internal/middleware/ratelimit_test.go | Test refactored to a table-driven structure covering both sentinel errors; subtests are correctly parallelized and loop-variable capture is safe under Go 1.22+ semantics. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[RateLimit middleware] --> B{path == /mcp?}
B -- No --> C[Skipped outcome → next handler]
B -- Yes --> D[store.Increment]
D --> E{err != nil?}
E -- No --> F{count > limit?}
F -- No --> G[Allowed outcome → next handler]
F -- Yes --> H[Limited outcome → 429]
E -- Yes --> I{isContextEnded?}
I -- "Canceled or DeadlineExceeded" --> J["RateLimitOutcomeCanceled span attr → return (no response)"]
I -- Other error --> K[StoreError outcome → log + 503]
Reviews (1): Last reviewed commit: "fix: suppress deadline rate limit logs" | Re-trigger Greptile
| if isContextEnded(err) { | ||
| trace.SpanFromContext(r.Context()).SetAttributes(observability.RateLimitAttrs{Outcome: observability.RateLimitOutcomeCanceled, Limit: cfg.Requests, Window: cfg.Window}.Attributes()...) | ||
| return | ||
| } |
There was a problem hiding this comment.
DeadlineExceeded mapped to
canceled outcome in telemetry
Both context.Canceled and context.DeadlineExceeded flow through the same RateLimitOutcomeCanceled span attribute. In practice these represent meaningfully different situations — a client disconnect vs. a request timeout — so dashboards and alerts that bucket on ratelimit.outcome = "canceled" will silently absorb deadline-exceeded events. Consider adding a RateLimitOutcomeDeadlineExceeded constant (parallel to the existing canceled one) and branching on the specific sentinel so each cause is independently observable.
context.DeadlineExceededfromRateLimitstore checks as an ended requestisContextEndedkv.Storefailures on the existing error logging and503path