Expire feature flag cache after 1minute

This commit is contained in:
Pawel Chojnacki 2017-12-12 18:52:08 +01:00
parent fd0a516854
commit da19ce625b
2 changed files with 5 additions and 7 deletions

View File

@ -80,7 +80,7 @@ module Gitlab
def call_measurement_enabled?
expires_at = @@measurement_enabled_cache_expires_at.value
if expires_at < Time.now.to_i
if @@measurement_enabled_cache_expires_at.compare_and_set(expires_at, (Time.now + 30.seconds).to_i)
if @@measurement_enabled_cache_expires_at.compare_and_set(expires_at, 1.minute.from_now.to_i)
@@measurement_enabled_cache.value = Feature.get(:prometheus_metrics_method_instrumentation).enabled?
end
end

View File

@ -40,15 +40,13 @@ describe Gitlab::Metrics::MethodCall do
end
it 'expires feature check cache after 30 seconds' do
10.times do
method_call.measure { 'foo' }
Timecop.travel(1.minute.from_now) do
method_call.measure { 'foo' }
end
Timecop.travel(Time.now + 30.seconds) do
method_call.measure { 'foo' }
end
Timecop.travel(Time.now + 31.seconds) do
Timecop.travel(1.minute.from_now + 1.second) do
method_call.measure { 'foo' }
end