Commit 815b8db1 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Split call name to module and method name

parent cc7997d8
...@@ -102,8 +102,17 @@ module Gitlab ...@@ -102,8 +102,17 @@ module Gitlab
real_time = (real_stop - real_start) * 1000.0 real_time = (real_stop - real_start) * 1000.0
cpu_time = cpu_stop - cpu_start 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}_real_duration_seconds".to_sym,
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) "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}_real_time", real_time, false)
trans.increment("#{name}_cpu_time", cpu_time, false) trans.increment("#{name}_cpu_time", cpu_time, false)
......
...@@ -153,7 +153,8 @@ module Gitlab ...@@ -153,7 +153,8 @@ module Gitlab
proxy_module.class_eval <<-EOF, __FILE__, __LINE__ + 1 proxy_module.class_eval <<-EOF, __FILE__, __LINE__ + 1
def #{name}(#{args_signature}) def #{name}(#{args_signature})
if trans = Gitlab::Metrics::Instrumentation.transaction 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 else
super super
end end
......
...@@ -2,13 +2,14 @@ module Gitlab ...@@ -2,13 +2,14 @@ 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
BASE_LABELS = { module: nil, method: nil }
attr_reader :real_time, :cpu_time, :call_count attr_reader :real_time, :cpu_time, :call_count
def self.call_real_duration_histogram def self.call_real_duration_histogram
@call_real_duration_histogram ||= Gitlab::Metrics.histogram( @call_real_duration_histogram ||= Gitlab::Metrics.histogram(
:gitlab_method_call_real_duration_seconds, :gitlab_method_call_real_duration_seconds,
'Method calls real duration', '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] [0.1, 0.2, 0.5, 1, 2, 5, 10]
) )
end end
...@@ -17,7 +18,7 @@ module Gitlab ...@@ -17,7 +18,7 @@ module Gitlab
@call_duration_histogram ||= Gitlab::Metrics.histogram( @call_duration_histogram ||= Gitlab::Metrics.histogram(
:gitlab_method_call_cpu_duration_seconds, :gitlab_method_call_cpu_duration_seconds,
'Method calls cpu duration', '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] [0.1, 0.2, 0.5, 1, 2, 5, 10]
) )
end end
...@@ -25,7 +26,9 @@ module Gitlab ...@@ -25,7 +26,9 @@ module Gitlab
# name - The full name of the method (including namespace) such as # name - The full name of the method (including namespace) such as
# `User#sign_in`. # `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 @transaction = transaction
@name = name @name = name
@real_time = 0 @real_time = 0
...@@ -44,13 +47,17 @@ module Gitlab ...@@ -44,13 +47,17 @@ module Gitlab
@call_count += 1 @call_count += 1
if above_threshold? if above_threshold?
self.class.call_real_duration_histogram.observe(@transaction.labels.merge({ call_name: @name }), @real_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({ call_name: @name }), @cpu_time / 1000.0) self.class.call_cpu_duration_histogram.observe(@transaction.labels.merge(labels), @cpu_time / 1000.0)
end end
retval retval
end end
def labels
@labels ||= { module: @module_name, method: @method_name }
end
# Returns a Metric instance of the current method call. # Returns a Metric instance of the current method call.
def to_metric def to_metric
Metric.new( Metric.new(
......
...@@ -105,9 +105,9 @@ module Gitlab ...@@ -105,9 +105,9 @@ module Gitlab
end end
# Returns a MethodCall object for the given name. # 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] unless method = @methods[name]
@methods[name] = method = MethodCall.new(name, transaction) @methods[name] = method = MethodCall.new(name, module_name, method_name, self)
end end
method method
......
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