-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit of pcpg work based on exhisting benefits intake zsf wo…
…rk (#19180) * initial commit of pcpg work based on exhisting benefits intake zsf work * rubocop updates * update codeowners * add emails and tests * put back retries * remove zsf from benefits intake * refactor * add test for claim being nil
- Loading branch information
Showing
8 changed files
with
217 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'zero_silent_failures/monitor' | ||
|
||
module PCPG | ||
## | ||
# Monitor functions for Rails logging and StatsD | ||
# | ||
class Monitor < ::ZeroSilentFailures::Monitor | ||
# statsd key for api | ||
CLAIM_STATS_KEY = 'career-guidance-application' | ||
|
||
# statsd key for submit career counseling sidekiq | ||
SUBMISSION_STATS_KEY = 'worker.lighthouse.submit_career_counseling_job' | ||
# statsd key for benefits intake sidekiq | ||
BENEFITS_INTAKE_SUBMISSION_STATS_KEY = 'worker.lighthouse.submit_benefits_intake_claim' | ||
|
||
def initialize | ||
super('career-guidance-application') | ||
end | ||
|
||
def track_submission_exhaustion(msg, claim = nil) | ||
user_account_uuid = msg['args'].length <= 1 ? nil : msg['args'][1] | ||
additional_context = { | ||
form_id: claim&.form_id, | ||
claim_id: msg['args'].first, | ||
confirmation_number: claim&.confirmation_number, | ||
message: msg | ||
} | ||
# log_silent_failure calls the ZSF method which increases a special StatsD metric | ||
# and writes to the Rails log for additional ZSF tracking. | ||
log_silent_failure(additional_context, user_account_uuid, call_location: caller_locations.first) | ||
|
||
StatsD.increment("#{SUBMISSION_STATS_KEY}.exhausted") | ||
Rails.logger.error( | ||
"Failed all retries on SubmitCareerCounselingJob, last error: #{msg['error_message']}", | ||
user_uuid: user_account_uuid, **additional_context | ||
) | ||
end | ||
|
||
def track_benefits_intake_submission_exhaustion(msg, claim = nil) | ||
user_account_uuid = msg['args'].length <= 1 ? nil : msg['args'][1] | ||
additional_context = { | ||
form_id: claim&.form_id, | ||
claim_id: msg['args'].first, | ||
confirmation_number: claim&.confirmation_number, | ||
message: msg | ||
} | ||
# log_silent_failure calls the ZSF method which increases a special StatsD metric | ||
# and writes to the Rails log for additional ZSF tracking. | ||
log_silent_failure(additional_context, user_account_uuid, call_location: caller_locations.first) | ||
|
||
StatsD.increment("#{BENEFITS_INTAKE_SUBMISSION_STATS_KEY}.exhausted") | ||
Rails.logger.error( | ||
'Lighthouse::SubmitBenefitsIntakeClaim PCPG 28-8832 submission to LH exhausted!', | ||
user_uuid: user_account_uuid, **additional_context | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require_relative '../../../lib/pcpg/monitor' | ||
|
||
RSpec.describe PCPG::Monitor do | ||
let(:monitor) { described_class.new } | ||
let(:claim_stats_key) { described_class::CLAIM_STATS_KEY } | ||
let(:submission_stats_key) { described_class::SUBMISSION_STATS_KEY } | ||
let(:benefits_intake_submission_stats_key) { described_class::BENEFITS_INTAKE_SUBMISSION_STATS_KEY } | ||
let(:claim) { create(:education_career_counseling_claim) } | ||
let(:ipf) { create(:in_progress_form) } | ||
|
||
context 'with all params supplied' do | ||
let(:current_user) { create(:user) } | ||
let(:monitor_error) { create(:monitor_error) } | ||
let(:lh_service) { OpenStruct.new(uuid: 'uuid') } | ||
|
||
describe '#track_submission_exhaustion' do | ||
it 'logs sidekiq job exhaustion' do | ||
msg = { 'args' => [claim.id, current_user.uuid], error_message: 'Error!' } | ||
|
||
log = "Failed all retries on SubmitCareerCounselingJob, last error: #{msg['error_message']}" | ||
payload = { | ||
form_id: claim.form_id, | ||
claim_id: claim.id, | ||
confirmation_number: claim.confirmation_number, | ||
message: msg | ||
} | ||
|
||
expect(monitor).to receive(:log_silent_failure).with(payload, current_user.uuid, anything) | ||
expect(StatsD).to receive(:increment).with("#{submission_stats_key}.exhausted") | ||
expect(Rails.logger).to receive(:error).with(log, user_uuid: current_user.uuid, **payload) | ||
|
||
monitor.track_submission_exhaustion(msg, claim) | ||
end | ||
|
||
it 'logs with no claim information if claim is passed in as nil' do | ||
msg = { 'args' => [claim.id, current_user.uuid], error_message: 'Error!' } | ||
|
||
log = "Failed all retries on SubmitCareerCounselingJob, last error: #{msg['error_message']}" | ||
payload = { | ||
form_id: nil, | ||
claim_id: msg['args'].first, | ||
confirmation_number: nil, | ||
message: msg | ||
} | ||
|
||
expect(monitor).to receive(:log_silent_failure).with(payload, current_user.uuid, anything) | ||
expect(StatsD).to receive(:increment).with("#{submission_stats_key}.exhausted") | ||
expect(Rails.logger).to receive(:error).with(log, user_uuid: current_user.uuid, **payload) | ||
|
||
monitor.track_submission_exhaustion(msg, nil) | ||
end | ||
end | ||
|
||
describe '#track_benefits_intake_submission_exhaustion' do | ||
it 'logs sidekiq job exhaustion' do | ||
msg = { 'args' => [claim.id, current_user.uuid] } | ||
|
||
log = 'Lighthouse::SubmitBenefitsIntakeClaim PCPG 28-8832 submission to LH exhausted!' | ||
payload = { | ||
form_id: claim.form_id, | ||
claim_id: claim.id, | ||
confirmation_number: claim.confirmation_number, | ||
message: msg | ||
} | ||
|
||
expect(monitor).to receive(:log_silent_failure).with(payload, current_user.uuid, anything) | ||
expect(StatsD).to receive(:increment).with("#{benefits_intake_submission_stats_key}.exhausted") | ||
expect(Rails.logger).to receive(:error).with(log, user_uuid: current_user.uuid, **payload) | ||
|
||
monitor.track_benefits_intake_submission_exhaustion(msg, claim) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters