Commit 5a085dc1 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Add missing mutex guard to method call metrics

parent 765ddaeb
...@@ -2,25 +2,34 @@ module Gitlab ...@@ -2,25 +2,34 @@ module Gitlab
module Metrics module Metrics
# Class for tracking timing information about method calls # Class for tracking timing information about method calls
class MethodCall class MethodCall
MUTEX = Mutex.new
BASE_LABELS = { module: nil, method: nil }.freeze BASE_LABELS = { module: nil, method: nil }.freeze
attr_reader :real_time, :cpu_time, :call_count, :labels attr_reader :real_time, :cpu_time, :call_count, :labels
def self.call_real_duration_histogram def self.call_real_duration_histogram
@call_real_duration_histogram ||= Gitlab::Metrics.histogram( return @call_real_duration_histogram if @call_real_duration_histogram
:gitlab_method_call_real_duration_seconds,
'Method calls real duration', MUTEX.synchronize do
Transaction::BASE_LABELS.merge(BASE_LABELS), @call_real_duration_histogram ||= Gitlab::Metrics.histogram(
[0.1, 0.2, 0.5, 1, 2, 5, 10] :gitlab_method_call_real_duration_seconds,
) 'Method calls real duration',
Transaction::BASE_LABELS.merge(BASE_LABELS),
[0.1, 0.2, 0.5, 1, 2, 5, 10]
)
end
end end
def self.call_cpu_duration_histogram def self.call_cpu_duration_histogram
@call_duration_histogram ||= Gitlab::Metrics.histogram( return @call_cpu_duration_histogram if @call_cpu_duration_histogram
:gitlab_method_call_cpu_duration_seconds,
'Method calls cpu duration', MUTEX.synchronize do
Transaction::BASE_LABELS.merge(BASE_LABELS), @call_duration_histogram ||= Gitlab::Metrics.histogram(
[0.1, 0.2, 0.5, 1, 2, 5, 10] :gitlab_method_call_cpu_duration_seconds,
) 'Method calls cpu duration',
Transaction::BASE_LABELS.merge(BASE_LABELS),
[0.1, 0.2, 0.5, 1, 2, 5, 10]
)
end
end end
# name - The full name of the method (including namespace) such as # name - The full name of the method (including namespace) such as
......
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