Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
80e53070
Commit
80e53070
authored
Dec 21, 2021
by
Roy Zwambag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add safe navigators to sidekiq monitoring settings
parent
624e39dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
54 deletions
+88
-54
sidekiq_cluster/cli.rb
sidekiq_cluster/cli.rb
+3
-9
spec/commands/sidekiq_cluster/cli_spec.rb
spec/commands/sidekiq_cluster/cli_spec.rb
+77
-45
spec/spec_helper.rb
spec/spec_helper.rb
+8
-0
No files found.
sidekiq_cluster/cli.rb
View file @
80e53070
...
...
@@ -200,9 +200,7 @@ module Gitlab
end
def
sidekiq_exporter_enabled?
::
Settings
.
monitoring
.
sidekiq_exporter
.
enabled
rescue
Settingslogic
::
MissingSetting
nil
::
Settings
.
dig
(
'monitoring'
,
'sidekiq_exporter'
,
'enabled'
)
end
def
exporter_has_a_unique_port?
...
...
@@ -216,15 +214,11 @@ module Gitlab
end
def
sidekiq_exporter_port
::
Settings
.
monitoring
.
sidekiq_exporter
.
port
rescue
Settingslogic
::
MissingSetting
nil
::
Settings
.
dig
(
'monitoring'
,
'sidekiq_exporter'
,
'port'
)
end
def
sidekiq_health_check_port
::
Settings
.
monitoring
.
sidekiq_health_checks
.
port
rescue
Settingslogic
::
MissingSetting
nil
::
Settings
.
dig
(
'monitoring'
,
'sidekiq_health_checks'
,
'port'
)
end
def
metrics_server_enabled?
...
...
spec/commands/sidekiq_cluster/cli_spec.rb
View file @
80e53070
...
...
@@ -5,7 +5,7 @@ require 'rspec-parameterized'
require_relative
'../../../sidekiq_cluster/cli'
RSpec
.
describe
Gitlab
::
SidekiqCluster
::
CLI
do
# rubocop:disable RSpec/FilePath
RSpec
.
describe
Gitlab
::
SidekiqCluster
::
CLI
,
stubbing_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
...
...
@@ -16,19 +16,39 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath
let
(
:sidekiq_exporter_port
)
{
'3807'
}
let
(
:sidekiq_health_checks_port
)
{
'3807'
}
before
do
stub_env
(
'RAILS_ENV'
,
'test'
)
stub_config
(
monitoring:
{
sidekiq_exporter:
{
enabled:
sidekiq_exporter_enabled
,
port:
sidekiq_exporter_port
},
sidekiq_health_checks:
{
port:
sidekiq_health_checks_port
let
(
:config_file
)
{
Tempfile
.
new
(
'gitlab.yml'
)
}
let
(
:config
)
do
{
'test'
=>
{
'monitoring'
=>
{
'sidekiq_exporter'
=>
{
'address'
=>
'localhost'
,
'enabled'
=>
sidekiq_exporter_enabled
,
'port'
=>
sidekiq_exporter_port
},
'sidekiq_health_checks'
=>
{
'address'
=>
'localhost'
,
'enabled'
=>
sidekiq_exporter_enabled
,
'port'
=>
sidekiq_health_checks_port
}
}
}
)
}
end
before
do
stub_env
(
'RAILS_ENV'
,
'test'
)
config_file
.
write
(
YAML
.
dump
(
config
))
config_file
.
close
allow
(
::
Settings
).
to
receive
(
:source
).
and_return
(
config_file
.
path
)
::
Settings
.
reload!
end
after
do
config_file
.
unlink
end
describe
'#run'
do
...
...
@@ -272,16 +292,9 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath
context
'starting the server'
do
context
'without --dryrun'
do
context
'when there are no sidekiq_health_checks settings set'
do
before
do
stub_config
(
monitoring:
{
sidekiq_exporter:
{
enabled:
true
,
port:
sidekiq_exporter_port
}
}
)
let
(
:sidekiq_exporter_enabled
)
{
true
}
before
do
allow
(
Gitlab
::
SidekiqCluster
).
to
receive
(
:start
)
allow
(
cli
).
to
receive
(
:write_pid
)
allow
(
cli
).
to
receive
(
:trap_signals
)
...
...
@@ -293,25 +306,42 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath
cli
.
run
(
%w(foo)
)
end
it
'rescues Settingslogic::MissingSetting'
do
expect
{
cli
.
run
(
%w(foo)
)
}.
not_to
raise_error
(
Settingslogic
::
MissingSetting
)
end
end
context
'when the sidekiq_exporter.port setting is not set'
do
let
(
:sidekiq_exporter_enabled
)
{
true
}
before
do
stub_config
(
monitoring:
{
sidekiq_exporter:
{
enabled:
true
},
sidekiq_health_checks:
{
port:
sidekiq_health_checks_port
allow
(
Gitlab
::
SidekiqCluster
).
to
receive
(
:start
)
allow
(
cli
).
to
receive
(
:write_pid
)
allow
(
cli
).
to
receive
(
:trap_signals
)
allow
(
cli
).
to
receive
(
:start_loop
)
end
it
'does not start a sidekiq metrics server'
do
expect
(
MetricsServer
).
not_to
receive
(
:spawn
)
cli
.
run
(
%w(foo)
)
end
end
context
'when sidekiq_exporter.enabled setting is not set'
do
let
(
:config
)
do
{
'test'
=>
{
'monitoring'
=>
{
'sidekiq_exporter'
=>
{},
'sidekiq_health_checks'
=>
{
'address'
=>
'localhost'
,
'enabled'
=>
sidekiq_exporter_enabled
,
'port'
=>
sidekiq_health_checks_port
}
}
}
)
}
end
before
do
allow
(
Gitlab
::
SidekiqCluster
).
to
receive
(
:start
)
allow
(
cli
).
to
receive
(
:write_pid
)
allow
(
cli
).
to
receive
(
:trap_signals
)
...
...
@@ -323,23 +353,21 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath
cli
.
run
(
%w(foo)
)
end
it
'rescues Settingslogic::MissingSetting'
do
expect
{
cli
.
run
(
%w(foo)
)
}.
not_to
raise_error
(
Settingslogic
::
MissingSetting
)
end
end
context
'w
hen sidekiq_exporter.enabled setting is not set
'
do
before
do
stub_config
(
monitoring:
{
sidekiq_exporter:
{},
sidekiq_health_checks:
{
port:
sidekiq_health_checks_port
context
'w
ith a blank sidekiq_exporter setting
'
do
let
(
:config
)
do
{
'test'
=>
{
'monitoring'
=>
{
'sidekiq_exporter'
=>
nil
,
'sidekiq_health_checks'
=>
nil
}
}
)
}
end
before
do
allow
(
Gitlab
::
SidekiqCluster
).
to
receive
(
:start
)
allow
(
cli
).
to
receive
(
:write_pid
)
allow
(
cli
).
to
receive
(
:trap_signals
)
...
...
@@ -351,6 +379,10 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath
cli
.
run
(
%w(foo)
)
end
it
'does not throw an error'
do
expect
{
cli
.
run
(
%w(foo)
)
}.
not_to
raise_error
end
end
context
'with valid settings'
do
...
...
spec/spec_helper.rb
View file @
80e53070
...
...
@@ -463,6 +463,14 @@ RSpec.configure do |config|
$stdout
=
STDOUT
end
config
.
around
(
:each
,
stubbing_settings_source:
true
)
do
|
example
|
original_instance
=
::
Settings
.
instance_variable_get
(
:@instance
)
example
.
run
::
Settings
.
instance_variable_set
(
:@instance
,
original_instance
)
end
config
.
disable_monkey_patching!
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment