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
91a99136
Commit
91a99136
authored
Jan 16, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert active record
parent
66c2a3a8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
11 deletions
+9
-11
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+8
-10
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+1
-1
No files found.
lib/gitlab/metrics/subscribers/active_record.rb
View file @
91a99136
...
@@ -3,12 +3,13 @@ module Gitlab
...
@@ -3,12 +3,13 @@ module Gitlab
module
Subscribers
module
Subscribers
# Class for tracking the total query duration of a transaction.
# Class for tracking the total query duration of a transaction.
class
ActiveRecord
<
ActiveSupport
::
Subscriber
class
ActiveRecord
<
ActiveSupport
::
Subscriber
include
Gitlab
::
Metrics
::
Concern
attach_to
:active_record
attach_to
:active_record
def
sql
(
event
)
def
sql
(
event
)
return
unless
current_transaction
return
unless
current_transaction
metric
_sql_duration_seconds
.
observe
(
current_transaction
.
labels
,
event
.
duration
/
1000.0
)
self
.
class
.
gitlab
_sql_duration_seconds
.
observe
(
current_transaction
.
labels
,
event
.
duration
/
1000.0
)
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
current_transaction
.
increment
(
:sql_count
,
1
,
false
)
current_transaction
.
increment
(
:sql_count
,
1
,
false
)
...
@@ -16,17 +17,14 @@ module Gitlab
...
@@ -16,17 +17,14 @@ module Gitlab
private
private
def
current_transaction
define_histogram
:gitlab_sql_duration_seconds
do
Transaction
.
current
docstring
'SQL time'
base_labels
Transaction
::
BASE_LABELS
buckets
[
0.001
,
0.01
,
0.1
,
10.0
]
end
end
def
metric_sql_duration_seconds
def
current_transaction
@metric_sql_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
Transaction
.
current
:gitlab_sql_duration_seconds
,
'SQL time'
,
Transaction
::
BASE_LABELS
,
[
0.001
,
0.01
,
0.1
,
10.0
]
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
View file @
91a99136
...
@@ -25,7 +25,7 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do
...
@@ -25,7 +25,7 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do
expect
(
subscriber
).
to
receive
(
:current_transaction
)
expect
(
subscriber
).
to
receive
(
:current_transaction
)
.
at_least
(
:once
)
.
at_least
(
:once
)
.
and_return
(
transaction
)
.
and_return
(
transaction
)
expect
(
subscriber
.
send
(
:metric
_sql_duration_seconds
)).
to
receive
(
:observe
).
with
({},
0.002
)
expect
(
described_class
.
send
(
:gitlab
_sql_duration_seconds
)).
to
receive
(
:observe
).
with
({},
0.002
)
subscriber
.
sql
(
event
)
subscriber
.
sql
(
event
)
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