2018-12-20 10:07:26 -05:00
|
|
|
# This file was prefixed with zz_ because we want to load it the last!
|
2019-09-18 10:02:45 -04:00
|
|
|
# See: https://gitlab.com/gitlab-org/gitlab-foss/issues/55611
|
2018-12-20 10:07:26 -05:00
|
|
|
|
2017-01-23 09:41:32 -05:00
|
|
|
# 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.
|
|
|
|
#
|
2019-07-16 12:42:48 -04:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
2017-01-23 09:41:32 -05:00
|
|
|
def instrument_classes(instrumentation)
|
2019-12-17 19:08:09 -05:00
|
|
|
return if ENV['STATIC_VERIFICATION']
|
|
|
|
|
2017-01-23 09:41:32 -05:00
|
|
|
instrumentation.instrument_instance_methods(Gitlab::Shell)
|
|
|
|
|
|
|
|
instrumentation.instrument_methods(Gitlab::Git)
|
|
|
|
|
|
|
|
Gitlab::Git.constants.each do |name|
|
2019-10-15 23:06:12 -04:00
|
|
|
const = Gitlab::Git.const_get(name, false)
|
2017-01-23 09:41:32 -05:00
|
|
|
|
|
|
|
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 = {
|
2017-03-12 11:40:25 -04:00
|
|
|
%w(app finders) => %w(app finders),
|
|
|
|
%w(app mailers emails) => %w(app mailers),
|
|
|
|
# Don't instrument `app/services/concerns`
|
|
|
|
# It contains modules that are included in the services.
|
|
|
|
# The services themselves are instrumented so the methods from the modules
|
|
|
|
# are included.
|
|
|
|
%w(app services [^concerns]**) => %w(app services),
|
|
|
|
%w(lib gitlab conflicts) => ['lib'],
|
|
|
|
%w(lib gitlab email message) => ['lib'],
|
|
|
|
%w(lib gitlab checks) => ['lib']
|
2017-01-23 09:41:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
instrumentation.instrument_methods(Banzai::Renderer)
|
|
|
|
instrumentation.instrument_methods(Banzai::Querying)
|
|
|
|
|
|
|
|
instrumentation.instrument_instance_methods(Banzai::ObjectRenderer)
|
2019-07-16 16:19:08 -04:00
|
|
|
instrumentation.instrument_instance_methods(Banzai::ReferenceRedactor)
|
2017-01-23 09:41:32 -05:00
|
|
|
|
|
|
|
[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::Formatters::HTMLGitlab)
|
|
|
|
|
|
|
|
[:XML, :HTML].each do |namespace|
|
2019-10-15 23:06:12 -04:00
|
|
|
namespace_mod = Nokogiri.const_get(namespace, false)
|
2017-01-23 09:41:32 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-07-16 12:42:48 -04:00
|
|
|
Gitlab.ee do
|
2019-12-05 07:07:43 -05:00
|
|
|
instrumentation.instrument_instance_methods(Elastic::Latest::GitInstanceProxy)
|
|
|
|
instrumentation.instrument_instance_methods(Elastic::Latest::GitClassProxy)
|
2019-07-16 12:42:48 -04:00
|
|
|
|
|
|
|
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)
|
2020-04-21 11:21:10 -04:00
|
|
|
instrumentation.instrument_instance_methods(Gitlab::Elastic::Helper)
|
2019-07-16 12:42:48 -04:00
|
|
|
|
2019-08-09 04:15:34 -04:00
|
|
|
instrumentation.instrument_instance_methods(Elastic::ApplicationVersionedSearch)
|
2019-07-16 12:42:48 -04:00
|
|
|
instrumentation.instrument_instance_methods(Elastic::ProjectsSearch)
|
|
|
|
instrumentation.instrument_instance_methods(Elastic::RepositoriesSearch)
|
|
|
|
instrumentation.instrument_instance_methods(Elastic::SnippetsSearch)
|
|
|
|
instrumentation.instrument_instance_methods(Elastic::WikiRepositoriesSearch)
|
|
|
|
|
|
|
|
instrumentation.instrument_instance_methods(Gitlab::BitbucketImport::Importer)
|
|
|
|
instrumentation.instrument_instance_methods(Bitbucket::Connection)
|
|
|
|
|
|
|
|
instrumentation.instrument_instance_methods(Geo::RepositorySyncWorker)
|
|
|
|
end
|
|
|
|
|
2017-01-23 09:41:32 -05:00
|
|
|
# This is a Rails scope so we have to instrument it manually.
|
|
|
|
instrumentation.instrument_method(Project, :visible_to_user)
|
2017-06-14 07:01:38 -04:00
|
|
|
|
2019-09-18 10:02:45 -04:00
|
|
|
# Needed for https://gitlab.com/gitlab-org/gitlab-foss/issues/30224#note_32306159
|
2017-06-14 07:01:38 -04:00
|
|
|
instrumentation.instrument_instance_method(MergeRequestDiff, :load_commits)
|
2017-01-23 09:41:32 -05:00
|
|
|
end
|
2019-07-16 12:42:48 -04:00
|
|
|
# rubocop:enable Metrics/AbcSize
|
2017-01-23 09:41:32 -05:00
|
|
|
|
2018-05-07 04:46:23 -04:00
|
|
|
# With prometheus enabled by default this breaks all specs
|
|
|
|
# that stubs methods using `any_instance_of` for the models reloaded here.
|
|
|
|
#
|
|
|
|
# We should deprecate the usage of `any_instance_of` in the future
|
|
|
|
# check: https://github.com/rspec/rspec-mocks#settings-mocks-or-stubs-on-any-instance-of-a-class
|
|
|
|
#
|
2019-09-18 10:02:45 -04:00
|
|
|
# Related issue: https://gitlab.com/gitlab-org/gitlab-foss/issues/33587
|
2018-10-24 19:33:19 -04:00
|
|
|
#
|
|
|
|
# In development mode, we turn off eager loading when we're running
|
|
|
|
# `rails generate migration` because eager loading short-circuits the
|
|
|
|
# loading of our custom migration templates.
|
|
|
|
if Gitlab::Metrics.enabled? && !Rails.env.test? && !(Rails.env.development? && defined?(Rails::Generators))
|
2016-04-12 06:24:16 -04:00
|
|
|
require 'pathname'
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
require 'connection_pool'
|
2015-12-15 11:23:23 -05:00
|
|
|
require 'method_source'
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
|
|
|
|
# These are manually require'd so the classes are registered properly with
|
|
|
|
# ActiveSupport.
|
2017-03-13 09:07:38 -04:00
|
|
|
require_dependency 'gitlab/metrics/subscribers/action_view'
|
|
|
|
require_dependency 'gitlab/metrics/subscribers/active_record'
|
|
|
|
require_dependency 'gitlab/metrics/subscribers/rails_cache'
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
|
|
|
|
Gitlab::Application.configure do |config|
|
|
|
|
config.middleware.use(Gitlab::Metrics::RackMiddleware)
|
2016-05-26 11:53:21 -04:00
|
|
|
config.middleware.use(Gitlab::Middleware::RailsQueueDuration)
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Sidekiq.configure_server do |config|
|
|
|
|
config.server_middleware do |chain|
|
|
|
|
chain.add Gitlab::Metrics::SidekiqMiddleware
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-15 11:23:23 -05:00
|
|
|
# This instruments all methods residing in app/models that (appear to) use any
|
|
|
|
# of the ActiveRecord methods. This has to take place _after_ initializing as
|
|
|
|
# for some unknown reason calling eager_load! earlier breaks Devise.
|
|
|
|
Gitlab::Application.config.after_initialize do
|
|
|
|
Rails.application.eager_load!
|
|
|
|
|
|
|
|
models = Rails.root.join('app', 'models').to_s
|
|
|
|
|
|
|
|
regex = Regexp.union(
|
|
|
|
ActiveRecord::Querying.public_instance_methods(false).map(&:to_s)
|
|
|
|
)
|
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
Gitlab::Metrics::Instrumentation
|
|
|
|
.instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
|
2015-12-28 12:00:32 -05:00
|
|
|
# Instrumenting the ApplicationSetting class can lead to an infinite
|
|
|
|
# loop. Since the data is cached any way we don't really need to
|
|
|
|
# instrument it.
|
|
|
|
if klass == ApplicationSetting
|
|
|
|
false
|
|
|
|
else
|
|
|
|
loc = method.source_location
|
2015-12-15 11:23:23 -05:00
|
|
|
|
2015-12-28 12:00:32 -05:00
|
|
|
loc && loc[0].start_with?(models) && method.source =~ regex
|
|
|
|
end
|
2015-12-15 11:23:23 -05:00
|
|
|
end
|
2017-07-14 05:19:20 -04:00
|
|
|
|
|
|
|
# Ability is in app/models, is not an ActiveRecord model, but should still
|
|
|
|
# be instrumented.
|
|
|
|
Gitlab::Metrics::Instrumentation.instrument_methods(Ability)
|
2015-12-15 11:23:23 -05:00
|
|
|
end
|
|
|
|
|
2015-12-10 11:09:20 -05:00
|
|
|
Gitlab::Metrics::Instrumentation.configure do |config|
|
2017-01-23 09:41:32 -05:00
|
|
|
instrument_classes(config)
|
2015-12-10 11:09:20 -05:00
|
|
|
end
|
|
|
|
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
GC::Profiler.enable
|
|
|
|
|
2016-06-14 10:49:26 -04:00
|
|
|
module TrackNewRedisConnections
|
|
|
|
def connect(*args)
|
|
|
|
val = super
|
|
|
|
|
2019-02-10 05:30:37 -05:00
|
|
|
if current_transaction = ::Gitlab::Metrics::Transaction.current
|
2016-06-14 10:49:26 -04:00
|
|
|
current_transaction.increment(:new_redis_connections, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ::Redis::Client
|
|
|
|
prepend TrackNewRedisConnections
|
|
|
|
end
|
Storing of application metrics in InfluxDB
This adds the ability to write application metrics (e.g. SQL timings) to
InfluxDB. These metrics can in turn be visualized using Grafana, or
really anything else that can read from InfluxDB. These metrics can be
used to track application performance over time, between different Ruby
versions, different GitLab versions, etc.
== Transaction Metrics
Currently the following is tracked on a per transaction basis (a
transaction is a Rails request or a single Sidekiq job):
* Timings per query along with the raw (obfuscated) SQL and information
about what file the query originated from.
* Timings per view along with the path of the view and information about
what file triggered the rendering process.
* The duration of a request itself along with the controller/worker
class and method name.
* The duration of any instrumented method calls (more below).
== Sampled Metrics
Certain metrics can't be directly associated with a transaction. For
example, a process' total memory usage is unrelated to any running
transactions. While a transaction can result in the memory usage going
up there's no accurate way to determine what transaction is to blame,
this becomes especially problematic in multi-threaded environments.
To solve this problem there's a separate thread that takes samples at a
fixed interval. This thread (using the class Gitlab::Metrics::Sampler)
currently tracks the following:
* The process' total memory usage.
* The number of file descriptors opened by the process.
* The amount of Ruby objects (using ObjectSpace.count_objects).
* GC statistics such as timings, heap slots, etc.
The default/current interval is 15 seconds, any smaller interval might
put too much pressure on InfluxDB (especially when running dozens of
processes).
== Method Instrumentation
While currently not yet used methods can be instrumented to track how
long they take to run. Unlike the likes of New Relic this doesn't
require modifying the source code (e.g. including modules), it all
happens from the outside. For example, to track `User.by_login` we'd add
the following code somewhere in an initializer:
Gitlab::Metrics::Instrumentation.
instrument_method(User, :by_login)
to instead instrument an instance method:
Gitlab::Metrics::Instrumentation.
instrument_instance_method(User, :save)
Instrumentation for either all public model methods or a few crucial
ones will be added in the near future, I simply haven't gotten to doing
so just yet.
== Configuration
By default metrics are disabled. This means users don't have to bother
setting anything up if they don't want to. Metrics can be enabled by
editing one's gitlab.yml configuration file (see
config/gitlab.yml.example for example settings).
== Writing Data To InfluxDB
Because InfluxDB is still a fairly young product I expect the worse.
Data loss, unexpected reboots, the database not responding, you name it.
Because of this data is _not_ written to InfluxDB directly, instead it's
queued and processed by Sidekiq. This ensures that users won't notice
anything when InfluxDB is giving trouble.
The metrics worker can be started in a standalone manner as following:
bundle exec sidekiq -q metrics
The corresponding class is called MetricsWorker.
2015-12-09 10:45:51 -05:00
|
|
|
end
|