Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 8ab6e35

Browse files
author
Jaskanwal Pawar
committed
Exclude health check endpoint from rate-limiting
- Would previously be rate-limited which would cause health checks to incorrectly fail => downtime of API server [#171468535] Authored-by: Jaskanwal Pawar <jpawar@pivotal.io>
1 parent 487c3ce commit 8ab6e35

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

middleware/rate_limiter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def skip_rate_limiting?(env, request)
5252
end
5353

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

5858
def internal_api?(request)

spec/unit/middleware/rate_limiter_spec.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ module Middleware
181181
end
182182
end
183183

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

187187
it 'exempts them from rate limiting' do
@@ -193,7 +193,7 @@ module Middleware
193193
end
194194
end
195195

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

199199
it 'exempts them from rate limiting' do
@@ -204,6 +204,18 @@ module Middleware
204204
expect(response_headers['X-RateLimit-Reset']).to be_nil
205205
end
206206
end
207+
208+
context 'when the user is hitting a root path /healthz' do
209+
let(:fake_request) { instance_double(ActionDispatch::Request, fullpath: '/healthz') }
210+
211+
it 'exempts them from rate limiting' do
212+
allow(ActionDispatch::Request).to receive(:new).and_return(fake_request)
213+
_, response_headers, _ = middleware.call(unauthenticated_env)
214+
expect(response_headers['X-RateLimit-Limit']).to be_nil
215+
expect(response_headers['X-RateLimit-Remaining']).to be_nil
216+
expect(response_headers['X-RateLimit-Reset']).to be_nil
217+
end
218+
end
207219
end
208220

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

0 commit comments

Comments
 (0)