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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
dc9ee8e2
Commit
dc9ee8e2
authored
Mar 10, 2021
by
Alper Akgun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Harden Prometheus client wrapper
parent
77a98f10
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
changelogs/unreleased/aa-harden-with-prometheus-callback.yml
changelogs/unreleased/aa-harden-with-prometheus-callback.yml
+5
-0
lib/gitlab/utils/usage_data.rb
lib/gitlab/utils/usage_data.rb
+3
-1
spec/lib/gitlab/utils/usage_data_spec.rb
spec/lib/gitlab/utils/usage_data_spec.rb
+9
-2
No files found.
changelogs/unreleased/aa-harden-with-prometheus-callback.yml
0 → 100644
View file @
dc9ee8e2
---
title
:
Harden Prometheus client usage data wrapper
merge_request
:
56210
author
:
type
:
other
lib/gitlab/utils/usage_data.rb
View file @
dc9ee8e2
...
...
@@ -113,11 +113,13 @@ module Gitlab
end
end
def
with_prometheus_client
(
fallback:
nil
,
verify:
true
)
def
with_prometheus_client
(
fallback:
{}
,
verify:
true
)
client
=
prometheus_client
(
verify:
verify
)
return
fallback
unless
client
yield
client
rescue
fallback
end
def
measure_duration
...
...
spec/lib/gitlab/utils/usage_data_spec.rb
View file @
dc9ee8e2
...
...
@@ -246,6 +246,13 @@ RSpec.describe Gitlab::Utils::UsageData do
end
describe
'#with_prometheus_client'
do
it
'returns fallback with for an exception in yield block'
do
allow
(
described_class
).
to
receive
(
:prometheus_client
).
and_return
(
Gitlab
::
PrometheusClient
.
new
(
'http://localhost:9090'
))
result
=
described_class
.
with_prometheus_client
(
fallback:
-
42
)
{
|
client
|
raise
StandardError
}
expect
(
result
).
to
be
(
-
42
)
end
shared_examples
'query data from Prometheus'
do
it
'yields a client instance and returns the block result'
do
result
=
described_class
.
with_prometheus_client
{
|
client
|
client
}
...
...
@@ -255,10 +262,10 @@ RSpec.describe Gitlab::Utils::UsageData do
end
shared_examples
'does not query data from Prometheus'
do
it
'returns
nil
by default'
do
it
'returns
{}
by default'
do
result
=
described_class
.
with_prometheus_client
{
|
client
|
client
}
expect
(
result
).
to
be_nil
expect
(
result
).
to
eq
({})
end
it
'returns fallback if provided'
do
...
...
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