diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-03 12:37:08 +0100 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-03 12:37:08 +0100 |
commit | 5a085dc12670e6ececa566fc16172da08bac0972 (patch) | |
tree | 78612b363578b3a9b0b91683f30a0f24c9d2840f /lib | |
parent | 765ddaeb856d1bbd893ea5b9c820a2b47556e652 (diff) | |
download | gitlab-ce-5a085dc12670e6ececa566fc16172da08bac0972.tar.gz |
Add missing mutex guard to method call metricspawel/metrics-to-prometheus-33643
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/metrics/method_call.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 1d9cef7a6e8..90235095306 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -2,25 +2,34 @@ module Gitlab module Metrics # Class for tracking timing information about method calls class MethodCall + MUTEX = Mutex.new BASE_LABELS = { module: nil, method: nil }.freeze attr_reader :real_time, :cpu_time, :call_count, :labels def self.call_real_duration_histogram - @call_real_duration_histogram ||= Gitlab::Metrics.histogram( - :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] - ) + return @call_real_duration_histogram if @call_real_duration_histogram + + MUTEX.synchronize do + @call_real_duration_histogram ||= Gitlab::Metrics.histogram( + :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 def self.call_cpu_duration_histogram - @call_duration_histogram ||= Gitlab::Metrics.histogram( - :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] - ) + return @call_cpu_duration_histogram if @call_cpu_duration_histogram + + MUTEX.synchronize do + @call_duration_histogram ||= Gitlab::Metrics.histogram( + :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 # name - The full name of the method (including namespace) such as |