Commit 3cc28601 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Cleanup sampling code and fix bug with samplers running without sleep

parent b6d75b29
......@@ -43,7 +43,7 @@ module Gitlab
if thread
thread.wakeup if thread.alive?
thread.join
thread.join unless Thread.current == thread
@thread = nil
end
end
......
......@@ -10,7 +10,7 @@ module Gitlab
def self.call_real_duration_histogram
@call_real_duration_histogram ||= Gitlab::Metrics.histogram(:gitlab_method_call_real_duration_milliseconds,
'Method calls real duration',
{},
{call_name: nil},
[1, 2, 5, 10, 20, 50, 100, 1000])
end
......@@ -18,17 +18,16 @@ module Gitlab
def self.call_cpu_duration_histogram
@call_duration_histogram ||= Gitlab::Metrics.histogram(:gitlab_method_call_cpu_duration_milliseconds,
'Method calls cpu duration',
{},
{call_name: nil},
[1, 2, 5, 10, 20, 50, 100, 1000])
end
def initialize(name, tags = {})
def initialize(name)
@name = name
@real_time = 0
@cpu_time = 0
@call_count = 0
@tags = tags
end
# Measures the real and CPU execution time of the supplied block.
......@@ -42,25 +41,13 @@ module Gitlab
@call_count += 1
if above_threshold?
self.class.call_real_duration_histogram.observe(labels, @real_time)
self.class.call_cpu_duration_histogram.observe(labels, @cpu_time)
self.class.call_real_duration_histogram.observe({ call_name: @name }, @real_time)
self.class.call_cpu_duration_histogram.observe({ call_name: @name }, @cpu_time)
end
retval
end
def labels
@labels ||= @tags.merge(source_label).merge({ call_name: @name })
end
def source_label
if Sidekiq.server?
{ source: 'sidekiq' }
else
{ source: 'rails' }
end
end
# Returns a Metric instance of the current method call.
def to_metric
Metric.new(
......
require 'logger'
module Gitlab
module Metrics
module Samplers
......@@ -43,11 +44,14 @@ module Gitlab
private
attr_reader :running
def start_working
@running = true
sleep(sleep_interval)
while running
safe_sample
sleep(sleep_interval)
end
end
......
......@@ -32,7 +32,7 @@ module Gitlab
def init_metrics
metrics = {}
metrics[:sampler_duration] = Gitlab::Metrics.histogram(with_prefix(:sampler_duration, :seconds), 'Sampler time', source_label)
metrics[:sampler_duration] = Gitlab::Metrics.histogram(with_prefix(:sampler_duration, :seconds), 'Sampler time', {})
metrics[:total_time] = Gitlab::Metrics.gauge(with_prefix(:gc, :time_total), 'Total GC time', labels, :livesum)
GC.stat.keys.each do |key|
metrics[key] = Gitlab::Metrics.gauge(with_prefix(:gc, key), to_doc_string(key), labels, :livesum)
......
......@@ -43,18 +43,18 @@ module Gitlab
def self.metric_transaction_duration_milliseconds
@metrics_transaction_duration_milliseconds ||= Gitlab::Metrics.histogram(
:gitlab_transaction_duration_milliseconds,
'Method duration milliseconds',
'Transaction duration milliseconds',
{},
[1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]
[1, 2, 5, 10, 20, 50, 100, 500, 10000]
)
end
def self.metric_transaction_allocated_memory_bytes
@metric_transaction_allocated_memory_bytes ||= Gitlab::Metrics.histogram(
:gitlab_transaction_allocated_memory_bytes,
'Method duration milliseconds',
def self.metric_transaction_allocated_memory_megabytes
@metric_transaction_allocated_memory_megabytes ||= Gitlab::Metrics.histogram(
:gitlab_transaction_allocated_memory_megabytes,
'Transaction allocated memory bytes',
{},
[1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 5000000]
[1, 2, 5, 10, 20, 100]
)
end
......@@ -69,8 +69,8 @@ module Gitlab
@memory_after = System.memory_usage
@finished_at = System.monotonic_time
self.class.metric_transaction_duration_milliseconds.observe({}, duration)
self.class.metric_transaction_allocated_memory_bytes.observe({}, allocated_memory)
Transaction.metric_transaction_duration_milliseconds.observe({}, duration)
Transaction.metric_transaction_allocated_memory_megabytes.observe({}, allocated_memory)
Thread.current[THREAD_KEY] = nil
end
......
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