summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-12-19 17:45:25 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2017-12-19 17:45:25 +0100
commit3c545133e8f23b57698046bae8be23e2bc457aca (patch)
tree1ace4efa3f3c55ffb121d8dcdcf59ab8dcc84048
parenta8ebed6016726722a2283458e4176fc9177558af (diff)
downloadgitlab-ce-3c545133e8f23b57698046bae8be23e2bc457aca.tar.gz
Fix tests and formatting
-rw-r--r--lib/gitlab/metrics/influx_db.rb1
-rw-r--r--lib/gitlab/metrics/method_call.rb2
-rw-r--r--lib/gitlab/metrics/system.rb1
-rw-r--r--spec/lib/gitlab/metrics/method_call_spec.rb11
4 files changed, 8 insertions, 7 deletions
diff --git a/lib/gitlab/metrics/influx_db.rb b/lib/gitlab/metrics/influx_db.rb
index bdf7910b7c7..153e236d018 100644
--- a/lib/gitlab/metrics/influx_db.rb
+++ b/lib/gitlab/metrics/influx_db.rb
@@ -38,6 +38,7 @@ module Gitlab
# This is memoized since this method is called for every instrumented
# method. Loading data from an external cache on every method call slows
# things down too much.
+ # in milliseconds
@method_call_threshold ||= settings[:method_call_threshold]
end
diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb
index 6fb8f564237..a030092df37 100644
--- a/lib/gitlab/metrics/method_call.rb
+++ b/lib/gitlab/metrics/method_call.rb
@@ -72,7 +72,7 @@ module Gitlab
# Returns true if the total runtime of this method exceeds the method call
# threshold.
def above_threshold?
- real_time >= Metrics.method_call_threshold
+ real_time_milliseconds >= Metrics.method_call_threshold
end
def call_measurement_enabled?
diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb
index b31cc6236d1..4852017bf38 100644
--- a/lib/gitlab/metrics/system.rb
+++ b/lib/gitlab/metrics/system.rb
@@ -55,7 +55,6 @@ module Gitlab
#
# Returns the time as a Float.
def self.monotonic_time
-
Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
end
end
diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb
index 5341addf911..91a70ba01a0 100644
--- a/spec/lib/gitlab/metrics/method_call_spec.rb
+++ b/spec/lib/gitlab/metrics/method_call_spec.rb
@@ -8,7 +8,8 @@ describe Gitlab::Metrics::MethodCall do
it 'measures the performance of the supplied block' do
method_call.measure { 'foo' }
- expect(method_call.real_time).to be_a_kind_of(Numeric)
+ expect(method_call.real_time_seconds).to be_a_kind_of(Numeric)
+ expect(method_call.real_time_milliseconds).to be_a_kind_of(Numeric)
expect(method_call.cpu_time).to be_a_kind_of(Numeric)
expect(method_call.call_count).to eq(1)
end
@@ -84,13 +85,13 @@ describe Gitlab::Metrics::MethodCall do
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).to receive(:real_time_seconds).and_return(0.009)
expect(method_call.above_threshold?).to eq(false)
end
it 'returns true when the total call time is above the threshold' do
- expect(method_call).to receive(:real_time).and_return(9000)
+ expect(method_call).to receive(:real_time_seconds).and_return(9)
expect(method_call.above_threshold?).to eq(true)
end
@@ -131,7 +132,7 @@ describe Gitlab::Metrics::MethodCall do
describe '#real_time' do
context 'without timings' do
it 'returns 0.0' do
- expect(method_call.real_time).to eq(0.0)
+ expect(method_call.real_time_seconds).to eq(0.0)
end
end
@@ -139,7 +140,7 @@ describe Gitlab::Metrics::MethodCall do
it 'returns the total real time' do
method_call.measure { 'foo' }
- expect(method_call.real_time >= 0.0).to be(true)
+ expect(method_call.real_time_seconds >= 0.0).to be(true)
end
end
end