summaryrefslogtreecommitdiff
path: root/spec/commands/metrics_server/metrics_server_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/commands/metrics_server/metrics_server_spec.rb')
-rw-r--r--spec/commands/metrics_server/metrics_server_spec.rb81
1 files changed, 41 insertions, 40 deletions
diff --git a/spec/commands/metrics_server/metrics_server_spec.rb b/spec/commands/metrics_server/metrics_server_spec.rb
index b755801bb65..217aa185767 100644
--- a/spec/commands/metrics_server/metrics_server_spec.rb
+++ b/spec/commands/metrics_server/metrics_server_spec.rb
@@ -12,6 +12,11 @@ RSpec.describe 'bin/metrics-server', :aggregate_failures do
{
'test' => {
'monitoring' => {
+ 'web_exporter' => {
+ 'address' => 'localhost',
+ 'enabled' => true,
+ 'port' => 3807
+ },
'sidekiq_exporter' => {
'address' => 'localhost',
'enabled' => true,
@@ -22,56 +27,52 @@ RSpec.describe 'bin/metrics-server', :aggregate_failures do
}
end
- context 'with a running server' do
- let(:metrics_dir) { Dir.mktmpdir }
+ %w(puma sidekiq).each do |target|
+ context "with a running server targeting #{target}" do
+ let(:metrics_dir) { Dir.mktmpdir }
- before do
- # We need to send a request to localhost
- WebMock.allow_net_connect!
+ before do
+ # We need to send a request to localhost
+ WebMock.allow_net_connect!
- config_file.write(YAML.dump(config))
- config_file.close
+ config_file.write(YAML.dump(config))
+ config_file.close
- env = {
- 'GITLAB_CONFIG' => config_file.path,
- 'METRICS_SERVER_TARGET' => 'sidekiq',
- 'WIPE_METRICS_DIR' => '1',
- 'prometheus_multiproc_dir' => metrics_dir
- }
- @pid = Process.spawn(env, 'bin/metrics-server', pgroup: true)
- end
+ @pid = MetricsServer.spawn(target, metrics_dir: metrics_dir, gitlab_config: config_file.path, wipe_metrics_dir: true)
+ end
- after do
- webmock_enable!
+ after do
+ webmock_enable!
- if @pid
- pgrp = Process.getpgid(@pid)
+ if @pid
+ pgrp = Process.getpgid(@pid)
- Timeout.timeout(5) do
- Process.kill('TERM', -pgrp)
- Process.waitpid(@pid)
- end
+ Timeout.timeout(10) do
+ Process.kill('TERM', -pgrp)
+ Process.waitpid(@pid)
+ end
- expect(Gitlab::ProcessManagement.process_alive?(@pid)).to be(false)
+ expect(Gitlab::ProcessManagement.process_alive?(@pid)).to be(false)
+ end
+ rescue Errno::ESRCH => _
+ # 'No such process' means the process died before
+ ensure
+ config_file.unlink
+ FileUtils.rm_rf(metrics_dir, secure: true)
end
- rescue Errno::ESRCH => _
- # 'No such process' means the process died before
- ensure
- config_file.unlink
- FileUtils.rm_rf(metrics_dir, secure: true)
- end
- it 'serves /metrics endpoint' do
- expect do
- Timeout.timeout(5) do
- http_ok = false
- until http_ok
- sleep 1
- response = Gitlab::HTTP.try_get("http://localhost:3807/metrics", allow_local_requests: true)
- http_ok = response&.success?
+ it 'serves /metrics endpoint' do
+ expect do
+ Timeout.timeout(10) do
+ http_ok = false
+ until http_ok
+ sleep 1
+ response = Gitlab::HTTP.try_get("http://localhost:3807/metrics", allow_local_requests: true)
+ http_ok = response&.success?
+ end
end
- end
- end.not_to raise_error
+ end.not_to raise_error
+ end
end
end
end