Commit ea6196d4 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Move prometheus metrics to module. Use class instance variables for metrics...

Move prometheus metrics to module. Use class instance variables for metrics and metrics cache in metrics concern
parent 27359dbf
module Gitlab
module Metrics
extend Gitlab::Metrics::InfluxDb
extend Gitlab::Metrics::Prometheus
include Gitlab::Metrics::Prometheus
def self.enabled?
influx_metrics_enabled? || prometheus_metrics_enabled?
......
......@@ -6,12 +6,13 @@ module Gitlab
extend ActiveSupport::Concern
included do
@@_metric_provider_mutex = Mutex.new
@_metric_provider_mutex = Mutex.new
@_metrics_provider_cache = {}
end
class_methods do
def reload_metric!(name)
@_metrics_provider_cache&.delete(name)
@_metrics_provider_cache.delete(name)
end
private
......@@ -22,12 +23,12 @@ module Gitlab
end
define_singleton_method(name) do
@_metrics_provider_cache&.[](name) || init_metric(type, name, opts, &block)
@_metrics_provider_cache[name] || init_metric(type, name, opts, &block)
end
end
def fetch_metric(type, name, opts = {}, &block)
@_metrics_provider_cache&.[](name) || init_metric(type, name, opts, &block)
@_metrics_provider_cache[name] || init_metric(type, name, opts, &block)
end
def init_metric(type, name, opts = {}, &block)
......@@ -42,8 +43,7 @@ module Gitlab
end
def synchronized_cache_fill(key)
@@_metric_provider_mutex.synchronize do
@_metrics_provider_cache ||= {}
@_metric_provider_mutex.synchronize do
@_metrics_provider_cache[key] ||= yield
end
end
......
module Gitlab
module Metrics
module InfluxDb
include Gitlab::Metrics::Concern::ClassMethods
include Gitlab::Metrics::Concern
include Gitlab::CurrentSettings
extend self
......
......@@ -3,12 +3,16 @@ require 'prometheus/client'
module Gitlab
module Metrics
module Prometheus
extend ActiveSupport::Concern
include Gitlab::Metrics::Concern
include Gitlab::CurrentSettings
include Gitlab::Utils::StrongMemoize
REGISTRY_MUTEX = Mutex.new
PROVIDER_MUTEX = Mutex.new
class_methods do
include Gitlab::Utils::StrongMemoize
def metrics_folder_present?
multiprocess_files_dir = ::Prometheus::Client.configuration.multiprocess_files_dir
......@@ -73,4 +77,5 @@ module Gitlab
end
end
end
end
end
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