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
bafab35e
Commit
bafab35e
authored
Feb 07, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Prometheus counter instead of redis
parent
c00a17f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
14 deletions
+9
-14
app/workers/check_gcp_project_billing_worker.rb
app/workers/check_gcp_project_billing_worker.rb
+6
-5
spec/workers/check_gcp_project_billing_worker_spec.rb
spec/workers/check_gcp_project_billing_worker_spec.rb
+3
-9
No files found.
app/workers/check_gcp_project_billing_worker.rb
View file @
bafab35e
...
@@ -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
spec/workers/check_gcp_project_billing_worker_spec.rb
View file @
bafab35e
...
@@ -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
...
...
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