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
9210e9da
Commit
9210e9da
authored
Jul 20, 2021
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom fallback to GenericMetric
parent
c6282573
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
2 deletions
+60
-2
lib/gitlab/usage/metrics/instrumentations/generic_metric.rb
lib/gitlab/usage/metrics/instrumentations/generic_metric.rb
+12
-2
spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb
...lab/usage/metrics/instrumentations/generic_metric_spec.rb
+48
-0
No files found.
lib/gitlab/usage/metrics/instrumentations/generic_metric.rb
View file @
9210e9da
...
...
@@ -12,19 +12,25 @@ module Gitlab
# Gitlab::CurrentSettings.uuid
# end
# end
FALLBACK
=
-
1
class
<<
self
attr_reader
:metric_operation
@metric_operation
=
:alt
def
fallback
(
custom_fallback
)
@metric_fallback
=
custom_fallback
end
def
value
(
&
block
)
@metric_value
=
block
end
attr_reader
:metric_value
attr_reader
:metric_value
,
:metric_fallback
end
def
value
alt_usage_data
do
alt_usage_data
(
fallback:
fallback
)
do
self
.
class
.
metric_value
.
call
end
end
...
...
@@ -34,6 +40,10 @@ module Gitlab
self
.
class
.
metric_operation
)
end
def
fallback
self
.
class
.
metric_fallback
||
FALLBACK
end
end
end
end
...
...
spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb
0 → 100644
View file @
9210e9da
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
GenericMetric
do
context
'with custom fallback'
do
subject
do
Class
.
new
(
described_class
)
do
fallback
(
-
2
)
value
{
Gitlab
::
Database
.
version
}
end
.
new
(
time_frame:
'none'
)
end
describe
'#value'
do
it
'gives the correct value'
do
expect
(
subject
.
value
).
to
eq
(
Gitlab
::
Database
.
version
)
end
context
'when raising an exception'
do
it
'return the custom fallback'
do
expect
(
Gitlab
::
Database
).
to
receive
(
:version
).
and_raise
(
'Error'
)
expect
(
subject
.
value
).
to
eq
(
-
2
)
end
end
end
end
context
'with default fallback'
do
subject
do
Class
.
new
(
described_class
)
do
value
{
Gitlab
::
Database
.
version
}
end
.
new
(
time_frame:
'none'
)
end
describe
'#value'
do
it
'gives the correct value'
do
expect
(
subject
.
value
).
to
eq
(
Gitlab
::
Database
.
version
)
end
context
'when raising an exception'
do
it
'return the custom fallback'
do
expect
(
Gitlab
::
Database
).
to
receive
(
:version
).
and_raise
(
'Error'
)
expect
(
subject
.
value
).
to
eq
(
-
1
)
end
end
end
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