Commit 53dc9e83 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Cache feature check for 5 minutes for MethodCall instrumentation toggle

parent ad1c186e
......@@ -72,7 +72,9 @@ module Gitlab
end
def call_measurement_enabled?
Feature.get(:prometheus_metrics_method_instrumentation).enabled?
Rails.cache.fetch(:prometheus_metrics_method_instrumentation_enabled, expires_in: 5.minutes) do
Feature.get(:prometheus_metrics_method_instrumentation).enabled?
end
end
end
end
......
......@@ -23,6 +23,17 @@ describe Gitlab::Metrics::MethodCall do
Feature.get(:prometheus_metrics_method_instrumentation).enable
end
it 'feature check is cached for 5 minutes' do
allow(Feature.get(:prometheus_metrics_method_instrumentation)).to receive(:enabled?).and_call_original
allow(Rails.cache).to receive(:fetch).and_call_original
method_call.measure { 'foo' }
method_call.measure { 'foo' }
expect(Feature.get(:prometheus_metrics_method_instrumentation)).to have_received(:enabled?).twice
expect(Rails.cache).to have_received(:fetch).with(:prometheus_metrics_method_instrumentation_enabled, expires_in: 5.minutes).twice
end
it 'observes the performance of the supplied block' do
expect(described_class.call_duration_histogram)
.to receive(:observe)
......
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