Коммит 704d4974 создал по автору Dmitry Gruzd's avatar Dmitry Gruzd Зафиксировано автором Terri Chu
Просмотр файлов

Create new rake task with Advanced Search integration details

Changelog: added
EE: true
владелец b120d413
......@@ -477,6 +477,7 @@ The following are some available Rake tasks:
| Task | Description |
|:--------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`sudo gitlab-rake gitlab:elastic:info`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Outputs debugging information for the Advanced Search intergation. |
| [`sudo gitlab-rake gitlab:elastic:index`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Enables Elasticsearch indexing and run `gitlab:elastic:create_empty_index`, `gitlab:elastic:clear_index_status`, `gitlab:elastic:index_projects`, and `gitlab:elastic:index_snippets`. |
| [`sudo gitlab-rake gitlab:elastic:pause_indexing`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Pauses Elasticsearch indexing. Changes are still tracked. Useful for cluster/index migrations. |
| [`sudo gitlab-rake gitlab:elastic:resume_indexing`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/tasks/gitlab/elastic.rake) | Resumes Elasticsearch indexing. |
......
......@@ -179,8 +179,8 @@ namespace :gitlab do
desc "GitLab | Elasticsearch | Mark last reindexing job as failed"
task mark_reindex_failed: :environment do
if Elastic::ReindexingTask.running?
Elastic::ReindexingTask.current.failure!
if ::Elastic::ReindexingTask.running?
::Elastic::ReindexingTask.current.failure!
puts 'Marked the current reindexing job as failed.'.color(:green)
else
puts 'Did not find the current running reindexing job.'
......@@ -240,6 +240,82 @@ namespace :gitlab do
end
end
desc "GitLab | Elasticsearch | List information about Advanced Search integration"
task info: :environment do
helper = Gitlab::Elastic::Helper.default
setting = ApplicationSetting.current
puts ""
puts "Advanced Search".color(:yellow)
puts "Server version:\t\t#{helper.server_info[:version] || "unknown".color(:red)}"
puts "Server distribution:\t#{helper.server_info[:distribution] || "unknown".color(:red)}"
puts "Indexing enabled:\t#{setting.elasticsearch_indexing ? "yes".color(:green) : "no"}"
puts "Search enabled:\t\t#{setting.elasticsearch_search? ? "yes".color(:green) : "no"}"
puts "Pause indexing:\t\t#{setting.elasticsearch_pause_indexing? ? "yes".color(:yellow) : "no"}"
puts "File size limit:\t#{setting.elasticsearch_indexed_file_size_limit_kb} KiB"
puts ""
puts "Indexing Queues".color(:yellow)
puts "Initial queue:\t\t#{::Elastic::ProcessInitialBookkeepingService.queue_size}"
puts "Incremental queue:\t#{::Elastic::ProcessBookkeepingService.queue_size}"
check_handler do
pending_migrations = ::Elastic::DataMigrationService.pending_migrations
if pending_migrations.any?
puts ""
puts "Pending Migrations".color(:yellow)
pending_migrations.each do |migration|
puts migration.name
end
end
end
check_handler do
current_migration = ::Elastic::MigrationRecord.current_migration
if current_migration
current_state = current_migration.load_state
puts ""
puts "Current Migration".color(:yellow)
puts "Name:\t\t\t#{current_migration.name}"
puts "Started:\t\t#{current_migration.started? ? "yes".color(:green) : "no"}"
puts "Halted:\t\t\t#{current_migration.halted? ? "yes".color(:red) : "no".color(:green)}"
puts "Failed:\t\t\t#{current_migration.failed? ? "yes".color(:red) : "no".color(:green)}"
puts "Current state:\t\t#{current_state.to_json}" if current_state.present?
end
end
puts ""
puts "Indices".color(:yellow)
::Elastic::IndexSetting.order(:alias_name).each do |index_setting|
setting = begin
helper.client.indices.get_settings(index: index_setting.alias_name)
rescue StandardError
puts " - failed to load indices for #{index_setting.alias_name}".color(:red)
{}
end
setting.sort.each do |index_name, hash|
puts "- #{index_name}:"
puts " number_of_shards: #{hash.dig('settings', 'index', 'number_of_shards')}"
puts " number_of_replicas: #{hash.dig('settings', 'index', 'number_of_replicas')}"
(hash.dig('settings', 'index', 'blocks') || {}).each do |block, value|
next unless value == 'true'
puts " blocks.#{block}: yes".color(:red)
end
end
end
end
def check_handler(&blk)
yield
rescue StandardError => e
puts "An exception occurred during the retrieval of the data: #{e.class}: #{e.message}".color(:red)
end
def project_id_batches(&blk)
relation = Project.all
......@@ -263,9 +339,9 @@ namespace :gitlab do
end
def trigger_cluster_reindexing
Elastic::ReindexingTask.create!
::Elastic::ReindexingTask.create!
ElasticClusterReindexingCronWorker.perform_async
::ElasticClusterReindexingCronWorker.perform_async
puts 'Reindexing job was successfully scheduled'.color(:green)
rescue PG::UniqueViolation, ActiveRecord::RecordNotUnique
......
......@@ -383,4 +383,106 @@
end
end
end
describe 'info' do
subject { run_rake_task('gitlab:elastic:info') }
let(:settings) { ::Gitlab::CurrentSettings }
before do
settings.update!(elasticsearch_search: true, elasticsearch_indexing: true)
end
it 'outputs server version' do
expect { subject }.to output(/Server version:\s+\d+.\d+.\d+/).to_stdout
end
it 'outputs server distribution' do
expect { subject }.to output(/Server distribution:\s+\w+/).to_stdout
end
it 'outputs indexing and search settings' do
expect { subject }.to output(/Indexing enabled:\syes\s+Search enabled:\s+yes/).to_stdout
end
it 'outputs queue sizes' do
allow(Elastic::ProcessInitialBookkeepingService).to receive(:queue_size).and_return(100)
allow(Elastic::ProcessBookkeepingService).to receive(:queue_size).and_return(200)
expect { subject }.to output(/Initial queue:\s+100\s+Incremental queue:\s+200/).to_stdout
end
it 'outputs pending migrations' do
migration = instance_double(
Elastic::MigrationRecord,
name: 'TestMigration',
started?: true,
halted?: false,
failed?: false,
load_state: { test: 'value' }
)
allow(::Elastic::DataMigrationService).to receive(:pending_migrations).and_return([migration])
expect { subject }.to output(
/Pending Migrations\s+#{migration.name}/
).to_stdout
end
it 'outputs current migration' do
migration = instance_double(
Elastic::MigrationRecord,
name: 'TestMigration',
started?: true,
halted?: false,
failed?: false,
load_state: { test: 'value' }
)
allow(Elastic::MigrationRecord).to receive(:current_migration).and_return(migration)
expect { subject }.to output(
/Name:\s+TestMigration\s+Started:\s+yes\s+Halted:\s+no\s+Failed:\s+no\s+Current state:\s+{"test":"value"}/
).to_stdout
end
context 'with index settings' do
let(:setting) do
Elastic::IndexSetting.new(number_of_replicas: 1, number_of_shards: 8, alias_name: 'gitlab-development')
end
before do
allow(Elastic::IndexSetting).to receive(:order).and_return([setting])
end
it 'outputs failed index setting' do
allow(es_helper.client).to receive(:indices).and_raise(Timeout::Error)
expect { subject }.to output(
/failed to load indices for gitlab-development/
).to_stdout
end
it 'outputs index settings' do
indices = instance_double(Elasticsearch::API::Indices::IndicesClient)
allow(es_helper.client).to receive(:indices).and_return(indices)
allow(indices).to receive(:get_settings).with(index: setting.alias_name).and_return({
setting.alias_name => {
"settings" => {
"index" => {
"number_of_shards" => 5,
"number_of_replicas" => 1,
"blocks" => {
"write" => 'true'
}
}
}
}
})
expect { subject }.to output(
/#{setting.alias_name}:\s+number_of_shards: 5\s+number_of_replicas: 1\s+blocks\.write: yes/
).to_stdout
end
end
end
end
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать