Commit a6adcfb7 authored by Dylan Griffith's avatar Dylan Griffith

Improve Gitlab::Elastic::Indexer update logging

These logs can be useful in the event of disaster recovery by replaying
the updates during a period of time from logging information. The
previous format was being blocked before ingestion into our logging
infrastructure likely due to the `wiki` field having an incorrect
format as field names cannot be re-used in our logs without them being
the same type. Either way this new format should not conflict and is
more machine readable than the previous one.
parent bcc83adb
...@@ -38,9 +38,11 @@ module Gitlab ...@@ -38,9 +38,11 @@ module Gitlab
return update_index_status(Gitlab::Git::BLANK_SHA) unless commit return update_index_status(Gitlab::Git::BLANK_SHA) unless commit
repository.__elasticsearch__.elastic_writing_targets.each do |target| repository.__elasticsearch__.elastic_writing_targets.each do |target|
Sidekiq.logger.debug(message: "Indexation running for #{project.id} #{from_sha}..#{commit.sha}", logger.debug(message: "indexing_commit_range",
project_id: project.id, project_id: project.id,
wiki: index_wiki?) from_sha: from_sha,
to_sha: commit.sha,
index_wiki: index_wiki?)
run_indexer!(commit.sha, target) run_indexer!(commit.sha, target)
end end
...@@ -178,10 +180,10 @@ module Gitlab ...@@ -178,10 +180,10 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def update_index_status(to_sha) def update_index_status(to_sha)
unless Project.exists?(id: project.id) unless Project.exists?(id: project.id)
Gitlab::Elasticsearch::Logger.build.debug( logger.debug(
message: 'Index status could not be updated as the project does not exist', message: 'Index status could not be updated as the project does not exist',
project_id: project.id, project_id: project.id,
wiki: index_wiki? index_wiki: index_wiki?
) )
return false return false
end end
...@@ -204,6 +206,10 @@ module Gitlab ...@@ -204,6 +206,10 @@ module Gitlab
project.reload_index_status project.reload_index_status
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def logger
@logger ||= ::Gitlab::Elasticsearch::Logger.build
end
end end
end end
end end
...@@ -396,13 +396,14 @@ RSpec.describe Gitlab::Elastic::Indexer do ...@@ -396,13 +396,14 @@ RSpec.describe Gitlab::Elastic::Indexer do
before do before do
allow(Gitlab::Elasticsearch::Logger).to receive(:build).and_return(logger_double) allow(Gitlab::Elasticsearch::Logger).to receive(:build).and_return(logger_double)
allow(indexer).to receive(:run_indexer!) { Project.where(id: project.id).delete_all } allow(indexer).to receive(:run_indexer!) { Project.where(id: project.id).delete_all }
allow(logger_double).to receive(:debug)
end end
it 'does not raises an exception and prints log message' do it 'does not raises an exception and prints log message' do
expect(logger_double).to receive(:debug).with( expect(logger_double).to receive(:debug).with(
message: 'Index status could not be updated as the project does not exist', message: 'Index status could not be updated as the project does not exist',
project_id: project.id, project_id: project.id,
wiki: false index_wiki: false
) )
expect(IndexStatus).not_to receive(:safe_find_or_create_by!).with(project_id: project.id) expect(IndexStatus).not_to receive(:safe_find_or_create_by!).with(project_id: project.id)
expect { indexer.run }.not_to raise_error expect { indexer.run }.not_to raise_error
......
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