2018-12-20 15:07:26 +00:00
|
|
|
# This file was prefixed with zz_ because we want to load it the last!
|
|
|
|
# See: https://gitlab.com/gitlab-org/gitlab-ce/issues/55611
|
|
|
|
|
2017-01-23 14:41:32 +00: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 16:42:48 +00:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
2017-01-23 14:41:32 +00:00
|
|
|
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 = {
|
2017-03-12 15:40:25 +00: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 14:41:32 +00: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 20:19:08 +00:00
|
|
|
instrumentation.instrument_instance_methods(Banzai::ReferenceRedactor)
|
2017-01-23 14:41:32 +00: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|
|
|
|
|
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)
|
|
|
|
|
2019-07-16 16:42:48 +00:00
|
|
|
Gitlab.ee do
|
|
|
|
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)
|
|
|
|
|
|
|
|
instrumentation.instrument_instance_methods(Gitlab::BitbucketImport::Importer)
|
|
|
|
instrumentation.instrument_instance_methods(Bitbucket::Connection)
|
|
|
|
|
|
|
|
instrumentation.instrument_instance_methods(Geo::RepositorySyncWorker)
|
|
|
|
end
|
|
|
|
|
2017-01-23 14:41:32 +00:00
|
|
|
# This is a Rails scope so we have to instrument it manually.
|
|
|
|
instrumentation.instrument_method(Project, :visible_to_user)
|
2017-06-14 11:01:38 +00:00
|
|
|
|
|
|
|
# Needed for https://gitlab.com/gitlab-org/gitlab-ce/issues/30224#note_32306159
|
|
|
|
instrumentation.instrument_instance_method(MergeRequestDiff, :load_commits)
|
2017-01-23 14:41:32 +00:00
|
|
|
end
|
2019-07-16 16:42:48 +00:00
|
|
|
# rubocop:enable Metrics/AbcSize
|
2017-01-23 14:41:32 +00:00
|
|
|
|
2018-05-07 08:46:23 +00: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
|
|
|
|
#
|
|
|
|
# Related issue: https://gitlab.com/gitlab-org/gitlab-ce/issues/33587
|
2018-10-24 23:33:19 +00: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 10:24:16 +00: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 15:45:51 +00:00
|
|
|
require 'influxdb'
|
|
|
|
require 'connection_pool'
|
2015-12-15 16:23:23 +00: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 15:45:51 +00:00
|
|
|
|
|
|
|
# These are manually require'd so the classes are registered properly with
|
|
|
|
# ActiveSupport.
|
2017-03-13 13:07:38 +00: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 15:45:51 +00:00
|
|
|
|
|
|
|
Gitlab::Application.configure do |config|
|
|
|
|
config.middleware.use(Gitlab::Metrics::RackMiddleware)
|
2016-05-26 15:53:21 +00: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 15:45:51 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Sidekiq.configure_server do |config|
|
|
|
|
config.server_middleware do |chain|
|
|
|
|
chain.add Gitlab::Metrics::SidekiqMiddleware
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-15 16:23:23 +00: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 13:48:12 +00:00
|
|
|
Gitlab::Metrics::Instrumentation
|
|
|
|
.instrument_class_hierarchy(ActiveRecord::Base) do |klass, method|
|
2015-12-28 17:00:32 +00: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 16:23:23 +00:00
|
|
|
|
2015-12-28 17:00:32 +00:00
|
|
|
loc && loc[0].start_with?(models) && method.source =~ regex
|
|
|
|
end
|
2015-12-15 16:23:23 +00:00
|
|
|
end
|
2017-07-14 09:19:20 +00: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 16:23:23 +00:00
|
|
|
end
|
|
|
|
|
2015-12-10 16:09:20 +00:00
|
|
|
Gitlab::Metrics::Instrumentation.configure do |config|
|
2017-01-23 14:41:32 +00:00
|
|
|
instrument_classes(config)
|
2015-12-10 16:09:20 +00: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 15:45:51 +00:00
|
|
|
GC::Profiler.enable
|
|
|
|
|
2018-10-20 18:00:19 +00:00
|
|
|
Gitlab::Cluster::LifecycleEvents.on_worker_start do
|
|
|
|
Gitlab::Metrics::Samplers::InfluxSampler.initialize_instance.start
|
|
|
|
end
|
2016-06-14 14:49:26 +00:00
|
|
|
|
|
|
|
module TrackNewRedisConnections
|
|
|
|
def connect(*args)
|
|
|
|
val = super
|
|
|
|
|
2019-02-10 10:30:37 +00:00
|
|
|
if current_transaction = ::Gitlab::Metrics::Transaction.current
|
2016-06-14 14:49:26 +00: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 15:45:51 +00:00
|
|
|
end
|