Commit e6fcdd7a authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Stan Hu

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.
parent 4818211a
...@@ -6,7 +6,7 @@ class ReactiveCachingWorker ...@@ -6,7 +6,7 @@ class ReactiveCachingWorker
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def perform(class_name, id, *args) def perform(class_name, id, *args)
klass = begin klass = begin
Kernel.const_get(class_name) class_name.constantize
rescue NameError rescue NameError
nil nil
end end
......
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
# Returns the name of the series to use for storing method calls. # Returns the name of the series to use for storing method calls.
def self.series def self.series
@series ||= "#{Metrics.series_prefix}method_calls" @series ||= "#{::Gitlab::Metrics.series_prefix}method_calls"
end end
# Instruments a class method. # Instruments a class method.
...@@ -118,7 +118,7 @@ module Gitlab ...@@ -118,7 +118,7 @@ module Gitlab
# mod - The module containing the method. # mod - The module containing the method.
# name - The name of the method to instrument. # name - The name of the method to instrument.
def self.instrument(type, mod, name) def self.instrument(type, mod, name)
return unless Metrics.enabled? return unless ::Gitlab::Metrics.enabled?
name = name.to_sym name = name.to_sym
target = type == :instance ? mod : mod.singleton_class target = type == :instance ? mod : mod.singleton_class
......
...@@ -65,7 +65,7 @@ module Gitlab ...@@ -65,7 +65,7 @@ module Gitlab
# Returns true if the total runtime of this method exceeds the method call # Returns true if the total runtime of this method exceeds the method call
# threshold. # threshold.
def above_threshold? def above_threshold?
real_time.in_milliseconds >= Metrics.method_call_threshold real_time.in_milliseconds >= ::Gitlab::Metrics.method_call_threshold
end end
end end
end end
......
...@@ -58,11 +58,11 @@ module Gitlab ...@@ -58,11 +58,11 @@ module Gitlab
def build_metric!(type, name, options) def build_metric!(type, name, options)
case type case type
when :gauge 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 when :counter
Gitlab::Metrics.counter(name, options.docstring, options.base_labels) ::Gitlab::Metrics.counter(name, options.docstring, options.base_labels)
when :histogram 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 when :summary
raise NotImplementedError, "summary metrics are not currently supported" raise NotImplementedError, "summary metrics are not currently supported"
else else
......
...@@ -8,15 +8,15 @@ module Gitlab ...@@ -8,15 +8,15 @@ module Gitlab
end end
def self.http_request_total 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 end
def self.rack_uncaught_errors_count 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 end
def self.http_request_duration_seconds 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]) {}, [0.05, 0.1, 0.25, 0.5, 0.7, 1, 2.5, 5, 10, 25])
end end
......
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
# statistics, etc. # statistics, etc.
class InfluxSampler < BaseSampler class InfluxSampler < BaseSampler
# interval - The sampling interval in seconds. # interval - The sampling interval in seconds.
def initialize(interval = Metrics.settings[:sample_interval]) def initialize(interval = ::Gitlab::Metrics.settings[:sample_interval])
super(interval) super(interval)
@last_step = nil @last_step = nil
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
end end
def flush def flush
Metrics.submit_metrics(@metrics.map(&:to_hash)) ::Gitlab::Metrics.submit_metrics(@metrics.map(&:to_hash))
end end
def sample_memory_usage def sample_memory_usage
......
...@@ -24,14 +24,14 @@ module Gitlab ...@@ -24,14 +24,14 @@ module Gitlab
def init_metrics def init_metrics
metrics = {} metrics = {}
metrics[:sampler_duration] = Metrics.counter(with_prefix(:sampler, :duration_seconds_total), 'Sampler time', labels) metrics[:sampler_duration] = ::Gitlab::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[:total_time] = ::Gitlab::Metrics.counter(with_prefix(:gc, :duration_seconds_total), 'Total GC time', labels)
GC.stat.keys.each do |key| 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 end
metrics[:memory_usage] = Metrics.gauge(with_prefix(:memory, :bytes), 'Memory used', labels, :livesum) metrics[:memory_usage] = ::Gitlab::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[:file_descriptors] = ::Gitlab::Metrics.gauge(with_prefix(:file, :descriptors), 'File descriptors used', labels, :livesum)
metrics metrics
end end
......
...@@ -9,11 +9,11 @@ module Gitlab ...@@ -9,11 +9,11 @@ module Gitlab
end end
def unicorn_active_connections 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 end
def unicorn_queued_connections 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 end
def enabled? def enabled?
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
LOG_FILENAME = File.join(Rails.root, 'log', 'sidekiq_exporter.log') LOG_FILENAME = File.join(Rails.root, 'log', 'sidekiq_exporter.log')
def enabled? def enabled?
Gitlab::Metrics.metrics_folder_present? && settings.enabled ::Gitlab::Metrics.metrics_folder_present? && settings.enabled
end end
def settings def settings
......
...@@ -64,7 +64,7 @@ module Gitlab ...@@ -64,7 +64,7 @@ module Gitlab
end end
def metric_cache_operation_duration_seconds 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, :gitlab_cache_operation_duration_seconds,
'Cache access time', 'Cache access time',
Transaction::BASE_LABELS.merge({ action: nil }), Transaction::BASE_LABELS.merge({ action: nil }),
...@@ -73,7 +73,7 @@ module Gitlab ...@@ -73,7 +73,7 @@ module Gitlab
end end
def metric_cache_misses_total def metric_cache_misses_total
@metric_cache_misses_total ||= Gitlab::Metrics.counter( @metric_cache_misses_total ||= ::Gitlab::Metrics.counter(
:gitlab_cache_misses_total, :gitlab_cache_misses_total,
'Cache read miss', 'Cache read miss',
Transaction::BASE_LABELS Transaction::BASE_LABELS
......
...@@ -64,7 +64,7 @@ module Gitlab ...@@ -64,7 +64,7 @@ module Gitlab
end end
def add_metric(series, values, tags = {}) 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 end
# Tracks a business level event # Tracks a business level event
...@@ -127,7 +127,7 @@ module Gitlab ...@@ -127,7 +127,7 @@ module Gitlab
hash hash
end end
Metrics.submit_metrics(submit_hashes) ::Gitlab::Metrics.submit_metrics(submit_hashes)
end end
def labels def labels
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment