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
9487db4a
Commit
9487db4a
authored
Apr 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
12d6bd72
e6f548fc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
5 deletions
+58
-5
changelogs/unreleased/jc-client-gitaly-session-id.yml
changelogs/unreleased/jc-client-gitaly-session-id.yml
+5
-0
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+7
-1
lib/gitlab/profiler.rb
lib/gitlab/profiler.rb
+1
-1
spec/lib/gitlab/gitaly_client_spec.rb
spec/lib/gitlab/gitaly_client_spec.rb
+42
-0
spec/lib/gitlab/profiler_spec.rb
spec/lib/gitlab/profiler_spec.rb
+3
-3
No files found.
changelogs/unreleased/jc-client-gitaly-session-id.yml
0 → 100644
View file @
9487db4a
---
title
:
Add gitaly session id & catfile-cache feature flag
merge_request
:
27472
author
:
type
:
performance
lib/gitlab/gitaly_client.rb
View file @
9487db4a
...
...
@@ -31,6 +31,9 @@ module Gitlab
MAXIMUM_GITALY_CALLS
=
30
CLIENT_NAME
=
(
Sidekiq
.
server?
?
'gitlab-sidekiq'
:
'gitlab-web'
).
freeze
SERVER_FEATURE_CATFILE_CACHE
=
'catfile-cache'
.
freeze
SERVER_FEATURE_FLAGS
=
[
SERVER_FEATURE_CATFILE_CACHE
].
freeze
MUTEX
=
Mutex
.
new
define_histogram
:gitaly_controller_action_duration_seconds
do
...
...
@@ -219,6 +222,7 @@ module Gitlab
metadata
[
'call_site'
]
=
feature
.
to_s
if
feature
metadata
[
'gitaly-servers'
]
=
address_metadata
(
remote_storage
)
if
remote_storage
metadata
[
'x-gitlab-correlation-id'
]
=
Labkit
::
Correlation
::
CorrelationId
.
current_id
if
Labkit
::
Correlation
::
CorrelationId
.
current_id
metadata
[
'gitaly-session-id'
]
=
session_id
if
feature_enabled?
(
SERVER_FEATURE_CATFILE_CACHE
)
metadata
.
merge!
(
server_feature_flags
)
...
...
@@ -235,7 +239,9 @@ module Gitlab
result
end
SERVER_FEATURE_FLAGS
=
%w[]
.
freeze
def
self
.
session_id
Gitlab
::
SafeRequestStore
[
:gitaly_session_id
]
||=
SecureRandom
.
uuid
end
def
self
.
server_feature_flags
SERVER_FEATURE_FLAGS
.
map
do
|
f
|
...
...
lib/gitlab/profiler.rb
View file @
9487db4a
...
...
@@ -73,7 +73,7 @@ module Gitlab
result
=
with_custom_logger
(
logger
)
do
with_user
(
user
)
do
RubyProf
.
profile
{
app
.
public_send
(
verb
,
url
,
p
ost_data
,
headers
)
}
# rubocop:disable GitlabSecurity/PublicSend
RubyProf
.
profile
{
app
.
public_send
(
verb
,
url
,
p
arams:
post_data
,
headers:
headers
)
}
# rubocop:disable GitlabSecurity/PublicSend
end
end
...
...
spec/lib/gitlab/gitaly_client_spec.rb
View file @
9487db4a
...
...
@@ -142,6 +142,48 @@ describe Gitlab::GitalyClient do
end
end
describe
'.request_kwargs'
do
context
'when catfile-cache feature is enabled'
do
before
do
stub_feature_flags
(
'gitaly_catfile-cache'
:
true
)
end
it
'sets the gitaly-session-id in the metadata'
do
results
=
described_class
.
request_kwargs
(
'default'
,
nil
)
expect
(
results
[
:metadata
]).
to
include
(
'gitaly-session-id'
)
end
context
'when RequestStore is not enabled'
do
it
'sets a different gitaly-session-id per request'
do
gitaly_session_id
=
described_class
.
request_kwargs
(
'default'
,
nil
)[
:metadata
][
'gitaly-session-id'
]
expect
(
described_class
.
request_kwargs
(
'default'
,
nil
)[
:metadata
][
'gitaly-session-id'
]).
not_to
eq
(
gitaly_session_id
)
end
end
context
'when RequestStore is enabled'
,
:request_store
do
it
'sets the same gitaly-session-id on every outgoing request metadata'
do
gitaly_session_id
=
described_class
.
request_kwargs
(
'default'
,
nil
)[
:metadata
][
'gitaly-session-id'
]
3
.
times
do
expect
(
described_class
.
request_kwargs
(
'default'
,
nil
)[
:metadata
][
'gitaly-session-id'
]).
to
eq
(
gitaly_session_id
)
end
end
end
end
context
'when catfile-cache feature is disabled'
do
before
do
stub_feature_flags
({
'gitaly_catfile-cache'
:
false
})
end
it
'does not set the gitaly-session-id in the metadata'
do
results
=
described_class
.
request_kwargs
(
'default'
,
nil
)
expect
(
results
[
:metadata
]).
not_to
include
(
'gitaly-session-id'
)
end
end
end
describe
'enforce_gitaly_request_limits?'
do
def
call_gitaly
(
count
=
1
)
(
1
..
count
).
each
do
...
...
spec/lib/gitlab/profiler_spec.rb
View file @
9487db4a
...
...
@@ -27,13 +27,13 @@ describe Gitlab::Profiler do
it
'sends a POST request when data is passed'
do
post_data
=
'{"a":1}'
expect
(
app
).
to
receive
(
:post
).
with
(
anything
,
p
ost_data
,
anything
)
expect
(
app
).
to
receive
(
:post
).
with
(
anything
,
p
arams:
post_data
,
headers:
anything
)
described_class
.
profile
(
'/'
,
post_data:
post_data
)
end
it
'uses the private_token for auth if given'
do
expect
(
app
).
to
receive
(
:get
).
with
(
'/'
,
nil
,
'Private-Token'
=>
private_token
)
expect
(
app
).
to
receive
(
:get
).
with
(
'/'
,
params:
nil
,
headers:
{
'Private-Token'
=>
private_token
}
)
expect
(
app
).
to
receive
(
:get
).
with
(
'/api/v4/users'
)
described_class
.
profile
(
'/'
,
private_token:
private_token
)
...
...
@@ -51,7 +51,7 @@ describe Gitlab::Profiler do
user
=
double
(
:user
)
expect
(
described_class
).
to
receive
(
:with_user
).
with
(
nil
).
and_call_original
expect
(
app
).
to
receive
(
:get
).
with
(
'/'
,
nil
,
'Private-Token'
=>
private_token
)
expect
(
app
).
to
receive
(
:get
).
with
(
'/'
,
params:
nil
,
headers:
{
'Private-Token'
=>
private_token
}
)
expect
(
app
).
to
receive
(
:get
).
with
(
'/api/v4/users'
)
described_class
.
profile
(
'/'
,
user:
user
,
private_token:
private_token
)
...
...
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