summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2015-12-15 16:38:25 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2015-12-17 17:25:48 +0100
commita41287d8989d7d49b405fd8f658d6c6e4edfd307 (patch)
tree283b85ee5892e999e029afdf035c7713e2dcdc0d
parent13dbd663acbbe91ddac77b650a90377cd12c54b8 (diff)
downloadgitlab-ce-a41287d8989d7d49b405fd8f658d6c6e4edfd307.tar.gz
Only track method calls above a certain threshold
This ensures we don't end up wasting resources by tracking method calls that only take a few microseconds. By default the threshold is 10 milliseconds but this can be changed using the gitlab.yml configuration file.
-rw-r--r--config/gitlab.yml.example3
-rw-r--r--lib/gitlab/metrics.rb4
-rw-r--r--lib/gitlab/metrics/instrumentation.rb8
-rw-r--r--spec/lib/gitlab/metrics/instrumentation_spec.rb24
4 files changed, 36 insertions, 3 deletions
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index 38b0920890f..24f3f6f02dc 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -432,6 +432,9 @@ production: &base
# pool_size: 16
# The timeout of a connection in seconds.
# timeout: 10
+ # The minimum amount of milliseconds a method call has to take before it's
+ # tracked. Defaults to 10.
+ # method_call_threshold: 10
development:
<<: *base
diff --git a/lib/gitlab/metrics.rb b/lib/gitlab/metrics.rb
index 007429fa194..4b92c3244fa 100644
--- a/lib/gitlab/metrics.rb
+++ b/lib/gitlab/metrics.rb
@@ -16,6 +16,10 @@ module Gitlab
!!Settings.metrics['enabled']
end
+ def self.method_call_threshold
+ Settings.metrics['method_call_threshold'] || 10
+ end
+
def self.pool
@pool
end
diff --git a/lib/gitlab/metrics/instrumentation.rb b/lib/gitlab/metrics/instrumentation.rb
index 91e09694cd8..ca2dffbc46a 100644
--- a/lib/gitlab/metrics/instrumentation.rb
+++ b/lib/gitlab/metrics/instrumentation.rb
@@ -99,9 +99,11 @@ module Gitlab
retval = __send__(#{alias_name.inspect}, *args, &block)
duration = (Time.now - start) * 1000.0
- trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
- { duration: duration },
- method: #{label.inspect})
+ if duration >= Gitlab::Metrics.method_call_threshold
+ trans.add_metric(Gitlab::Metrics::Instrumentation::SERIES,
+ { duration: duration },
+ method: #{label.inspect})
+ end
retval
else
diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb
index 5fe7a369cba..71d7209db0f 100644
--- a/spec/lib/gitlab/metrics/instrumentation_spec.rb
+++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb
@@ -42,6 +42,9 @@ describe Gitlab::Metrics::Instrumentation do
end
it 'tracks the call duration upon calling the method' do
+ allow(Gitlab::Metrics).to receive(:method_call_threshold).
+ and_return(0)
+
allow(described_class).to receive(:transaction).
and_return(transaction)
@@ -51,6 +54,15 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.foo
end
+
+ it 'does not track method calls below a given duration threshold' do
+ allow(Gitlab::Metrics).to receive(:method_call_threshold).
+ and_return(100)
+
+ expect(transaction).to_not receive(:add_metric)
+
+ @dummy.foo
+ end
end
describe 'with metrics disabled' do
@@ -84,6 +96,9 @@ describe Gitlab::Metrics::Instrumentation do
end
it 'tracks the call duration upon calling the method' do
+ allow(Gitlab::Metrics).to receive(:method_call_threshold).
+ and_return(0)
+
allow(described_class).to receive(:transaction).
and_return(transaction)
@@ -93,6 +108,15 @@ describe Gitlab::Metrics::Instrumentation do
@dummy.new.bar
end
+
+ it 'does not track method calls below a given duration threshold' do
+ allow(Gitlab::Metrics).to receive(:method_call_threshold).
+ and_return(100)
+
+ expect(transaction).to_not receive(:add_metric)
+
+ @dummy.new.bar
+ end
end
describe 'with metrics disabled' do