diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb index 65d55576ac2f620f70d211241f6c80d77837ffac..ab7e7a06a77417bf22935a1606012478055b9eb2 100644 --- a/lib/gitlab/metrics/method_call.rb +++ b/lib/gitlab/metrics/method_call.rb @@ -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 diff --git a/spec/lib/gitlab/metrics/method_call_spec.rb b/spec/lib/gitlab/metrics/method_call_spec.rb index 5341addf91104c732f4680834b840ca6b5ec65d9..df4c5167497fdd29317ee7af80c075d0a3982314 100644 --- a/spec/lib/gitlab/metrics/method_call_spec.rb +++ b/spec/lib/gitlab/metrics/method_call_spec.rb @@ -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)