multi: add Rack::Attack rate limiting throttling and GET /v1/sismos/stats endpoint - #3
Conversation
WalkthroughThe API adds a ChangesEarthquake statistics endpoint
Rack::Attack throttling
Release workflow permissions and action pinning
Review path filter
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant SismosController
participant EarthquakeData
Client->>SismosController: GET /v1/sismos/stats
SismosController->>EarthquakeData: calculate statistics
EarthquakeData-->>SismosController: aggregate metrics
SismosController-->>Client: stats JSON response
sequenceDiagram
participant Client
participant RackAttack
participant RailsApplication
Client->>RackAttack: HTTP request
RackAttack->>RailsApplication: forward request within limit
RailsApplication-->>Client: application response
RackAttack-->>Client: HTTP 429 and Retry-After after limit
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/controllers/sismos_controller.rb`:
- Around line 205-211: Update serialize_stats so the returned data resource
includes a stable id alongside type and attributes. Use the endpoint’s
established stable stats identifier, while preserving the existing stats_data
attributes and resource type.
In `@config/initializers/rack_attack.rb`:
- Around line 12-13: Update the reports/ip throttle matcher in the Rack::Attack
configuration to accept optional format suffixes such as .json while retaining
the existing endpoint and POST constraints. Add an integration test covering a
formatted POST report request and verifying it is subject to the 5-per-minute
report limit.
- Line 4: Replace the process-local MemoryStore assignment in the Rack::Attack
initializer with Rails.cache. Add the redis gem dependency and configure the
production cache store as redis_cache_store using the required REDIS_URL
environment variable, so Rack::Attack shares the Rails Redis-backed cache across
Puma workers.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: af266033-f2d3-44d5-bdb4-eba7f5520f2c
⛔ Files ignored due to path filters (1)
Gemfile.lockis excluded by!**/*.lock,!Gemfile.lock
📒 Files selected for processing (9)
.coderabbit.yamlGemfileapp/controllers/sismos_controller.rbconfig/application.rbconfig/initializers/rack_attack.rbconfig/routes.rbtest/controllers/sismos_controller_test.rbtest/integration/rate_limiting_test.rbtest/test_helper.rb
c263af2 to
f3aff8b
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/release.yml:
- Line 96: Optionally replace the pinned softprops/action-gh-release step with
the preinstalled gh CLI, using gh release create and its --generate-notes option
to preserve automatic release-note generation and the existing release behavior.
- Around line 60-62: Add a concise explanatory comment immediately above the
permissions block in the release workflow, documenting why the release job
requires contents: write and packages: write. Keep the existing permission
values unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c7ffcc50-c44b-4ea1-bfc5-a3eb58364c78
⛔ Files ignored due to path filters (1)
Gemfile.lockis excluded by!**/*.lock,!Gemfile.lock
📒 Files selected for processing (10)
.coderabbit.yaml.github/workflows/release.ymlGemfileapp/controllers/sismos_controller.rbconfig/application.rbconfig/initializers/rack_attack.rbconfig/routes.rbtest/controllers/sismos_controller_test.rbtest/integration/rate_limiting_test.rbtest/test_helper.rb
f3aff8b to
fdbf5de
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config/initializers/rack_attack.rb`:
- Around line 6-16: Update the Redis configuration in the Rack::Attack cache
setup to validate that production Redis URLs use the rediss:// scheme before
constructing ActiveSupport::Cache::RedisCacheStore. Reject non-TLS URLs in
production while preserving the existing missing-URL error and non-production
MemoryStore fallback.
In `@test/controllers/sismos_controller_test.rb`:
- Line 126: Update the assertion in the stats response test to verify that
attrs['by_mag_type']['ml'] equals the fixture’s expected count of 2, rather than
only checking that the 'ml' key exists.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 81e1bb61-0d1f-4de2-861d-8e3591b2e3ff
⛔ Files ignored due to path filters (1)
Gemfile.lockis excluded by!**/*.lock,!Gemfile.lock
📒 Files selected for processing (10)
.coderabbit.yaml.github/workflows/release.ymlGemfileapp/controllers/sismos_controller.rbconfig/application.rbconfig/initializers/rack_attack.rbconfig/routes.rbtest/controllers/sismos_controller_test.rbtest/integration/rate_limiting_test.rbtest/test_helper.rb
Summary by CodeRabbit
Retry-Afterindicator.