Skip to content

Sample repeated rejection logs so one client can't flood the log - #237

Merged
thushan merged 8 commits into
mainfrom
fix/reject-log-flood
Oct 27, 2026
Merged

thushan merged 8 commits into
mainfrom
fix/reject-log-flood

Conversation

@thushan

@thushan thushan commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Olla logged one or more WARN/ERROR lines for every request it rejected itself. One client hammering it produced 13.7M lines in 10 minutes.

Each rejection is now sampled per key. The first one in a 10s window is logged in full, then one repeats suppressed line carries suppressed=N. Sampled rejections:

  • 429 rate limit;
  • 413/431 size limit, keyed by body or headers;
  • dashboard 403;
  • the proxy's final "Request rejected", keyed by status|client;
  • translator routing rejections;
  • chunked bodies over the limit (MaxBytesError).

These per-request duplicates are gone or moved to Debug:

  • Model routing rejected request;
  • Large request blocked;
  • the provider "failing closed" line;
  • the alias-resolution WARNs;
  • the translator's own ERRORs on a rejection.

Tracking stays small:

  • keys are capped at 64 bytes and stored with strings.Clone;
  • at most 256 keys per layer, plus an overflow bucket;
  • expired windows are cleared inside Allow, with no goroutines;
  • pending summaries are flushed on shutdown.

Backend 4xx/5xx responses (those with X-Olla-Endpoint) are never sampled. Non-test code is about +540/-85; the rest is tests.

Type of change

  • Bug fix
  • Documentation

How was this tested?

Tests cover each layer, using a fake clock:

  • logger Throttle and ThrottleSet;
  • security size and rate limiters, including an oversize flood through the production MetricsAdapter, a mixed-reason case and a distinct-IP storm;
  • handlers, including an alias flood, MaxBytesError, a long X-Forwarded-For, and TestTranslationHandler_StrictRejectionFloodLogsBounded with 0 ERROR lines over 300 rejections;
  • dashboard;
  • middleware, including backend statuses never being sampled.

Each behavioural test fails with its fix reverted.

Live run on integration/test-october at 85f9244, re-checked at c9d134c:

  • 500 rate-limited requests logged 1 WARN plus suppressed=494.
  • 413 floods (Content-Length and chunked) and unknown-model floods stayed bounded.
  • Backend 4xx responses were still logged per request.

Checklist

  • make ready passes at 7e911a3
  • Tests added or updated for the change
  • Documentation updated: configuration/practices/security.md "Rejection Log Sampling", plus the v0.0.30 release note
  • No new dependencies added

Out of scope:

  • Per-request INFO "Request received"/"Access log" lines on unknown-model floods.
  • A pre-existing per-request WARN on /olla/anthropic/v1/messages, "No compatible endpoints found for path, falling back to all endpoints". It's logged for every request there, not just rejections, so it's tracked separately.

Summary by CodeRabbit

  • New Features

    • Repeated Olla-generated request rejections are now summarised in logs: the first rejection in each 10-second window is logged in full, with subsequent rejections counted in a summary.
    • Rejection summaries are grouped by request source and type, and pending summaries are written when the service shuts down.
    • Rate-limit and request-size counters continue to count every rejection. Backend errors and successful requests remain logged per request.
  • Bug Fixes

    • Oversized request bodies no longer produce error-level logs when the size limit is reached.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

This change adds bounded sampling for repeated rejection logs across security validators, request logging, proxy routing, and dashboard access. It preserves rejection responses and security violation metrics, adds summary flushing during shutdown, and documents the logging behaviour.

Changes

Rejection-log sampling

Layer / File(s) Summary
Throttle state and summary reporting
internal/logger/*, internal/adapter/health/checker.go
Adds a window-based throttle with bounded keys, overflow handling, summary callbacks, and flush support. Tests cover window rollover, concurrency, key limits, and summaries. Removes the previous health-check log throttle interval constant.
Security rejection sampling
internal/adapter/security/*
Rate-limit and request-size validators throttle warning logs while keeping rejection handling and violation metrics. Adapter stop paths flush pending summaries. Tests check rejection counts, statuses, rollover, key limits, and shutdown flushing.
Application request and proxy rejection logs
internal/app/handlers/application.go, internal/app/handlers/reject_logs.go, internal/app/handlers/handler_proxy.go, internal/app/handlers/handler_translation.go, internal/app/middleware/logging.go, internal/adapter/translator/*, internal/adapter/proxy/core/retry.go, internal/app/services/http.go
Shares rejection throttles across request logging and proxy-routing paths. Adds quiet translator error writing for already-logged rejections. Oversized-body errors use sampled rejection logging. Application shutdown flushes pending summaries. Tests cover response classification, routing and translation rejections, body limits, and flushing.
Dashboard rejection logs and release notes
internal/app/handlers/dashboard/*, internal/app/handlers/server_routes.go, docs/content/configuration/practices/security.md, docs/content/about/release-notes.md
Dashboard access denials share a throttle across dashboard routes and use the TCP-source client IP. Tests check denial responses, shared throttling, and flushing. The security guide and release notes describe the sampling behaviour.

Priority: Not assessed

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CombinedLoggingMiddleware
  participant Handler
  participant Throttle
  participant StyledLogger
  Client->>CombinedLoggingMiddleware: Send request
  CombinedLoggingMiddleware->>Handler: Pass request
  Handler-->>CombinedLoggingMiddleware: Return response
  CombinedLoggingMiddleware->>Throttle: Check Olla rejection key
  Throttle-->>CombinedLoggingMiddleware: Allow or suppress log
  CombinedLoggingMiddleware->>StyledLogger: Write allowed rejection log
  Throttle->>StyledLogger: Report suppressed count
Loading

Possibly related PRs

  • thushan/olla#236: Adds capability-unavailable routing refusals and changes their warning behaviour, which connects to this change’s proxy routing rejection logs.
Merge Risk: Minimal · up to 8cfda

No identified issue needs correction before merge; normal checks remain appropriate.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

# Conflicts:
#	docs/content/about/release-notes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant