Commit 3c86b08a authored by Dylan Griffith's avatar Dylan Griffith

Add logging to error in Elastic::IndexRecordService

parent f91c27a2
......@@ -22,13 +22,16 @@ module Elastic
update_issue_notes(record, options["changed_fields"]) if record.class == Issue
true
rescue Elasticsearch::Transport::Transport::Errors::NotFound, ActiveRecord::RecordNotFound
rescue Elasticsearch::Transport::Transport::Errors::NotFound, ActiveRecord::RecordNotFound => e
# These errors can happen in several cases, including:
# - A record is updated, then removed before the update is handled
# - Indexing is enabled, but not every item has been indexed yet - updating
# and deleting the un-indexed records will raise exception
#
# We can ignore these.
logger.error(message: 'elastic_index_record_service_caught_exception', error_class: e.class.name, error_message: e.message)
true
end
......@@ -88,5 +91,9 @@ module Elastic
ids = errors.map { |error| error['index']['_id'][/_(\d+)$/, 1] }
association.id_in(ids).es_import(options)
end
def logger
@logger ||= ::Gitlab::Elasticsearch::Logger.build
end
end
end
......@@ -50,6 +50,14 @@ describe Elastic::IndexRecordService, :elastic do
Gitlab::Elastic::Helper.refresh_index
end.to change { Elasticsearch::Model.search('new').records.size }.by(1)
end
it 'ignores Elasticsearch::Transport::Transport::Errors::NotFound errors' do
object = create(type)
allow(object.__elasticsearch__).to receive(:index_document).and_raise(Elasticsearch::Transport::Transport::Errors::NotFound)
expect(subject.execute(object, true)).to eq(true)
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