Move settings writers to writable_application_settings

What does this MR do and why?

Related to #640053.

This is the first step split out of !272809, as asked in this comment. !272809 will rebase onto it once it is merged.

Code that writes the application settings record currently gets it from Gitlab::CurrentSettings.current_application_settings, the same accessor that readers use, or calls Gitlab::CurrentSettings.update(!) through method_missing. This MR separates the writers from the readers:

  • Gitlab::CurrentSettings.writable_application_settings returns the ApplicationSetting record with the same request-store memoization as before. current_application_settings calls it, so readers still get the same object.
  • Gitlab::CurrentSettings.update and update! are explicit methods that write through writable_application_settings. Before, they went through method_missing.
  • Code that writes the record now uses writable_application_settings or Gitlab::CurrentSettings.update(!): services, workers, rake helpers, and fixtures that call update, update!, update_columns, save, with_lock, reset, or setters, or that pass the record to ApplicationSettings::UpdateService. Readers do not change.

Behaviour does not change: both accessors return the same object. With this in place, !272809 only has to change what current_application_settings returns.

Not included, because they do not write the record: SecretsManagement::InstanceEnrollment.fallback_settings (it returns a read-only copy), the markdown_field views, and the Elasticsearch invalidate_elasticsearch_indexes_cache*! calls (they only clear a Rails cache).

Measurements

None. This refactor changes no request path. The saving comes with !272809.

Testing

bundle exec rspec spec/lib/gitlab/current_settings_spec.rb

This covers the new methods: writable_application_settings returns the object that current_application_settings returns, update and update! persist through it, and an invalid write returns false or raises. The specs of each changed writer were updated where they stubbed or wrote through current_application_settings.

Production monitoring

I do not have access to GitLab.com logs. No metric should move: both accessors return the same object. To catch a regression, someone with access can compare the 24 hours before and after the deploy in Kibana (log.gprd.gitlab.net). Check the field names against the index pattern first:

json.exception.class : "NoMethodError" and json.exception.message : *CurrentSettings*
json.class : "Search::Elastic::TriggerIndexingWorker" and json.job_status : "fail"

The first query is on pubsub-rails-inf-gprd* and the second on pubsub-sidekiq-inf-gprd*. Read the count for each. A rise means a writer lost access to a settings method.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.


Generated by GitLab Performance Optimisation

Merge request reports

Loading
Loading