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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
1c439f93
Commit
1c439f93
authored
Mar 22, 2021
by
Quang-Minh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor subscriber observe method
parent
e921514a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
ee/lib/ee/gitlab/metrics/subscribers/active_record.rb
ee/lib/ee/gitlab/metrics/subscribers/active_record.rb
+3
-1
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+7
-7
No files found.
ee/lib/ee/gitlab/metrics/subscribers/active_record.rb
View file @
1c439f93
...
...
@@ -54,7 +54,9 @@ module EE
end
def
observe_db_role_duration
(
db_role
,
event
)
observe
(
"gitlab_sql_
#{
db_role
}
_duration_seconds"
.
to_sym
,
event
)
observe
(
"gitlab_sql_
#{
db_role
}
_duration_seconds"
.
to_sym
,
event
)
do
buckets
::
Gitlab
::
Metrics
::
Subscribers
::
ActiveRecord
::
SQL_DURATION_BUCKET
end
duration
=
event
.
duration
/
1000.0
duration_key
=
"db_
#{
db_role
}
_duration_s"
.
to_sym
...
...
lib/gitlab/metrics/subscribers/active_record.rb
View file @
1c439f93
...
...
@@ -11,14 +11,14 @@ module Gitlab
DB_COUNTERS
=
%i{db_count db_write_count db_cached_count}
.
freeze
SQL_COMMANDS_WITH_COMMENTS_REGEX
=
/\A(\/\*.*\*\/\s)?((?!(.*[^\w'"](DELETE|UPDATE|INSERT INTO)[^\w'"])))(WITH.*)?(SELECT)((?!(FOR UPDATE|FOR SHARE)).)*$/i
.
freeze
DURATION_BUCKET
=
[
0.05
,
0.1
,
0.25
].
freeze
SQL_
DURATION_BUCKET
=
[
0.05
,
0.1
,
0.25
].
freeze
TRANSACTION_DURATION_BUCKET
=
[
0.1
,
0.25
,
1
].
freeze
# This event is published from ActiveRecordBaseTransactionMetrics and
# used to record a database transaction duration when calling
# ActiveRecord::Base.transaction {} block.
def
transaction
(
event
)
current_transaction
&
.
observe
(
:gitlab_database_transaction_seconds
,
event
.
duration
/
1000.0
)
do
observe
(
:gitlab_database_transaction_seconds
,
event
)
do
buckets
TRANSACTION_DURATION_BUCKET
end
end
...
...
@@ -36,7 +36,9 @@ module Gitlab
increment
(
:db_cached_count
)
if
cached_query?
(
payload
)
increment
(
:db_write_count
)
unless
select_sql_command?
(
payload
)
observe
(
:gitlab_sql_duration_seconds
,
event
)
observe
(
:gitlab_sql_duration_seconds
,
event
)
do
buckets
SQL_DURATION_BUCKET
end
end
def
self
.
db_counter_payload
...
...
@@ -69,10 +71,8 @@ module Gitlab
Gitlab
::
SafeRequestStore
[
counter
]
=
Gitlab
::
SafeRequestStore
[
counter
].
to_i
+
1
end
def
observe
(
histogram
,
event
)
current_transaction
&
.
observe
(
histogram
,
event
.
duration
/
1000.0
)
do
buckets
DURATION_BUCKET
end
def
observe
(
histogram
,
event
,
&
block
)
current_transaction
&
.
observe
(
histogram
,
event
.
duration
/
1000.0
,
&
block
)
end
def
current_transaction
...
...
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