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

report MOAB_NOT_FOUND errors to honeybadger #1532

Merged
merged 1 commit into from
May 13, 2020
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
1 change: 1 addition & 0 deletions app/services/audit_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AuditResults

HONEYBADGER_REPORT_CODES = [
MOAB_FILE_CHECKSUM_MISMATCH,
MOAB_NOT_FOUND,
ZIP_PART_CHECKSUM_MISMATCH,
ZIP_PART_NOT_FOUND,
ZIP_PARTS_COUNT_DIFFERS_FROM_ACTUAL,
Expand Down
19 changes: 18 additions & 1 deletion spec/lib/audit/catalog_to_moab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
results_as_string: nil)
end
let(:exp_details_prefix) { 'check_catalog_version (actual location: fixture_sr1; ' }
let(:events_client) { instance_double(Dor::Services::Client::Events) }
let(:hb_exp_msg) do
'check_catalog_version\\(bj102hs9687, fixture_sr1\\)' \
' db CompleteMoab \\(created .*Z; last updated .*Z\\) exists but Moab not found'
end

before do
allow(WorkflowReporter).to receive(:report_error)
Expand Down Expand Up @@ -79,12 +84,24 @@
end

it 'calls online_moab_found?' do
allow(Dor::Services::Client).to receive(:object).with("druid:#{druid}").and_return(
instance_double(Dor::Services::Client::Object, events: events_client)
)
allow(Honeybadger).to receive(:notify).with(Regexp.new(hb_exp_msg))
allow(events_client).to receive(:create).with(type: 'preservation_audit_failure', data: instance_of(Hash))
expect(c2m).to receive(:online_moab_found?)
c2m.check_catalog_version
end

context 'moab is nil (exists in catalog but not online)' do
before { allow(Moab::StorageObject).to receive(:new).with(druid, String).and_return(nil) }
before do
allow(Moab::StorageObject).to receive(:new).with(druid, String).and_return(nil)
allow(Dor::Services::Client).to receive(:object).with("druid:#{druid}").and_return(
instance_double(Dor::Services::Client::Object, events: events_client)
)
allow(Honeybadger).to receive(:notify).with(Regexp.new(hb_exp_msg))
allow(events_client).to receive(:create).with(type: 'preservation_audit_failure', data: instance_of(Hash))
end

it 'adds a MOAB_NOT_FOUND result' do
c2m.instance_variable_set(:@results, results_double)
Expand Down
12 changes: 12 additions & 0 deletions spec/services/audit_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,25 @@
ar.add_result(result_code, addl)
ar
}
let(:events_client) { instance_double(Dor::Services::Client::Events) }
let(:reason) { "db CompleteMoab \\(created #{create_date}; last updated #{update_date}\\) exists but Moab not found" }
let(:exp_msg) { "\\(ab123cd4567, fixture_sr1\\) #{reason}" }

before do
allow(Honeybadger).to receive(:notify)
allow(Dor::Services::Client).to receive(:object).and_return(
instance_double(Dor::Services::Client::Object, events: events_client)
)
allow(events_client).to receive(:create).with(type: 'preservation_audit_failure', data: instance_of(Hash))
end

it 'message sent includes CompleteMoab create date' do
expected = Regexp.escape("db CompleteMoab (created #{create_date}")
expect(WorkflowReporter).to receive(:report_error).with(
druid, actual_version, 'preservation-audit', ms_root, a_string_matching(expected)
)
my_audit_results.report_results
expect(Honeybadger).to have_received(:notify).with(Regexp.new(exp_msg))
end

it 'message sent includes CompleteMoab updated date' do
Expand Down
28 changes: 28 additions & 0 deletions spec/services/checksum_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,17 @@

describe '#validate_checksums' do
context 'moab is missing from storage' do
let(:events_client) { instance_double(Dor::Services::Client::Events) }

before do
# fake a moab gone missing by updating the preserved object to use a non-existent druid
comp_moab.preserved_object.update(druid: 'tr808sp1200')
allow(Honeybadger).to receive(:notify)
allow(Dor::Services::Client).to receive(:object).with("druid:tr808sp1200").and_return(
instance_double(Dor::Services::Client::Object, events: events_client)
)
allow(Honeybadger).to receive(:notify)
allow(events_client).to receive(:create).with(type: 'preservation_audit_failure', data: instance_of(Hash))
end

it 'sets status to online_moab_not_found and adds corresponding audit result' do
Expand All @@ -216,6 +224,26 @@
expect(cv.results.result_array.first).to have_key(:moab_not_found)
end

it 'sends results in HONEYBADGER_REPORT_CODES errors' do
reason = "db CompleteMoab \\(created .*Z; last updated .*Z\\) exists but Moab not found"
exp_msg = "validate_checksums\\(tr808sp1200, fixture_sr3\\) #{reason}"
cv.validate_checksums

expect(Honeybadger).to have_received(:notify).with(Regexp.new(exp_msg))
expect(events_client).to have_received(:create).once.with(
type: 'preservation_audit_failure',
data: {
host: instance_of(String),
invoked_by: 'preservation-catalog',
storage_root: ms_root.name,
actual_version: 0,
check_name: 'validate_checksums',
error_result: { moab_not_found: a_string_matching(reason) }
}
)
expect(Dor::Services::Client).to have_received(:object).with("druid:tr808sp1200").once
end

it 'calls AuditResults.report_results' do
expect(cv.results).to receive(:report_results)
cv.validate_checksums
Expand Down