Skip to content

Commit

Permalink
Created two separate methods for failures and exhausted failures
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshingYou1 committed Sep 6, 2024
1 parent 0ec91d8 commit 878153c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 44 deletions.
5 changes: 2 additions & 3 deletions app/sidekiq/hca/ezr_submission_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class EzrSubmissionJob
sidekiq_options retry: 14

sidekiq_retries_exhausted do |msg, _e|
Form1010Ezr::Service.new(nil).log_submission_failure(
decrypt_form(msg['args'][0]),
retries_exhausted: true
Form1010Ezr::Service.new(nil).log_exhausted_submission_failure(
decrypt_form(msg['args'][0])
)
end

Expand Down
31 changes: 25 additions & 6 deletions lib/form1010_ezr/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,41 @@ def submit_form(parsed_form)
log_and_raise_error(e, parsed_form)
end

def log_submission_failure(parsed_form, retries_exhausted: false)
StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.failed#{'_wont_retry' if retries_exhausted}")
def log_submission_failure(parsed_form)
StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.failed")

if parsed_form.present?
PersonalInformationLog.create!(
data: parsed_form,

Check failure

Code scanning / CodeQL

Clear-text storage of sensitive information High

This stores sensitive data returned by
a write to veteranDateOfBirth
as clear text.
This stores sensitive data returned by
a write to veteranSocialSecurityNumber
as clear text.
error_class: "Form1010Ezr Failed#{'WontRetry' if retries_exhausted}"
error_class: 'Form1010Ezr Failed'
)

failure_message = "1010EZR #{'total ' if retries_exhausted}failure"
failure_message = '1010EZR failure'

Check failure on line 76 in lib/form1010_ezr/service.rb

View workflow job for this annotation

GitHub Actions / Linting and Security

Lint/UselessAssignment: Useless assignment to variable - `failure_message`.

log_message_to_sentry(
failure_message,
'1010EZR failure',
:error,
veteran_initials(parsed_form),
ezr: retries_exhausted ? :total_failure : :failure
ezr: :failure
)
end
end

# When a submission runs out of retry attempts
def log_exhausted_submission_failure(parsed_form)
StatsD.increment("#{Form1010Ezr::Service::STATSD_KEY_PREFIX}.failed_wont_retry")

if parsed_form.present?
PersonalInformationLog.create!(
data: parsed_form,
error_class: 'Form1010Ezr FailedWontRetry'
)

log_message_to_sentry(
'1010EZR total failure',
:error,
veteran_initials(parsed_form),
ezr: :total_failure
)
end
end
Expand Down
78 changes: 43 additions & 35 deletions spec/lib/form1010_ezr/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,48 +175,56 @@ def expect_personal_info_log(message)
end

context "when 'parsed_form' is present" do
context "when 'retries_exhausted' is false" do
it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a failure message to sentry" do
# The names for these errors will not include 'total' or 'wont_retry' as they are not for total failures
allow(StatsD).to receive(:increment)
expect(StatsD).to receive(:increment).with('api.1010ezr.failed')
expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with(
'1010EZR failure',
:error,
{
first_initial: 'F',
middle_initial: 'M',
last_initial: 'Z'
},
ezr: :failure
)
it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a failure message to sentry" do
allow(StatsD).to receive(:increment)
expect(StatsD).to receive(:increment).with('api.1010ezr.failed')
expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with(
'1010EZR failure',
:error,
{
first_initial: 'F',
middle_initial: 'M',
last_initial: 'Z'
},
ezr: :failure
)

described_class.new(nil).log_submission_failure(form)
described_class.new(nil).log_submission_failure(form)

expect_personal_info_log('Form1010Ezr Failed')
end
expect_personal_info_log('Form1010Ezr Failed')
end
end
end

context "when 'retries_exhausted' is true" do
it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a TOTAL failure message to sentry" do
allow(StatsD).to receive(:increment)
describe '#log_exhausted_submission_failure' do
context "when 'parsed_form' is not present" do
it 'only increments StatsD' do
allow(StatsD).to receive(:increment)
expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry')

expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry')
expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with(
'1010EZR total failure',
:error,
{
first_initial: 'F',
middle_initial: 'M',
last_initial: 'Z'
},
ezr: :total_failure
)
described_class.new(nil).log_exhausted_submission_failure(nil)
end
end

described_class.new(nil).log_submission_failure(form, retries_exhausted: true)
context "when 'parsed_form' is present" do
it "increments StatsD, creates a 'PersonalInformationLog' record, and logs a failure message to sentry" do
allow(StatsD).to receive(:increment)

expect_personal_info_log('Form1010Ezr FailedWontRetry')
end
expect(StatsD).to receive(:increment).with('api.1010ezr.failed_wont_retry')
expect_any_instance_of(SentryLogging).to receive(:log_message_to_sentry).with(
'1010EZR total failure',
:error,
{
first_initial: 'F',
middle_initial: 'M',
last_initial: 'Z'
},
ezr: :total_failure
)

described_class.new(nil).log_exhausted_submission_failure(form)

expect_personal_info_log('Form1010Ezr FailedWontRetry')
end
end
end
Expand Down

0 comments on commit 878153c

Please sign in to comment.