Skip to content

Commit

Permalink
[DR-65544] Log KPIs for Higher Level Reviews (create + contestable is…
Browse files Browse the repository at this point in the history
…sues) (#16267)

* add success/failure logging for HLR submission

* add logging for getting HLR contestable issues

* rubocop nits
  • Loading branch information
anniebtran authored Apr 10, 2024
1 parent f93f85d commit a4dd1de
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
22 changes: 20 additions & 2 deletions lib/decision_review_v1/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ class Service < Common::Client::Base
def create_higher_level_review(request_body:, user:)
with_monitoring_and_error_handling do
headers = create_higher_level_review_headers(user)
response = perform :post, 'higher_level_reviews', request_body, headers
common_log_params = { key: :overall_claim_submission, form_id: '996', user_uuid: user.uuid,
downstream_system: 'Lighthouse' }
begin
response = perform :post, 'higher_level_reviews', request_body, headers
log_formatted(**common_log_params.merge(is_success: true, status_code: response.status, body: '[Redacted]'))
rescue => e
log_formatted(**common_log_params.merge(is_success: false, response_error: e))
raise e
end
raise_schema_error_unless_200_status response.status
validate_against_schema json: response.body, schema: HLR_CREATE_RESPONSE_SCHEMA,
append_to_error_class: ' (HLR_V1)'
Expand Down Expand Up @@ -72,7 +80,17 @@ def get_higher_level_review_contestable_issues(user:, benefit_type:)
with_monitoring_and_error_handling do
path = "contestable_issues/higher_level_reviews?benefit_type=#{benefit_type}"
headers = get_contestable_issues_headers(user)
response = perform :get, path, nil, headers
common_log_params = { key: :get_contestable_issues, form_id: '996', user_uuid: user.uuid,
upstream_system: 'Lighthouse' }
begin
response = perform :get, path, nil, headers
log_formatted(**common_log_params.merge(is_success: true, status_code: response.status, body: '[Redacted]'))
rescue => e
# We can freely log Lighthouse's error responses because they do not include PII or PHI.
# See https://developer.va.gov/explore/api/decision-reviews/docs?version=v1.
log_formatted(**common_log_params.merge(is_success: false, response_error: e))
raise e
end
raise_schema_error_unless_200_status response.status
validate_against_schema(
json: response.body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@

RSpec.describe V1::HigherLevelReviews::ContestableIssuesController do
let(:user) { build(:user, :loa3) }
let(:success_log_args) do
{
message: 'Get contestable issues success!',
user_uuid: user.uuid,
action: 'Get contestable issues',
form_id: '996',
upstream_system: 'Lighthouse',
downstream_system: nil,
is_success: true,
http: {
status_code: 200,
body: '[Redacted]'
}
}
end
let(:error_log_args) do
{
message: 'Get contestable issues failure!',
user_uuid: user.uuid,
action: 'Get contestable issues',
form_id: '996',
upstream_system: 'Lighthouse',
downstream_system: nil,
is_success: false,
http: {
status_code: 404,
body: anything
}
}
end

before { sign_in_as(user) }

Expand All @@ -19,6 +49,8 @@ def personal_information_logs
it 'fetches issues that the Veteran could contest via a higher-level review' do
VCR.use_cassette('decision_review/HLR-GET-CONTESTABLE-ISSUES-RESPONSE-200_V1') do
VCR.use_cassette('decision_review/HLR-GET-LEGACY_APPEALS-RESPONSE-200_V1') do
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with(success_log_args)
subject
expect(response).to be_successful
expect(JSON.parse(response.body)['data']).to be_an Array
Expand All @@ -39,8 +71,10 @@ def personal_information_logs
end

it 'adds to the PersonalInformationLog when an exception is thrown' do
VCR.use_cassette('decision_review/HLR-GET-CONTESTABLE-ISSUES-RESPONSE-404') do
VCR.use_cassette('decision_review/HLR-GET-CONTESTABLE-ISSUES-RESPONSE-404_V1') do
expect(personal_information_logs.count).to be 0
allow(Rails.logger).to receive(:error)
expect(Rails.logger).to receive(:error).with(error_log_args)
subject
expect(personal_information_logs.count).to be 1
pil = personal_information_logs.first
Expand Down
42 changes: 42 additions & 0 deletions spec/requests/v1/higher_level_reviews_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@
RSpec.describe V1::HigherLevelReviewsController do
let(:user) { build(:user, :loa3) }
let(:headers) { { 'CONTENT_TYPE' => 'application/json' } }
let(:success_log_args) do
{
message: 'Overall claim submission success!',
user_uuid: user.uuid,
action: 'Overall claim submission',
form_id: '996',
upstream_system: nil,
downstream_system: 'Lighthouse',
is_success: true,
http: {
status_code: 200,
body: '[Redacted]'
}
}
end
let(:error_log_args) do
{
message: 'Overall claim submission failure!',
user_uuid: user.uuid,
action: 'Overall claim submission',
form_id: '996',
upstream_system: nil,
downstream_system: 'Lighthouse',
is_success: false,
http: {
status_code: 422,
body: anything
}
}
end

before { sign_in_as(user) }

Expand All @@ -25,6 +55,12 @@ def personal_information_logs
# Create an InProgressForm
in_progress_form = create(:in_progress_form, user_uuid: user.uuid, form_id: '20-0996')
expect(in_progress_form).not_to be_nil

allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with(success_log_args)
allow(StatsD).to receive(:increment)
expect(StatsD).to receive(:increment).with('decision_review.form_996.overall_claim_submission.success')

subject
expect(response).to be_successful
appeal_uuid = JSON.parse(response.body)['data']['id']
Expand All @@ -38,6 +74,12 @@ def personal_information_logs
it 'adds to the PersonalInformationLog when an exception is thrown' do
VCR.use_cassette('decision_review/HLR-CREATE-RESPONSE-422_V1') do
expect(personal_information_logs.count).to be 0

allow(Rails.logger).to receive(:error)
expect(Rails.logger).to receive(:error).with(error_log_args)
allow(StatsD).to receive(:increment)
expect(StatsD).to receive(:increment).with('decision_review.form_996.overall_claim_submission.failure')

subject
expect(personal_information_logs.count).to be 1
pil = personal_information_logs.first
Expand Down

0 comments on commit a4dd1de

Please sign in to comment.