Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 12:45:46 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 12:45:46 +0300
commita7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch)
tree7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/commands
parentee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff)
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/commands')
-rw-r--r--spec/commands/metrics_server/metrics_server_spec.rb81
-rw-r--r--spec/commands/sidekiq_cluster/cli_spec.rb23
2 files changed, 53 insertions, 51 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
diff --git a/spec/commands/sidekiq_cluster/cli_spec.rb b/spec/commands/sidekiq_cluster/cli_spec.rb
index d7488e8d965..15b738cacd1 100644
--- a/spec/commands/sidekiq_cluster/cli_spec.rb
+++ b/spec/commands/sidekiq_cluster/cli_spec.rb
@@ -3,9 +3,10 @@
require 'fast_spec_helper'
require 'rspec-parameterized'
+require_relative '../../support/stub_settings_source'
require_relative '../../../sidekiq_cluster/cli'
-RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do # rubocop:disable RSpec/FilePath
+RSpec.describe Gitlab::SidekiqCluster::CLI, stub_settings_source: true do # rubocop:disable RSpec/FilePath
let(:cli) { described_class.new('/dev/null') }
let(:timeout) { Gitlab::SidekiqCluster::DEFAULT_SOFT_TIMEOUT_SECONDS }
let(:default_options) do
@@ -302,7 +303,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
end
it 'does not start a sidekiq metrics server' do
- expect(MetricsServer).not_to receive(:spawn)
+ expect(MetricsServer).not_to receive(:fork)
cli.run(%w(foo))
end
@@ -319,7 +320,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
end
it 'does not start a sidekiq metrics server' do
- expect(MetricsServer).not_to receive(:spawn)
+ expect(MetricsServer).not_to receive(:fork)
cli.run(%w(foo))
end
@@ -349,7 +350,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
end
it 'does not start a sidekiq metrics server' do
- expect(MetricsServer).not_to receive(:spawn)
+ expect(MetricsServer).not_to receive(:fork)
cli.run(%w(foo))
end
@@ -375,7 +376,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
end
it 'does not start a sidekiq metrics server' do
- expect(MetricsServer).not_to receive(:spawn)
+ expect(MetricsServer).not_to receive(:fork)
cli.run(%w(foo))
end
@@ -405,9 +406,9 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
specify do
if start_metrics_server
- expect(MetricsServer).to receive(:spawn).with('sidekiq', metrics_dir: metrics_dir, wipe_metrics_dir: true, trapped_signals: trapped_signals)
+ expect(MetricsServer).to receive(:fork).with('sidekiq', metrics_dir: metrics_dir, wipe_metrics_dir: true, reset_signals: trapped_signals)
else
- expect(MetricsServer).not_to receive(:spawn)
+ expect(MetricsServer).not_to receive(:fork)
end
cli.run(%w(foo))
@@ -420,7 +421,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
let(:sidekiq_exporter_enabled) { true }
it 'does not start the server' do
- expect(MetricsServer).not_to receive(:spawn)
+ expect(MetricsServer).not_to receive(:fork)
cli.run(%w(foo --dryrun))
end
@@ -433,7 +434,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
before do
allow(cli).to receive(:sleep).with(a_kind_of(Numeric))
- allow(MetricsServer).to receive(:spawn).and_return(99)
+ allow(MetricsServer).to receive(:fork).and_return(99)
cli.start_metrics_server
end
@@ -452,8 +453,8 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do #
allow(Gitlab::ProcessManagement).to receive(:all_alive?).with(an_instance_of(Array)).and_return(false)
allow(cli).to receive(:stop_metrics_server)
- expect(MetricsServer).to receive(:spawn).with(
- 'sidekiq', metrics_dir: metrics_dir, wipe_metrics_dir: false, trapped_signals: trapped_signals
+ expect(MetricsServer).to receive(:fork).with(
+ 'sidekiq', metrics_dir: metrics_dir, wipe_metrics_dir: false, reset_signals: trapped_signals
)
cli.start_loop