More parsable labels in method performance measurements

This commit is contained in:
Pawel Chojnacki 2017-09-06 13:35:47 +02:00
parent 43a9777e5e
commit cc7997d8d0
2 changed files with 7 additions and 7 deletions

View File

@ -8,7 +8,7 @@ module Gitlab
@call_real_duration_histogram ||= Gitlab::Metrics.histogram(
:gitlab_method_call_real_duration_seconds,
'Method calls real duration',
{ action: nil, call_name: nil },
Transaction::BASE_LABELS.merge({ call_name: nil }),
[0.1, 0.2, 0.5, 1, 2, 5, 10]
)
end
@ -17,7 +17,7 @@ module Gitlab
@call_duration_histogram ||= Gitlab::Metrics.histogram(
:gitlab_method_call_cpu_duration_seconds,
'Method calls cpu duration',
{ action: nil, call_name: nil },
Transaction::BASE_LABELS.merge({ call_name: nil }),
[0.1, 0.2, 0.5, 1, 2, 5, 10]
)
end
@ -25,8 +25,8 @@ module Gitlab
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
def initialize(name, action)
@action = action
def initialize(name, transaction)
@transaction = transaction
@name = name
@real_time = 0
@cpu_time = 0
@ -44,8 +44,8 @@ module Gitlab
@call_count += 1
if above_threshold?
self.class.call_real_duration_histogram.observe({ call_name: @name, action: @action }, @real_time / 1000.0)
self.class.call_cpu_duration_histogram.observe({ call_name: @name, action: @action }, @cpu_time / 1000.0)
self.class.call_real_duration_histogram.observe(@transaction.labels.merge({ call_name: @name }), @real_time / 1000.0)
self.class.call_cpu_duration_histogram.observe(@transaction.labels.merge({ call_name: @name }), @cpu_time / 1000.0)
end
retval

View File

@ -107,7 +107,7 @@ module Gitlab
# Returns a MethodCall object for the given name.
def method_call_for(name)
unless method = @methods[name]
@methods[name] = method = MethodCall.new(name, action)
@methods[name] = method = MethodCall.new(name, transaction)
end
method