From a2bc64b5f4ab52c1226390f753f3cc202a6db3ac Mon Sep 17 00:00:00 2001 From: Nathan Burgess Date: Thu, 3 Oct 2024 12:23:30 -0400 Subject: [PATCH] Add notification email dispatch logging (#18726) The Form0781DocumentUploadFailureEmail and Form4142DocumentUploadFailureEmail jobs are used to send VA Notify emails to Veterans when those respective forms fail to upload to EVSS so they can do a manual workaround These jobs were missing a logging statement for dispatching the email, which we want to use in DataDog to monitor the frequency and success rate of sending these emails --- .../form0781_document_upload_failure_email.rb | 14 ++++++++++- .../form4142_document_upload_failure_email.rb | 14 ++++++++++- ...0781_document_upload_failure_email_spec.rb | 24 ++++++++++++++++--- ...4142_document_upload_failure_email_spec.rb | 24 ++++++++++++++++--- 4 files changed, 68 insertions(+), 8 deletions(-) diff --git a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb index 2d6f2100bfa..e8dddf518ca 100644 --- a/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email.rb @@ -80,7 +80,7 @@ def perform(form526_submission_id) } ) - StatsD.increment("#{STATSD_METRIC_PREFIX}.success") + log_mailer_dispatch(form526_submission_id) end rescue => e retryable_error_handler(e) @@ -95,6 +95,18 @@ def retryable_error_handler(error) raise error end + def log_mailer_dispatch(form526_submission_id) + Rails.logger.info( + 'Form0781DocumentUploadFailureEmail notification dispatched', + { + form526_submission_id:, + timestamp: Time.now.utc + } + ) + + StatsD.increment("#{STATSD_METRIC_PREFIX}.success") + end + def mailer_template_id Settings.vanotify.services .benefits_disability.template_id.form0781_upload_failure_notification_template_id diff --git a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb index d11cc350c69..779ca4807d4 100644 --- a/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb +++ b/app/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email.rb @@ -80,7 +80,7 @@ def perform(form526_submission_id) } ) - StatsD.increment("#{STATSD_METRIC_PREFIX}.success") + log_mailer_dispatch(form526_submission_id) end rescue => e retryable_error_handler(e) @@ -95,6 +95,18 @@ def retryable_error_handler(error) raise error end + def log_mailer_dispatch(form526_submission_id) + Rails.logger.info( + 'Form4142DocumentUploadFailureEmail notification dispatched', + { + form526_submission_id:, + timestamp: Time.now.utc + } + ) + + StatsD.increment("#{STATSD_METRIC_PREFIX}.success") + end + def mailer_template_id Settings.vanotify.services .benefits_disability.template_id.form4142_upload_failure_notification_template_id diff --git a/spec/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email_spec.rb b/spec/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email_spec.rb index ae5368ae944..fc0c445f1ae 100644 --- a/spec/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/form0781_document_upload_failure_email_spec.rb @@ -38,9 +38,11 @@ end describe 'logging' do - it 'increments a Statsd metric' do + before do allow(notification_client).to receive(:send_email) + end + it 'increments a Statsd metric' do expect do subject.perform_async(form526_submission.id) subject.drain @@ -49,9 +51,25 @@ ) end - it 'creates a Form526JobStatus' do - allow(notification_client).to receive(:send_email) + it 'logs to the Rails logger' do + allow(Rails.logger).to receive(:info) + exhaustion_time = Time.new(1985, 10, 26).utc + Timecop.freeze(exhaustion_time) do + subject.perform_async(form526_submission.id) + subject.drain + + expect(Rails.logger).to have_received(:info).with( + 'Form0781DocumentUploadFailureEmail notification dispatched', + { + form526_submission_id: form526_submission.id, + timestamp: exhaustion_time + } + ) + end + end + + it 'creates a Form526JobStatus' do expect do subject.perform_async(form526_submission.id) subject.drain diff --git a/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb b/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb index 706fdfbd089..58a5fe2ee4e 100644 --- a/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb +++ b/spec/sidekiq/evss/disability_compensation_form/form4142_document_upload_failure_email_spec.rb @@ -38,9 +38,11 @@ end describe 'logging' do - it 'increments a Statsd metric' do + before do allow(notification_client).to receive(:send_email) + end + it 'increments a Statsd metric' do expect do subject.perform_async(form526_submission.id) subject.drain @@ -49,9 +51,25 @@ ) end - it 'creates a Form526JobStatus' do - allow(notification_client).to receive(:send_email) + it 'logs to the Rails logger' do + allow(Rails.logger).to receive(:info) + exhaustion_time = Time.new(1985, 10, 26).utc + Timecop.freeze(exhaustion_time) do + subject.perform_async(form526_submission.id) + subject.drain + + expect(Rails.logger).to have_received(:info).with( + 'Form4142DocumentUploadFailureEmail notification dispatched', + { + form526_submission_id: form526_submission.id, + timestamp: exhaustion_time + } + ) + end + end + + it 'creates a Form526JobStatus' do expect do subject.perform_async(form526_submission.id) subject.drain