diff options
-rw-r--r-- | app/workers/check_gcp_project_billing_worker.rb | 11 | ||||
-rw-r--r-- | spec/workers/check_gcp_project_billing_worker_spec.rb | 12 |
2 files changed, 9 insertions, 14 deletions
diff --git a/app/workers/check_gcp_project_billing_worker.rb b/app/workers/check_gcp_project_billing_worker.rb index c12211e13ea..c3a7929bd14 100644 --- a/app/workers/check_gcp_project_billing_worker.rb +++ b/app/workers/check_gcp_project_billing_worker.rb @@ -54,8 +54,11 @@ class CheckGcpProjectBillingWorker "gitlab:gcp:session:#{token_key}" end - def self.redis_billing_change_key - "gitlab:gcp:billing_enabled_changes" + def billing_changed_counter + @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 def try_obtain_lease_for(token) @@ -73,8 +76,6 @@ class CheckGcpProjectBillingWorker def update_billing_change_counter(previous_state, current_state) return unless previous_state == 'false' && current_state - Gitlab::Redis::SharedState.with do |redis| - redis.incr(self.class.redis_billing_change_key) - end + billing_changed_counter.increment end end diff --git a/spec/workers/check_gcp_project_billing_worker_spec.rb b/spec/workers/check_gcp_project_billing_worker_spec.rb index 5f473d05e60..132f9751f92 100644 --- a/spec/workers/check_gcp_project_billing_worker_spec.rb +++ b/spec/workers/check_gcp_project_billing_worker_spec.rb @@ -87,9 +87,7 @@ describe CheckGcpProjectBillingWorker do end it 'does not increment the billing change counter' do - Gitlab::Redis::SharedState.with do |redis| - expect(redis).not_to receive(:incr) - end + expect_any_instance_of(described_class).not_to receive(:billing_changed_counter) subject end @@ -101,9 +99,7 @@ describe CheckGcpProjectBillingWorker do end it 'increments the billing change counter' do - Gitlab::Redis::SharedState.with do |redis| - expect(redis).to receive(:incr) - end + expect_any_instance_of(described_class).to receive_message_chain(:billing_changed_counter, :increment) subject end @@ -117,9 +113,7 @@ describe CheckGcpProjectBillingWorker do end it 'does not increment the billing change counter' do - Gitlab::Redis::SharedState.with do |redis| - expect(redis).not_to receive(:incr) - end + expect_any_instance_of(described_class).not_to receive(:billing_changed_counter) subject end |