From 666e23b364fef6c11c3297c8fb9a96ddac6cedaa Mon Sep 17 00:00:00 2001 From: mchristiansonVA <95487885+mchristiansonVA@users.noreply.github.com> Date: Tue, 16 May 2023 11:15:20 -0400 Subject: [PATCH] Api 25831 faraday healthchecks (#12557) * In progress * Updates to call specific localBGS methods * Updates to spec test for new Faraday checks * Rubocop fixes * Disable line length for Rubocop * Add specific identifiers to avoid exceptions * Add settings for environment-specific params, update FaradayBGSCheck to use * Fix typo in settings name * Refactor to add healthcheck for service wsdl, update tests to use * Update rspec for updated healthcheck * Rubocop fixes * Line length * Revert changes to settings.yml --- .../config/initializers/okcomputer.rb | 45 ++++++++++++++++--- .../claims_api/lib/bgs_service/local_bgs.rb | 6 +++ .../spec/requests/metadata_request_spec.rb | 24 +++------- 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/modules/claims_api/config/initializers/okcomputer.rb b/modules/claims_api/config/initializers/okcomputer.rb index 1a4097f0296..bfe27370962 100644 --- a/modules/claims_api/config/initializers/okcomputer.rb +++ b/modules/claims_api/config/initializers/okcomputer.rb @@ -3,7 +3,7 @@ require 'bgs/services' require 'mpi/service' require 'evss/service' -# require 'bgs_service/local_bgs' +require 'bgs_service/local_bgs' OkComputer.mount_at = false OkComputer.check_in_parallel = true @@ -75,6 +75,29 @@ def name end end +class FaradayBGSCheck < BaseCheck + def initialize(endpoint) + @endpoint = endpoint + end + + def check + faraday_service = ClaimsApi::LocalBGS.new( + external_uid: 'healthcheck_uid', + external_key: 'healthcheck_key' + ) + status = faraday_service.send('healthcheck', @endpoint) + status == 200 ? process_success : process_failure + rescue + process_failure + end + + protected + + def name + "Faraday BGS #{@endpoint}" + end +end + class VbmsCheck < BaseCheck def check connection = Faraday::Connection.new @@ -96,11 +119,23 @@ def name 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 'bgs-ebenefits_benefit_claims_status', BgsCheck.new('ebenefits_benefit_claims_status') -OkComputer::Registry.register 'bgs-tracked_items', BgsCheck.new('tracked_items') + +OkComputer::Registry.register 'localbgs-claimant', + FaradayBGSCheck.new('ClaimantServiceBean/ClaimantWebService') +OkComputer::Registry.register 'localbgs-person', + FaradayBGSCheck.new('PersonWebServiceBean/PersonWebService') +OkComputer::Registry.register 'localbgs-org', + FaradayBGSCheck.new('OrgWebServiceBean/OrgWebService') +# rubocop:disable Layout/LineLength +OkComputer::Registry.register 'localbgs-ebenefitsbenftclaim', + FaradayBGSCheck.new('EBenefitsBnftClaimStatusWebServiceBean/EBenefitsBnftClaimStatusWebService') +# rubocop:enable Layout/LineLength +OkComputer::Registry.register 'localbgs-intenttofile', + FaradayBGSCheck.new('IntentToFileWebServiceBean/IntentToFileWebService') +OkComputer::Registry.register 'localbgs-trackeditem', + FaradayBGSCheck.new('TrackedItemService/TrackedItemService') + 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/lib/bgs_service/local_bgs.rb b/modules/claims_api/lib/bgs_service/local_bgs.rb index fe95dca902e..10352d0d0d0 100644 --- a/modules/claims_api/lib/bgs_service/local_bgs.rb +++ b/modules/claims_api/lib/bgs_service/local_bgs.rb @@ -122,6 +122,12 @@ def make_request(endpoint:, action:, body:, key: nil) # rubocop:disable Metrics/ end end + def healthcheck(endpoint) + connection = Faraday::Connection.new(ssl: { verify_mode: @ssl_verify_mode }) + wsdl = connection.get("#{Settings.bgs.url}/#{endpoint}?WSDL") + wsdl.status + end + def find_poa_by_participant_id(id) body = Nokogiri::XML::DocumentFragment.parse <<~EOXML diff --git a/modules/claims_api/spec/requests/metadata_request_spec.rb b/modules/claims_api/spec/requests/metadata_request_spec.rb index b5204ebd8d2..a527969a772 100644 --- a/modules/claims_api/spec/requests/metadata_request_spec.rb +++ b/modules/claims_api/spec/requests/metadata_request_spec.rb @@ -44,21 +44,17 @@ allow(EVSS::Service).to receive(:service_is_up?).and_return(true) allow(MPI::Service).to receive(:service_is_up?).and_return(true) allow_any_instance_of(BGS::Services).to receive(:vet_record).and_return(Struct.new(:healthy?).new(true)) - # rubocop:disable Layout/LineLength - allow_any_instance_of(BGS::Services).to receive(:corporate_update).and_return(Struct.new(:healthy?).new(true)) - allow_any_instance_of(BGS::Services).to receive(:intent_to_file).and_return(Struct.new(:healthy?).new(true)) - allow_any_instance_of(BGS::Services).to receive(:claimant).and_return(Struct.new(:healthy?).new(true)) allow_any_instance_of(BGS::Services).to receive(:contention).and_return(Struct.new(:healthy?).new(true)) - allow_any_instance_of(BGS::Services).to receive(:ebenefits_benefit_claims_status).and_return(Struct.new(:healthy?).new(true)) - # rubocop:enable Layout/LineLength - allow_any_instance_of(BGS::Services).to receive(:tracked_items).and_return(Struct.new(:healthy?).new(true)) + allow_any_instance_of(BGS::Services).to receive(:corporate_update).and_return(Struct.new(:healthy?).new(true)) + allow_any_instance_of(ClaimsApi::LocalBGS).to receive(:healthcheck).and_return(200) allow_any_instance_of(Faraday::Connection).to receive(:get).and_return(Struct.new(:status).new(200)) get "/services/claims/#{version}/upstream_healthcheck" expect(response).to have_http_status(:ok) end - 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 = %w[evss mpi] + optional_upstream_services = %w[vbms bgs-vet_record bgs-corporate_update bgs-contention + localbgs-healthcheck] (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') @@ -67,16 +63,10 @@ .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(BGS::Services).to receive(:ebenefits_benefit_claims_status) - .and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-ebenefits_benefit_claims_status')) - allow_any_instance_of(BGS::Services).to receive(:tracked_items) - .and_return(Struct.new(:healthy?).new(upstream_service != 'bgs-tracked_items')) + allow_any_instance_of(ClaimsApi::LocalBGS).to receive(:healthcheck) + .and_return(200) 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/#{version}/upstream_healthcheck"