Skip to content

Commit

Permalink
Exclude health check endpoint from rate-limiting
Browse files Browse the repository at this point in the history
- Would previously be rate-limited which would cause health checks to
incorrectly fail => downtime of API server

[#171468535]

Authored-by: Jaskanwal Pawar <[email protected]>
  • Loading branch information
Jaskanwal Pawar committed May 6, 2020
1 parent 487c3ce commit 8ab6e35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion middleware/rate_limiter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def skip_rate_limiting?(env, request)
end

def root_api?(request)
request.fullpath.match(%r{\A(?:/v2/info|/v3|/)\z})
request.fullpath.match(%r{\A(?:/v2/info|/v3|/|/healthz)\z})
end

def internal_api?(request)
Expand Down
16 changes: 14 additions & 2 deletions spec/unit/middleware/rate_limiter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module Middleware
end
end

context 'when the user is hitting a root path /v2/info"' do
context 'when the user is hitting a root path /v2/info' do
let(:fake_request) { instance_double(ActionDispatch::Request, fullpath: '/v2/info') }

it 'exempts them from rate limiting' do
Expand All @@ -193,7 +193,7 @@ module Middleware
end
end

context 'when the user is hitting a root path /v3"' do
context 'when the user is hitting a root path /v3' do
let(:fake_request) { instance_double(ActionDispatch::Request, fullpath: '/v3') }

it 'exempts them from rate limiting' do
Expand All @@ -204,6 +204,18 @@ module Middleware
expect(response_headers['X-RateLimit-Reset']).to be_nil
end
end

context 'when the user is hitting a root path /healthz' do
let(:fake_request) { instance_double(ActionDispatch::Request, fullpath: '/healthz') }

it 'exempts them from rate limiting' do
allow(ActionDispatch::Request).to receive(:new).and_return(fake_request)
_, response_headers, _ = middleware.call(unauthenticated_env)
expect(response_headers['X-RateLimit-Limit']).to be_nil
expect(response_headers['X-RateLimit-Remaining']).to be_nil
expect(response_headers['X-RateLimit-Reset']).to be_nil
end
end
end

describe 'when the user has a "HTTP_X_FORWARDED_FOR" header from proxy' do
Expand Down

0 comments on commit 8ab6e35

Please sign in to comment.