Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBEX] log when Form 0781 document upload fails #17625

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/lighthouse526_document_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Lighthouse526DocumentUpload < ApplicationRecord
end
end

def form0781_types?
[FORM_0781_DOCUMENT_TYPE, FORM_0781A_DOCUMENT_TYPE].include?(document_type)
end

private

def veteran_upload?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,52 @@ def update_documents_status

def update_document_status(status)
document_upload = @lighthouse526_document_uploads.find_by!(lighthouse_document_request_id: status['requestId'])
statsd_document_base_key(STATSD_DOCUMENT_TYPE_KEY_MAP[document_upload.document_type])

# UploadStatusUpdater encapsulates all parsing of a status response from Lighthouse
status_updater = BenefitsDocuments::Form526::UploadStatusUpdater.new(status, document_upload)
status_updater.update_status

statsd_document_type_key = STATSD_DOCUMENT_TYPE_KEY_MAP[document_upload.document_type]
statsd_document_base_key = "#{STATSD_BASE_KEY}.#{statsd_document_type_key}"
status_updater(status, document_upload)
@status_updater.update_status

if document_upload.completed?
# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.complete'
StatsD.increment("#{statsd_document_base_key}.#{STATSD_DOCUMENT_COMPLETE_KEY}")
StatsD.increment("#{@statsd_document_base_key}.#{STATSD_DOCUMENT_COMPLETE_KEY}")
elsif document_upload.failed?
# Because Lighthouse's processing steps are subject to change, these metrics must be dyanmic.
# Currently, this should return either claims_evidence or benefits_gateway_service
failure_step_key = status_updater.get_failure_step.downcase

# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.failed.claims_evidence'
StatsD.increment("#{statsd_document_base_key}.#{STATSD_DOCUMENT_FAILED_KEY}.#{failure_step_key}")
elsif status_updater.processing_timeout?
log_failure(document_upload)
elsif @status_updater.processing_timeout?
# Triggered when a document is still pending more than 24 hours after processing began
# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.processing_timeout'
StatsD.increment("#{statsd_document_base_key}.#{STATSD_PROCESSING_TIMEOUT_KEY}")
StatsD.increment("#{@statsd_document_base_key}.#{STATSD_PROCESSING_TIMEOUT_KEY}")
end
end

def status_updater(status, document_upload)
# UploadStatusUpdater encapsulates all parsing of a status response from Lighthouse
@status_updater ||= BenefitsDocuments::Form526::UploadStatusUpdater.new(status, document_upload)
end

def statsd_document_base_key(statsd_document_type_key)
@statsd_document_base_key ||= "#{STATSD_BASE_KEY}.#{statsd_document_type_key}"
end

def log_failure(document_upload)
Comment on lines +83 to +93
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like that you pulled out some logic fromupdate_document_status and made these methods 🎉

# Because Lighthouse's processing steps are subject to change, these metrics must be dynamic.
# Currently, this should return either CLAIMS_EVIDENCE or BENEFITS_GATEWAY_SERVICE
failure_step = @status_updater.get_failure_step

# ex. 'api.form526.lighthouse_document_upload_processing_status.bdd_instructions.failed.claims_evidence'
StatsD.increment("#{@statsd_document_base_key}.#{STATSD_DOCUMENT_FAILED_KEY}.#{failure_step.downcase}")
return unless document_upload.form0781_types?

submission = document_upload.form526_submission
Rails.logger.warn(
'Benefits Documents API responded with a failed document upload status', {
form526_submission_id: submission.id,
document_type: document_upload.document_type,
failure_step:,
lighthouse_document_request_id: document_upload.lighthouse_document_request_id,
user_uuid: submission.user_uuid
}
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,49 @@ def mock_success_response(request_id)
'api.form526.lighthouse_document_upload_processing_status.veteran_upload.complete'
end
end

describe 'logging when Form 0781 document upload fails' do
let(:form0781_document_upload) { create(:lighthouse526_document_upload, document_type: 'Form 0781') }
let(:uploads) { Lighthouse526DocumentUpload.where(id: form0781_document_upload.id) }
let(:status_response) do
{
'data' => {
'statuses' => [
{
'requestId' => form0781_document_upload.lighthouse_document_request_id,
'status' => 'FAILED',
'time' => { 'startTime' => 499_152_030, 'endTime' => 499_152_060 },
'steps' => [
{ 'name' => 'CLAIMS_EVIDENCE', 'status' => 'FAILED' },
{ 'name' => 'BENEFITS_GATEWAY_SERVICE', 'status' => 'NOT_STARTED' }
],
'error' => { 'detail' => 'VBMS System Outage', 'step' => 'CLAIMS_EVIDENCE' }
}
]
}
}
end

let(:submission) { form0781_document_upload.form526_submission }

before do
allow_any_instance_of(BenefitsDocuments::Form526::UploadStatusUpdater).to receive(:update_status)
allow_any_instance_of(Lighthouse526DocumentUpload).to receive(:failed?).and_return(true)
allow(Rails.logger).to receive(:warn)
end

it 'logs the latest_status_response to the Rails logger' do
described_class.call(uploads, status_response)

expect(Rails.logger).to have_received(:warn).with(
'Benefits Documents API responded with a failed document upload status', {
form526_submission_id: submission.id,
document_type: form0781_document_upload.document_type,
failure_step: 'CLAIMS_EVIDENCE',
lighthouse_document_request_id: form0781_document_upload.lighthouse_document_request_id,
user_uuid: submission.user_uuid
}
)
end
end
end
16 changes: 16 additions & 0 deletions spec/models/lighthouse526_document_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,21 @@
end
end
end

describe '#form0781_types?' do
it 'returns true for Form 0781 and Form 0781a document types' do
['Form 0781', 'Form 0781a'].each do |document_type|
upload = build(:lighthouse526_document_upload, document_type:)
expect(upload.form0781_types?).to be(true)
end
end

it 'returns false for other document types' do
['BDD Instructions', 'Veteran Upload'].each do |document_type|
upload = build(:lighthouse526_document_upload, document_type:)
expect(upload.form0781_types?).to be(false)
end
end
end
end
end
Loading