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
fd2e0dfa
Commit
fd2e0dfa
authored
Nov 18, 2021
by
Matthias Käppler
Committed by
Heinrich Lee Yu
Nov 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run SidekiqExporter only on first worker
parent
16a9ff55
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
75 deletions
+27
-75
config/initializers/7_prometheus_metrics.rb
config/initializers/7_prometheus_metrics.rb
+9
-5
lib/gitlab/metrics/exporter/sidekiq_exporter.rb
lib/gitlab/metrics/exporter/sidekiq_exporter.rb
+0
-23
spec/lib/gitlab/metrics/exporter/sidekiq_exporter_spec.rb
spec/lib/gitlab/metrics/exporter/sidekiq_exporter_spec.rb
+0
-36
spec/sidekiq_cluster/sidekiq_cluster_spec.rb
spec/sidekiq_cluster/sidekiq_cluster_spec.rb
+18
-11
No files found.
config/initializers/7_prometheus_metrics.rb
View file @
fd2e0dfa
...
...
@@ -28,11 +28,15 @@ Gitlab::Application.configure do |config|
config
.
middleware
.
insert_after
(
Labkit
::
Middleware
::
Rack
,
Gitlab
::
Metrics
::
RequestsRackMiddleware
)
end
Sidekiq
.
configure_server
do
|
config
|
config
.
on
(
:startup
)
do
# Do not clean the metrics directory here - the supervisor script should
# have already taken care of that
Gitlab
::
Metrics
::
Exporter
::
SidekiqExporter
.
instance
.
start
if
Gitlab
::
Runtime
.
sidekiq?
&&
(
!
ENV
[
'SIDEKIQ_WORKER_ID'
]
||
ENV
[
'SIDEKIQ_WORKER_ID'
]
==
'0'
)
# The single worker outside of a sidekiq-cluster, or the first worker (sidekiq_0)
# in a cluster of processes, is responsible for serving health checks.
Sidekiq
.
configure_server
do
|
config
|
config
.
on
(
:startup
)
do
# Do not clean the metrics directory here - the supervisor script should
# have already taken care of that
Gitlab
::
Metrics
::
Exporter
::
SidekiqExporter
.
instance
.
start
end
end
end
...
...
lib/gitlab/metrics/exporter/sidekiq_exporter.rb
View file @
fd2e0dfa
...
...
@@ -15,29 +15,6 @@ module Gitlab
File
::
NULL
end
end
private
# Sidekiq Exporter does not work properly in sidekiq-cluster
# mode. It tries to start the service on the same port for
# each of the cluster workers, this results in failure
# due to duplicate binding.
#
# For now we ignore this error, as metrics are still "kind of"
# valid as they are rendered from shared directory.
#
# Issue: https://gitlab.com/gitlab-org/gitlab/issues/5714
def
start_working
super
rescue
Errno
::
EADDRINUSE
=>
e
Sidekiq
.
logger
.
error
(
class:
self
.
class
.
to_s
,
message:
'Cannot start sidekiq_exporter'
,
'exception.message'
=>
e
.
message
)
false
end
end
end
end
...
...
spec/lib/gitlab/metrics/exporter/sidekiq_exporter_spec.rb
View file @
fd2e0dfa
...
...
@@ -50,40 +50,4 @@ RSpec.describe Gitlab::Metrics::Exporter::SidekiqExporter do
expect
(
exporter
.
log_filename
).
to
end_with
(
'sidekiq_exporter.log'
)
end
end
context
'when port is already taken'
do
let
(
:first_exporter
)
{
described_class
.
new
}
before
do
stub_config
(
monitoring:
{
sidekiq_exporter:
{
enabled:
true
,
port:
9992
,
address:
'127.0.0.1'
}
}
)
first_exporter
.
start
end
after
do
first_exporter
.
stop
end
it
'does print error message'
do
expect
(
Sidekiq
.
logger
).
to
receive
(
:error
)
.
with
(
class:
described_class
.
to_s
,
message:
'Cannot start sidekiq_exporter'
,
'exception.message'
=>
anything
)
exporter
.
start
end
it
'does not start thread'
do
expect
(
exporter
.
start
).
to
be_nil
end
end
end
spec/sidekiq_cluster/sidekiq_cluster_spec.rb
View file @
fd2e0dfa
...
...
@@ -7,19 +7,26 @@ require_relative '../../sidekiq_cluster/sidekiq_cluster'
RSpec
.
describe
Gitlab
::
SidekiqCluster
do
# rubocop:disable RSpec/FilePath
describe
'.start'
do
it
'starts Sidekiq with the given queues, environment and options'
do
expected_options
=
{
env: :production
,
directory:
'foo/bar'
,
max_concurrency:
20
,
min_concurrency:
10
,
timeout:
25
,
dryrun:
true
process_options
=
{
pgroup:
true
,
err:
$stderr
,
out:
$stdout
}
expect
(
described_class
).
to
receive
(
:start_sidekiq
).
ordered
.
with
(
%w(foo)
,
expected_options
.
merge
(
worker_id:
0
))
expect
(
described_class
).
to
receive
(
:start_sidekiq
).
ordered
.
with
(
%w(bar baz)
,
expected_options
.
merge
(
worker_id:
1
))
described_class
.
start
([
%w(foo)
,
%w(bar baz)
],
env: :production
,
directory:
'foo/bar'
,
max_concurrency:
20
,
min_concurrency:
10
,
dryrun:
true
)
expect
(
Process
).
to
receive
(
:spawn
).
ordered
.
with
({
"ENABLE_SIDEKIQ_CLUSTER"
=>
"1"
,
"SIDEKIQ_WORKER_ID"
=>
"0"
},
"bundle"
,
"exec"
,
"sidekiq"
,
"-c10"
,
"-eproduction"
,
"-t25"
,
"-gqueues:foo"
,
"-rfoo/bar"
,
"-qfoo,1"
,
process_options
)
expect
(
Process
).
to
receive
(
:spawn
).
ordered
.
with
({
"ENABLE_SIDEKIQ_CLUSTER"
=>
"1"
,
"SIDEKIQ_WORKER_ID"
=>
"1"
},
"bundle"
,
"exec"
,
"sidekiq"
,
"-c10"
,
"-eproduction"
,
"-t25"
,
"-gqueues:bar,baz"
,
"-rfoo/bar"
,
"-qbar,1"
,
"-qbaz,1"
,
process_options
)
described_class
.
start
([
%w(foo)
,
%w(bar baz)
],
env: :production
,
directory:
'foo/bar'
,
max_concurrency:
20
,
min_concurrency:
10
)
end
it
'starts Sidekiq with the given queues and sensible default options'
do
...
...
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