Commit ab8d9688 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch 'elastic-rake-explain-unindexed' into 'master'

elastic.rake: Ignore unindexed projects that have no repository

See merge request gitlab-org/gitlab!83870
parents 9a00cb7d b5ed9e38
...@@ -160,7 +160,15 @@ namespace :gitlab do ...@@ -160,7 +160,15 @@ namespace :gitlab do
desc "GitLab | Elasticsearch | Display which projects are not indexed" desc "GitLab | Elasticsearch | Display which projects are not indexed"
task projects_not_indexed: :environment do task projects_not_indexed: :environment do
not_indexed = Project.where.not(id: IndexStatus.select(:project_id).distinct) not_indexed = []
Project.where.not(id: IndexStatus.select(:project_id).distinct).each_batch do |batch|
batch.each do |project|
next if !project.repository_exists? || project.empty_repo?
not_indexed << project
end
end
if not_indexed.count == 0 if not_indexed.count == 0
puts 'All projects are currently indexed'.color(:green) puts 'All projects are currently indexed'.color(:green)
...@@ -271,9 +279,7 @@ namespace :gitlab do ...@@ -271,9 +279,7 @@ namespace :gitlab do
projects[1..500] projects[1..500]
end end
arr.each do |p| arr.each { |p| puts "Project '#{p.full_path}' (ID: #{p.id}) isn't indexed.".color(:red) }
puts "Project '#{p.full_path}' (ID: #{p.id}) isn't indexed.".color(:red)
end
puts "#{arr.count} out of #{projects.count} non-indexed projects shown." puts "#{arr.count} out of #{projects.count} non-indexed projects shown."
end end
......
...@@ -348,4 +348,37 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic, :silence_stdout ...@@ -348,4 +348,37 @@ RSpec.describe 'gitlab:elastic namespace rake tasks', :elastic, :silence_stdout
end end
end end
end end
describe 'projects_not_indexed' do
subject { run_rake_task('gitlab:elastic:projects_not_indexed') }
let_it_be(:project) { create(:project, :repository) }
context 'no projects are indexed' do
it 'displays non-indexed projects' do
expected = <<~END
Project '#{project.full_path}' (ID: #{project.id}) isn't indexed.
1 out of 1 non-indexed projects shown.
END
expect { subject }.to output(expected).to_stdout
end
end
context 'all projects are indexed' do
before do
IndexStatus.create!(project: project, indexed_at: Time.current, last_commit: 'foo')
end
it 'displays that all projects are indexed' do
expect { subject }.to output(/All projects are currently indexed/).to_stdout
end
it 'does not include projects without repositories' do
create(:project)
expect { subject }.to output(/All projects are currently indexed/).to_stdout
end
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