diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-23 15:28:37 +0100 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-11-23 23:33:01 +0100 |
commit | 0051b5fbcc3154dacf20b1e89387b9ea55827266 (patch) | |
tree | 7f27a93b1aeb9783b34ff53d00942bf08da35aca | |
parent | efe4cab92b1c93b2beb75fc6b4c0dbe0787d301e (diff) | |
download | gitlab-ce-0051b5fbcc3154dacf20b1e89387b9ea55827266.tar.gz |
Use only real duration to measure method call performance via Prometheus
-rw-r--r-- | db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/metrics/method_call.rb | 27 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/method_call_spec.rb | 22 |
3 files changed, 15 insertions, 35 deletions
diff --git a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb index 9a07d1b281c..c25646ead9d 100644 --- a/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb +++ b/db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb @@ -13,4 +13,3 @@ class AddPrometheusInstrumentationToApplicationSettings < ActiveRecord::Migratio remove_column(:application_settings, :prometheus_metrics_method_instrumentation_enabled) end end - diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 03bdb5885a8..518aefa19ee 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -6,29 +6,15 @@ module Gitlab BASE_LABELS = { module: nil, method: nil }.freeze attr_reader :real_time, :cpu_time, :call_count, :labels - def self.call_real_duration_histogram - 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 - return @call_cpu_duration_histogram if @call_cpu_duration_histogram + def self.call_duration_histogram + return @call_duration_histogram if @call_duration_histogram MUTEX.synchronize do @call_duration_histogram ||= Gitlab::Metrics.histogram( - :gitlab_method_call_cpu_duration_seconds, - 'Method calls cpu duration', + :gitlab_method_call_duration_seconds, + 'Method calls real duration', Transaction::BASE_LABELS.merge(BASE_LABELS), - [0.1, 0.2, 0.5, 1, 2, 5, 10] - ) + [0.01, 0.05, 0.1, 0.5, 1]) end end @@ -60,8 +46,7 @@ module Gitlab @call_count += 1 if prometheus_enabled? && above_threshold? - 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) + self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0) end retval diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index cffd061a54d..b20c9e227d6 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -25,11 +25,7 @@ describe Gitlab::Metrics::MethodCall do end it 'observes the performance of the supplied block' do - expect(described_class.call_real_duration_histogram) - .to receive(:observe) - .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) - - expect(described_class.call_cpu_duration_histogram) + expect(described_class.call_duration_histogram) .to receive(:observe) .with({ module: :Foo, method: '#bar' }, be_a_kind_of(Numeric)) @@ -44,10 +40,7 @@ describe Gitlab::Metrics::MethodCall do end it 'does not observe the performance' do - expect(described_class.call_real_duration_histogram) - .not_to receive(:observe) - - expect(described_class.call_cpu_duration_histogram) + expect(described_class.call_duration_histogram) .not_to receive(:observe) method_call.measure { 'foo' } @@ -64,10 +57,7 @@ describe Gitlab::Metrics::MethodCall do end it 'does not observe the performance' do - expect(described_class.call_real_duration_histogram) - .not_to receive(:observe) - - expect(described_class.call_cpu_duration_histogram) + expect(described_class.call_duration_histogram) .not_to receive(:observe) method_call.measure { 'foo' } @@ -92,7 +82,13 @@ describe Gitlab::Metrics::MethodCall do end describe '#above_threshold?' do + before do + allow(Gitlab::Metrics).to receive(:method_call_threshold).and_return(100) + end + it 'returns false when the total call time is not above the threshold' do + expect(method_call).to receive(:real_time).and_return(9) + expect(method_call.above_threshold?).to eq(false) end |