Skip to content

Commit

Permalink
Api 25831 faraday healthchecks (#12557)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mchristiansonVA authored May 16, 2023
1 parent ea16378 commit 666e23b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
45 changes: 40 additions & 5 deletions modules/claims_api/config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]
6 changes: 6 additions & 0 deletions modules/claims_api/lib/bgs_service/local_bgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<ptcpntId />
Expand Down
24 changes: 7 additions & 17 deletions modules/claims_api/spec/requests/metadata_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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"
Expand Down

0 comments on commit 666e23b

Please sign in to comment.