Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-01-16 17:47:07 +0300
committerPawel Chojnacki <pawel@chojnacki.ws>2018-01-29 17:13:03 +0300
commit66c1acba0bada535cedcdc4d8e62ff966b4d0374 (patch)
tree03b6f1e0e1d747038152514278c55404dcd2e846 /lib
parent53f818fdac35d1c0810faa81a8dde20bbf8a3697 (diff)
Fix code after refactoring
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/concern.rb19
-rw-r--r--lib/gitlab/metrics/concern/metric_options.rb24
-rw-r--r--lib/gitlab/metrics/method_call.rb9
-rw-r--r--lib/gitlab/metrics/transaction.rb37
4 files changed, 44 insertions, 45 deletions
diff --git a/lib/gitlab/metrics/concern.rb b/lib/gitlab/metrics/concern.rb
index a9c45380a5d..e7c91df94bc 100644
--- a/lib/gitlab/metrics/concern.rb
+++ b/lib/gitlab/metrics/concern.rb
@@ -9,6 +9,10 @@ module Gitlab
end
class_methods do
+ def reload_metric!(name)
+ @@_metrics_provider_cache.delete(name)
+ end
+
private
def define_metric(type, name, opts = {}, &block)
@@ -16,7 +20,7 @@ module Gitlab
raise ArgumentError, "metrics method #{name} already exists"
end
- define_method(name) do
+ define_singleton_method(name) do
# avoid unnecessary method call to speed up metric access
return @@_metrics_provider_cache[name] if @@_metrics_provider_cache.has_key?(name)
@@ -45,12 +49,11 @@ module Gitlab
case type
when :gauge
- Gitlab::Metrics.gauge(name, options.docs, 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.docs, options.base_labels)
+ Gitlab::Metrics.counter(name, options.docstring, options.base_labels)
when :histogram
- options[:buckets] ||= ::Prometheus::Client::Histogram::DEFAULT_BUCKETS
- Gitlab::Metrics.histogram(name, options.docs, 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
@@ -58,12 +61,6 @@ module Gitlab
end
end
- counter :global do
- docstring "Global counter"
- multiprocess_mode :all
- buckets [0, 1]
- end
-
# Fetch and/or initialize counter metric
# @param [Symbol] name
# @param [Hash] opts
diff --git a/lib/gitlab/metrics/concern/metric_options.rb b/lib/gitlab/metrics/concern/metric_options.rb
index 502805c135a..996757e11d5 100644
--- a/lib/gitlab/metrics/concern/metric_options.rb
+++ b/lib/gitlab/metrics/concern/metric_options.rb
@@ -6,34 +6,36 @@ module Gitlab
@multiprocess_mode = options[:multiprocess_mode] || :all
@buckets = options[:buckets] || ::Prometheus::Client::Histogram::DEFAULT_BUCKETS
@base_labels = options[:base_labels] || {}
+ @docstring = options[:docstring]
+ @with_feature = options[:with_feature]
end
- def docs(docs = nil)
- @docs = docs unless docs.nil?
+ def docstring(docstring = nil)
+ @docstring = docstring unless docstring.nil?
- @docs
+ @docstring
end
- def multiprocess_mode(mode)
- @multiprocess_mode = mode unless @multiprocess_mode.nil?
+ def multiprocess_mode(mode = nil)
+ @multiprocess_mode = mode unless mode.nil?
@multiprocess_mode
end
- def buckets(buckets)
- @buckets = buckets unless @buckets.nil?
+ def buckets(buckets = nil)
+ @buckets = buckets unless buckets.nil?
@buckets
end
- def base_labels(base_labels)
- @base_labels = base_labels unless @base_labels.nil?
+ def base_labels(base_labels = nil)
+ @base_labels = base_labels unless base_labels.nil?
@base_labels
end
- def with_feature(name)
- @feature_name = name unless @feature_name.nil?
+ def with_feature(name = nil)
+ @feature_name = name unless name.nil?
@feature_name
end
diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb
index 5cd5c388fb6..7cb153237d4 100644
--- a/lib/gitlab/metrics/method_call.rb
+++ b/lib/gitlab/metrics/method_call.rb
@@ -8,10 +8,11 @@ module Gitlab
BASE_LABELS = { module: nil, method: nil }.freeze
attr_reader :real_time, :cpu_time, :call_count, :labels
- histogram :gitlab_method_call_duration_seconds, 'Method calls real duration',
- base_labels: Transaction::BASE_LABELS.merge(BASE_LABELS),
- buckets: [0.01, 0.05, 0.1, 0.5, 1],
- with_feature: :prometheus_metrics_method_instrumentation
+ define_histogram :gitlab_method_call_duration_seconds,
+ docstring: 'Method calls real duration',
+ base_labels: Transaction::BASE_LABELS.merge(BASE_LABELS),
+ 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
# `User#sign_in`.
diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb
index 8d979a1ef72..41acfb5e819 100644
--- a/lib/gitlab/metrics/transaction.rb
+++ b/lib/gitlab/metrics/transaction.rb
@@ -2,11 +2,12 @@ module Gitlab
module Metrics
# Class for storing metrics information of a single transaction.
class Transaction
+ include Gitlab::Metrics::Concern
+
# base labels shared among all transactions
BASE_LABELS = { controller: nil, action: nil }.freeze
THREAD_KEY = :_gitlab_metrics_transaction
- METRICS_MUTEX = Mutex.new
# The series to store events (e.g. Git pushes) in.
EVENT_SERIES = 'events'.freeze
@@ -136,27 +137,25 @@ module Gitlab
"#{labels[:controller]}##{labels[:action]}" if labels && !labels.empty?
end
- histogram :gitlab_transaction_duration_seconds, 'Transaction duration',
- base_labels: BASE_LABELS,
- buckets: [0.001, 0.01, 0.1, 0.5, 10.0],
- with_feature: :prometheus_metrics_method_instrumentation
+ define_histogram :gitlab_transaction_duration_seconds,
+ docstring: 'Transaction duration',
+ base_labels: BASE_LABELS,
+ buckets: [0.001, 0.01, 0.1, 0.5, 10.0],
+ with_feature: :prometheus_metrics_method_instrumentation
- histogram :gitlab_transaction_allocated_memory_bytes, 'Transaction allocated memory bytes',
- base_labels: BASE_LABELS,
- buckets: [100, 1000, 10000, 100000, 1000000, 10000000]
+ define_histogram :gitlab_transaction_allocated_memory_bytes,
+ docstring: 'Transaction allocated memory bytes',
+ base_labels: BASE_LABELS,
+ buckets: [100, 1000, 10000, 100000, 1000000, 10000000]
def self.transaction_metric(name, type, prefix: nil, tags: {})
- return @transaction_metric[name] if @transaction_metric[name]&.has_key?(name)
-
- METRICS_MUTEX.synchronize do
- @transaction_metric ||= {}
- @transaction_metric[name] ||= if type == :counter
- Gitlab::Metrics.counter("gitlab_transaction_#{prefix}#{name}_total".to_sym,
- "Transaction #{prefix}#{name} counter", tags.merge(BASE_LABELS))
- else
- Gitlab::Metrics.gauge("gitlab_transaction_#{name}".to_sym,
- "Transaction gauge #{name} ", tags.merge(BASE_LABELS), :livesum)
- end
+ metric_name = "gitlab_transaction_#{prefix}#{name}_total".to_sym
+ fetch_metric(type, metric_name) do
+ docstring "Transaction #{prefix}#{name} #{type}"
+ base_labels tags.merge(BASE_LABELS)
+ if type == :gauge
+ multiprocess_mode :livesum
+ end
end
end
end