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
7799a9bc
Commit
7799a9bc
authored
Oct 31, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add metrics tagging to the sidekiq middleware
parent
8266c78c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
20 deletions
+40
-20
app/workers/update_merge_requests_worker.rb
app/workers/update_merge_requests_worker.rb
+10
-0
lib/gitlab/metrics/sidekiq_middleware.rb
lib/gitlab/metrics/sidekiq_middleware.rb
+2
-0
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
+28
-20
No files found.
app/workers/update_merge_requests_worker.rb
View file @
7799a9bc
...
...
@@ -2,6 +2,12 @@ class UpdateMergeRequestsWorker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
attr_reader
:targets
# for metrics tags
def
initialize
@targets
=
{}
end
def
perform
(
project_id
,
user_id
,
oldrev
,
newrev
,
ref
)
project
=
Project
.
find_by
(
id:
project_id
)
return
unless
project
...
...
@@ -9,6 +15,10 @@ class UpdateMergeRequestsWorker
user
=
User
.
find_by
(
id:
user_id
)
return
unless
user
@targets
=
{
project_id:
project_id
,
user_id:
user_id
}
MergeRequests
::
RefreshService
.
new
(
project
,
user
).
execute
(
oldrev
,
newrev
,
ref
)
end
end
lib/gitlab/metrics/sidekiq_middleware.rb
View file @
7799a9bc
...
...
@@ -11,6 +11,8 @@ module Gitlab
# Old gitlad-shell messages don't provide enqueued_at/created_at attributes
trans
.
set
(
:sidekiq_queue_duration
,
Time
.
now
.
to_f
-
(
message
[
'enqueued_at'
]
||
message
[
'created_at'
]
||
0
))
trans
.
run
{
yield
}
worker
.
targets
.
each
{
|
name
,
target
|
trans
.
add_tag
(
name
,
target
)
}
if
worker
.
respond_to?
(
:targets
)
rescue
Exception
=>
error
# rubocop: disable Lint/RescueException
trans
.
add_event
(
:sidekiq_exception
)
...
...
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
View file @
7799a9bc
...
...
@@ -4,10 +4,7 @@ describe Gitlab::Metrics::SidekiqMiddleware do
let
(
:middleware
)
{
described_class
.
new
}
let
(
:message
)
{
{
'args'
=>
[
'test'
],
'enqueued_at'
=>
Time
.
new
(
2016
,
6
,
23
,
6
,
59
).
to_f
}
}
describe
'#call'
do
it
'tracks the transaction'
do
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
def
run
(
worker
,
message
)
expect
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:new
)
.
with
(
'TestWorker#perform'
)
.
and_call_original
...
...
@@ -20,19 +17,17 @@ describe Gitlab::Metrics::SidekiqMiddleware do
middleware
.
call
(
worker
,
message
,
:test
)
{
nil
}
end
it
'tracks the transaction (for messages without `enqueued_at`)'
do
describe
'#call'
do
it
'tracks the transaction'
do
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
(
:set
)
.
with
(
:sidekiq_queue_duration
,
instance_of
(
Float
))
run
(
worker
,
message
)
end
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:finish
)
it
'tracks the transaction (for messages without `enqueued_at`)'
do
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
middleware
.
call
(
worker
,
{},
:test
)
{
nil
}
run
(
worker
,
{})
end
it
'tracks any raised exceptions'
do
...
...
@@ -50,5 +45,18 @@ describe Gitlab::Metrics::SidekiqMiddleware do
expect
{
middleware
.
call
(
worker
,
message
,
:test
)
}
.
to
raise_error
(
RuntimeError
)
end
it
'tags the metrics accordingly'
do
targets
=
{
one:
1
,
two:
2
}
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
allow
(
worker
).
to
receive
(
:targets
).
and_return
(
targets
)
targets
.
each
do
|
tag
,
value
|
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:add_tag
)
.
with
(
tag
,
value
)
end
run
(
worker
,
message
)
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