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
iv
gitlab-ce
Commits
66a997a9
Commit
66a997a9
authored
Jan 04, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track total query/view timings in transactions
parent
96075be6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
0 deletions
+62
-0
config/initializers/metrics.rb
config/initializers/metrics.rb
+1
-0
lib/gitlab/metrics/subscribers/action_view.rb
lib/gitlab/metrics/subscribers/action_view.rb
+1
-0
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+22
-0
spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
+3
-0
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+35
-0
No files found.
config/initializers/metrics.rb
View file @
66a997a9
...
@@ -6,6 +6,7 @@ if Gitlab::Metrics.enabled?
...
@@ -6,6 +6,7 @@ if Gitlab::Metrics.enabled?
# These are manually require'd so the classes are registered properly with
# These are manually require'd so the classes are registered properly with
# ActiveSupport.
# ActiveSupport.
require
'gitlab/metrics/subscribers/action_view'
require
'gitlab/metrics/subscribers/action_view'
require
'gitlab/metrics/subscribers/active_record'
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/action_view.rb
View file @
66a997a9
...
@@ -19,6 +19,7 @@ module Gitlab
...
@@ -19,6 +19,7 @@ module Gitlab
values
=
values_for
(
event
)
values
=
values_for
(
event
)
tags
=
tags_for
(
event
)
tags
=
tags_for
(
event
)
current_transaction
.
increment
(
:view_duration
,
event
.
duration
)
current_transaction
.
add_metric
(
SERIES
,
values
,
tags
)
current_transaction
.
add_metric
(
SERIES
,
values
,
tags
)
end
end
...
...
lib/gitlab/metrics/subscribers/active_record.rb
0 → 100644
View file @
66a997a9
module
Gitlab
module
Metrics
module
Subscribers
# Class for tracking the total query duration of a transaction.
class
ActiveRecord
<
ActiveSupport
::
Subscriber
attach_to
:active_record
def
sql
(
event
)
return
unless
current_transaction
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
)
end
private
def
current_transaction
Transaction
.
current
end
end
end
end
end
spec/lib/gitlab/metrics/subscribers/action_view_spec.rb
View file @
66a997a9
...
@@ -28,6 +28,9 @@ describe Gitlab::Metrics::Subscribers::ActionView do
...
@@ -28,6 +28,9 @@ describe Gitlab::Metrics::Subscribers::ActionView do
line:
4
line:
4
}
}
expect
(
transaction
).
to
receive
(
:increment
).
with
(
:view_duration
,
2.1
)
expect
(
transaction
).
to
receive
(
:add_metric
).
expect
(
transaction
).
to
receive
(
:add_metric
).
with
(
described_class
::
SERIES
,
values
,
tags
)
with
(
described_class
::
SERIES
,
values
,
tags
)
...
...
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
0 → 100644
View file @
66a997a9
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Subscribers
::
ActiveRecord
do
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
(
'rspec'
)
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:event
)
do
double
(
:event
,
duration:
0.2
,
payload:
{
sql:
'SELECT * FROM users WHERE id = 10'
})
end
describe
'#sql'
do
describe
'without a current transaction'
do
it
'simply returns'
do
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
).
to_not
receive
(
:increment
)
subscriber
.
sql
(
event
)
end
end
describe
'with a current transaction'
do
it
'increments the :sql_duration value'
do
expect
(
subscriber
).
to
receive
(
:current_transaction
).
at_least
(
:once
).
and_return
(
transaction
)
expect
(
transaction
).
to
receive
(
:increment
).
with
(
:sql_duration
,
0.2
)
subscriber
.
sql
(
event
)
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