Commit 5381ebf0 authored by Terri Chu's avatar Terri Chu Committed by Gabriel Mazetto

Use Gitlab::ErrorTracking to log, track, & raise instead of logger

Indexing projects with a missing project_feature object is throwing
an error. Move to using Gitlab::ErrorTracking in place of
project.logger.
parent aad8b990
---
title: Use Gitlab::ErrorTracking in place of project.logger for indexing errors
merge_request: 39979
author:
type: fixed
...@@ -44,9 +44,8 @@ module Elastic ...@@ -44,9 +44,8 @@ module Elastic
# When this happens, log the errors to help with debugging, and raise the error to prevent indexing bad data # When this happens, log the errors to help with debugging, and raise the error to prevent indexing bad data
TRACKED_FEATURE_SETTINGS.each do |feature| TRACKED_FEATURE_SETTINGS.each do |feature|
data[feature] = target.project_feature.public_send(feature) # rubocop:disable GitlabSecurity/PublicSend data[feature] = target.project_feature.public_send(feature) # rubocop:disable GitlabSecurity/PublicSend
rescue NoMethodError => err rescue NoMethodError => e
target.logger.error("Elasticsearch failed to read feature #{feature} for #{target.class} #{target.id}: #{err}") Gitlab::ErrorTracking.track_and_raise_exception(e, project_id: target.id, feature: feature)
raise
end end
data data
......
...@@ -33,7 +33,10 @@ RSpec.describe Elastic::Latest::ProjectInstanceProxy do ...@@ -33,7 +33,10 @@ RSpec.describe Elastic::Latest::ProjectInstanceProxy do
it 'raises an error for a project with an empty project_feature' do it 'raises an error for a project with an empty project_feature' do
allow(project).to receive(:project_feature).and_return(nil) allow(project).to receive(:project_feature).and_return(nil)
expect(project.logger).to receive(:error) expect(Gitlab::ErrorTracking).to receive(:track_and_raise_exception).with(
NoMethodError,
project_id: project.id,
feature: 'issues_access_level').and_call_original
expect { subject.as_indexed_json }.to raise_error NoMethodError expect { subject.as_indexed_json }.to raise_error NoMethodError
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment