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
076ac5bb
Commit
076ac5bb
authored
Mar 09, 2022
by
Matthias Käppler
Committed by
Stan Hu
Mar 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix startup crash in Puma single mode
Changelog: fixed
parent
7f5f4509
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
32 deletions
+25
-32
config.ru
config.ru
+0
-10
config/initializers/7_prometheus_metrics.rb
config/initializers/7_prometheus_metrics.rb
+18
-6
config/initializers/zz_metrics.rb
config/initializers/zz_metrics.rb
+4
-0
lib/gitlab/cluster/lifecycle_events.rb
lib/gitlab/cluster/lifecycle_events.rb
+3
-16
No files found.
config.ru
View file @
076ac5bb
...
@@ -4,17 +4,7 @@
...
@@ -4,17 +4,7 @@
require
::
File
.
expand_path
(
'../config/environment'
,
__FILE__
)
require
::
File
.
expand_path
(
'../config/environment'
,
__FILE__
)
def
master_process?
Prometheus
::
PidProvider
.
worker_id
==
'puma_master'
end
warmup
do
|
app
|
warmup
do
|
app
|
# The following is necessary to ensure stale Prometheus metrics don't accumulate over time.
# It needs to be done as early as here to ensure metrics files aren't deleted.
# After we hit our app in `warmup`, first metrics and corresponding files already being created,
# for example in `lib/gitlab/metrics/requests_rack_middleware.rb`.
Prometheus
::
CleanupMultiprocDirService
.
new
.
execute
if
master_process?
client
=
Rack
::
MockRequest
.
new
(
app
)
client
=
Rack
::
MockRequest
.
new
(
app
)
client
.
get
(
'/'
)
client
.
get
(
'/'
)
end
end
...
...
config/initializers/7_prometheus_metrics.rb
View file @
076ac5bb
...
@@ -13,6 +13,24 @@ def prometheus_default_multiproc_dir
...
@@ -13,6 +13,24 @@ def prometheus_default_multiproc_dir
end
end
end
end
def
puma_metrics_server_process?
Prometheus
::
PidProvider
.
worker_id
==
'puma_master'
end
def
sidekiq_metrics_server_process?
Gitlab
::
Runtime
.
sidekiq?
&&
(
!
ENV
[
'SIDEKIQ_WORKER_ID'
]
||
ENV
[
'SIDEKIQ_WORKER_ID'
]
==
'0'
)
end
if
puma_metrics_server_process?
||
sidekiq_metrics_server_process?
# The following is necessary to ensure stale Prometheus metrics don't accumulate over time.
# It needs to be done as early as here to ensure metrics files aren't deleted.
# After we hit our app in `warmup`, first metrics and corresponding files already being created,
# for example in `lib/gitlab/metrics/requests_rack_middleware.rb`.
Prometheus
::
CleanupMultiprocDirService
.
new
.
execute
::
Prometheus
::
Client
.
reinitialize_on_pid_change
(
force:
true
)
end
::
Prometheus
::
Client
.
configure
do
|
config
|
::
Prometheus
::
Client
.
configure
do
|
config
|
config
.
logger
=
Gitlab
::
AppLogger
config
.
logger
=
Gitlab
::
AppLogger
...
@@ -49,15 +67,9 @@ if Gitlab::Runtime.sidekiq? && (!ENV['SIDEKIQ_WORKER_ID'] || ENV['SIDEKIQ_WORKER
...
@@ -49,15 +67,9 @@ if Gitlab::Runtime.sidekiq? && (!ENV['SIDEKIQ_WORKER_ID'] || ENV['SIDEKIQ_WORKER
end
end
Gitlab
::
Cluster
::
LifecycleEvents
.
on_master_start
do
Gitlab
::
Cluster
::
LifecycleEvents
.
on_master_start
do
# When running Puma in a Single mode, `on_master_start` and `on_worker_start` are the same.
# Thus, we order these events to run `reinitialize_on_pid_change` with `force: true` first.
::
Prometheus
::
Client
.
reinitialize_on_pid_change
(
force:
true
)
Gitlab
::
Metrics
.
gauge
(
:deployments
,
'GitLab Version'
,
{},
:max
).
set
({
version:
Gitlab
::
VERSION
,
revision:
Gitlab
.
revision
},
1
)
Gitlab
::
Metrics
.
gauge
(
:deployments
,
'GitLab Version'
,
{},
:max
).
set
({
version:
Gitlab
::
VERSION
,
revision:
Gitlab
.
revision
},
1
)
if
Gitlab
::
Runtime
.
puma?
if
Gitlab
::
Runtime
.
puma?
Gitlab
::
Metrics
::
RequestsRackMiddleware
.
initialize_metrics
Gitlab
::
Metrics
::
Samplers
::
PumaSampler
.
instance
.
start
Gitlab
::
Metrics
::
Samplers
::
PumaSampler
.
instance
.
start
# Starts a metrics server to export metrics from the Puma primary.
# Starts a metrics server to export metrics from the Puma primary.
...
...
config/initializers/zz_metrics.rb
View file @
076ac5bb
...
@@ -36,6 +36,10 @@ if Gitlab::Metrics.enabled? && !Rails.env.test? && !(Rails.env.development? && d
...
@@ -36,6 +36,10 @@ if Gitlab::Metrics.enabled? && !Rails.env.test? && !(Rails.env.development? && d
config
.
middleware
.
use
(
Gitlab
::
Metrics
::
ElasticsearchRackMiddleware
)
config
.
middleware
.
use
(
Gitlab
::
Metrics
::
ElasticsearchRackMiddleware
)
end
end
if
Gitlab
::
Runtime
.
puma?
Gitlab
::
Metrics
::
RequestsRackMiddleware
.
initialize_metrics
end
GC
::
Profiler
.
enable
GC
::
Profiler
.
enable
module
TrackNewRedisConnections
module
TrackNewRedisConnections
...
...
lib/gitlab/cluster/lifecycle_events.rb
View file @
076ac5bb
...
@@ -70,7 +70,7 @@ module Gitlab
...
@@ -70,7 +70,7 @@ module Gitlab
# Hook registration methods (called from initializers)
# Hook registration methods (called from initializers)
#
#
def
on_worker_start
(
&
block
)
def
on_worker_start
(
&
block
)
if
in_clustered_
environment
?
if
in_clustered_
puma
?
# Defer block execution
# Defer block execution
(
@worker_start_hooks
||=
[])
<<
block
(
@worker_start_hooks
||=
[])
<<
block
else
else
...
@@ -101,7 +101,7 @@ module Gitlab
...
@@ -101,7 +101,7 @@ module Gitlab
end
end
def
on_master_start
(
&
block
)
def
on_master_start
(
&
block
)
if
in_clustered_
environment
?
if
in_clustered_
puma
?
on_before_fork
(
&
block
)
on_before_fork
(
&
block
)
else
else
on_worker_start
(
&
block
)
on_worker_start
(
&
block
)
...
@@ -158,21 +158,8 @@ module Gitlab
...
@@ -158,21 +158,8 @@ module Gitlab
end
end
end
end
def
in_clustered_environment?
# Sidekiq doesn't fork
return
false
if
Gitlab
::
Runtime
.
sidekiq?
# Puma sometimes forks
return
true
if
in_clustered_puma?
# Default assumption is that we don't fork
false
end
def
in_clustered_puma?
def
in_clustered_puma?
return
false
unless
Gitlab
::
Runtime
.
puma?
Gitlab
::
Runtime
.
puma?
&&
@puma_options
&&
@puma_options
[
:workers
]
&&
@puma_options
[
:workers
]
>
0
@puma_options
&&
@puma_options
[
:workers
]
&&
@puma_options
[
:workers
]
>
0
end
end
end
end
end
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