Skip to content

Commit

Permalink
Reverts v2 healthcheck updates (#12005)
Browse files Browse the repository at this point in the history
  • Loading branch information
stiehlrod authored Mar 8, 2023
1 parent db0bdb1 commit a42b255
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module ClaimsApi
class UpstreamHealthcheckController < ::OkComputer::OkComputerController
end
end

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 11 additions & 4 deletions modules/claims_api/config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
OkComputer.check_in_parallel = true

class BaseCheck < OkComputer::Check
# def initialize(version = 'v1')
# @version = version
# end

protected

def name
Expand Down Expand Up @@ -94,3 +90,14 @@ def name
'VBMS'
end
end

OkComputer::Registry.register 'evss', EvssCheck.new
OkComputer::Registry.register 'mpi', MpiCheck.new
OkComputer::Registry.register 'bgs-vet_record', BgsCheck.new('vet_record')
OkComputer::Registry.register 'bgs-corporate_update', BgsCheck.new('corporate_update')
OkComputer::Registry.register 'bgs-intent_to_file', BgsCheck.new('intent_to_file')
OkComputer::Registry.register 'bgs-claimant', BgsCheck.new('claimant')
OkComputer::Registry.register 'bgs-contention', BgsCheck.new('contention')
OkComputer::Registry.register 'vbms', VbmsCheck.new

OkComputer.make_optional %w[vbms bgs-vet_record bgs-corporate_update bgs-contention]
4 changes: 1 addition & 3 deletions modules/claims_api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

ClaimsApi::Engine.routes.draw do
get '/metadata', to: 'metadata#index'
get '/:version/upstream_healthcheck', to: 'upstream_healthcheck#index', defaults: { format: 'json' }
get '/:version/upstream_healthcheck/faraday/corporate', to: 'upstream_faraday_healthcheck#corporate'
get '/:version/upstream_healthcheck/faraday/claimant', to: 'upstream_faraday_healthcheck#claimant'
get '/:version/upstream_healthcheck/faraday/itf', to: 'upstream_faraday_healthcheck#itf'
match '/v1/*path', to: 'application#cors_preflight', via: [:options]

namespace :v1, defaults: { format: 'json' } do
mount OkComputer::Engine, at: '/healthcheck'
# get '/upstream_healthcheck', to: 'upstream_healthcheck#index', defaults: { format: 'json' }
get '/upstream_healthcheck', to: 'ok_computer#index', defaults: { format: 'json' }

resources :claims, only: %i[index show]
namespace :forms do
Expand All @@ -37,7 +36,6 @@

namespace :v2, defaults: { format: 'json' } do
mount OkComputer::Engine, at: '/healthcheck'
get '/upstream_healthcheck', to: 'ok_computer#index', defaults: { format: 'json' }

post '/veteran-id:find', to: 'veteran_identifier#find', constraints: { find: /:find/ }
namespace :veterans do
Expand Down
68 changes: 24 additions & 44 deletions modules/claims_api/spec/requests/metadata_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,32 @@
get "/services/claims/#{version}/upstream_healthcheck"
expect(response).to have_http_status(:ok)
end
end
end
end

describe 'when a v1 upstream service is not healthy' do
it 'returns the correct status' do
allow(EVSS::Service).to receive(:service_is_up?).and_return(false)
allow(MPI::Service).to receive(:service_is_up?).and_return(false)
allow_any_instance_of(BGS::Services).to receive(:vet_record).and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:corporate_update).and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:intent_to_file).and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:claimant).and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:contention).and_return(Struct.new(:status).new(500))
allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(Struct.new(:status).new(500))
required_upstream_services = %w[evss mpi bgs-intent_to_file bgs-claimant]
optional_upstream_services = %w[vbms bgs-vet_record bgs-corporate_update bgs-contention]
(required_upstream_services + optional_upstream_services).each do |upstream_service|
it "returns correct status when #{upstream_service} is not healthy" do
allow(EVSS::Service).to receive(:service_is_up?).and_return(upstream_service != 'evss')
allow(MPI::Service).to receive(:service_is_up?).and_return(upstream_service != 'mpi')
allow_any_instance_of(BGS::Services).to receive(:vet_record)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-vet_record'))
allow_any_instance_of(BGS::Services).to receive(:corporate_update)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-corporate_update'))
allow_any_instance_of(BGS::Services).to receive(:intent_to_file)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-intent_to_file'))
allow_any_instance_of(BGS::Services).to receive(:claimant)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-claimant'))
allow_any_instance_of(BGS::Services).to receive(:contention)
.and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-contention'))
allow_any_instance_of(Faraday::Connection).to receive(:get)
.and_return(upstream_service == 'vbms' ? Struct.new(:status).new(500) : Struct.new(:status).new(200))

get '/services/claims/v1/upstream_healthcheck'

res = JSON.parse(response.body)
expect(res['evss']['message']).to eq('EVSS is unavailable')
expect(res['mpi']['message']).to eq('MPI is unavailable')
expect(res['bgs-vet_record']['message']).to eq('BGS vet_record is unavailable')
expect(res['bgs-corporate_update']['message']).to eq('BGS corporate_update is unavailable')
expect(res['bgs-intent_to_file']['message']).to eq('BGS intent_to_file is unavailable')
expect(res['bgs-claimant']['message']).to eq('BGS claimant is unavailable')
expect(res['bgs-contention']['message']).to eq('BGS contention is unavailable')
expect(res['vbms']['message']).to eq('VBMS is unavailable')
end
end

describe 'when a v2 upstream service is not healthy' do
it 'returns the correct status' do
allow(MPI::Service).to receive(:service_is_up?).and_return(false)
allow_any_instance_of(BGS::Services).to receive(:ebenefits_benefit_claims_status)
.and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:intent_to_file).and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:intent_to_file).and_return(Struct.new(:status).new(500))
allow_any_instance_of(BGS::Services).to receive(:tracked_items).and_return(Struct.new(:status).new(500))

get '/services/claims/v2/upstream_healthcheck'

res = JSON.parse(response.body)
expect(res['mpi']['message']).to eq('MPI is unavailable')
expect(res['bgs-ebenefits_benefit_claims_status']['message'])
.to eq('BGS ebenefits_benefit_claims_status is unavailable')
expect(res['bgs-intent_to_file']['message']).to eq('BGS intent_to_file is unavailable')
expect(res['bgs-tracked_items']['message']).to eq('BGS tracked_items is unavailable')
get "/services/claims/#{version}/upstream_healthcheck"
expected_status = required_upstream_services.include?(upstream_service) ? :internal_server_error : :success
expect(response).to have_http_status(expected_status)
end
end
end
end
end
end

0 comments on commit a42b255

Please sign in to comment.