Merge branch 'osw-send-max-patch-bytes-to-gitaly' into 'master'

Send max_patch_bytes to Gitaly via Gitaly::CommitDiffRequest

Closes #50635

See merge request gitlab-org/gitlab-ce!21575
This commit is contained in:
Douwe Maan 2018-09-07 14:02:17 +00:00
commit 7f2b287f66
4 changed files with 25 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
title: Send max_patch_bytes to Gitaly via Gitaly::CommitDiffRequest
merge_request: 21575
author:
type: other

View file

@ -11,7 +11,7 @@ module Gitlab
delegate :max_files, :max_lines, :max_bytes, :safe_max_files, :safe_max_lines, :safe_max_bytes, to: :limits delegate :max_files, :max_lines, :max_bytes, :safe_max_files, :safe_max_lines, :safe_max_bytes, to: :limits
def self.collection_limits(options = {}) def self.limits(options = {})
limits = {} limits = {}
limits[:max_files] = options.fetch(:max_files, DEFAULT_LIMITS[:max_files]) limits[:max_files] = options.fetch(:max_files, DEFAULT_LIMITS[:max_files])
limits[:max_lines] = options.fetch(:max_lines, DEFAULT_LIMITS[:max_lines]) limits[:max_lines] = options.fetch(:max_lines, DEFAULT_LIMITS[:max_lines])
@ -19,13 +19,14 @@ module Gitlab
limits[:safe_max_files] = [limits[:max_files], DEFAULT_LIMITS[:max_files]].min limits[:safe_max_files] = [limits[:max_files], DEFAULT_LIMITS[:max_files]].min
limits[:safe_max_lines] = [limits[:max_lines], DEFAULT_LIMITS[:max_lines]].min limits[:safe_max_lines] = [limits[:max_lines], DEFAULT_LIMITS[:max_lines]].min
limits[:safe_max_bytes] = limits[:safe_max_files] * 5.kilobytes # Average 5 KB per file limits[:safe_max_bytes] = limits[:safe_max_files] * 5.kilobytes # Average 5 KB per file
limits[:max_patch_bytes] = Gitlab::Git::Diff::SIZE_LIMIT
OpenStruct.new(limits) OpenStruct.new(limits)
end end
def initialize(iterator, options = {}) def initialize(iterator, options = {})
@iterator = iterator @iterator = iterator
@limits = self.class.collection_limits(options) @limits = self.class.limits(options)
@enforce_limits = !!options.fetch(:limits, true) @enforce_limits = !!options.fetch(:limits, true)
@expanded = !!options.fetch(:expanded, true) @expanded = !!options.fetch(:expanded, true)

View file

@ -369,7 +369,7 @@ module Gitlab
request_params[:ignore_whitespace_change] = options.fetch(:ignore_whitespace_change, false) request_params[:ignore_whitespace_change] = options.fetch(:ignore_whitespace_change, false)
request_params[:enforce_limits] = options.fetch(:limits, true) request_params[:enforce_limits] = options.fetch(:limits, true)
request_params[:collapse_diffs] = !options.fetch(:expanded, true) request_params[:collapse_diffs] = !options.fetch(:expanded, true)
request_params.merge!(Gitlab::Git::DiffCollection.collection_limits(options).to_h) request_params.merge!(Gitlab::Git::DiffCollection.limits(options).to_h)
request = Gitaly::CommitDiffRequest.new(request_params) request = Gitaly::CommitDiffRequest.new(request_params)
response = GitalyClient.call(@repository.storage, :diff_service, :commit_diff, request, timeout: GitalyClient.medium_timeout) response = GitalyClient.call(@repository.storage, :diff_service, :commit_diff, request, timeout: GitalyClient.medium_timeout)

View file

@ -19,7 +19,14 @@ describe Gitlab::GitalyClient::CommitService do
right_commit_id: commit.id, right_commit_id: commit.id,
collapse_diffs: false, collapse_diffs: false,
enforce_limits: true, enforce_limits: true,
**Gitlab::Git::DiffCollection.collection_limits.to_h # Tests limitation parameters explicitly
max_files: 100,
max_lines: 5000,
max_bytes: 512000,
safe_max_files: 100,
safe_max_lines: 5000,
safe_max_bytes: 512000,
max_patch_bytes: 102400
) )
expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash))
@ -37,7 +44,14 @@ describe Gitlab::GitalyClient::CommitService do
right_commit_id: initial_commit.id, right_commit_id: initial_commit.id,
collapse_diffs: false, collapse_diffs: false,
enforce_limits: true, enforce_limits: true,
**Gitlab::Git::DiffCollection.collection_limits.to_h # Tests limitation parameters explicitly
max_files: 100,
max_lines: 5000,
max_bytes: 512000,
safe_max_files: 100,
safe_max_lines: 5000,
safe_max_bytes: 512000,
max_patch_bytes: 102400
) )
expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash))