Actually make the new methods work
This commit is contained in:
parent
ef44fef15f
commit
e5d6141541
|
@ -9,7 +9,7 @@ module Gitlab
|
||||||
@@_metrics_provider_mutex ||= Mutex.new
|
@@_metrics_provider_mutex ||= Mutex.new
|
||||||
|
|
||||||
if instance_methods(false).include?(name)
|
if instance_methods(false).include?(name)
|
||||||
raise ArgumentError, "metrics class method #{name} already exists"
|
raise ArgumentError, "metrics method #{name} already exists"
|
||||||
end
|
end
|
||||||
options[:base_labels] ||= {}
|
options[:base_labels] ||= {}
|
||||||
|
|
||||||
|
@ -24,55 +24,58 @@ module Gitlab
|
||||||
args << options[:buckets].inspect
|
args << options[:buckets].inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
metric_fetching_code = %{Gitlab::Metrics::Prometheus.#{type}(#{args.join(', ')})}
|
metric_fetching_code = %{Gitlab::Metrics.#{type}(#{args.join(', ')})}
|
||||||
|
|
||||||
# optionally wrap in feature
|
# optionally wrap in feature
|
||||||
metric_fetching_code = if options[:with_feature].is_a?(Symbol)
|
if options[:with_feature].is_a?(Symbol)
|
||||||
<<-FETCH.strip_heredoc
|
metric_fetching_code = <<-FETCH.strip_heredoc
|
||||||
if Feature.get(#{options[:with_feature].inspect}).enabled?
|
if Feature.get(#{options[:with_feature].inspect}).enabled?
|
||||||
#{metric_fetching_code}
|
#{metric_fetching_code}
|
||||||
else
|
else
|
||||||
Gitlab::Metrics::NullMetric.new
|
Gitlab::Metrics::NullMetric.new
|
||||||
end
|
end
|
||||||
FETCH
|
FETCH
|
||||||
end
|
end
|
||||||
|
|
||||||
method_code, line = <<-METRIC, __LINE__ + 1
|
method_code, line = <<-METRIC, __LINE__ + 1
|
||||||
|
@@_metric_provider_cached_#{name} = nil
|
||||||
def #{name}
|
def #{name}
|
||||||
@@_metric_provider_cached_#{name} if @@_metric_provider_cached_#{name}
|
return @@_metric_provider_cached_#{name} if @@_metric_provider_cached_#{name}
|
||||||
|
|
||||||
@@_metrics_provider_mutex.synchronize do
|
@@_metrics_provider_mutex.synchronize do
|
||||||
@_metric_provider_cached_#{name} ||= #{metric_fetching_code}
|
puts "Initiaalized"
|
||||||
|
@@_metric_provider_cached_#{name} ||= #{metric_fetching_code}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
METRIC
|
METRIC
|
||||||
|
puts method_code
|
||||||
|
|
||||||
class_eval(method_code, __FILE__, line)
|
instance_eval(method_code, __FILE__, line)
|
||||||
module_eval(method_code, __FILE__, line)
|
module_eval(method_code, __FILE__, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Declare a Counter
|
# Declare a Counter
|
||||||
# @param [Symbol] name
|
# @param [Symbol] name
|
||||||
# @param [String] docstring
|
# @param [String] docstring
|
||||||
# @param [Hash] opts
|
# @param [Hash] options
|
||||||
def counter(name, docstring, opts = {})
|
def counter(name, docstring, options = {})
|
||||||
metrics_provider(:counter, name, docstring, options)
|
metrics_provider(:counter, name, docstring, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Declare a Gauge
|
# Declare a Gauge
|
||||||
# @param [Symbol] name
|
# @param [Symbol] name
|
||||||
# @param [String] docstring
|
# @param [String] docstring
|
||||||
# @param [Hash] opts
|
# @param [Hash] options
|
||||||
def gauge(name, docstring, opts = {})
|
def gauge(name, docstring, options = {})
|
||||||
metrics_provider(:counter, name, docstring, opts)
|
metrics_provider(:counter, name, docstring, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Declare a Histograam
|
# Declare a Histograam
|
||||||
# @param [Symbol] name
|
# @param [Symbol] name
|
||||||
# @param [String] docstring
|
# @param [String] docstring
|
||||||
# @param [Hash] opts
|
# @param [Hash] options
|
||||||
def histogram(name, docstring, opts = {})
|
def histogram(name, docstring, options = {})
|
||||||
metrics_provider(:histogram, name, docstring, opts)
|
metrics_provider(:histogram, name, docstring, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def summary(*args)
|
def summary(*args)
|
||||||
|
|
|
@ -10,7 +10,8 @@ module Gitlab
|
||||||
|
|
||||||
histogram :gitlab_method_call_duration_seconds, 'Method calls real duration',
|
histogram :gitlab_method_call_duration_seconds, 'Method calls real duration',
|
||||||
base_labels: Transaction::BASE_LABELS.merge(BASE_LABELS),
|
base_labels: Transaction::BASE_LABELS.merge(BASE_LABELS),
|
||||||
buckets: [0.01, 0.05, 0.1, 0.5, 1]
|
buckets: [0.01, 0.05, 0.1, 0.5, 1],
|
||||||
|
with_feature: :prometheus_metrics_method_instrumentation
|
||||||
|
|
||||||
# name - The full name of the method (including namespace) such as
|
# name - The full name of the method (including namespace) such as
|
||||||
# `User#sign_in`.
|
# `User#sign_in`.
|
||||||
|
|
Loading…
Reference in New Issue