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
30a4bb66
Commit
30a4bb66
authored
Oct 19, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix sidekiq middleware tests
parent
043545de
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
27 deletions
+14
-27
lib/gitlab/metrics/sidekiq_transaction.rb
lib/gitlab/metrics/sidekiq_transaction.rb
+3
-2
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+1
-3
lib/gitlab/metrics/web_transaction.rb
lib/gitlab/metrics/web_transaction.rb
+1
-1
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
+8
-20
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
+1
-1
No files found.
lib/gitlab/metrics/sidekiq_transaction.rb
View file @
30a4bb66
module
Gitlab
module
Gitlab
module
Metrics
module
Metrics
class
SidekiqTransaction
class
SidekiqTransaction
<
Transaction
def
initialize
(
worker_class
)
def
initialize
(
worker_class
)
super
()
@worker_class
=
worker_class
@worker_class
=
worker_class
end
end
protected
protected
def
labels
def
labels
{
controller:
worker
.
class
.
name
,
action:
'perform'
}
{
controller:
@worker_
class
.
name
,
action:
'perform'
}
end
end
end
end
end
end
...
...
lib/gitlab/metrics/
base_
transaction.rb
→
lib/gitlab/metrics/transaction.rb
View file @
30a4bb66
module
Gitlab
module
Gitlab
module
Metrics
module
Metrics
# Class for storing metrics information of a single transaction.
# Class for storing metrics information of a single transaction.
class
Base
Transaction
class
Transaction
# base labels shared among all transactions
# base labels shared among all transactions
BASE_LABELS
=
{
controller:
nil
,
action:
nil
}.
freeze
BASE_LABELS
=
{
controller:
nil
,
action:
nil
}.
freeze
...
@@ -131,8 +131,6 @@ module Gitlab
...
@@ -131,8 +131,6 @@ module Gitlab
"
#{
labels
[
:controller
]
}
#
#{
labels
[
:action
]
}
"
if
labels
&&
!
labels
.
empty?
"
#{
labels
[
:controller
]
}
#
#{
labels
[
:action
]
}
"
if
labels
&&
!
labels
.
empty?
end
end
protected
def
self
.
metric_transaction_duration_seconds
def
self
.
metric_transaction_duration_seconds
@metric_transaction_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
@metric_transaction_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_duration_seconds
,
:gitlab_transaction_duration_seconds
,
...
...
lib/gitlab/metrics/web_transaction.rb
View file @
30a4bb66
module
Gitlab
module
Gitlab
module
Metrics
module
Metrics
class
WebTransaction
<
Base
Transaction
class
WebTransaction
<
Transaction
CONTROLLER_KEY
=
'action_controller.instance'
.
freeze
CONTROLLER_KEY
=
'action_controller.instance'
.
freeze
ENDPOINT_KEY
=
'api.endpoint'
.
freeze
ENDPOINT_KEY
=
'api.endpoint'
.
freeze
...
...
spec/lib/gitlab/metrics/sidekiq_middleware_spec.rb
View file @
30a4bb66
...
@@ -6,7 +6,7 @@ describe Gitlab::Metrics::SidekiqMiddleware do
...
@@ -6,7 +6,7 @@ describe Gitlab::Metrics::SidekiqMiddleware do
def
run
(
worker
,
message
)
def
run
(
worker
,
message
)
expect
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:new
)
expect
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:new
)
.
with
(
'TestWorker#perform'
)
.
with
(
worker
.
class
)
.
and_call_original
.
and_call_original
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:set
)
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
).
to
receive
(
:set
)
...
@@ -18,21 +18,22 @@ describe Gitlab::Metrics::SidekiqMiddleware do
...
@@ -18,21 +18,22 @@ describe Gitlab::Metrics::SidekiqMiddleware do
end
end
describe
'#call'
do
describe
'#call'
do
it
'tracks the transaction'
do
let
(
:test_worker_class
)
{
double
(
:class
,
name:
'TestWorker'
)
}
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
let
(
:worker
)
{
double
(
:worker
,
class:
test_worker_class
)
}
it
'reports correct action based on worker class'
do
end
it
'tracks the transaction'
do
run
(
worker
,
message
)
run
(
worker
,
message
)
end
end
it
'tracks the transaction (for messages without `enqueued_at`)'
do
it
'tracks the transaction (for messages without `enqueued_at`)'
do
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
run
(
worker
,
{})
run
(
worker
,
{})
end
end
it
'tracks any raised exceptions'
do
it
'tracks any raised exceptions'
do
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
)
expect_any_instance_of
(
Gitlab
::
Metrics
::
Transaction
)
.
to
receive
(
:run
).
and_raise
(
RuntimeError
)
.
to
receive
(
:run
).
and_raise
(
RuntimeError
)
...
@@ -45,18 +46,5 @@ describe Gitlab::Metrics::SidekiqMiddleware do
...
@@ -45,18 +46,5 @@ describe Gitlab::Metrics::SidekiqMiddleware do
expect
{
middleware
.
call
(
worker
,
message
,
:test
)
}
expect
{
middleware
.
call
(
worker
,
message
,
:test
)
}
.
to
raise_error
(
RuntimeError
)
.
to
raise_error
(
RuntimeError
)
end
end
it
'tags the metrics accordingly'
do
tags
=
{
one:
1
,
two:
2
}
worker
=
double
(
:worker
,
class:
double
(
:class
,
name:
'TestWorker'
))
allow
(
worker
).
to
receive
(
:metrics_tags
).
and_return
(
tags
)
tags
.
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
end
end
spec/lib/gitlab/metrics/subscribers/rails_cache_spec.rb
View file @
30a4bb66
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Metrics
::
Subscribers
::
RailsCache
do
describe
Gitlab
::
Metrics
::
Subscribers
::
RailsCache
do
let
(
:env
)
{
{}
}
let
(
:env
)
{
{}
}
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
(
env
)
}
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Web
Transaction
.
new
(
env
)
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:event
)
{
double
(
:event
,
duration:
15.2
)
}
let
(
:event
)
{
double
(
:event
,
duration:
15.2
)
}
...
...
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