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
Boxiang Sun
gitlab-ce
Commits
d65e7aa9
Commit
d65e7aa9
authored
Jan 11, 2016
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'add-action-to-all-metrics' into 'master'
See merge request !2370
parents
701e9ee4
35b501f3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
25 deletions
+41
-25
lib/gitlab/metrics/rack_middleware.rb
lib/gitlab/metrics/rack_middleware.rb
+2
-4
lib/gitlab/metrics/sidekiq_middleware.rb
lib/gitlab/metrics/sidekiq_middleware.rb
+1
-6
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+15
-2
spec/lib/gitlab/metrics/rack_middleware_spec.rb
spec/lib/gitlab/metrics/rack_middleware_spec.rb
+1
-1
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
+5
-12
spec/lib/gitlab/metrics/transaction_spec.rb
spec/lib/gitlab/metrics/transaction_spec.rb
+17
-0
No files found.
lib/gitlab/metrics/rack_middleware.rb
View file @
d65e7aa9
...
...
@@ -40,9 +40,7 @@ module Gitlab
def
tag_controller
(
trans
,
env
)
controller
=
env
[
CONTROLLER_KEY
]
label
=
"
#{
controller
.
class
.
name
}
#
#{
controller
.
action_name
}
"
trans
.
add_tag
(
:action
,
label
)
trans
.
action
=
"
#{
controller
.
class
.
name
}
#
#{
controller
.
action_name
}
"
end
end
end
...
...
lib/gitlab/metrics/sidekiq_middleware.rb
View file @
d65e7aa9
...
...
@@ -5,19 +5,14 @@ module Gitlab
# This middleware is intended to be used as a server-side middleware.
class
SidekiqMiddleware
def
call
(
worker
,
message
,
queue
)
trans
=
Transaction
.
new
trans
=
Transaction
.
new
(
"
#{
worker
.
class
.
name
}
#perform"
)
begin
trans
.
run
{
yield
}
ensure
tag_worker
(
trans
,
worker
)
trans
.
finish
end
end
def
tag_worker
(
trans
,
worker
)
trans
.
add_tag
(
:action
,
"
#{
worker
.
class
.
name
}
#perform"
)
end
end
end
end
lib/gitlab/metrics/transaction.rb
View file @
d65e7aa9
...
...
@@ -6,11 +6,15 @@ module Gitlab
attr_reader
:tags
,
:values
attr_accessor
:action
def
self
.
current
Thread
.
current
[
THREAD_KEY
]
end
def
initialize
# action - A String describing the action performed, usually the class
# plus method name.
def
initialize
(
action
=
nil
)
@metrics
=
[]
@started_at
=
nil
...
...
@@ -18,6 +22,7 @@ module Gitlab
@values
=
Hash
.
new
(
0
)
@tags
=
{}
@action
=
action
end
def
duration
...
...
@@ -70,7 +75,15 @@ module Gitlab
end
def
submit
Metrics
.
submit_metrics
(
@metrics
.
map
(
&
:to_hash
))
metrics
=
@metrics
.
map
do
|
metric
|
hash
=
metric
.
to_hash
hash
[
:tags
][
:action
]
||=
@action
if
@action
hash
end
Metrics
.
submit_metrics
(
metrics
)
end
def
sidekiq?
...
...
spec/lib/gitlab/metrics/rack_middleware_spec.rb
View file @
d65e7aa9
...
...
@@ -57,7 +57,7 @@ describe Gitlab::Metrics::RackMiddleware do
middleware
.
tag_controller
(
transaction
,
env
)
expect
(
transaction
.
tags
[
:action
]
).
to
eq
(
'TestController#show'
)
expect
(
transaction
.
action
).
to
eq
(
'TestController#show'
)
end
end
end
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
View file @
d65e7aa9
...
...
@@ -5,22 +5,15 @@ describe Gitlab::Metrics::SidekiqMiddleware do
describe
'#call'
do
it
'tracks the transaction'
do
worker
=
Class
.
new
.
new
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
expect
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:new
).
with
(
'TestWorker#perform'
).
and_call_original
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:finish
)
middleware
.
call
(
worker
,
'test'
,
:test
)
{
nil
}
end
end
describe
'#tag_worker'
do
it
'adds the worker class and action to the transaction'
do
trans
=
Gitlab
::
Metrics
::
Transaction
.
new
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
expect
(
trans
).
to
receive
(
:add_tag
).
with
(
:action
,
'TestWorker#perform'
)
middleware
.
tag_worker
(
trans
,
worker
)
end
end
end
spec/lib/gitlab/metrics/transaction_spec.rb
View file @
d65e7aa9
...
...
@@ -96,5 +96,22 @@ describe Gitlab::Metrics::Transaction do
transaction
.
submit
end
it
'adds the action as a tag for every metric'
do
transaction
.
action
=
'Foo#bar'
transaction
.
track_self
hash
=
{
series:
'rails_transactions'
,
tags:
{
action:
'Foo#bar'
},
values:
{
duration:
0.0
},
timestamp:
an_instance_of
(
Fixnum
)
}
expect
(
Gitlab
::
Metrics
).
to
receive
(
:submit_metrics
).
with
([
hash
])
transaction
.
submit
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