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
1e26f1e4
Commit
1e26f1e4
authored
Apr 05, 2021
by
Quang-Minh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add start time to external http items in the performance bar
Issue
https://gitlab.com/groups/gitlab-org/-/epics/5590
parent
f48f1396
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
31 deletions
+64
-31
lib/gitlab/metrics/subscribers/external_http.rb
lib/gitlab/metrics/subscribers/external_http.rb
+3
-2
spec/lib/gitlab/metrics/subscribers/external_http_spec.rb
spec/lib/gitlab/metrics/subscribers/external_http_spec.rb
+38
-19
spec/lib/peek/views/external_http_spec.rb
spec/lib/peek/views/external_http_spec.rb
+23
-10
No files found.
lib/gitlab/metrics/subscribers/external_http.rb
View file @
1e26f1e4
...
...
@@ -37,7 +37,7 @@ module Gitlab
def
request
(
event
)
payload
=
event
.
payload
add_to_detail_store
(
payload
)
add_to_detail_store
(
event
.
time
,
payload
)
add_to_request_store
(
payload
)
expose_metrics
(
payload
)
end
...
...
@@ -48,10 +48,11 @@ module Gitlab
::
Gitlab
::
Metrics
::
Transaction
.
current
end
def
add_to_detail_store
(
payload
)
def
add_to_detail_store
(
start
,
payload
)
return
unless
Gitlab
::
PerformanceBar
.
enabled_for_request?
self
.
class
.
detail_store
<<
{
start:
start
,
duration:
payload
[
:duration
],
scheme:
payload
[
:scheme
],
method:
payload
[
:method
],
...
...
spec/lib/gitlab/metrics/subscribers/external_http_spec.rb
View file @
1e26f1e4
...
...
@@ -6,29 +6,45 @@ RSpec.describe Gitlab::Metrics::Subscribers::ExternalHttp, :request_store do
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
}
let
(
:subscriber
)
{
described_class
.
new
}
around
do
|
example
|
freeze_time
{
example
.
run
}
end
let
(
:event_1
)
do
double
(
:event
,
payload:
{
double
(
:event
,
payload:
{
method:
'POST'
,
code:
"200"
,
duration:
0.321
,
scheme:
'https'
,
host:
'gitlab.com'
,
port:
80
,
path:
'/api/v4/projects'
,
query:
'current=true'
})
},
time:
Time
.
current
)
end
let
(
:event_2
)
do
double
(
:event
,
payload:
{
double
(
:event
,
payload:
{
method:
'GET'
,
code:
"301"
,
duration:
0.12
,
scheme:
'http'
,
host:
'gitlab.com'
,
port:
80
,
path:
'/api/v4/projects/2'
,
query:
'current=true'
})
},
time:
Time
.
current
)
end
let
(
:event_3
)
do
double
(
:event
,
payload:
{
double
(
:event
,
payload:
{
method:
'POST'
,
duration:
5.3
,
scheme:
'http'
,
host:
'gitlab.com'
,
port:
80
,
path:
'/api/v4/projects/2/issues'
,
query:
'current=true'
,
exception_object:
Net
::
ReadTimeout
.
new
})
},
time:
Time
.
current
)
end
describe
'.detail_store'
do
...
...
@@ -134,19 +150,22 @@ RSpec.describe Gitlab::Metrics::Subscribers::ExternalHttp, :request_store do
subscriber
.
request
(
event_3
)
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
].
length
).
to
eq
(
3
)
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
][
0
]).
to
include
(
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
][
0
]).
to
match
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
method:
'POST'
,
code:
"200"
,
duration:
0.321
,
scheme:
'https'
,
host:
'gitlab.com'
,
port:
80
,
path:
'/api/v4/projects'
,
query:
'current=true'
,
exception_object:
nil
,
backtrace:
be_a
(
Array
)
)
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
][
1
]).
to
include
(
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
][
1
]).
to
match
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
method:
'GET'
,
code:
"301"
,
duration:
0.12
,
scheme:
'http'
,
host:
'gitlab.com'
,
port:
80
,
path:
'/api/v4/projects/2'
,
query:
'current=true'
,
exception_object:
nil
,
backtrace:
be_a
(
Array
)
)
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
][
2
]).
to
include
(
expect
(
Gitlab
::
SafeRequestStore
[
:external_http_detail_store
][
2
]).
to
match
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
method:
'POST'
,
duration:
5.3
,
scheme:
'http'
,
host:
'gitlab.com'
,
port:
80
,
path:
'/api/v4/projects/2/issues'
,
query:
'current=true'
,
...
...
spec/lib/peek/views/external_http_spec.rb
View file @
1e26f1e4
...
...
@@ -11,6 +11,10 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
allow
(
Gitlab
::
PerformanceBar
).
to
receive
(
:enabled_for_request?
).
and_return
(
true
)
end
around
do
|
example
|
freeze_time
{
example
.
run
}
end
let
(
:event_1
)
do
{
method:
'POST'
,
code:
"200"
,
duration:
0.03
,
...
...
@@ -44,9 +48,9 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'returns aggregated results'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_2
))
subscriber
.
request
(
double
(
:event
,
payload:
event_3
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
subscriber
.
request
(
double
(
:event
,
payload:
event_2
,
time:
Time
.
current
))
subscriber
.
request
(
double
(
:event
,
payload:
event_3
,
time:
Time
.
current
))
results
=
subject
.
results
expect
(
results
[
:calls
]).
to
eq
(
3
)
...
...
@@ -55,6 +59,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
expected
=
[
{
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST https://gitlab.com:80/api/v4/projects?current=true"
,
code:
"Response status: 200"
,
...
...
@@ -63,6 +68,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
warnings:
[]
},
{
start:
be_like_time
(
Time
.
current
),
duration:
1300
,
label:
"POST http://gitlab.com:80/api/v4/projects/2/issues?current=true"
,
code:
nil
,
...
...
@@ -71,6 +77,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
warnings:
[
"1300.0 over 100"
]
},
{
start:
be_like_time
(
Time
.
current
),
duration:
5.0
,
label:
"GET http://gitlab.com:80/api/v4/projects/2?current=true"
,
code:
"Response status: 301"
,
...
...
@@ -81,7 +88,7 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
]
expect
(
results
[
:details
].
map
{
|
data
|
data
.
slice
(
:duration
,
:label
,
:code
,
:proxy
,
:error
,
:warnings
)
}
results
[
:details
].
map
{
|
data
|
data
.
slice
(
:
start
,
:
duration
,
:label
,
:code
,
:proxy
,
:error
,
:warnings
)
}
).
to
match_array
(
expected
)
end
...
...
@@ -91,10 +98,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'displays IPv4 in the label'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
expect
(
subject
.
results
[
:details
]).
to
contain_exactly
(
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST https://1.2.3.4:80/api/v4/projects?current=true"
,
code:
"Response status: 200"
,
...
...
@@ -112,10 +120,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'displays IPv6 in the label'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
expect
(
subject
.
results
[
:details
]).
to
contain_exactly
(
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST https://[2606:4700:90:0:f22e:fbec:5bed:a9b9]:80/api/v4/projects?current=true"
,
code:
"Response status: 200"
,
...
...
@@ -133,10 +142,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'converts query hash into a query string'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
expect
(
subject
.
results
[
:details
]).
to
contain_exactly
(
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST https://gitlab.com:80/api/v4/projects?current=true&item1=string&item2%5B%5D=1&item2%5B%5D=2"
,
code:
"Response status: 200"
,
...
...
@@ -154,10 +164,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'displays unknown in the label'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
expect
(
subject
.
results
[
:details
]).
to
contain_exactly
(
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST unknown"
,
code:
"Response status: 200"
,
...
...
@@ -176,10 +187,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'displays unknown in the label'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
expect
(
subject
.
results
[
:details
]).
to
contain_exactly
(
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST unknown"
,
code:
"Response status: 200"
,
...
...
@@ -198,10 +210,11 @@ RSpec.describe Peek::Views::ExternalHttp, :request_store do
end
it
'displays unknown in the label'
do
subscriber
.
request
(
double
(
:event
,
payload:
event_1
))
subscriber
.
request
(
double
(
:event
,
payload:
event_1
,
time:
Time
.
current
))
expect
(
subject
.
results
[
:details
]).
to
contain_exactly
(
a_hash_including
(
start:
be_like_time
(
Time
.
current
),
duration:
30.0
,
label:
"POST unknown"
,
code:
"Response status: 200"
,
...
...
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