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
cb8df09f
Commit
cb8df09f
authored
Jan 24, 2017
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'add-metrics-initializer-spec-ee' into 'master'
Add metric initializer spec See merge request !1109
parents
1bf684f7
7e467d1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
153 additions
and
126 deletions
+153
-126
config/initializers/metrics.rb
config/initializers/metrics.rb
+137
-126
spec/initializers/metrics_spec.rb
spec/initializers/metrics_spec.rb
+16
-0
No files found.
config/initializers/metrics.rb
View file @
cb8df09f
# Autoload all classes that we want to instrument, and instrument the methods we
# need. This takes the Gitlab::Metrics::Instrumentation module as an argument so
# that we can stub it for testing, as it is only called when metrics are
# enabled.
#
# rubocop:disable Metrics/AbcSize
def
instrument_classes
(
instrumentation
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
Shell
)
instrumentation
.
instrument_methods
(
Gitlab
::
Git
)
Gitlab
::
Git
.
constants
.
each
do
|
name
|
const
=
Gitlab
::
Git
.
const_get
(
name
)
next
unless
const
.
is_a?
(
Module
)
instrumentation
.
instrument_methods
(
const
)
instrumentation
.
instrument_instance_methods
(
const
)
end
# Path to search => prefix to strip from constant
paths_to_instrument
=
{
[
'app'
,
'finders'
]
=>
[
'app'
,
'finders'
],
[
'app'
,
'mailers'
,
'emails'
]
=>
[
'app'
,
'mailers'
],
[
'app'
,
'services'
,
'**'
]
=>
[
'app'
,
'services'
],
[
'lib'
,
'gitlab'
,
'conflicts'
]
=>
[
'lib'
],
[
'lib'
,
'gitlab'
,
'diff'
]
=>
[
'lib'
],
[
'lib'
,
'gitlab'
,
'email'
,
'message'
]
=>
[
'lib'
],
[
'lib'
,
'gitlab'
,
'checks'
]
=>
[
'lib'
]
}
paths_to_instrument
.
each
do
|
(
path
,
prefix
)
|
prefix
=
Rails
.
root
.
join
(
*
prefix
)
Dir
[
Rails
.
root
.
join
(
*
path
+
[
'*.rb'
])].
each
do
|
file_path
|
path
=
Pathname
.
new
(
file_path
).
relative_path_from
(
prefix
)
const
=
path
.
to_s
.
sub
(
'.rb'
,
''
).
camelize
.
constantize
instrumentation
.
instrument_methods
(
const
)
instrumentation
.
instrument_instance_methods
(
const
)
end
end
instrumentation
.
instrument_methods
(
Premailer
::
Adapter
::
Nokogiri
)
instrumentation
.
instrument_instance_methods
(
Premailer
::
Adapter
::
Nokogiri
)
[
:Blame
,
:Branch
,
:BranchCollection
,
:Blob
,
:Commit
,
:Diff
,
:Repository
,
:Tag
,
:TagCollection
,
:Tree
].
each
do
|
name
|
const
=
Rugged
.
const_get
(
name
)
instrumentation
.
instrument_methods
(
const
)
instrumentation
.
instrument_instance_methods
(
const
)
end
# Instruments all Banzai filters and reference parsers
{
Filter
:
Rails
.
root
.
join
(
'lib'
,
'banzai'
,
'filter'
,
'*.rb'
),
ReferenceParser
:
Rails
.
root
.
join
(
'lib'
,
'banzai'
,
'reference_parser'
,
'*.rb'
)
}.
each
do
|
const_name
,
path
|
Dir
[
path
].
each
do
|
file
|
klass
=
File
.
basename
(
file
,
File
.
extname
(
file
)).
camelize
const
=
Banzai
.
const_get
(
const_name
).
const_get
(
klass
)
instrumentation
.
instrument_methods
(
const
)
instrumentation
.
instrument_instance_methods
(
const
)
end
end
instrumentation
.
instrument_methods
(
Banzai
::
Renderer
)
instrumentation
.
instrument_methods
(
Banzai
::
Querying
)
instrumentation
.
instrument_instance_methods
(
Banzai
::
ObjectRenderer
)
instrumentation
.
instrument_instance_methods
(
Banzai
::
Redactor
)
instrumentation
.
instrument_methods
(
Banzai
::
NoteRenderer
)
[
Issuable
,
Mentionable
,
Participable
].
each
do
|
klass
|
instrumentation
.
instrument_instance_methods
(
klass
)
instrumentation
.
instrument_instance_methods
(
klass
::
ClassMethods
)
end
instrumentation
.
instrument_methods
(
Gitlab
::
ReferenceExtractor
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
ReferenceExtractor
)
# Instrument the classes used for checking if somebody has push access.
instrumentation
.
instrument_instance_methods
(
Gitlab
::
GitAccess
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
GitAccessWiki
)
instrumentation
.
instrument_instance_methods
(
API
::
Helpers
)
instrumentation
.
instrument_instance_methods
(
RepositoryCheck
::
SingleRepositoryWorker
)
instrumentation
.
instrument_instance_methods
(
Rouge
::
Plugins
::
Redcarpet
)
instrumentation
.
instrument_instance_methods
(
Rouge
::
Formatters
::
HTMLGitlab
)
[
:XML
,
:HTML
].
each
do
|
namespace
|
namespace_mod
=
Nokogiri
.
const_get
(
namespace
)
instrumentation
.
instrument_methods
(
namespace_mod
)
instrumentation
.
instrument_methods
(
namespace_mod
::
Document
)
end
instrumentation
.
instrument_methods
(
Rinku
)
instrumentation
.
instrument_instance_methods
(
Repository
)
instrumentation
.
instrument_methods
(
Gitlab
::
Highlight
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
Highlight
)
instrumentation
.
instrument_methods
(
Elasticsearch
::
Git
::
Repository
)
instrumentation
.
instrument_instance_methods
(
Elasticsearch
::
Git
::
Repository
)
instrumentation
.
instrument_instance_methods
(
Search
::
GlobalService
)
instrumentation
.
instrument_instance_methods
(
Search
::
ProjectService
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
SearchResults
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
ProjectSearchResults
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
Indexer
)
instrumentation
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
SnippetSearchResults
)
instrumentation
.
instrument_methods
(
Gitlab
::
Elastic
::
Helper
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
ApplicationSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
IssuesSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
MergeRequestsSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
MilestonesSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
NotesSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
ProjectsSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
RepositoriesSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
SnippetsSearch
)
instrumentation
.
instrument_instance_methods
(
Elastic
::
WikiRepositoriesSearch
)
# This is a Rails scope so we have to instrument it manually.
instrumentation
.
instrument_method
(
Project
,
:visible_to_user
)
end
# rubocop:enable Metrics/AbcSize
if
Gitlab
::
Metrics
.
enabled?
require
'pathname'
require
'influxdb'
...
...
@@ -49,132 +185,7 @@ if Gitlab::Metrics.enabled?
end
Gitlab
::
Metrics
::
Instrumentation
.
configure
do
|
config
|
config
.
instrument_instance_methods
(
Gitlab
::
Shell
)
config
.
instrument_methods
(
Gitlab
::
Git
)
Gitlab
::
Git
.
constants
.
each
do
|
name
|
const
=
Gitlab
::
Git
.
const_get
(
name
)
next
unless
const
.
is_a?
(
Module
)
config
.
instrument_methods
(
const
)
config
.
instrument_instance_methods
(
const
)
end
# Path to search => prefix to strip from constant
paths_to_instrument
=
{
[
'app'
,
'finders'
]
=>
[
'app'
,
'finders'
],
[
'app'
,
'mailers'
,
'emails'
]
=>
[
'app'
,
'mailers'
],
[
'app'
,
'services'
,
'**'
]
=>
[
'app'
,
'services'
],
[
'lib'
,
'gitlab'
,
'conflicts'
]
=>
[
'lib'
],
[
'lib'
,
'gitlab'
,
'diff'
]
=>
[
'lib'
],
[
'lib'
,
'gitlab'
,
'email'
,
'message'
]
=>
[
'lib'
],
[
'lib'
,
'gitlab'
,
'checks'
]
=>
[
'lib'
]
}
paths_to_instrument
.
each
do
|
(
path
,
prefix
)
|
prefix
=
Rails
.
root
.
join
(
*
prefix
)
Dir
[
Rails
.
root
.
join
(
*
path
+
[
'*.rb'
])].
each
do
|
file_path
|
path
=
Pathname
.
new
(
file_path
).
relative_path_from
(
prefix
)
const
=
path
.
to_s
.
sub
(
'.rb'
,
''
).
camelize
.
constantize
config
.
instrument_methods
(
const
)
config
.
instrument_instance_methods
(
const
)
end
end
config
.
instrument_methods
(
Premailer
::
Adapter
::
Nokogiri
)
config
.
instrument_instance_methods
(
Premailer
::
Adapter
::
Nokogiri
)
[
:Blame
,
:Branch
,
:BranchCollection
,
:Blob
,
:Commit
,
:Diff
,
:Repository
,
:Tag
,
:TagCollection
,
:Tree
].
each
do
|
name
|
const
=
Rugged
.
const_get
(
name
)
config
.
instrument_methods
(
const
)
config
.
instrument_instance_methods
(
const
)
end
# Instruments all Banzai filters and reference parsers
{
Filter
:
Rails
.
root
.
join
(
'lib'
,
'banzai'
,
'filter'
,
'*.rb'
),
ReferenceParser
:
Rails
.
root
.
join
(
'lib'
,
'banzai'
,
'reference_parser'
,
'*.rb'
)
}.
each
do
|
const_name
,
path
|
Dir
[
path
].
each
do
|
file
|
klass
=
File
.
basename
(
file
,
File
.
extname
(
file
)).
camelize
const
=
Banzai
.
const_get
(
const_name
).
const_get
(
klass
)
config
.
instrument_methods
(
const
)
config
.
instrument_instance_methods
(
const
)
end
end
config
.
instrument_methods
(
Banzai
::
Renderer
)
config
.
instrument_methods
(
Banzai
::
Querying
)
config
.
instrument_instance_methods
(
Banzai
::
ObjectRenderer
)
config
.
instrument_instance_methods
(
Banzai
::
Redactor
)
config
.
instrument_methods
(
Banzai
::
NoteRenderer
)
[
Issuable
,
Mentionable
,
Participable
].
each
do
|
klass
|
config
.
instrument_instance_methods
(
klass
)
config
.
instrument_instance_methods
(
klass
::
ClassMethods
)
end
config
.
instrument_methods
(
Gitlab
::
ReferenceExtractor
)
config
.
instrument_instance_methods
(
Gitlab
::
ReferenceExtractor
)
# Instrument the classes used for checking if somebody has push access.
config
.
instrument_instance_methods
(
Gitlab
::
GitAccess
)
config
.
instrument_instance_methods
(
Gitlab
::
GitAccessWiki
)
config
.
instrument_instance_methods
(
API
::
Helpers
)
config
.
instrument_instance_methods
(
RepositoryCheck
::
SingleRepositoryWorker
)
config
.
instrument_instance_methods
(
Rouge
::
Plugins
::
Redcarpet
)
config
.
instrument_instance_methods
(
Rouge
::
Formatters
::
HTMLGitlab
)
[
:XML
,
:HTML
].
each
do
|
namespace
|
namespace_mod
=
Nokogiri
.
const_get
(
namespace
)
config
.
instrument_methods
(
namespace_mod
)
config
.
instrument_methods
(
namespace_mod
::
Document
)
end
config
.
instrument_methods
(
Rinku
)
config
.
instrument_instance_methods
(
Repository
)
config
.
instrument_methods
(
Gitlab
::
Highlight
)
config
.
instrument_instance_methods
(
Gitlab
::
Highlight
)
config
.
instrument_methods
(
Elasticsearch
::
Git
::
Repository
)
config
.
instrument_instance_methods
(
Elasticsearch
::
Git
::
Repository
)
config
.
instrument_instance_methods
(
Search
::
GlobalService
)
config
.
instrument_instance_methods
(
Search
::
ProjectService
)
config
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
SearchResults
)
config
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
ProjectSearchResults
)
config
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
Indexer
)
config
.
instrument_instance_methods
(
Gitlab
::
Elastic
::
SnippetSearchResults
)
config
.
instrument_methods
(
Gitlab
::
Elastic
::
Helper
)
config
.
instrument_instance_methods
(
Elastic
::
ApplicationSearch
)
config
.
instrument_instance_methods
(
Elastic
::
IssuesSearch
)
config
.
instrument_instance_methods
(
Elastic
::
MergeRequestsSearch
)
config
.
instrument_instance_methods
(
Elastic
::
MilestonesSearch
)
config
.
instrument_instance_methods
(
Elastic
::
NotesSearch
)
config
.
instrument_instance_methods
(
Elastic
::
ProjectsSearch
)
config
.
instrument_instance_methods
(
Elastic
::
RepositoriesSearch
)
config
.
instrument_instance_methods
(
Elastic
::
SnippetsSearch
)
config
.
instrument_instance_methods
(
Elastic
::
WikiRepositoriesSearch
)
# This is a Rails scope so we have to instrument it manually.
config
.
instrument_method
(
Project
,
:visible_to_user
)
instrument_classes
(
config
)
end
GC
::
Profiler
.
enable
...
...
spec/initializers/metrics_spec.rb
0 → 100644
View file @
cb8df09f
require
'spec_helper'
require_relative
'../../config/initializers/metrics'
describe
'instrument_classes'
,
lib:
true
do
let
(
:config
)
{
double
(
:config
)
}
before
do
allow
(
config
).
to
receive
(
:instrument_method
)
allow
(
config
).
to
receive
(
:instrument_methods
)
allow
(
config
).
to
receive
(
:instrument_instance_methods
)
end
it
'can autoload and instrument all files'
do
expect
{
instrument_classes
(
config
)
}.
not_to
raise_error
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