提交 815b8db1 编写于 作者: P Pawel Chojnacki

Split call name to module and method name

上级 cc7997d8
......@@ -102,8 +102,17 @@ module Gitlab
real_time = (real_stop - real_start) * 1000.0
cpu_time = cpu_stop - cpu_start
Gitlab::Metrics.histogram("gitlab_#{name}_real_duration_seconds".to_sym, "Measure #{name}", {}, [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2]).observe({}, real_time / 1000.0)
Gitlab::Metrics.histogram("gitlab_#{name}_cpu_duration_seconds".to_sym, "Measure #{name}", {}, [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2]).observe({}, cpu_time / 1000.0)
Gitlab::Metrics.histogram("gitlab_#{name}_real_duration_seconds".to_sym,
"Measure #{name}",
Transaction::BASE_LABELS,
[0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2])
.observe(trans.labels, real_time / 1000.0)
Gitlab::Metrics.histogram("gitlab_#{name}_cpu_duration_seconds".to_sym,
"Measure #{name}",
Transaction::BASE_LABELS,
[0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2])
.observe(trans.labels, cpu_time / 1000.0)
trans.increment("#{name}_real_time", real_time, false)
trans.increment("#{name}_cpu_time", cpu_time, false)
......
......@@ -153,7 +153,8 @@ module Gitlab
proxy_module.class_eval <<-EOF, __FILE__, __LINE__ + 1
def #{name}(#{args_signature})
if trans = Gitlab::Metrics::Instrumentation.transaction
trans.method_call_for(#{label.to_sym.inspect}).measure { super }
trans.method_call_for(#{label.to_sym.inspect}, #{mod.name.to_sym.inspect}, #{name.to_sym.inspect})
.measure { super }
else
super
end
......
......@@ -2,13 +2,14 @@ module Gitlab
module Metrics
# Class for tracking timing information about method calls
class MethodCall
BASE_LABELS = { module: nil, method: nil }
attr_reader :real_time, :cpu_time, :call_count
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({ call_name: nil }),
Transaction::BASE_LABELS.merge(BASE_LABELS),
[0.1, 0.2, 0.5, 1, 2, 5, 10]
)
end
......@@ -17,7 +18,7 @@ module Gitlab
@call_duration_histogram ||= Gitlab::Metrics.histogram(
:gitlab_method_call_cpu_duration_seconds,
'Method calls cpu duration',
Transaction::BASE_LABELS.merge({ call_name: nil }),
Transaction::BASE_LABELS.merge(BASE_LABELS),
[0.1, 0.2, 0.5, 1, 2, 5, 10]
)
end
......@@ -25,7 +26,9 @@ module Gitlab
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
def initialize(name, transaction)
def initialize(name, module_name, method_name, transaction)
@module_name = module_name
@method_name = method_name
@transaction = transaction
@name = name
@real_time = 0
......@@ -44,13 +47,17 @@ module Gitlab
@call_count += 1
if above_threshold?
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)
self.class.call_real_duration_histogram.observe(@transaction.labels.merge(labels), @real_time / 1000.0)
self.class.call_cpu_duration_histogram.observe(@transaction.labels.merge(labels), @cpu_time / 1000.0)
end
retval
end
def labels
@labels ||= { module: @module_name, method: @method_name }
end
# Returns a Metric instance of the current method call.
def to_metric
Metric.new(
......
......@@ -105,9 +105,9 @@ module Gitlab
end
# Returns a MethodCall object for the given name.
def method_call_for(name)
def method_call_for(name, module_name, method_name)
unless method = @methods[name]
@methods[name] = method = MethodCall.new(name, transaction)
@methods[name] = method = MethodCall.new(name, module_name, method_name, self)
end
method
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册