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
f6b8f7b6
Commit
f6b8f7b6
authored
Mar 11, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
0fcbbdc3
d018f1dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
3 deletions
+51
-3
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+14
-2
spec/lib/gitlab/gitaly_client_spec.rb
spec/lib/gitlab/gitaly_client_spec.rb
+37
-1
No files found.
lib/gitlab/gitaly_client.rb
View file @
f6b8f7b6
...
...
@@ -257,8 +257,7 @@ module Gitlab
# This is this actual number of times this call was made. Used for information purposes only
actual_call_count
=
increment_call_count
(
"gitaly_
#{
call_site
}
_actual"
)
# Do no enforce limits in production
return
if
Rails
.
env
.
production?
||
ENV
[
"GITALY_DISABLE_REQUEST_LIMITS"
]
return
unless
enforce_gitaly_request_limits?
# Check if this call is nested within a allow_n_plus_1_calls
# block and skip check if it is
...
...
@@ -275,6 +274,19 @@ module Gitlab
raise
TooManyInvocationsError
.
new
(
call_site
,
actual_call_count
,
max_call_count
,
max_stacks
)
end
def
self
.
enforce_gitaly_request_limits?
# We typically don't want to enforce request limits in production
# However, we have some production-like test environments, i.e., ones
# where `Rails.env.production?` returns `true`. We do want to be able to
# check if the limit is being exceeded while testing in those environments
# In that case we can use a feature flag to indicate that we do want to
# enforce request limits.
return
true
if
feature_enabled?
(
'enforce_requests_limits'
)
!
(
Rails
.
env
.
production?
||
ENV
[
"GITALY_DISABLE_REQUEST_LIMITS"
])
end
private_class_method
:enforce_gitaly_request_limits?
def
self
.
allow_n_plus_1_calls
return
yield
unless
Gitlab
::
SafeRequestStore
.
active?
...
...
spec/lib/gitlab/gitaly_client_spec.rb
View file @
f6b8f7b6
...
...
@@ -149,11 +149,21 @@ describe Gitlab::GitalyClient do
end
end
context
'when RequestStore is enabled'
,
:request_store
do
context
'when RequestStore is enabled and the maximum number of calls is not enforced by a feature flag'
,
:request_store
do
before
do
stub_feature_flags
(
gitaly_enforce_requests_limits:
false
)
end
it
'allows up the maximum number of allowed calls'
do
expect
{
call_gitaly
(
Gitlab
::
GitalyClient
::
MAXIMUM_GITALY_CALLS
)
}.
not_to
raise_error
end
it
'allows the maximum number of calls to be exceeded if GITALY_DISABLE_REQUEST_LIMITS is set'
do
stub_env
(
'GITALY_DISABLE_REQUEST_LIMITS'
,
'true'
)
expect
{
call_gitaly
(
Gitlab
::
GitalyClient
::
MAXIMUM_GITALY_CALLS
+
1
)
}.
not_to
raise_error
end
context
'when the maximum number of calls has been reached'
do
before
do
call_gitaly
(
Gitlab
::
GitalyClient
::
MAXIMUM_GITALY_CALLS
)
...
...
@@ -189,6 +199,32 @@ describe Gitlab::GitalyClient do
end
end
context
'in production and when RequestStore is enabled'
,
:request_store
do
before
do
allow
(
Rails
.
env
).
to
receive
(
:production?
).
and_return
(
true
)
end
context
'when the maximum number of calls is enforced by a feature flag'
do
before
do
stub_feature_flags
(
gitaly_enforce_requests_limits:
true
)
end
it
'does not allow the maximum number of calls to be exceeded'
do
expect
{
call_gitaly
(
Gitlab
::
GitalyClient
::
MAXIMUM_GITALY_CALLS
+
1
)
}.
to
raise_error
(
Gitlab
::
GitalyClient
::
TooManyInvocationsError
)
end
end
context
'when the maximum number of calls is not enforced by a feature flag'
do
before
do
stub_feature_flags
(
gitaly_enforce_requests_limits:
false
)
end
it
'allows the maximum number of calls to be exceeded'
do
expect
{
call_gitaly
(
Gitlab
::
GitalyClient
::
MAXIMUM_GITALY_CALLS
+
1
)
}.
not_to
raise_error
end
end
end
context
'when RequestStore is not active'
do
it
'does not raise errors when the maximum number of allowed calls is exceeded'
do
expect
{
call_gitaly
(
Gitlab
::
GitalyClient
::
MAXIMUM_GITALY_CALLS
+
2
)
}.
not_to
raise_error
...
...
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