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
a3eb8264
Commit
a3eb8264
authored
Jun 05, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Metric tests to use more common code
parent
eccc187a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
19 deletions
+16
-19
spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb
...b/gitlab/prometheus/queries/matched_metrics_query_spec.rb
+13
-7
spec/support/prometheus/matched_metrics_query_helper.rb
spec/support/prometheus/matched_metrics_query_helper.rb
+0
-9
spec/support/prometheus/metric_builders.rb
spec/support/prometheus/metric_builders.rb
+3
-3
No files found.
spec/lib/gitlab/prometheus/queries/matched_metrics_query_spec.rb
View file @
a3eb8264
...
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
,
lib:
true
do
include
Prometheus
::
MatchedMetricsQueryHelper
include
Prometheus
::
MetricBuilders
let
(
:metric_group_class
)
{
Gitlab
::
Prometheus
::
MetricGroup
}
let
(
:metric_class
)
{
Gitlab
::
Prometheus
::
Metric
}
...
...
@@ -83,30 +84,35 @@ describe Gitlab::Prometheus::Queries::MatchedMetricsQuery, lib: true do
end
end
context
'with two groups where only one metric is found'
do
context
'with two groups where metrics are found in each group'
do
let
(
:second_metric_group
)
{
simple_metric_group
(
name:
'nameb'
,
metrics:
simple_metrics
(
added_metric_name:
'metric_c'
))
}
before
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
,
simple_metric_group
(
'nameb'
,
simple_metrics
(
'metric_c'
))])
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
,
second_metric_group
])
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
'metric_c'
)
end
context
'
both metrics in the group
pass requirements'
do
context
'
all metrics in both groups
pass requirements'
do
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_with_environment
(
'metric_c'
))
end
it
'responds with one metrics as active and no missing requiremens'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'nameb'
,
priority:
1
,
active_metrics:
1
,
metrics_missing_requirements:
0
}])
expect
(
subject
.
query
).
to
eq
([
{
group:
'name'
,
priority:
1
,
active_metrics:
1
,
metrics_missing_requirements:
0
},
{
group:
'nameb'
,
priority:
1
,
active_metrics:
2
,
metrics_missing_requirements:
0
}])
end
end
context
'no metri
s in group
pass requirements'
do
context
'no metri
cs in groups
pass requirements'
do
before
do
allow
(
client
).
to
receive
(
:series
).
and_return
(
series_info_without_environment
)
end
it
'responds with one metrics as active and no missing requiremens'
do
expect
(
subject
.
query
).
to
eq
([{
group:
'nameb'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
1
}])
expect
(
subject
.
query
).
to
eq
([
{
group:
'name'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
1
},
{
group:
'nameb'
,
priority:
1
,
active_metrics:
0
,
metrics_missing_requirements:
2
}])
end
end
end
...
...
spec/support/prometheus/matched_metrics_query_helper.rb
View file @
a3eb8264
...
...
@@ -4,15 +4,6 @@ module Prometheus
%w{metric_a metric_b}
end
def
simple_metrics
(
metric_name
=
'metric_a'
)
[
Gitlab
::
Prometheus
::
Metric
.
new
(
'title'
,
%W(
#{
metric_name
}
metric_b)
,
nil
,
nil
),
Gitlab
::
Prometheus
::
Metric
.
new
(
'title'
,
[
metric_name
],
nil
,
nil
)]
end
def
simple_metric_group
(
name
=
'name'
,
metrics
=
simple_metrics
)
Gitlab
::
Prometheus
::
MetricGroup
.
new
(
name
,
1
,
metrics
)
end
def
series_info_with_environment
(
*
more_metrics
)
%w{metric_a metric_b}
.
concat
(
more_metrics
).
map
{
|
metric_name
|
{
'__name__'
=>
metric_name
,
'environment'
=>
''
}
}
end
...
...
spec/support/prometheus/metric_builders.rb
View file @
a3eb8264
...
...
@@ -12,10 +12,10 @@ module Prometheus
Gitlab
::
Prometheus
::
Metric
.
new
(
title
,
required_metrics
,
nil
,
nil
,
queries
)
end
def
simple_metrics
def
simple_metrics
(
added_metric_name:
'metric_a'
)
[
simple_metric
(
required_metrics:
%
w(metric_a
metric_b)
,
queries:
simple_queries
),
simple_metric
(
required_metrics:
%w{metric_a}
,
queries:
[
simple_query
(
'empty'
)]),
simple_metric
(
required_metrics:
%
W(
#{
added_metric_name
}
metric_b)
,
queries:
simple_queries
),
simple_metric
(
required_metrics:
[
added_metric_name
]
,
queries:
[
simple_query
(
'empty'
)]),
simple_metric
(
required_metrics:
%w{metric_c}
)
]
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