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
Jérome Perrin
gitlab-ce
Commits
39ac6acb
Commit
39ac6acb
authored
Sep 06, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Active record and transaction specs
parent
38fbd25b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
10 deletions
+22
-10
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+1
-1
spec/lib/gitlab/metrics/instrumentation_spec.rb
spec/lib/gitlab/metrics/instrumentation_spec.rb
+2
-1
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+13
-4
spec/lib/gitlab/metrics/transaction_spec.rb
spec/lib/gitlab/metrics/transaction_spec.rb
+6
-4
No files found.
lib/gitlab/metrics/transaction.rb
View file @
39ac6acb
...
...
@@ -101,7 +101,7 @@ module Gitlab
# tags - A set of tags to attach to the event.
def
add_event
(
event_name
,
tags
=
{})
self
.
class
.
metric_event_counter
(
event_name
,
tags
).
increment
(
tags
.
merge
(
labels
))
@metrics
<<
Metric
.
new
(
EVENT_SERIES
,
{
count:
1
},
tags
,
:event
)
@metrics
<<
Metric
.
new
(
EVENT_SERIES
,
{
count:
1
},
tags
.
merge
(
event:
event_name
)
,
:event
)
end
# Returns a MethodCall object for the given name.
...
...
spec/lib/gitlab/metrics/instrumentation_spec.rb
View file @
39ac6acb
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Instrumentation
do
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
}
let
(
:env
)
{
{}
}
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
(
env
)
}
before
do
@dummy
=
Class
.
new
do
...
...
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
View file @
39ac6acb
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Subscribers
::
ActiveRecord
do
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
}
let
(
:env
)
{
{}
}
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
(
env
)
}
let
(
:subscriber
)
{
described_class
.
new
}
let
(
:event
)
do
double
(
:event
,
duration:
0.
2
,
double
(
:event
,
duration:
2
,
payload:
{
sql:
'SELECT * FROM users WHERE id = 10'
})
end
...
...
@@ -20,16 +21,24 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do
end
describe
'with a current transaction'
do
it
'observes sql_duration metric'
do
expect
(
subscriber
).
to
receive
(
:current_transaction
)
.
at_least
(
:once
)
.
and_return
(
transaction
)
expect
(
described_class
.
metric_sql_duration_seconds
).
to
receive
(
:observe
).
with
({},
0.002
)
subscriber
.
sql
(
event
)
end
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
)
.
with
(
:sql_duration
,
2
,
false
)
expect
(
transaction
).
to
receive
(
:increment
)
.
with
(
:sql_count
,
1
)
.
with
(
:sql_count
,
1
,
false
)
subscriber
.
sql
(
event
)
end
...
...
spec/lib/gitlab/metrics/transaction_spec.rb
View file @
39ac6acb
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Transaction
do
let
(
:transaction
)
{
described_class
.
new
}
let
(
:env
)
{
{}
}
let
(
:transaction
)
{
described_class
.
new
(
env
)
}
describe
'#duration'
do
it
'returns the duration of a transaction in seconds'
do
...
...
@@ -48,7 +49,7 @@ describe Gitlab::Metrics::Transaction do
describe
'#method_call_for'
do
it
'returns a MethodCall'
do
method
=
transaction
.
method_call_for
(
'Foo#bar'
)
method
=
transaction
.
method_call_for
(
'Foo#bar'
,
:Foo
,
'#bar'
)
expect
(
method
).
to
be_an_instance_of
(
Gitlab
::
Metrics
::
MethodCall
)
end
...
...
@@ -119,7 +120,7 @@ describe Gitlab::Metrics::Transaction do
end
it
'adds the action as a tag for every metric'
do
transaction
.
action
=
'Foo#bar'
allow
(
transaction
).
to
receive
(
:labels
).
and_return
(
controller:
'Foo'
,
action:
'bar'
)
transaction
.
track_self
hash
=
{
...
...
@@ -136,7 +137,8 @@ describe Gitlab::Metrics::Transaction do
end
it
'does not add an action tag for events'
do
transaction
.
action
=
'Foo#bar'
allow
(
transaction
).
to
receive
(
:labels
).
and_return
(
controller:
'Foo'
,
action:
'bar'
)
transaction
.
add_event
(
:meow
)
hash
=
{
...
...
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