debian-mirror-gitlab/config/initializers/zz_metrics.rb

65 lines
2.3 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2019-02-15 15:39:39 +05:30
# This file was prefixed with zz_ because we want to load it the last!
2019-12-04 20:38:33 +05:30
# See: https://gitlab.com/gitlab-org/gitlab-foss/issues/55611
2019-02-15 15:39:39 +05:30
2018-10-15 14:42:47 +05:30
# 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-12-04 20:38:33 +05:30
# Related issue: https://gitlab.com/gitlab-org/gitlab-foss/issues/33587
2018-12-13 13:39:08 +05:30
#
# 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))
2017-08-17 22:00:37 +05:30
require 'pathname'
require 'connection_pool'
require 'method_source'
# These are manually require'd so the classes are registered properly with
# ActiveSupport.
2021-04-17 20:07:23 +05:30
require_dependency 'gitlab/metrics/subscribers/action_cable'
2017-08-17 22:00:37 +05:30
require_dependency 'gitlab/metrics/subscribers/action_view'
require_dependency 'gitlab/metrics/subscribers/active_record'
require_dependency 'gitlab/metrics/subscribers/rails_cache'
Gitlab::Application.configure do |config|
2021-09-30 23:02:18 +05:30
# We want to track certain metrics during the Load Balancing host resolving process.
# Because of that, we need to have metrics code available earlier for Load Balancing.
2021-11-18 22:05:49 +05:30
config.middleware.insert_before Gitlab::Database::LoadBalancing::RackMiddleware,
Gitlab::Metrics::RackMiddleware
2021-09-30 23:02:18 +05:30
2017-08-17 22:00:37 +05:30
config.middleware.use(Gitlab::Middleware::RailsQueueDuration)
2020-06-23 00:09:42 +05:30
config.middleware.use(Gitlab::Metrics::ElasticsearchRackMiddleware)
2017-08-17 22:00:37 +05:30
end
2022-04-04 11:22:00 +05:30
if Gitlab::Runtime.puma?
Gitlab::Metrics::RequestsRackMiddleware.initialize_metrics
end
2017-08-17 22:00:37 +05:30
GC::Profiler.enable
module TrackNewRedisConnections
def connect(*args)
val = super
2021-12-11 22:18:48 +05:30
if current_transaction = (::Gitlab::Metrics::WebTransaction.current || ::Gitlab::Metrics::BackgroundTransaction.current)
2020-10-24 23:57:45 +05:30
current_transaction.increment(:gitlab_transaction_new_redis_connections_total, 1)
2017-08-17 22:00:37 +05:30
end
val
end
end
class ::Redis::Client
prepend TrackNewRedisConnections
end
2021-03-11 19:13:27 +05:30
Labkit::NetHttpPublisher.labkit_prepend!
Labkit::ExconPublisher.labkit_prepend!
Labkit::HTTPClientPublisher.labkit_prepend!
2017-08-17 22:00:37 +05:30
end