Class: Gitlab::Middleware::BasicHealthCheck
- Inherits:
-
Object
- Object
- Gitlab::Middleware::BasicHealthCheck
- Defined in:
- lib/gitlab/middleware/basic_health_check.rb
Constant Summary collapse
- OK_RESPONSE =
This can’t be frozen because Rails::Rack::Logger wraps the body rubocop:disable Style/MutableConstant
[200, { 'Content-Type' => 'text/plain' }, ["GitLab OK"]]
- EMPTY_RESPONSE =
[404, { 'Content-Type' => 'text/plain' }, [""]]
- HEALTH_PATH =
rubocop:enable Style/MutableConstant
'/-/health'
Instance Method Summary collapse
- #call(env) ⇒ Object
- #client_ip_whitelisted?(request) ⇒ Boolean
-
#initialize(app) ⇒ BasicHealthCheck
constructor
A new instance of BasicHealthCheck.
- #ip_whitelist ⇒ Object
Constructor Details
#initialize(app) ⇒ BasicHealthCheck
Returns a new instance of BasicHealthCheck.
20 21 22 |
# File 'lib/gitlab/middleware/basic_health_check.rb', line 20 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab/middleware/basic_health_check.rb', line 24 def call(env) return @app.call(env) unless env['PATH_INFO'] == HEALTH_PATH # We should be using ActionDispatch::Request instead of # Rack::Request to be consistent with Rails, but due to a Rails # bug described in # https://gitlab.com/gitlab-org/gitlab-foss/issues/58573#note_149799010 # hosts behind a load balancer will only see 127.0.0.1 for the # load balancer's IP. request = Rack::Request.new(env) return OK_RESPONSE if client_ip_whitelisted?(request) EMPTY_RESPONSE end |
#client_ip_whitelisted?(request) ⇒ Boolean
40 41 42 |
# File 'lib/gitlab/middleware/basic_health_check.rb', line 40 def client_ip_whitelisted?(request) ip_whitelist.any? { |e| e.include?(request.ip) } end |
#ip_whitelist ⇒ Object
44 45 46 |
# File 'lib/gitlab/middleware/basic_health_check.rb', line 44 def ip_whitelist @ip_whitelist ||= Settings.monitoring.ip_whitelist.map(&IPAddr.method(:new)) end |