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

Count all billing_state transitions with labels

parent 55535245
......@@ -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
......@@ -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
......
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