Skip to content

Commit 3a9175f

Browse files
stanhubalasankarc
authored andcommitted
Consolidate Puma low-level handler
Previously the Puma low-level error handler was specified in three different places (Cloud Native GitLab, Omnibus GitLab, GitLab Development Kit). Any time a change was needed we would have to update three different files. We can simplify this by using a central class that each of the configuration files can use. This change requires https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132581 Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/426135 Changelog: changed
1 parent 9d4ec70 commit 3a9175f

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

files/gitlab-cookbooks/gitlab/templates/default/puma.rb.erb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ directory '<%= @working_directory %>'
7171

7272
workers <%= @worker_processes %>
7373

74-
require_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/cluster/lifecycle_events"
74+
require "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/cluster/lifecycle_events"
7575

7676
on_restart do
7777
# Signal application hooks that we're about to restart
@@ -113,22 +113,16 @@ worker_timeout <%= @worker_timeout %>
113113
wait_for_less_busy_worker ENV.fetch('PUMA_WAIT_FOR_LESS_BUSY_WORKER', 0.001).to_f
114114

115115
# Use customised JSON formatter for Puma log
116-
require_relative "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/puma_logging/json_formatter"
116+
require "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/puma_logging/json_formatter"
117117

118118
json_formatter = Gitlab::PumaLogging::JSONFormatter.new
119119
log_formatter do |str|
120120
json_formatter.call(str)
121121
end
122122

123-
lowlevel_error_handler do |ex, env, status_code|
124-
# Puma v6.4.0 added the status_code argument in
125-
# https://github.com/puma/puma/pull/3094
126-
status_code ||= 500
127-
128-
if Raven.configuration.capture_allowed?
129-
Raven.capture_exception(ex, tags: { 'handler': 'puma_low_level' }, extra: { puma_env: env, status_code: status_code })
130-
end
123+
require "<%= @install_dir %>/embedded/service/gitlab-rails/lib/gitlab/puma/error_handler"
124+
error_handler = Gitlab::Puma::ErrorHandler.new(ENV['RAILS_ENV'] == 'production')
131125

132-
# note the below is just a Rack response
133-
[status_code, {}, ["An error has occurred and reported in the system's low-level error handler."]]
126+
lowlevel_error_handler do |ex, env, status_code|
127+
error_handler.execute(ex, env, status_code)
134128
end

spec/chef/cookbooks/gitlab/recipes/puma_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
)
8383
expect(chef_run).to render_file('/var/opt/gitlab/gitlab-rails/etc/puma.rb').with_content { |content|
8484
expect(content).to match(/lowlevel_error_handler/)
85-
expect(content).to include('Raven.capture_exception')
85+
expect(content).to include('require "/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/puma/error_handler"')
8686
}
8787
end
8888

spec/chef/cookbooks/gitlab/resources/puma_config_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
expect(content).to match(%r(^bind 'unix:///var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'))
2222
expect(content).to match(%r(^bind 'tcp://127.0.0.1:8080'))
2323
expect(content).to match(%r(^directory '/var/opt/gitlab/gitlab-rails/working'))
24-
expect(content).to match(%r(^require_relative "/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/cluster/lifecycle_events"$))
24+
expect(content).to match(%r(^require "/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/cluster/lifecycle_events"$))
2525
expect(content).to match(/^options = { workers: 2 }$/)
2626
expect(content).to match(/^preload_app!$/)
27-
expect(content).to match(%r(^require_relative "/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/puma_logging/json_formatter"$))
27+
expect(content).to match(%r(^require "/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/puma_logging/json_formatter"$))
2828
}
2929
end
3030
end

0 commit comments

Comments
 (0)