diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-03 06:14:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-03 06:14:42 +0300 |
commit | c657078ecb4bff69e58f6911713e143c99f2c71f (patch) | |
tree | 5a4dc8bf80b14c3202de9c7bd51363f3d73af541 /spec/commands | |
parent | 498ba9dc41fcf2b4be30a8f3721543953efb3c3b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/commands')
-rw-r--r-- | spec/commands/metrics_server/metrics_server_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/commands/metrics_server/metrics_server_spec.rb b/spec/commands/metrics_server/metrics_server_spec.rb new file mode 100644 index 00000000000..4eff9136f2b --- /dev/null +++ b/spec/commands/metrics_server/metrics_server_spec.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_relative '../../../metrics_server/metrics_server' + +# End-to-end tests for the metrics server process we use to serve metrics +# from forking applications (Sidekiq, Puma) to the Prometheus scraper. +RSpec.describe 'bin/metrics-server', :aggregate_failures do + let(:config_file) { Tempfile.new('gitlab.yml') } + let(:config) do + { + 'test' => { + 'monitoring' => { + 'sidekiq_exporter' => { + 'address' => 'localhost', + 'enabled' => true, + 'port' => 3807 + } + } + } + } + end + + context 'with a running server' do + before do + # We need to send a request to localhost + WebMock.allow_net_connect! + + config_file.write(YAML.dump(config)) + config_file.close + @pid = MetricsServer.spawn('sidekiq', gitlab_config: config_file.path) + end + + after do + webmock_enable! + + if @pid + Timeout.timeout(5) do + Process.kill('TERM', @pid) + Process.waitpid(@pid) + end + end + rescue Errno::ESRCH => _ + # 'No such process' means the process died before + ensure + config_file.unlink + 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? + end + end + end.not_to raise_error + end + end +end |