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
Léo-Paul Géneau
gitlab-ce
Commits
bec7f060
Commit
bec7f060
authored
Sep 04, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore irrelevant sql commands in metrics
Fix #51005
parent
91003c6e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
0 deletions
+70
-0
changelogs/unreleased/skip-irrelevant-sql-commands-in-metrics.yml
...gs/unreleased/skip-irrelevant-sql-commands-in-metrics.yml
+5
-0
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+6
-0
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
+59
-0
No files found.
changelogs/unreleased/skip-irrelevant-sql-commands-in-metrics.yml
0 → 100644
View file @
bec7f060
---
title
:
Ignore irrelevant sql commands in metrics
merge_request
:
21498
author
:
type
:
other
lib/gitlab/metrics/subscribers/active_record.rb
View file @
bec7f060
...
...
@@ -6,9 +6,15 @@ module Gitlab
include
Gitlab
::
Metrics
::
Methods
attach_to
:active_record
IGNORABLE_SQL
=
%w{BEGIN COMMIT}
.
freeze
def
sql
(
event
)
return
unless
current_transaction
payload
=
event
.
payload
return
if
payload
[
:name
]
==
'SCHEMA'
||
IGNORABLE_SQL
.
include?
(
payload
[
:sql
])
self
.
class
.
gitlab_sql_duration_seconds
.
observe
(
current_transaction
.
labels
,
event
.
duration
/
1000.0
)
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
...
...
spec/lib/gitlab/metrics/subscribers/active_record_spec.rb
View file @
bec7f060
...
...
@@ -42,6 +42,65 @@ describe Gitlab::Metrics::Subscribers::ActiveRecord do
subscriber
.
sql
(
event
)
end
context
'events are internal to Rails or irrelevant'
do
let
(
:schema_event
)
do
double
(
:event
,
name:
'sql.active_record'
,
payload:
{
sql:
"SELECT attr.attname FROM pg_attribute attr INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = any(cons.conkey) WHERE cons.contype = 'p' AND cons.conrelid = '
\"
projects
\"
'::regclass"
,
name:
'SCHEMA'
,
connection_id:
135
,
statement_name:
nil
,
binds:
[]
},
duration:
0.7
)
end
let
(
:begin_event
)
do
double
(
:event
,
name:
'sql.active_record'
,
payload:
{
sql:
"BEGIN"
,
name:
nil
,
connection_id:
231
,
statement_name:
nil
,
binds:
[]
},
duration:
1.1
)
end
let
(
:commit_event
)
do
double
(
:event
,
name:
'sql.active_record'
,
payload:
{
sql:
"COMMIT"
,
name:
nil
,
connection_id:
212
,
statement_name:
nil
,
binds:
[]
},
duration:
1.6
)
end
it
'skips schema/begin/commit sql commands'
do
expect
(
subscriber
).
to
receive
(
:current_transaction
)
.
at_least
(
:once
)
.
and_return
(
transaction
)
expect
(
transaction
).
not_to
receive
(
:increment
)
subscriber
.
sql
(
schema_event
)
subscriber
.
sql
(
begin_event
)
subscriber
.
sql
(
commit_event
)
end
end
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