BigW Consortium Gitlab

Commit da19ce62 by Pawel Chojnacki

Expire feature flag cache after 1minute

parent fd0a5168
......@@ -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
......
......@@ -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' }
end
method_call.measure { 'foo' }
Timecop.travel(Time.now + 30.seconds) do
Timecop.travel(1.minute.from_now) 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
......
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