Commit cd89f9c0 authored by Stan Hu's avatar Stan Hu

Fix stale Prometheus metrics directory not being restored

metrics_server_spec.rb used a temporary directory to store Prometheus
metrics, but there is a class variable that stores the current
configuration. When the directory was wiped, the configuration was not
properly restored, so any subsequent specs that attempted to log metrics
would fail.

We fix this by restoring the old metrics dir in the config after the
spec runs.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/347499
parent a0315e77
...@@ -32,6 +32,7 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath ...@@ -32,6 +32,7 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
let(:prometheus_config) { ::Prometheus::Client::Configuration.new } let(:prometheus_config) { ::Prometheus::Client::Configuration.new }
let(:metrics_dir) { Dir.mktmpdir } let(:metrics_dir) { Dir.mktmpdir }
let(:settings_double) { double(:settings, sidekiq_exporter: {}) } let(:settings_double) { double(:settings, sidekiq_exporter: {}) }
let!(:old_metrics_dir) { ::Prometheus::Client.configuration.multiprocess_files_dir }
subject(:metrics_server) { described_class.new('fake', metrics_dir, true)} subject(:metrics_server) { described_class.new('fake', metrics_dir, true)}
...@@ -43,8 +44,11 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath ...@@ -43,8 +44,11 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
end end
after do after do
Gitlab::Metrics.reset_registry!
::Prometheus::CleanupMultiprocDirService.new.execute ::Prometheus::CleanupMultiprocDirService.new.execute
Dir.rmdir(metrics_dir) Dir.rmdir(metrics_dir)
::Prometheus::Client.configuration.multiprocess_files_dir = old_metrics_dir
end end
it 'configures ::Prometheus::Client' do it 'configures ::Prometheus::Client' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment