BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
67fcd061
Commit
67fcd061
authored
Jan 18, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test if feature is respected
parent
afeb7ce9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
21 deletions
+54
-21
metric_options.rb
lib/gitlab/metrics/concern/metric_options.rb
+2
-2
concern_spec.rb
spec/lib/gitlab/metrics/concern_spec.rb
+52
-19
No files found.
lib/gitlab/metrics/concern/metric_options.rb
View file @
67fcd061
...
...
@@ -44,9 +44,9 @@ module Gitlab
# Use feature toggle to control whether certain metric is enabled/disabled
def
with_feature
(
name
=
nil
)
@
feature_nam
e
=
name
unless
name
.
nil?
@
with_featur
e
=
name
unless
name
.
nil?
@
feature_nam
e
@
with_featur
e
end
def
evaluate
(
&
block
)
...
...
spec/lib/gitlab/metrics/concern_spec.rb
View file @
67fcd061
...
...
@@ -5,47 +5,47 @@ describe Gitlab::Metrics::Concern do
shared_context
'metric'
do
|
metric_type
,
*
args
|
let
(
:docstring
)
{
'description'
}
let
(
:metric
)
{
:sample_metric
}
let
(
:metric
_name
)
{
:sample_metric
}
describe
"#define_
#{
metric_type
}
"
do
let
(
:define_method
)
{
"define_
#{
metric_type
}
"
.
to_sym
}
context
'metrics access method not defined'
do
it
"defines metrics accessing method"
do
expect
(
subject
).
not_to
respond_to
(
metric
)
expect
(
subject
).
not_to
respond_to
(
metric
_name
)
subject
.
send
(
define_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
define_method
,
metric
_name
,
docstring:
docstring
)
expect
(
subject
).
to
respond_to
(
metric
)
expect
(
subject
).
to
respond_to
(
metric
_name
)
end
end
context
'metrics access method defined'
do
before
do
subject
.
send
(
define_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
define_method
,
metric
_name
,
docstring:
docstring
)
end
it
'raises error when trying to redefine method'
do
expect
{
subject
.
send
(
define_method
,
metric
,
docstring:
docstring
)
}.
to
raise_error
(
ArgumentError
)
expect
{
subject
.
send
(
define_method
,
metric
_name
,
docstring:
docstring
)
}.
to
raise_error
(
ArgumentError
)
end
context
'metric is not cached'
do
it
'calls fetch_metric'
do
expect
(
subject
).
to
receive
(
:fetch_metric
).
with
(
metric_type
,
metric
,
docstring:
docstring
)
expect
(
subject
).
to
receive
(
:fetch_metric
).
with
(
metric_type
,
metric
_name
,
docstring:
docstring
)
subject
.
send
(
metric
)
subject
.
send
(
metric
_name
)
end
end
context
'metric is cached'
do
before
do
subject
.
send
(
metric
)
subject
.
send
(
metric
_name
)
end
it
'returns cached metric'
do
expect
(
subject
).
not_to
receive
(
:fetch_metric
)
subject
.
send
(
metric
)
subject
.
send
(
metric
_name
)
end
end
end
...
...
@@ -55,38 +55,71 @@ describe Gitlab::Metrics::Concern do
let
(
:fetch_method
)
{
"fetch_
#{
metric_type
}
"
.
to_sym
}
let
(
:null_metric
)
{
Gitlab
::
Metrics
::
NullMetric
.
new
}
context
"when
#{
metric_type
}
fetched first time
"
do
context
"when
#{
metric_type
}
is not cached
"
do
it
'initializes counter metric'
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric
,
docstring
,
*
args
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric
_name
,
docstring
,
*
args
)
end
end
context
"when
#{
metric_type
}
is
fetched second time
"
do
context
"when
#{
metric_type
}
is
cached
"
do
before
do
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
end
it
'uses class metric cache'
do
expect
(
Gitlab
::
Metrics
).
not_to
receive
(
metric_type
)
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
end
context
'when metric is reloaded'
do
before
do
subject
.
reload_metric!
(
metric
)
subject
.
reload_metric!
(
metric
_name
)
end
it
"initializes
#{
metric_type
}
metric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
subject
.
send
(
fetch_method
,
metric
,
docstring:
docstring
)
subject
.
send
(
fetch_method
,
metric
_name
,
docstring:
docstring
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric
,
docstring
,
*
args
)
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric_name
,
docstring
,
*
args
)
end
end
end
context
'when metric is configured with feature'
do
let
(
:feature_name
)
{
:some_metric_feature
}
let
(
:metric
)
{
subject
.
send
(
fetch_method
,
metric_name
,
docstring:
docstring
,
with_feature:
feature_name
)
}
context
'when feature is enabled'
do
before
do
Feature
.
get
(
feature_name
).
enable
end
it
"initializes
#{
metric_type
}
metric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
metric
expect
(
Gitlab
::
Metrics
).
to
have_received
(
metric_type
).
with
(
metric_name
,
docstring
,
*
args
)
end
end
context
'when feature is disabled'
do
before
do
Feature
.
get
(
feature_name
).
disable
end
it
"returns NullMetric"
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
metric_type
).
and_return
(
null_metric
)
expect
(
metric
).
to
be_instance_of
(
Gitlab
::
Metrics
::
NullMetric
)
expect
(
Gitlab
::
Metrics
).
not_to
have_received
(
metric_type
)
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