Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-15 03:08:48 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-15 03:08:48 +0300
commitb69f406585ff64b1c5140ebba775cc754fabb358 (patch)
tree9af7dfeb0c3f0f8db189a6e18c6be398a7729e2d /lib
parent866ca4e49ff74ffadf8e6f6ff663a168489c2aba (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/helpers/internal_helpers.rb24
-rw-r--r--lib/api/internal/base.rb35
-rw-r--r--lib/gitlab/data_builder/build.rb6
-rw-r--r--lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb9
-rw-r--r--lib/gitlab/sidekiq_logging/structured_logger.rb19
-rw-r--r--lib/gitlab/utils/log_limited_array.rb27
6 files changed, 36 insertions, 84 deletions
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index b17cb2633d8..ab43096a1de 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -55,30 +55,6 @@ module API
::Users::ActivityService.new(actor).execute if commands.include?(params[:action])
end
- def merge_request_urls
- ::MergeRequests::GetUrlsService.new(project).execute(params[:changes])
- end
-
- def process_mr_push_options(push_options, project, user, changes)
- Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/61359')
-
- service = ::MergeRequests::PushOptionsHandlerService.new(
- project,
- user,
- changes,
- push_options
- ).execute
-
- if service.errors.present?
- push_options_warning(service.errors.join("\n\n"))
- end
- end
-
- def push_options_warning(warning)
- options = Array.wrap(params[:push_options]).map { |p| "'#{p}'" }.join(' ')
- "WARNINGS:\nError encountered with push options #{options}: #{warning}"
- end
-
def redis_ping
result = Gitlab::Redis::SharedState.with { |redis| redis.ping }
diff --git a/lib/api/internal/base.rb b/lib/api/internal/base.rb
index 9de3644daa8..382bbeb66de 100644
--- a/lib/api/internal/base.rb
+++ b/lib/api/internal/base.rb
@@ -212,40 +212,7 @@ module API
post '/post_receive' do
status 200
- response = Gitlab::InternalPostReceive::Response.new
-
- # Try to load the project and users so we have the application context
- # available for logging before we schedule any jobs.
- user = actor.user
- project
-
- push_options = Gitlab::PushOptions.new(params[:push_options])
-
- response.reference_counter_decreased = Gitlab::ReferenceCounter.new(params[:gl_repository]).decrease
-
- PostReceive.perform_async(params[:gl_repository], params[:identifier],
- params[:changes], push_options.as_json)
-
- mr_options = push_options.get(:merge_request)
- if mr_options.present?
- message = process_mr_push_options(mr_options, project, user, params[:changes])
- response.add_alert_message(message)
- end
-
- broadcast_message = BroadcastMessage.current&.last&.message
- response.add_alert_message(broadcast_message)
-
- response.add_merge_request_urls(merge_request_urls)
-
- # Neither User nor Project are guaranteed to be returned; an orphaned write deploy
- # key could be used
- if user && project
- redirect_message = Gitlab::Checks::ProjectMoved.fetch_message(user.id, project.id)
- project_created_message = Gitlab::Checks::ProjectCreated.fetch_message(user.id, project.id)
-
- response.add_basic_message(redirect_message)
- response.add_basic_message(project_created_message)
- end
+ response = PostReceiveService.new(actor.user, project, params).execute
ee_post_receive_response_hook(response)
diff --git a/lib/gitlab/data_builder/build.rb b/lib/gitlab/data_builder/build.rb
index f7b7db50b2f..e6702c5a38b 100644
--- a/lib/gitlab/data_builder/build.rb
+++ b/lib/gitlab/data_builder/build.rb
@@ -38,11 +38,7 @@ module Gitlab
project_id: project.id,
project_name: project.full_name,
- user: {
- id: user.try(:id),
- name: user.try(:name),
- email: user.try(:email)
- },
+ user: user.try(:hook_attrs),
commit: {
# note: commit.id is actually the pipeline id
diff --git a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
index 9bb1e8fc7a2..837473d47cd 100644
--- a/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
+++ b/lib/gitlab/grape_logging/formatters/lograge_with_timestamp.rb
@@ -25,9 +25,12 @@ module Gitlab
def process_params(data)
return [] unless data.has_key?(:params)
- data[:params]
- .each_pair
- .map { |k, v| { key: k, value: utf8_encode_values(v) } }
+ params_array =
+ data[:params]
+ .each_pair
+ .map { |k, v| { key: k, value: utf8_encode_values(v) } }
+
+ Gitlab::Utils::LogLimitedArray.log_limited_array(params_array)
end
def utf8_encode_values(data)
diff --git a/lib/gitlab/sidekiq_logging/structured_logger.rb b/lib/gitlab/sidekiq_logging/structured_logger.rb
index 8e7626b8eb6..6dacca5529b 100644
--- a/lib/gitlab/sidekiq_logging/structured_logger.rb
+++ b/lib/gitlab/sidekiq_logging/structured_logger.rb
@@ -6,8 +6,6 @@ require 'active_record/log_subscriber'
module Gitlab
module SidekiqLogging
class StructuredLogger
- MAXIMUM_JOB_ARGUMENTS_LENGTH = 10.kilobytes
-
def call(job, queue)
started_time = get_time
base_payload = parse_job(job)
@@ -85,7 +83,7 @@ module Gitlab
job['pid'] = ::Process.pid
job.delete('args') unless ENV['SIDEKIQ_LOG_ARGUMENTS']
- job['args'] = limited_job_args(job['args']) if job['args']
+ job['args'] = Gitlab::Utils::LogLimitedArray.log_limited_array(job['args']) if job['args']
job
end
@@ -108,21 +106,6 @@ module Gitlab
def current_time
Gitlab::Metrics::System.monotonic_time
end
-
- def limited_job_args(args)
- return unless args.is_a?(Array)
-
- total_length = 0
- limited_args = args.take_while do |arg|
- total_length += arg.to_json.length
-
- total_length <= MAXIMUM_JOB_ARGUMENTS_LENGTH
- end
-
- limited_args.push('...') if total_length > MAXIMUM_JOB_ARGUMENTS_LENGTH
-
- limited_args
- end
end
end
end
diff --git a/lib/gitlab/utils/log_limited_array.rb b/lib/gitlab/utils/log_limited_array.rb
new file mode 100644
index 00000000000..fe8aadf9020
--- /dev/null
+++ b/lib/gitlab/utils/log_limited_array.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Utils
+ module LogLimitedArray
+ MAXIMUM_ARRAY_LENGTH = 10.kilobytes
+
+ # Prepare an array for logging by limiting its JSON representation
+ # to around 10 kilobytes. Once we hit the limit, add "..." as the
+ # last item in the returned array.
+ def self.log_limited_array(array)
+ return [] unless array.is_a?(Array)
+
+ total_length = 0
+ limited_array = array.take_while do |arg|
+ total_length += arg.to_json.length
+
+ total_length <= MAXIMUM_ARRAY_LENGTH
+ end
+
+ limited_array.push('...') if total_length > MAXIMUM_ARRAY_LENGTH
+
+ limited_array
+ end
+ end
+ end
+end