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
46273e14
Commit
46273e14
authored
Jun 01, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store Sherlock::Query in Peek adapter
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
d39ecf1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
0 deletions
+104
-0
config/initializers/peek.rb
config/initializers/peek.rb
+32
-0
lib/gitlab/performance_bar/peek_mysql_with_queries.rb
lib/gitlab/performance_bar/peek_mysql_with_queries.rb
+36
-0
lib/gitlab/performance_bar/peek_pg_with_queries.rb
lib/gitlab/performance_bar/peek_pg_with_queries.rb
+36
-0
No files found.
config/initializers/peek.rb
View file @
46273e14
...
...
@@ -7,3 +7,35 @@ Peek.into Peek::Views::Redis
Peek
.
into
Peek
::
Views
::
Sidekiq
Peek
.
into
Peek
::
Views
::
Rblineprof
Peek
.
into
Peek
::
Views
::
GC
if
Gitlab
::
Database
.
mysql?
class
Mysql2::Client
class
<<
self
attr_accessor
:query_details
end
self
.
query_details
=
Concurrent
::
Array
.
new
end
module
Peek
module
Views
class
Mysql2
<
View
prepend
::
Gitlab
::
PerformanceBar
::
PeekMysqlWithQueries
end
end
end
else
class
PG::Connection
class
<<
self
attr_accessor
:query_details
end
self
.
query_details
=
Concurrent
::
Array
.
new
end
module
Peek
module
Views
class
PG
<
View
prepend
::
Gitlab
::
PerformanceBar
::
PeekPgWithQueries
end
end
end
end
lib/gitlab/performance_bar/peek_mysql_with_queries.rb
0 → 100644
View file @
46273e14
# Inspired by https://github.com/peek/peek-mysql2/blob/master/lib/peek/views/mysql2.rb
module
Gitlab
module
PerformanceBar
module
PeekMysqlWithQueries
def
queries
::
Mysql2
::
Client
.
query_details
end
def
results
super
.
merge
(
queries:
queries
)
end
private
def
setup_subscribers
super
# Reset each counter when a new request starts
before_request
do
::
Mysql2
::
Client
.
query_details
=
[]
end
subscribe
(
'sql.active_record'
)
do
|
_
,
start
,
finish
,
_
,
data
|
if
RequestStore
.
active?
&&
RequestStore
.
store
[
:peek_enabled
]
track_query
(
data
[
:sql
].
strip
,
data
[
:binds
],
start
,
finish
)
end
end
end
def
track_query
(
raw_query
,
bindings
,
start
,
finish
)
query
=
Gitlab
::
Sherlock
::
Query
.
new
(
raw_query
,
start
,
finish
)
::
Mysql2
::
Client
.
query_details
<<
query
.
formatted_query
end
end
end
end
lib/gitlab/performance_bar/peek_pg_with_queries.rb
0 → 100644
View file @
46273e14
# Inspired by https://github.com/peek/peek-pg/blob/master/lib/peek/views/pg.rb
module
Gitlab
module
PerformanceBar
module
PeekPgWithQueries
def
queries
::
PG
::
Connection
.
query_details
end
def
results
super
.
merge
(
queries:
queries
)
end
private
def
setup_subscribers
super
# Reset each counter when a new request starts
before_request
do
::
PG
::
Connection
.
query_details
=
[]
end
subscribe
(
'sql.active_record'
)
do
|
_
,
start
,
finish
,
_
,
data
|
if
RequestStore
.
active?
&&
RequestStore
.
store
[
:peek_enabled
]
track_query
(
data
[
:sql
].
strip
,
data
[
:binds
],
start
,
finish
)
end
end
end
def
track_query
(
raw_query
,
bindings
,
start
,
finish
)
query
=
Gitlab
::
Sherlock
::
Query
.
new
(
raw_query
,
start
,
finish
)
::
PG
::
Connection
.
query_details
<<
query
.
formatted_query
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