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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
833808d7
Commit
833808d7
authored
Apr 08, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'instrument-rails-cache' into 'master'
Instrument Rails cache code See merge request !3619
parents
5ef170ae
c56f702e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
0 deletions
+111
-0
config/initializers/metrics.rb
config/initializers/metrics.rb
+1
-0
lib/gitlab/metrics/subscribers/rails_cache.rb
lib/gitlab/metrics/subscribers/rails_cache.rb
+39
-0
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
+71
-0
No files found.
config/initializers/metrics.rb
View file @
833808d7
...
@@ -7,6 +7,7 @@ if Gitlab::Metrics.enabled?
...
@@ -7,6 +7,7 @@ if Gitlab::Metrics.enabled?
# ActiveSupport.
# ActiveSupport.
require
'gitlab/metrics/subscribers/action_view'
require
'gitlab/metrics/subscribers/action_view'
require
'gitlab/metrics/subscribers/active_record'
require
'gitlab/metrics/subscribers/active_record'
require
'gitlab/metrics/subscribers/rails_cache'
Gitlab
::
Application
.
configure
do
|
config
|
Gitlab
::
Application
.
configure
do
|
config
|
config
.
middleware
.
use
(
Gitlab
::
Metrics
::
RackMiddleware
)
config
.
middleware
.
use
(
Gitlab
::
Metrics
::
RackMiddleware
)
...
...
lib/gitlab/metrics/subscribers/rails_cache.rb
0 → 100644
View file @
833808d7
module
Gitlab
module
Metrics
module
Subscribers
# Class for tracking the total time spent in Rails cache calls
class
RailsCache
<
ActiveSupport
::
Subscriber
attach_to
:active_support
def
cache_read
(
event
)
increment
(
:cache_read_duration
,
event
.
duration
)
end
def
cache_write
(
event
)
increment
(
:cache_write_duration
,
event
.
duration
)
end
def
cache_delete
(
event
)
increment
(
:cache_delete_duration
,
event
.
duration
)
end
def
cache_exist?
(
event
)
increment
(
:cache_exists_duration
,
event
.
duration
)
end
def
increment
(
key
,
duration
)
return
unless
current_transaction
current_transaction
.
increment
(
:cache_duration
,
duration
)
current_transaction
.
increment
(
key
,
duration
)
end
private
def
current_transaction
Transaction
.
current
end
end
end
end
end
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
0 → 100644
View file @
833808d7
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Subscribers
::
RailsCache
do
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:event
)
{
double
(
:event
,
duration:
15.2
)
}
describe
'#cache_read'
do
it
'increments the cache_read duration'
do
expect
(
subscriber
).
to
receive
(
:increment
).
with
(
:cache_read_duration
,
event
.
duration
)
subscriber
.
cache_read
(
event
)
end
end
describe
'#cache_write'
do
it
'increments the cache_write duration'
do
expect
(
subscriber
).
to
receive
(
:increment
).
with
(
:cache_write_duration
,
event
.
duration
)
subscriber
.
cache_write
(
event
)
end
end
describe
'#cache_delete'
do
it
'increments the cache_delete duration'
do
expect
(
subscriber
).
to
receive
(
:increment
).
with
(
:cache_delete_duration
,
event
.
duration
)
subscriber
.
cache_delete
(
event
)
end
end
describe
'#cache_exist?'
do
it
'increments the cache_exists duration'
do
expect
(
subscriber
).
to
receive
(
:increment
).
with
(
:cache_exists_duration
,
event
.
duration
)
subscriber
.
cache_exist?
(
event
)
end
end
describe
'#increment'
do
context
'without a transaction'
do
it
'returns'
do
expect
(
transaction
).
not_to
receive
(
:increment
)
subscriber
.
increment
(
:foo
,
15.2
)
end
end
context
'with a transaction'
do
before
do
allow
(
subscriber
).
to
receive
(
:current_transaction
).
and_return
(
transaction
)
end
it
'increments the total and specific cache duration'
do
expect
(
transaction
).
to
receive
(
:increment
).
with
(
:cache_duration
,
event
.
duration
)
expect
(
transaction
).
to
receive
(
:increment
).
with
(
:cache_delete_duration
,
event
.
duration
)
subscriber
.
increment
(
:cache_delete_duration
,
event
.
duration
)
end
end
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