Add application setting for elasticsearch retry on failure

What does this MR do and why?

Configure Elasticsearch Ruby client without ret... (!67273 - merged) set the number of retry on failures for Elasticsearch requests to 0 if ::Gitlab::CurrentSettings.elasticsearch_config[:retry_on_failure] is not set but we never added the retry_on_failure application setting. Some customers have asked for this setting in order to retry elasticsearch requests when they have failover hosts configured and this is also recommended by Elasticsearch docs:

Screenshot_2024-10-21_at_12.10.23

This MR:

  • Adds a new application setting called elasticsearch_retry_on_failure - integer, default to 0, not null, validation for >= 0
  • Passes the setting to the Elasticsearch client builder so that every Elasticsearch request has this retry_on_failure set (it's currently always set to 0)
  • Allows admins to set this setting on the search settings page

It closes Allow admin to configure Elasticsearch client r... (#337588 - closed) and part of Make sure we use retry_on_failure option for s... (#486935 - closed).

#486935 (closed) proposes to always set retry_on_failure to 1 for search requests only but that can be done separately.

Side note: we should consolidate all elasticsearch settings into one jsonb setting according to the developer docs. I created Consolidate elasticsearch application settings ... (#500267 - closed) for this.

Database review

This MR adds a migration to add a column to application_settings table.

  • Migration reversable: up and down methods provided

db:gitlabcom-database-testing output: !169903 (comment 2170772690)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Admin search settings page:

Screenshot_2024-10-22_at_13.08.43

How to set up and validate locally

  1. On master, check that Gitlab::Elastic::Helper.default.client.transport.transport.options[:retry_on_failure] is 0
  2. Checkout this branch
  3. Execute migration: bundle exec rake db:migrate:up:main VERSION=20241021084712
  4. Check that ::Gitlab::CurrentSettings.elasticsearch_config[:retry_on_failure] is 0
  5. Check that Gitlab::Elastic::Helper.default.client.transport.transport.options[:retry_on_failure] is 0
  6. Change the setting in the UI at http://localhost:3000/admin/application_settings/advanced_search
  7. Check that ::Gitlab::CurrentSettings.elasticsearch_config[:retry_on_failure] is changed
  8. Check that Gitlab::Elastic::Helper.default.client.transport.transport.options[:retry_on_failure] is changed
  9. Undo migration: bundle exec rake db:migrate:down:main VERSION=20241021084712

Related to #486935 (closed)

Edited by Madelein van Niekerk

Merge request reports

Loading