Update Metrics references to Object path

On reload, references to Metrics within classes in the Gitlab::Metrics
module fail. Update all references to ::Gitlab::Metrics so that
constant lookup finds the right module in development. This fix should
not impact production.
This commit is contained in:
Sarah Yasonik 2019-02-14 18:05:35 +00:00 committed by Stan Hu
parent 4818211a3a
commit e6fcdd7aca
11 changed files with 24 additions and 24 deletions

View file

@ -6,7 +6,7 @@ class ReactiveCachingWorker
# rubocop: disable CodeReuse/ActiveRecord
def perform(class_name, id, *args)
klass = begin
Kernel.const_get(class_name)
class_name.constantize
rescue NameError
nil
end

View file

@ -19,7 +19,7 @@ module Gitlab
# Returns the name of the series to use for storing method calls.
def self.series
@series ||= "#{Metrics.series_prefix}method_calls"
@series ||= "#{::Gitlab::Metrics.series_prefix}method_calls"
end
# Instruments a class method.
@ -118,7 +118,7 @@ module Gitlab
# mod - The module containing the method.
# name - The name of the method to instrument.
def self.instrument(type, mod, name)
return unless Metrics.enabled?
return unless ::Gitlab::Metrics.enabled?
name = name.to_sym
target = type == :instance ? mod : mod.singleton_class

View file

@ -65,7 +65,7 @@ module Gitlab
# Returns true if the total runtime of this method exceeds the method call
# threshold.
def above_threshold?
real_time.in_milliseconds >= Metrics.method_call_threshold
real_time.in_milliseconds >= ::Gitlab::Metrics.method_call_threshold
end
end
end

View file

@ -58,11 +58,11 @@ module Gitlab
def build_metric!(type, name, options)
case type
when :gauge
Gitlab::Metrics.gauge(name, options.docstring, options.base_labels, options.multiprocess_mode)
::Gitlab::Metrics.gauge(name, options.docstring, options.base_labels, options.multiprocess_mode)
when :counter
Gitlab::Metrics.counter(name, options.docstring, options.base_labels)
::Gitlab::Metrics.counter(name, options.docstring, options.base_labels)
when :histogram
Gitlab::Metrics.histogram(name, options.docstring, options.base_labels, options.buckets)
::Gitlab::Metrics.histogram(name, options.docstring, options.base_labels, options.buckets)
when :summary
raise NotImplementedError, "summary metrics are not currently supported"
else

View file

@ -8,15 +8,15 @@ module Gitlab
end
def self.http_request_total
@http_request_total ||= Gitlab::Metrics.counter(:http_requests_total, 'Request count')
@http_request_total ||= ::Gitlab::Metrics.counter(:http_requests_total, 'Request count')
end
def self.rack_uncaught_errors_count
@rack_uncaught_errors_count ||= Gitlab::Metrics.counter(:rack_uncaught_errors_total, 'Request handling uncaught errors count')
@rack_uncaught_errors_count ||= ::Gitlab::Metrics.counter(:rack_uncaught_errors_total, 'Request handling uncaught errors count')
end
def self.http_request_duration_seconds
@http_request_duration_seconds ||= Gitlab::Metrics.histogram(:http_request_duration_seconds, 'Request handling execution time',
@http_request_duration_seconds ||= ::Gitlab::Metrics.histogram(:http_request_duration_seconds, 'Request handling execution time',
{}, [0.05, 0.1, 0.25, 0.5, 0.7, 1, 2.5, 5, 10, 25])
end

View file

@ -10,7 +10,7 @@ module Gitlab
# statistics, etc.
class InfluxSampler < BaseSampler
# interval - The sampling interval in seconds.
def initialize(interval = Metrics.settings[:sample_interval])
def initialize(interval = ::Gitlab::Metrics.settings[:sample_interval])
super(interval)
@last_step = nil
@ -32,7 +32,7 @@ module Gitlab
end
def flush
Metrics.submit_metrics(@metrics.map(&:to_hash))
::Gitlab::Metrics.submit_metrics(@metrics.map(&:to_hash))
end
def sample_memory_usage

View file

@ -24,14 +24,14 @@ module Gitlab
def init_metrics
metrics = {}
metrics[:sampler_duration] = Metrics.counter(with_prefix(:sampler, :duration_seconds_total), 'Sampler time', labels)
metrics[:total_time] = Metrics.counter(with_prefix(:gc, :duration_seconds_total), 'Total GC time', labels)
metrics[:sampler_duration] = ::Gitlab::Metrics.counter(with_prefix(:sampler, :duration_seconds_total), 'Sampler time', labels)
metrics[:total_time] = ::Gitlab::Metrics.counter(with_prefix(:gc, :duration_seconds_total), 'Total GC time', labels)
GC.stat.keys.each do |key|
metrics[key] = Metrics.gauge(with_prefix(:gc_stat, key), to_doc_string(key), labels, :livesum)
metrics[key] = ::Gitlab::Metrics.gauge(with_prefix(:gc_stat, key), to_doc_string(key), labels, :livesum)
end
metrics[:memory_usage] = Metrics.gauge(with_prefix(:memory, :bytes), 'Memory used', labels, :livesum)
metrics[:file_descriptors] = Metrics.gauge(with_prefix(:file, :descriptors), 'File descriptors used', labels, :livesum)
metrics[:memory_usage] = ::Gitlab::Metrics.gauge(with_prefix(:memory, :bytes), 'Memory used', labels, :livesum)
metrics[:file_descriptors] = ::Gitlab::Metrics.gauge(with_prefix(:file, :descriptors), 'File descriptors used', labels, :livesum)
metrics
end

View file

@ -9,11 +9,11 @@ module Gitlab
end
def unicorn_active_connections
@unicorn_active_connections ||= Gitlab::Metrics.gauge(:unicorn_active_connections, 'Unicorn active connections', {}, :max)
@unicorn_active_connections ||= ::Gitlab::Metrics.gauge(:unicorn_active_connections, 'Unicorn active connections', {}, :max)
end
def unicorn_queued_connections
@unicorn_queued_connections ||= Gitlab::Metrics.gauge(:unicorn_queued_connections, 'Unicorn queued connections', {}, :max)
@unicorn_queued_connections ||= ::Gitlab::Metrics.gauge(:unicorn_queued_connections, 'Unicorn queued connections', {}, :max)
end
def enabled?

View file

@ -9,7 +9,7 @@ module Gitlab
LOG_FILENAME = File.join(Rails.root, 'log', 'sidekiq_exporter.log')
def enabled?
Gitlab::Metrics.metrics_folder_present? && settings.enabled
::Gitlab::Metrics.metrics_folder_present? && settings.enabled
end
def settings

View file

@ -64,7 +64,7 @@ module Gitlab
end
def metric_cache_operation_duration_seconds
@metric_cache_operation_duration_seconds ||= Gitlab::Metrics.histogram(
@metric_cache_operation_duration_seconds ||= ::Gitlab::Metrics.histogram(
:gitlab_cache_operation_duration_seconds,
'Cache access time',
Transaction::BASE_LABELS.merge({ action: nil }),
@ -73,7 +73,7 @@ module Gitlab
end
def metric_cache_misses_total
@metric_cache_misses_total ||= Gitlab::Metrics.counter(
@metric_cache_misses_total ||= ::Gitlab::Metrics.counter(
:gitlab_cache_misses_total,
'Cache read miss',
Transaction::BASE_LABELS

View file

@ -64,7 +64,7 @@ module Gitlab
end
def add_metric(series, values, tags = {})
@metrics << Metric.new("#{Metrics.series_prefix}#{series}", values, tags)
@metrics << Metric.new("#{::Gitlab::Metrics.series_prefix}#{series}", values, tags)
end
# Tracks a business level event
@ -127,7 +127,7 @@ module Gitlab
hash
end
Metrics.submit_metrics(submit_hashes)
::Gitlab::Metrics.submit_metrics(submit_hashes)
end
def labels