diff --git a/modules/claims_api/app/controllers/claims_api/upstream_healthcheck_controller.rb b/modules/claims_api/app/controllers/claims_api/upstream_healthcheck_controller.rb new file mode 100644 index 00000000000..73f966f23ba --- /dev/null +++ b/modules/claims_api/app/controllers/claims_api/upstream_healthcheck_controller.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +module ClaimsApi + class UpstreamHealthcheckController < ::OkComputer::OkComputerController + end +end diff --git a/modules/claims_api/app/controllers/claims_api/v1/ok_computer_controller.rb b/modules/claims_api/app/controllers/claims_api/v1/ok_computer_controller.rb deleted file mode 100644 index 8e6d907b46d..00000000000 --- a/modules/claims_api/app/controllers/claims_api/v1/ok_computer_controller.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require 'bgs/service' -require 'mpi/service' -require 'evss/service' - -module ClaimsApi - module V1 - class OkComputerController < ::OkComputer::OkComputerController - def index - evss = run_check('evss', EvssCheck) - mpi = run_check('mpi', MpiCheck) - bgs_vet_record = run_check('bgs-vet_record', BgsCheck) - bgs_corporate_update = run_check('bgs-corporate_update', BgsCheck) - bgs_intent_to_file = run_check('bgs-intent_to_file', BgsCheck) - bgs_claimant = run_check('bgs-claimant', BgsCheck) - bgs_contention = run_check('bgs-contention', BgsCheck) - vbms = run_check('vbms', VbmsCheck) - OkComputer.make_optional %w[vbms bgs-vet_record bgs-corporate_update bgs-contention] - - render json: { - mpi: mpi, vbms: vbms, evss: evss, 'bgs-claimant': bgs_claimant, - 'bgs-contention': bgs_contention, 'bgs-corporate_update': bgs_corporate_update, - 'bgs-intent_to_file': bgs_intent_to_file, 'bgs-vet_record': bgs_vet_record - } - end - - def run_check(check_name, class_name = nil) - arg = %w[evss mpi].include?(check_name) ? nil : check_name.split('-')[1] - check = OkComputer::Registry.register check_name, arg.nil? ? class_name.new : class_name.new(arg) - check.run - - get_display(check) - end - - def get_display(check) - display = {} - display['success'] = !check.failure_occurred - display['time'] = check.time - display['message'] = check.message - - display - end - end - end -end diff --git a/modules/claims_api/app/controllers/claims_api/v1/upstream_healthcheck_controller.rb b/modules/claims_api/app/controllers/claims_api/v1/upstream_healthcheck_controller.rb deleted file mode 100644 index 3d849948236..00000000000 --- a/modules/claims_api/app/controllers/claims_api/v1/upstream_healthcheck_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -module ClaimsApi - module V1 - class UpstreamHealthcheckController < ::OkComputer::OkComputerController - end - end -end diff --git a/modules/claims_api/app/controllers/claims_api/v2/ok_computer_controller.rb b/modules/claims_api/app/controllers/claims_api/v2/ok_computer_controller.rb deleted file mode 100644 index b84a189869c..00000000000 --- a/modules/claims_api/app/controllers/claims_api/v2/ok_computer_controller.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -require 'bgs/service' -require 'mpi/service' -require 'evss/service' - -module ClaimsApi - module V2 - class OkComputerController < ::OkComputer::OkComputerController - def index - mpi = run_check('mpi', MpiCheck) - ebenefits_benefit_claims_status = run_check('bgs-ebenefits_benefit_claims_status', BgsCheck) - bgs_intent_to_file = run_check('bgs-intent_to_file', BgsCheck) - bgs_tracked_items = run_check('bgs-tracked_items', BgsCheck) - - render json: { - mpi: mpi, - 'bgs-ebenefits_benefit_claims_status': ebenefits_benefit_claims_status, - 'bgs-intent_to_file': bgs_intent_to_file, 'bgs-tracked_items': bgs_tracked_items - } - end - - def run_check(check_name, class_name = nil) - arg = %w[evss mpi].include?(check_name) ? nil : check_name.split('-')[1] - check = OkComputer::Registry.register check_name, arg.nil? ? class_name.new : class_name.new(arg) - check.run - - get_display(check) - end - - def get_display(check) - display = {} - display['success'] = !check.failure_occurred - display['time'] = check.time - display['message'] = check.message - - display - end - end - end -end diff --git a/modules/claims_api/config/initializers/okcomputer.rb b/modules/claims_api/config/initializers/okcomputer.rb index e27bd663c96..75c61ff927c 100644 --- a/modules/claims_api/config/initializers/okcomputer.rb +++ b/modules/claims_api/config/initializers/okcomputer.rb @@ -8,10 +8,6 @@ OkComputer.check_in_parallel = true class BaseCheck < OkComputer::Check - # def initialize(version = 'v1') - # @version = version - # end - protected def name @@ -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] diff --git a/modules/claims_api/config/routes.rb b/modules/claims_api/config/routes.rb index 9e4336d8d83..c5a31df88b9 100644 --- a/modules/claims_api/config/routes.rb +++ b/modules/claims_api/config/routes.rb @@ -2,6 +2,7 @@ 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' @@ -9,8 +10,6 @@ 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 @@ -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 diff --git a/modules/claims_api/spec/requests/metadata_request_spec.rb b/modules/claims_api/spec/requests/metadata_request_spec.rb index 862ba756efb..d5a577185e5 100644 --- a/modules/claims_api/spec/requests/metadata_request_spec.rb +++ b/modules/claims_api/spec/requests/metadata_request_spec.rb @@ -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