Skip to content

Commit

Permalink
Move health probes to Grape API v2 (closes #2066) (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali authored and Louis committed Feb 15, 2019
1 parent 603a1ca commit 0fdd307
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
12 changes: 12 additions & 0 deletions app/api/v2/public/tools.rb
Expand Up @@ -21,6 +21,18 @@ class Tools < Grape::API
present OpenStruct.new(v), with: Entities::Version
end
end

resource :health do
desc 'Get application liveness status'
head "/alive" do
status Services::HealthChecker.alive? ? 200 : 503
end

desc 'Get application readiness status'
head "/ready" do
status Services::HealthChecker.ready? ? 200 : 503
end
end
end
end
end
Expand Down
20 changes: 0 additions & 20 deletions app/controllers/public/health_controller.rb

This file was deleted.

3 changes: 0 additions & 3 deletions config/routes.rb
Expand Up @@ -55,9 +55,6 @@ def draw(routes_name)
end
end

get 'health/alive', to: 'public/health#alive'
get 'health/ready', to: 'public/health#ready'

get 'trading/:market_id', to: BlackHoleRouter.new, as: :trading

draw :admin
Expand Down
26 changes: 26 additions & 0 deletions spec/api/v2/public/tools_spec.rb
Expand Up @@ -10,4 +10,30 @@
expect(JSON.parse(response.body)).to be_between(now.iso8601, (now + 1).iso8601)
end
end

describe '/health' do
it 'returns successful liveness probe' do
head '/api/v2/public/health/alive'
expect(response).to be_success
end

it 'returns failed liveness probe' do
Market.stubs(:connected?).returns(false)

head '/api/v2/public/health/alive'
expect(response).to have_http_status(503)
end

it 'returns successful readiness probe' do
head '/api/v2/public/health/ready'
expect(response).to be_success
end

it 'returns failed readiness probe' do
Bunny.stubs(:run).returns(false)

head '/api/v2/public/health/alive'
expect(response).to have_http_status(503)
end
end
end

0 comments on commit 0fdd307

Please sign in to comment.