From a4dd1de13b2515c50d9becb782676bb4953efb61 Mon Sep 17 00:00:00 2001 From: Annie Tran Date: Wed, 10 Apr 2024 09:27:39 -0500 Subject: [PATCH] [DR-65544] Log KPIs for Higher Level Reviews (create + contestable issues) (#16267) * add success/failure logging for HLR submission * add logging for getting HLR contestable issues * rubocop nits --- lib/decision_review_v1/service.rb | 22 +++++++++- ...testable_issues_controller_request_spec.rb | 36 +++++++++++++++- ...r_level_reviews_controller_request_spec.rb | 42 +++++++++++++++++++ 3 files changed, 97 insertions(+), 3 deletions(-) diff --git a/lib/decision_review_v1/service.rb b/lib/decision_review_v1/service.rb index 86eee1cf5ef..4c246bd91e6 100644 --- a/lib/decision_review_v1/service.rb +++ b/lib/decision_review_v1/service.rb @@ -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)' @@ -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, diff --git a/spec/requests/v1/higher_level_reviews/contestable_issues_controller_request_spec.rb b/spec/requests/v1/higher_level_reviews/contestable_issues_controller_request_spec.rb index ca5cf924ffd..cf00f1818e2 100644 --- a/spec/requests/v1/higher_level_reviews/contestable_issues_controller_request_spec.rb +++ b/spec/requests/v1/higher_level_reviews/contestable_issues_controller_request_spec.rb @@ -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) } @@ -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 @@ -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 diff --git a/spec/requests/v1/higher_level_reviews_controller_request_spec.rb b/spec/requests/v1/higher_level_reviews_controller_request_spec.rb index d9e8acc6a40..27f38a67162 100644 --- a/spec/requests/v1/higher_level_reviews_controller_request_spec.rb +++ b/spec/requests/v1/higher_level_reviews_controller_request_spec.rb @@ -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) } @@ -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'] @@ -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