diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-17 06:12:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-17 06:12:17 +0300 |
commit | d6f38acd8158768f6a8df6814c65ebbbbe2e0445 (patch) | |
tree | 6937c31ed1d0a3c6fa45470c5117d479b23be955 /app/controllers | |
parent | 77ed02d1fe93001f3649b878ddbe28697e77d5d9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 24 | ||||
-rw-r--r-- | app/controllers/concerns/request_payload_logger.rb | 32 | ||||
-rw-r--r-- | app/controllers/oauth/tokens_controller.rb | 3 |
3 files changed, 36 insertions, 23 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bfd3388da1b..f60da46826a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -24,6 +24,7 @@ class ApplicationController < BaseActionController include ::Gitlab::EndpointAttributes include FlocOptOut include CheckRateLimit + include RequestPayloadLogger extend ContentSecurityPolicyPatch before_action :limit_session_time, if: -> { !current_user } @@ -180,29 +181,6 @@ class ApplicationController < BaseActionController @workhorse_excluded_content_types ||= %w[text/html application/json] end - def append_info_to_payload(payload) - super - - payload[:ua] = request.env["HTTP_USER_AGENT"] - payload[:remote_ip] = request.remote_ip - - payload[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id - payload[:metadata] = @current_context - payload[:request_urgency] = urgency&.name - payload[:target_duration_s] = urgency&.duration - logged_user = auth_user - if logged_user.present? - payload[:user_id] = logged_user.try(:id) - payload[:username] = logged_user.try(:username) - end - - payload[:queue_duration_s] = request.env[::Gitlab::Middleware::RailsQueueDuration::GITLAB_RAILS_QUEUE_DURATION_KEY] - - payload[:response_bytes] = response.body_parts.sum(&:bytesize) if Feature.enabled?(:log_response_length) - - store_cloudflare_headers!(payload, request) - end - ## # Controllers such as GitHttpController may use alternative methods # (e.g. tokens) to authenticate the user, whereas Devise sets current_user. diff --git a/app/controllers/concerns/request_payload_logger.rb b/app/controllers/concerns/request_payload_logger.rb new file mode 100644 index 00000000000..b13164e5c57 --- /dev/null +++ b/app/controllers/concerns/request_payload_logger.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module RequestPayloadLogger + extend ActiveSupport::Concern + include Gitlab::Logging::CloudflareHelper + + def append_info_to_payload(payload) + super + + payload[:ua] = request.env["HTTP_USER_AGENT"] + payload[:remote_ip] = request.remote_ip + payload[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id + + payload[:metadata] = Gitlab::ApplicationContext.current + + if defined?(urgency) + payload[:request_urgency] = urgency&.name + payload[:target_duration_s] = urgency&.duration + end + + logged_user = auth_user + if logged_user.present? + payload[:user_id] = logged_user.try(:id) + payload[:username] = logged_user.try(:username) + end + + payload[:queue_duration_s] = request.env[::Gitlab::Middleware::RailsQueueDuration::GITLAB_RAILS_QUEUE_DURATION_KEY] + payload[:response_bytes] = response.body_parts.sum(&:bytesize) if Feature.enabled?(:log_response_length) + + store_cloudflare_headers!(payload, request) + end +end diff --git a/app/controllers/oauth/tokens_controller.rb b/app/controllers/oauth/tokens_controller.rb index 012fa318eea..7889e89fc5c 100644 --- a/app/controllers/oauth/tokens_controller.rb +++ b/app/controllers/oauth/tokens_controller.rb @@ -2,4 +2,7 @@ class Oauth::TokensController < Doorkeeper::TokensController include EnforcesTwoFactorAuthentication + include RequestPayloadLogger + + alias_method :auth_user, :current_user end |