Commit f008d7e7 authored by Matthias Käppler's avatar Matthias Käppler Committed by Rémy Coutable

Fix Prometheus client state not being reset

parent d0306a75
......@@ -8,14 +8,22 @@ require_relative '../support/helpers/next_instance_of'
RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
include NextInstanceOf
let(:prometheus_config) { ::Prometheus::Client.configuration }
let(:metrics_dir) { Dir.mktmpdir }
# Prometheus::Client is a singleton, i.e. shared global state, so
# we need to reset it after testing.
let!(:old_multiprocess_files_dir) { prometheus_config.multiprocess_files_dir }
before do
# We do not want this to have knock-on effects on the test process.
allow(Gitlab::ProcessManagement).to receive(:modify_signals)
end
after do
Gitlab::Metrics.reset_registry!
prometheus_config.multiprocess_files_dir = old_multiprocess_files_dir
FileUtils.rm_rf(metrics_dir, secure: true)
end
......@@ -55,9 +63,7 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
describe '#start' do
let(:exporter_class) { Class.new(Gitlab::Metrics::Exporter::BaseExporter) }
let(:exporter_double) { double('fake_exporter', start: true) }
let(:prometheus_config) { ::Prometheus::Client.configuration }
let(:settings) { { "fake_exporter" => { "enabled" => true } } }
let!(:old_metrics_dir) { prometheus_config.multiprocess_files_dir }
let(:ruby_sampler_double) { double(Gitlab::Metrics::Samplers::RubySampler) }
subject(:metrics_server) { described_class.new('fake', metrics_dir, true)}
......@@ -71,11 +77,6 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
allow(ruby_sampler_double).to receive(:start)
end
after do
Gitlab::Metrics.reset_registry!
prometheus_config.multiprocess_files_dir = old_metrics_dir
end
it 'configures ::Prometheus::Client' do
metrics_server.start
......
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