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.
|
|
|
|
#
|
|
|
|
# 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 = {
|
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 diff) => ['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)
|
|
|
|
|
|
|
|
[
|
|
|
|
: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)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
# Needed for https://gitlab.com/gitlab-org/gitlab-ce/issues/30224#note_32306159
|
|
|
|
instrumentation.instrument_instance_method(MergeRequestDiff, :load_commits)
|
2017-08-28 09:21:05 -04:00
|
|
|
|
|
|
|
# Needed for https://gitlab.com/gitlab-org/gitlab-ce/issues/36061
|
|
|
|
instrumentation.instrument_instance_method(MergeRequest, :ensure_ref_fetched)
|
2017-09-01 03:36:37 -04:00
|
|
|
instrumentation.instrument_instance_method(MergeRequest, :fetch_ref)
|
2017-01-23 09:41:32 -05:00
|
|
|
end
|
|
|
|
# rubocop:enable Metrics/AbcSize
|
|
|
|
|
2017-07-04 18:51:01 -04:00
|
|
|
Gitlab::Metrics::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_sampler_interval).start
|
2017-07-04 11:28:34 -04:00
|
|
|
|
|
|
|
Gitlab::Application.configure do |config|
|
|
|
|
# 0 should be Sentry to catch errors in this middleware
|
2017-07-12 18:46:17 -04:00
|
|
|
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
|
2017-07-04 11:28:34 -04: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
|
|
|
if Gitlab::Metrics.enabled?
|
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 'influxdb'
|
|
|
|
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
|
|
|
|
|
2017-07-04 11:28:34 -04:00
|
|
|
Gitlab::Metrics::InfluxSampler.initialize_instance.start
|
2016-06-14 10:49:26 -04:00
|
|
|
|
|
|
|
module TrackNewRedisConnections
|
|
|
|
def connect(*args)
|
|
|
|
val = super
|
|
|
|
|
|
|
|
if current_transaction = Gitlab::Metrics::Transaction.current
|
|
|
|
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
|