summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-12-13 18:46:40 +0000
committerRobert Speicher <robert@gitlab.com>2017-12-13 18:46:40 +0000
commit83998c0a33c70c786f48eef5ce723eb6dd76761f (patch)
tree916201803f9e34b0a4803622548eee8d6484f882 /spec/lib
parent4fe92b1de16469e0f8534d7c85d3e8b5c868b558 (diff)
parentdb9e5bf75e8546649ddd65a5696ff4edb87ded20 (diff)
downloadgitlab-ce-83998c0a33c70c786f48eef5ce723eb6dd76761f.tar.gz
Merge branch 'pawel/cache_feature_check_for_5_minutes_for_method_call' into 'master'
Cache feature check for 1 minute for MethodCall instrumentation toggle See merge request gitlab-org/gitlab-ce!15800
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/metrics/method_call_spec.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb
index 5341addf911..78767d06462 100644
--- a/spec/lib/gitlab/metrics/method_call_spec.rb
+++ b/spec/lib/gitlab/metrics/method_call_spec.rb
@@ -20,9 +20,39 @@ describe Gitlab::Metrics::MethodCall do
context 'prometheus instrumentation is enabled' do
before do
+ allow(Feature.get(:prometheus_metrics_method_instrumentation)).to receive(:enabled?).and_call_original
+ described_class.measurement_enabled_cache_expires_at.value = Time.now.to_i - 1
Feature.get(:prometheus_metrics_method_instrumentation).enable
end
+ around do |example|
+ Timecop.freeze do
+ example.run
+ end
+ end
+
+ it 'caches subsequent invocations of feature check' do
+ 10.times do
+ method_call.measure { 'foo' }
+ end
+
+ expect(Feature.get(:prometheus_metrics_method_instrumentation)).to have_received(:enabled?).once
+ end
+
+ it 'expires feature check cache after 1 minute' do
+ method_call.measure { 'foo' }
+
+ Timecop.travel(1.minute.from_now) do
+ method_call.measure { 'foo' }
+ end
+
+ Timecop.travel(1.minute.from_now + 1.second) do
+ method_call.measure { 'foo' }
+ end
+
+ expect(Feature.get(:prometheus_metrics_method_instrumentation)).to have_received(:enabled?).twice
+ end
+
it 'observes the performance of the supplied block' do
expect(described_class.call_duration_histogram)
.to receive(:observe)
@@ -34,6 +64,8 @@ describe Gitlab::Metrics::MethodCall do
context 'prometheus instrumentation is disabled' do
before do
+ described_class.measurement_enabled_cache_expires_at.value = Time.now.to_i - 1
+
Feature.get(:prometheus_metrics_method_instrumentation).disable
end