Allow to better debug initialize connection

What does this MR do and why?

Allow to better debug initialize connection

Enable optional debugging of unexpected DB connections during route initialization. The backtrace was only logged if rails was not in production mode. This can now be overriden by setting SKIP_DEBUG_INITIALIZE_CONNECTIONS as envionment variable.

Relates https://gitlab.com/gitlab-com/request-for-help/-/work_items/4019

Testing

  1. Set rails into production mode
  2. Add Project.first somewhere in config/routes/api.rb.
  3. Confirm the startup fails with RuntimeError: Database connection should not be called during initializers.
  4. Set SKIP_DEBUG_INITIALIZE_CONNECTIONS=off and GITLAB_LOG_LEVEL=debug
  5. Confirm startup continues to fail, but with a
  6. Confirm "InitializerConnections Backtrace is logged

References

Screenshots or screen recordings

Before After

How to set up and validate locally

MR acceptance checklist

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

Edited by Clemens Beck

Merge request reports

Loading