Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
f95d9fdc
Commit
f95d9fdc
authored
Feb 12, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Count all billing_state transitions with labels
parent
55535245
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
19 deletions
+16
-19
app/workers/check_gcp_project_billing_worker.rb
app/workers/check_gcp_project_billing_worker.rb
+12
-15
spec/workers/check_gcp_project_billing_worker_spec.rb
spec/workers/check_gcp_project_billing_worker_spec.rb
+4
-4
No files found.
app/workers/check_gcp_project_billing_worker.rb
View file @
f95d9fdc
...
...
@@ -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"
def
state
_transition
(
previous_state
,
current_state
)
if
previous_state
.
nil?
&&
!
current_state
'no_billing'
elsif
previous_state
.
nil?
&&
current_state
"with_billing"
'with_billing'
elsif
!
previous_state
&&
current_state
"billing_configured"
'billing_configured'
end
Rails
.
logger
.
info
"
#{
self
.
class
}
: state:
#{
state_message
}
"
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
spec/workers/check_gcp_project_billing_worker_spec.rb
View file @
f95d9fdc
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment