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-04-26 00:09:46 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-26 00:09:46 +0300
commit44fb0702f3d2161d286df9b409f4309ed41207df (patch)
tree413f71c07a4ef9d13f17fee357832693e6cb3c48 /spec/metrics_server
parentc7531da771f30a54e2220f8f62efeba4b0b1a674 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/metrics_server')
-rw-r--r--spec/metrics_server/metrics_server_spec.rb114
1 files changed, 90 insertions, 24 deletions
diff --git a/spec/metrics_server/metrics_server_spec.rb b/spec/metrics_server/metrics_server_spec.rb
index 591840dcba2..4a3580ed4b1 100644
--- a/spec/metrics_server/metrics_server_spec.rb
+++ b/spec/metrics_server/metrics_server_spec.rb
@@ -15,6 +15,8 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
let(:ruby_sampler_double) { double(Gitlab::Metrics::Samplers::RubySampler) }
before do
+ # Make sure we never actually spawn any new processes in a unit test.
+ %i(spawn fork detach).each { |m| allow(Process).to receive(m) }
# We do not want this to have knock-on effects on the test process.
allow(Gitlab::ProcessManagement).to receive(:modify_signals)
@@ -67,35 +69,69 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
end
describe '.spawn' do
- let(:expected_env) do
- {
- 'METRICS_SERVER_TARGET' => target,
- 'WIPE_METRICS_DIR' => '0'
- }
- end
+ context 'for legacy Ruby server' do
+ let(:expected_env) do
+ {
+ 'METRICS_SERVER_TARGET' => target,
+ 'WIPE_METRICS_DIR' => '0',
+ 'GITLAB_CONFIG' => 'path/to/config/gitlab.yml'
+ }
+ end
- it 'spawns a new server process and returns its PID' do
- expect(Process).to receive(:spawn).with(
- expected_env,
- end_with('bin/metrics-server'),
- hash_including(pgroup: true)
- ).and_return(99)
- expect(Process).to receive(:detach).with(99)
+ before do
+ stub_env('GITLAB_CONFIG', 'path/to/config/gitlab.yml')
+ end
+
+ it 'spawns a new server process and returns its PID' do
+ expect(Process).to receive(:spawn).with(
+ expected_env,
+ end_with('bin/metrics-server'),
+ hash_including(pgroup: true)
+ ).and_return(99)
+ expect(Process).to receive(:detach).with(99)
- pid = described_class.spawn(target, metrics_dir: metrics_dir)
+ pid = described_class.spawn(target, metrics_dir: metrics_dir)
- expect(pid).to eq(99)
+ expect(pid).to eq(99)
+ end
end
- context 'when path to gitlab.yml is passed' do
- it 'sets the GITLAB_CONFIG environment variable' do
+ context 'for Golang server' do
+ let(:expected_port) { target == 'puma' ? '8083' : '8082' }
+ let(:expected_env) do
+ {
+ 'GME_MMAP_METRICS_DIR' => metrics_dir,
+ 'GME_PROBES' => 'self,mmap',
+ 'GME_SERVER_HOST' => 'localhost',
+ 'GME_SERVER_PORT' => expected_port
+ }
+ end
+
+ before do
+ stub_env('GITLAB_GOLANG_METRICS_SERVER', '1')
+ end
+
+ it 'spawns a new server process and returns its PID' do
expect(Process).to receive(:spawn).with(
- expected_env.merge('GITLAB_CONFIG' => 'path/to/config/gitlab.yml'),
- end_with('bin/metrics-server'),
+ expected_env,
+ 'gitlab-metrics-exporter',
+ hash_including(pgroup: true)
+ ).and_return(99)
+ expect(Process).to receive(:detach).with(99)
+
+ pid = described_class.spawn(target, metrics_dir: metrics_dir)
+
+ expect(pid).to eq(99)
+ end
+
+ it 'can launch from explicit path instead of PATH' do
+ expect(Process).to receive(:spawn).with(
+ expected_env,
+ '/path/to/gme/gitlab-metrics-exporter',
hash_including(pgroup: true)
).and_return(99)
- described_class.spawn(target, metrics_dir: metrics_dir, gitlab_config: 'path/to/config/gitlab.yml')
+ described_class.spawn(target, metrics_dir: metrics_dir, path: '/path/to/gme/')
end
end
end
@@ -112,10 +148,21 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
end
describe '.spawn' do
- it 'raises an error' do
- expect { described_class.spawn('unsupported', metrics_dir: metrics_dir) }.to(
- raise_error('Target must be one of [puma,sidekiq]')
- )
+ context 'for legacy Ruby server' do
+ it 'raises an error' do
+ expect { described_class.spawn('unsupported', metrics_dir: metrics_dir) }.to(
+ raise_error('Target must be one of [puma,sidekiq]')
+ )
+ end
+ end
+
+ context 'for Golang server' do
+ it 'raises an error' do
+ stub_env('GITLAB_GOLANG_METRICS_SERVER', '1')
+ expect { described_class.spawn('unsupported', metrics_dir: metrics_dir) }.to(
+ raise_error('Target must be one of [puma,sidekiq]')
+ )
+ end
end
end
end
@@ -245,4 +292,23 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath
end
end
end
+
+ describe '.start_for_sidekiq' do
+ context 'for legacy Ruby server' do
+ it 'forks the parent process' do
+ expect(Process).to receive(:fork).and_return(42)
+
+ described_class.start_for_sidekiq(metrics_dir: '/path/to/metrics')
+ end
+ end
+
+ context 'for Golang server' do
+ it 'spawns the server process' do
+ stub_env('GITLAB_GOLANG_METRICS_SERVER', '1')
+ expect(Process).to receive(:spawn).and_return(42)
+
+ described_class.start_for_sidekiq(metrics_dir: '/path/to/metrics')
+ end
+ end
+ end
end