Commit e56b3d18 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Refactor transaction metrics

parent d97548da
...@@ -54,8 +54,8 @@ module Gitlab ...@@ -54,8 +54,8 @@ module Gitlab
@memory_after = System.memory_usage @memory_after = System.memory_usage
@finished_at = System.monotonic_time @finished_at = System.monotonic_time
self.class.metric_transaction_duration_seconds.observe(labels, duration) self.class.gitlab_transaction_duration_seconds.observe(labels, duration)
self.class.metric_transaction_allocated_memory_bytes.observe(labels, allocated_memory * 1024.0) self.class.gitlab_transaction_allocated_memory_bytes.observe(labels, allocated_memory * 1024.0)
Thread.current[THREAD_KEY] = nil Thread.current[THREAD_KEY] = nil
end end
...@@ -72,7 +72,7 @@ module Gitlab ...@@ -72,7 +72,7 @@ module Gitlab
# event_name - The name of the event (e.g. "git_push"). # event_name - The name of the event (e.g. "git_push").
# tags - A set of tags to attach to the event. # tags - A set of tags to attach to the event.
def add_event(event_name, tags = {}) def add_event(event_name, tags = {})
self.class.metric_event_counter(event_name, tags).increment(tags.merge(labels)) self.class.transaction_metric(event_name, :counter, prefix: 'event_', tags: tags).increment(tags.merge(labels))
@metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags.merge(event: event_name), :event) @metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags.merge(event: event_name), :event)
end end
...@@ -86,12 +86,12 @@ module Gitlab ...@@ -86,12 +86,12 @@ module Gitlab
end end
def increment(name, value, use_prometheus = true) def increment(name, value, use_prometheus = true)
self.class.metric_transaction_counter(name).increment(labels, value) if use_prometheus self.class.transaction_metric(name, :counter).increment(labels, value) if use_prometheus
@values[name] += value @values[name] += value
end end
def set(name, value, use_prometheus = true) def set(name, value, use_prometheus = true)
self.class.metric_transaction_gauge(name).set(labels, value) if use_prometheus self.class.transaction_metric(name, :gauge).set(labels, value) if use_prometheus
@values[name] = value @values[name] = value
end end
...@@ -136,64 +136,27 @@ module Gitlab ...@@ -136,64 +136,27 @@ module Gitlab
"#{labels[:controller]}##{labels[:action]}" if labels && !labels.empty? "#{labels[:controller]}##{labels[:action]}" if labels && !labels.empty?
end end
def self.metric_transaction_duration_seconds histogram :gitlab_transaction_duration_seconds, 'Transaction duration',
return @metric_transaction_duration_seconds if @metric_transaction_duration_seconds base_labels: BASE_LABELS,
buckets: [0.001, 0.01, 0.1, 0.5, 10.0],
with_feature: :prometheus_metrics_method_instrumentation
METRICS_MUTEX.synchronize do histogram :gitlab_transaction_allocated_memory_bytes, 'Transaction allocated memory bytes',
@metric_transaction_duration_seconds ||= Gitlab::Metrics.histogram( base_labels: BASE_LABELS,
:gitlab_transaction_duration_seconds, buckets: [100, 1000, 10000, 100000, 1000000, 10000000]
'Transaction duration',
BASE_LABELS,
[0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0]
)
end
end
def self.metric_transaction_allocated_memory_bytes def self.transaction_metric(name, type, prefix: nil, tags: {})
return @metric_transaction_allocated_memory_bytes if @metric_transaction_allocated_memory_bytes return @transaction_metric[name] if @transaction_metric[name]&.has_key?(name)
METRICS_MUTEX.synchronize do METRICS_MUTEX.synchronize do
@metric_transaction_allocated_memory_bytes ||= Gitlab::Metrics.histogram( @transaction_metric ||= {}
:gitlab_transaction_allocated_memory_bytes, @transaction_metric[name] ||= if type == :counter
'Transaction allocated memory bytes', Gitlab::Metrics.counter("gitlab_transaction_#{prefix}#{name}_total".to_sym,
BASE_LABELS, "Transaction #{prefix}#{name} counter", tags.merge(BASE_LABELS))
[1000, 10000, 20000, 500000, 1000000, 2000000, 5000000, 10000000, 20000000, 100000000] else
) Gitlab::Metrics.gauge("gitlab_transaction_#{name}".to_sym,
end "Transaction gauge #{name} ", tags.merge(BASE_LABELS), :livesum)
end
def self.metric_event_counter(event_name, tags)
return @metric_event_counters[event_name] if @metric_event_counters&.has_key?(event_name)
METRICS_MUTEX.synchronize do
@metric_event_counters ||= {}
@metric_event_counters[event_name] ||= Gitlab::Metrics.counter(
"gitlab_transaction_event_#{event_name}_total".to_sym,
"Transaction event #{event_name} counter",
tags.merge(BASE_LABELS)
)
end
end end
def self.metric_transaction_counter(name)
return @metric_transaction_counters[name] if @metric_transaction_counters&.has_key?(name)
METRICS_MUTEX.synchronize do
@metric_transaction_counters ||= {}
@metric_transaction_counters[name] ||= Gitlab::Metrics.counter(
"gitlab_transaction_#{name}_total".to_sym, "Transaction #{name} counter", BASE_LABELS
)
end
end
def self.metric_transaction_gauge(name)
return @metric_transaction_gauges[name] if @metric_transaction_gauges&.has_key?(name)
METRICS_MUTEX.synchronize do
@metric_transaction_gauges ||= {}
@metric_transaction_gauges[name] ||= Gitlab::Metrics.gauge(
"gitlab_transaction_#{name}".to_sym, "Transaction gauge #{name}", BASE_LABELS, :livesum
)
end 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