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
3b6ce56a
Commit
3b6ce56a
authored
Aug 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
93529258
b31b6764
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
205 additions
and
16 deletions
+205
-16
config/initializers/peek.rb
config/initializers/peek.rb
+1
-0
lib/gitlab/performance_bar/with_top_level_warnings.rb
lib/gitlab/performance_bar/with_top_level_warnings.rb
+19
-0
lib/peek/views/active_record.rb
lib/peek/views/active_record.rb
+18
-0
lib/peek/views/detailed_view.rb
lib/peek/views/detailed_view.rb
+34
-11
lib/peek/views/gitaly.rb
lib/peek/views/gitaly.rb
+18
-0
lib/peek/views/rugged.rb
lib/peek/views/rugged.rb
+1
-1
spec/lib/gitlab/performance_bar/with_top_level_warnings_spec.rb
...ib/gitlab/performance_bar/with_top_level_warnings_spec.rb
+29
-0
spec/lib/peek/views/detailed_view_spec.rb
spec/lib/peek/views/detailed_view_spec.rb
+81
-0
spec/lib/peek/views/redis_detailed_spec.rb
spec/lib/peek/views/redis_detailed_spec.rb
+4
-4
No files found.
config/initializers/peek.rb
View file @
3b6ce56a
require
'peek/adapters/redis'
Peek
::
Adapters
::
Redis
.
prepend
::
Gitlab
::
PerformanceBar
::
RedisAdapterWhenPeekEnabled
Peek
.
singleton_class
.
prepend
::
Gitlab
::
PerformanceBar
::
WithTopLevelWarnings
Rails
.
application
.
config
.
peek
.
adapter
=
:redis
,
{
client:
::
Redis
.
new
(
Gitlab
::
Redis
::
Cache
.
params
)
}
...
...
lib/gitlab/performance_bar/with_top_level_warnings.rb
0 → 100644
View file @
3b6ce56a
# frozen_string_literal: true
module
Gitlab
module
PerformanceBar
module
WithTopLevelWarnings
def
results
results
=
super
results
.
merge
(
has_warnings:
has_warnings?
(
results
))
end
def
has_warnings?
(
results
)
results
[
:data
].
any?
do
|
_
,
value
|
value
[
:warnings
].
present?
end
end
end
end
end
lib/peek/views/active_record.rb
View file @
3b6ce56a
...
...
@@ -3,6 +3,24 @@
module
Peek
module
Views
class
ActiveRecord
<
DetailedView
DEFAULT_THRESHOLDS
=
{
calls:
100
,
duration:
3
,
individual_call:
1
}.
freeze
THRESHOLDS
=
{
production:
{
calls:
100
,
duration:
15
,
individual_call:
5
}
}.
freeze
def
self
.
thresholds
@thresholds
||=
THRESHOLDS
.
fetch
(
Rails
.
env
.
to_sym
,
DEFAULT_THRESHOLDS
)
end
private
def
setup_subscribers
...
...
lib/peek/views/detailed_view.rb
View file @
3b6ce56a
...
...
@@ -3,11 +3,16 @@
module
Peek
module
Views
class
DetailedView
<
View
def
self
.
thresholds
{}
end
def
results
{
duration:
format
ted_duration
,
duration:
format
_duration
(
duration
)
,
calls:
calls
,
details:
details
details:
details
,
warnings:
warnings
}
end
...
...
@@ -18,30 +23,48 @@ module Peek
private
def
duration
detail_store
.
map
{
|
entry
|
entry
[
:duration
]
}.
sum
# rubocop:disable CodeReuse/ActiveRecord
detail_store
.
map
{
|
entry
|
entry
[
:duration
]
}.
sum
*
1000
# rubocop:disable CodeReuse/ActiveRecord
end
def
calls
detail_store
.
count
end
def
details
call_details
.
sort
{
|
a
,
b
|
b
[
:duration
]
<=>
a
[
:duration
]
}
.
map
(
&
method
(
:format_call_details
))
end
def
warnings
[
warning_for
(
calls
,
self
.
class
.
thresholds
[
:calls
],
label:
"
#{
key
}
calls"
),
warning_for
(
duration
,
self
.
class
.
thresholds
[
:duration
],
label:
"
#{
key
}
duration"
)
].
flatten
.
compact
end
def
call_details
detail_store
end
def
format_call_details
(
call
)
call
.
merge
(
duration:
(
call
[
:duration
]
*
1000
).
round
(
3
))
end
duration
=
(
call
[
:duration
]
*
1000
).
round
(
3
)
def
details
call_details
.
sort
{
|
a
,
b
|
b
[
:duration
]
<=>
a
[
:duration
]
}
.
map
(
&
method
(
:format_call_details
))
call
.
merge
(
duration:
duration
,
warnings:
warning_for
(
duration
,
self
.
class
.
thresholds
[
:individual_call
]))
end
def
formatted_duration
ms
=
duration
*
1000
def
warning_for
(
actual
,
threshold
,
label:
nil
)
if
threshold
&&
actual
>
threshold
prefix
=
"
#{
label
}
: "
if
label
[
"
#{
prefix
}#{
actual
}
over
#{
threshold
}
"
]
else
[]
end
end
def
format_duration
(
ms
)
if
ms
>=
1000
"%.2fms"
%
ms
else
...
...
lib/peek/views/gitaly.rb
View file @
3b6ce56a
...
...
@@ -3,6 +3,24 @@
module
Peek
module
Views
class
Gitaly
<
DetailedView
DEFAULT_THRESHOLDS
=
{
calls:
30
,
duration:
1
,
individual_call:
0.5
}.
freeze
THRESHOLDS
=
{
production:
{
calls:
30
,
duration:
1
,
individual_call:
0.5
}
}.
freeze
def
self
.
thresholds
@thresholds
||=
THRESHOLDS
.
fetch
(
Rails
.
env
.
to_sym
,
DEFAULT_THRESHOLDS
)
end
private
def
duration
...
...
lib/peek/views/rugged.rb
View file @
3b6ce56a
...
...
@@ -12,7 +12,7 @@ module Peek
private
def
duration
::
Gitlab
::
RuggedInstrumentation
.
query_time
::
Gitlab
::
RuggedInstrumentation
.
query_time
_ms
end
def
calls
...
...
spec/lib/gitlab/performance_bar/with_top_level_warnings_spec.rb
0 → 100644
View file @
3b6ce56a
# frozen_string_literal: true
require
'fast_spec_helper'
require
'rspec-parameterized'
describe
Gitlab
::
PerformanceBar
::
WithTopLevelWarnings
do
using
RSpec
::
Parameterized
::
TableSyntax
subject
{
Module
.
new
}
before
do
subject
.
singleton_class
.
prepend
(
described_class
)
end
describe
'#has_warnings?'
do
where
(
:has_warnings
,
:results
)
do
false
|
{
data:
{}
}
false
|
{
data:
{
gitaly:
{
warnings:
[]
}
}
}
true
|
{
data:
{
gitaly:
{
warnings:
[
1
]
}
}
}
true
|
{
data:
{
gitaly:
{
warnings:
[]
},
redis:
{
warnings:
[
1
]
}
}
}
end
with_them
do
it
do
expect
(
subject
.
has_warnings?
(
results
)).
to
eq
(
has_warnings
)
end
end
end
end
spec/lib/peek/views/detailed_view_spec.rb
0 → 100644
View file @
3b6ce56a
# frozen_string_literal: true
require
'fast_spec_helper'
describe
Peek
::
Views
::
DetailedView
,
:request_store
do
context
'when a class defines thresholds'
do
let
(
:threshold_view
)
do
Class
.
new
(
described_class
)
do
def
self
.
thresholds
{
calls:
1
,
duration:
10
,
individual_call:
5
}
end
def
key
'threshold-view'
end
end
.
new
end
context
'when the results exceed the calls threshold'
do
before
do
allow
(
threshold_view
)
.
to
receive
(
:detail_store
).
and_return
([{
duration:
0.001
},
{
duration:
0.001
}])
end
it
'adds a warning to the results key'
do
expect
(
threshold_view
.
results
).
to
include
(
warnings:
[
a_string_matching
(
'threshold-view calls'
)])
end
end
context
'when the results exceed the duration threshold'
do
before
do
allow
(
threshold_view
)
.
to
receive
(
:detail_store
).
and_return
([{
duration:
0.011
}])
end
it
'adds a warning to the results key'
do
expect
(
threshold_view
.
results
).
to
include
(
warnings:
[
a_string_matching
(
'threshold-view duration'
)])
end
end
context
'when a single call exceeds the duration threshold'
do
before
do
allow
(
threshold_view
)
.
to
receive
(
:detail_store
).
and_return
([{
duration:
0.001
},
{
duration:
0.006
}])
end
it
'adds a warning to that call detail entry'
do
expect
(
threshold_view
.
results
)
.
to
include
(
details:
a_collection_containing_exactly
(
{
duration:
1.0
,
warnings:
[]
},
{
duration:
6.0
,
warnings:
[
'6.0 over 5'
]
}
))
end
end
end
context
'when a view does not define thresholds'
do
let
(
:no_threshold_view
)
{
Class
.
new
(
described_class
).
new
}
before
do
allow
(
no_threshold_view
)
.
to
receive
(
:detail_store
).
and_return
([{
duration:
100
},
{
duration:
100
}])
end
it
'does not add warnings to the top level'
do
expect
(
no_threshold_view
.
results
).
to
include
(
warnings:
[])
end
it
'does not add warnings to call details entries'
do
expect
(
no_threshold_view
.
results
)
.
to
include
(
details:
a_collection_containing_exactly
(
{
duration:
100000
,
warnings:
[]
},
{
duration:
100000
,
warnings:
[]
}
))
end
end
end
spec/lib/peek/views/redis_detailed_spec.rb
View file @
3b6ce56a
...
...
@@ -21,10 +21,10 @@ describe Peek::Views::RedisDetailed, :request_store do
expect
(
subject
.
results
[
:details
].
count
).
to
eq
(
1
)
expect
(
subject
.
results
[
:details
].
first
)
.
to
eq
({
cmd:
expected
,
duration:
1000
})
.
to
include
({
cmd:
expected
,
duration:
1000
})
end
end
...
...
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