Commit bafab35e authored by Matija Čupić's avatar Matija Čupić

Use Prometheus counter instead of redis

parent c00a17f6
...@@ -54,8 +54,11 @@ class CheckGcpProjectBillingWorker ...@@ -54,8 +54,11 @@ class CheckGcpProjectBillingWorker
"gitlab:gcp:session:#{token_key}" "gitlab:gcp:session:#{token_key}"
end end
def self.redis_billing_change_key def billing_changed_counter
"gitlab:gcp:billing_enabled_changes" @billing_changed_counter ||= Gitlab::Metrics.counter(
:gcp_billing_change_count,
"Counts the number of times a GCP project changed billing_enabled state from false to true"
)
end end
def try_obtain_lease_for(token) def try_obtain_lease_for(token)
...@@ -73,8 +76,6 @@ class CheckGcpProjectBillingWorker ...@@ -73,8 +76,6 @@ class CheckGcpProjectBillingWorker
def update_billing_change_counter(previous_state, current_state) def update_billing_change_counter(previous_state, current_state)
return unless previous_state == 'false' && current_state return unless previous_state == 'false' && current_state
Gitlab::Redis::SharedState.with do |redis| billing_changed_counter.increment
redis.incr(self.class.redis_billing_change_key)
end
end end
end end
...@@ -87,9 +87,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -87,9 +87,7 @@ describe CheckGcpProjectBillingWorker do
end end
it 'does not increment the billing change counter' do it 'does not increment the billing change counter' do
Gitlab::Redis::SharedState.with do |redis| expect_any_instance_of(described_class).not_to receive(:billing_changed_counter)
expect(redis).not_to receive(:incr)
end
subject subject
end end
...@@ -101,9 +99,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -101,9 +99,7 @@ describe CheckGcpProjectBillingWorker do
end end
it 'increments the billing change counter' do it 'increments the billing change counter' do
Gitlab::Redis::SharedState.with do |redis| expect_any_instance_of(described_class).to receive_message_chain(:billing_changed_counter, :increment)
expect(redis).to receive(:incr)
end
subject subject
end end
...@@ -117,9 +113,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -117,9 +113,7 @@ describe CheckGcpProjectBillingWorker do
end end
it 'does not increment the billing change counter' do it 'does not increment the billing change counter' do
Gitlab::Redis::SharedState.with do |redis| expect_any_instance_of(described_class).not_to receive(:billing_changed_counter)
expect(redis).not_to receive(:incr)
end
subject subject
end 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