Skip to content

Fix TestLogger.logger to handle different ActiveSupport versions

Mark Lapierre requested to merge ml-handle-different-broadcast-loggers into master

What does this MR do and why?

Allows gitlab-qa to be used with activesupport versions <> 7.1.

!1254 (merged) changed TestLogger to use the new ActiveSupport::BroadcastLogger (introduced in https://github.com/rails/rails/pull/48615 in Rails 7.1). That was done to fix a NoMethodError error made possible by c91ef8df. However, that fix lead to errors when gitlab-qa was used in a bundle with activesupport < 7.1 (e.g. https://gitlab.com/gitlab-org/gitlab/-/jobs/5952342066#L335).

This change first checks for ActiveSupport::BroadcastLogger, and then ActiveSupport::Logger.broadcast, and raises an error if neither is available.

How to set up and validate locally

I did the following to test the two versions of activesupport we had problems with:

  1. Make sure the activesupport version < 7.1
    1. Set spec.add_runtime_dependency 'activesupport', '>= 6.1', '< 7.1' in gitlab-qa.gemspec
    2. Run bundle install
    3. Confirm it shows Using activesupport 7.0.8
  2. Run bundle exec exe/gitlab-qa Test::Instance::Any EE http://gdk.test and confirm it logs something. E.g.:
bundle exec exe/gitlab-qa Test::Instance::Any EE http://gdk.test 

[Jan 18 2024 11:02:57 AEDT (Gitlab QA)] INFO  -- Shell command: `docker pull -q gitlab/gitlab-ee-qa:nightly`
  1. Upgrade the activesupport version >= 7.1
    1. Set spec.add_runtime_dependency 'activesupport', '>= 6.1', '< 7.2' in gitlab-qa.gemspec
    2. Run bundle update activesupport
    3. Confirm it shows Using activesupport 7.1.3 (was 7.0.8)
  2. Run bundle exec exe/gitlab-qa Test::Instance::Any EE http://gdk.test and confirm it logs something again

Pipeline test results

Test staging pipeline: https://ops.gitlab.net/gitlab-org/quality/staging/-/pipelines/2759003
Test gitlab-org/gitlab pipeline (using activesupport 7.0.8): https://gitlab.com/gitlab-org/gitlab/-/pipelines/1142248564

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mark Lapierre

Merge request reports