summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2018-02-12 18:32:10 +0100
committerMatija Čupić <matteeyah@gmail.com>2018-02-12 21:32:56 +0100
commitf95d9fdcc5f52e6371ca78b21538e87e9ba738f1 (patch)
tree0cbaf4d332e1ead0c29fab786269513a3041b3de
parent5553524516135f573b1264785ef04f0fe638d5c2 (diff)
downloadgitlab-ce-41722-track-gcp-billing-enabled-project-changes.tar.gz
Count all billing_state transitions with labels41722-track-gcp-billing-enabled-project-changes
-rw-r--r--app/workers/check_gcp_project_billing_worker.rb27
-rw-r--r--spec/workers/check_gcp_project_billing_worker_spec.rb8
2 files changed, 16 insertions, 19 deletions
diff --git a/app/workers/check_gcp_project_billing_worker.rb b/app/workers/check_gcp_project_billing_worker.rb
index 624d515c6bc..363f81590ab 100644
--- a/app/workers/check_gcp_project_billing_worker.rb
+++ b/app/workers/check_gcp_project_billing_worker.rb
@@ -7,6 +7,7 @@ class CheckGcpProjectBillingWorker
LEASE_TIMEOUT = 3.seconds.to_i
SESSION_KEY_TIMEOUT = 5.minutes
BILLING_TIMEOUT = 1.hour
+ BILLING_CHANGED_LABELS = { state_transition: nil }.freeze
def self.get_session_token(token_key)
Gitlab::Redis::SharedState.with do |redis|
@@ -70,26 +71,22 @@ class CheckGcpProjectBillingWorker
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"
+ "Counts the number of times a GCP project changed billing_enabled state from false to true",
+ BILLING_CHANGED_LABELS
)
end
- def log_transition(previous_state, current_state)
- state_message = if previous_state.nil? && !current_state
- "no_billing"
- elsif previous_state.nil? && current_state
- "with_billing"
- elsif !previous_state && current_state
- "billing_configured"
- end
-
- Rails.logger.info "#{self.class}: state: #{state_message}"
+ def state_transition(previous_state, current_state)
+ if previous_state.nil? && !current_state
+ 'no_billing'
+ elsif previous_state.nil? && current_state
+ 'with_billing'
+ elsif !previous_state && current_state
+ 'billing_configured'
+ end
end
def update_billing_change_counter(previous_state, current_state)
- log_transition(previous_state, current_state)
- return unless !previous_state && current_state
-
- billing_changed_counter.increment
+ billing_changed_counter.increment(state_transition: state_transition(previous_state, current_state))
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 179f26475e1..526ecf75921 100644
--- a/spec/workers/check_gcp_project_billing_worker_spec.rb
+++ b/spec/workers/check_gcp_project_billing_worker_spec.rb
@@ -80,8 +80,8 @@ describe CheckGcpProjectBillingWorker do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([])
end
- it 'does not increment the billing change counter' do
- expect_any_instance_of(described_class).not_to receive(:billing_changed_counter)
+ it 'increments the billing change counter' do
+ expect_any_instance_of(described_class).to receive_message_chain(:billing_changed_counter, :increment)
subject
end
@@ -106,8 +106,8 @@ describe CheckGcpProjectBillingWorker do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
end
- it 'does not increment the billing change counter' do
- expect_any_instance_of(described_class).not_to receive(:billing_changed_counter)
+ it 'increment the billing change counter' do
+ expect_any_instance_of(described_class).to receive_message_chain(:billing_changed_counter, :increment)
subject
end