Skip to content

Fix broken reports_daemon specs

Aleksei Lipniagov requested to merge 372850-fix-reports-daemon-spec into master

What does this MR do and why?

It seems that by merging !97532 (merged) we broke some specs.
Surprisingly, they pass on CI but break on my machine (OSX, GDK).

The explanation is:

  • For failures 1-5: our CI is on Linux, which means Jemalloc reports would likely work properly not return nil.
  • For 6: This is quite surprising, not failing on CI points to the fact we have /empty-dir on CI boxes? 🤔

This is a short-term fix in case the issue will break the master (should not) or will start causing issues for development (most likely; at least it does for me because I work with these components and run their specs).
The next step would be to rewrite Gitlab::Memory::ReportsDaemon with BackgroundTask.




➜  gitlab git:(372850-fix-reports-daemon-spec) bundle exec rspec spec/lib/gitlab/memory/reports_daemon_spec.rb
warning: parser/current is loading parser/ruby27, which recognizes2.7.6-compliant syntax, but you are running 2.7.5.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Test environment set up in 5.719102 seconds
FFF.FF..F

Failures:

  1) Gitlab::Memory::ReportsDaemon#run_thread runs reports
     Failure/Error: File.size(file_path.to_s)

       #<File (class)> received :size with unexpected arguments
         expected: (/\/tmp.*\.json/)
              got: ("")
       Diff:
       @@ -1 +1 @@
       -[/\/tmp.*\.json/]
       +[""]

        Please stub a default value first if message might be received with other args as well.
     # ./lib/gitlab/memory/reports_daemon.rb:100:in `file_size'
     # ./lib/gitlab/memory/reports_daemon.rb:47:in `block in run_thread'
     # ./lib/gitlab/memory/reports_daemon.rb:38:in `each'
     # ./lib/gitlab/memory/reports_daemon.rb:38:in `run_thread'
     # ./spec/lib/gitlab/memory/reports_daemon_spec.rb:28:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:416:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:407:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:403:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:56:in `with_raw_context'
     # ./spec/spec_helper.rb:403:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:240:in `block (2 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (3 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:60:in `with_cross_joins_prevented'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (2 levels) in <main>'

  2) Gitlab::Memory::ReportsDaemon#run_thread logs report execution
     Failure/Error: File.size(file_path.to_s)

       #<File (class)> received :size with unexpected arguments
         expected: (/\/tmp.*\.json/)
              got: ("")
       Diff:
       @@ -1 +1 @@
       -[/\/tmp.*\.json/]
       +[""]


  3) Gitlab::Memory::ReportsDaemon#run_thread sets real time duration gauge
     Failure/Error: File.size(file_path.to_s)

       #<File (class)> received :size with unexpected arguments
         expected: (/\/tmp.*\.json/)
              got: ("")
       Diff:
       @@ -1 +1 @@
       -[/\/tmp.*\.json/]
       +[""]


  4) Gitlab::Memory::ReportsDaemon#run_thread when the report object returns invalid file path logs `0` as `perf_report_size_bytes`
     Failure/Error: File.size(file_path.to_s)

       #<File (class)> received :size with unexpected arguments
         expected: (/\/tmp.*\.json/)
              got: ("")
       Diff:
       @@ -1 +1 @@
       -[/\/tmp.*\.json/]
       +[""]

  5) Gitlab::Memory::ReportsDaemon#run_thread sleep timers logic wakes up every (fixed interval + defined delta), sleeps between reports each cycle
     Failure/Error: File.size(file_path.to_s)

       #<File (class)> received :size with unexpected arguments
         expected: (/\/tmp.*\.json/)
              got: ("")
       Diff:
       @@ -1 +1 @@
       -[/\/tmp.*\.json/]
       +[""]


  6) Gitlab::Memory::ReportsDaemon timer intervals settings when settings are passed through the environment uses provided values
     Failure/Error: FileUtils.mkdir_p(@tmp_dir)

     Errno::EROFS:
       Read-only file system @ dir_s_mkdir - /empty-dir
     # ./lib/gitlab/memory/reports/jemalloc_stats.rb:25:in `initialize'
     # ./lib/gitlab/memory/reports_daemon.rb:27:in `new'
     # ./lib/gitlab/memory/reports_daemon.rb:27:in `initialize'
     # ./spec/lib/gitlab/memory/reports_daemon_spec.rb:127:in `new'
     # ./spec/lib/gitlab/memory/reports_daemon_spec.rb:127:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:416:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:407:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:403:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:56:in `with_raw_context'
     # ./spec/spec_helper.rb:403:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:240:in `block (2 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (3 levels) in <main>'
     # ./spec/support/database/prevent_cross_joins.rb:60:in `with_cross_joins_prevented'
     # ./spec/support/database/prevent_cross_joins.rb:106:in `block (2 levels) in <main>'

Finished in 8.93 seconds (files took 12.82 seconds to load)
9 examples, 6 failures

Failed examples:

rspec ./spec/lib/gitlab/memory/reports_daemon_spec.rb:25 # Gitlab::Memory::ReportsDaemon#run_thread runs reports
rspec ./spec/lib/gitlab/memory/reports_daemon_spec.rb:31 # Gitlab::Memory::ReportsDaemon#run_thread logs report execution
rspec ./spec/lib/gitlab/memory/reports_daemon_spec.rb:60 # Gitlab::Memory::ReportsDaemon#run_thread sets real time duration gauge
rspec ./spec/lib/gitlab/memory/reports_daemon_spec.rb:53 # Gitlab::Memory::ReportsDaemon#run_thread when the report object returns invalid file path logs `0` as `perf_report_size_bytes`
rspec ./spec/lib/gitlab/memory/reports_daemon_spec.rb:85 # Gitlab::Memory::ReportsDaemon#run_thread sleep timers logic wakes up every (fixed interval + defined delta), sleeps between reports each cycle
rspec ./spec/lib/gitlab/memory/reports_daemon_spec.rb:126 # Gitlab::Memory::ReportsDaemon timer intervals settings when settings are passed through the environment uses provided values

How to set up and validate locally

Specs-only MR.

Run bundle exec rspec spec/lib/gitlab/memory/reports_daemon_spec.rb on master and on this branch.

MR acceptance checklist

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

Related to #372850 (closed)

Edited by Aleksei Lipniagov

Merge request reports

Loading