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
Léo-Paul Géneau
gitlab-ce
Commits
eaaad702
Commit
eaaad702
authored
Jun 05, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional metrics test using multiple groups
parent
ae5268ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
32 deletions
+111
-32
spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb
...itlab/prometheus/queries/additional_metrics_query_spec.rb
+84
-12
spec/support/prometheus/additional_metrics_query_helper.rb
spec/support/prometheus/additional_metrics_query_helper.rb
+0
-20
spec/support/prometheus/metric_builders.rb
spec/support/prometheus/metric_builders.rb
+27
-0
No files found.
spec/lib/gitlab/prometheus/queries/additional_metrics_query_spec.rb
View file @
eaaad702
...
...
@@ -2,6 +2,7 @@ require 'spec_helper'
describe
Gitlab
::
Prometheus
::
Queries
::
AdditionalMetricsQuery
,
lib:
true
do
include
Prometheus
::
AdditionalMetricsQueryHelper
include
Prometheus
::
MetricBuilders
let
(
:metric_group_class
)
{
Gitlab
::
Prometheus
::
MetricGroup
}
let
(
:metric_class
)
{
Gitlab
::
Prometheus
::
Metric
}
...
...
@@ -11,6 +12,9 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do
subject
(
:query_result
)
{
described_class
.
new
(
client
).
query
(
environment
.
id
)
}
around
do
|
example
|
Timecop
.
freeze
{
example
.
run
}
end
context
'with one group where two metrics is found'
do
before
do
...
...
@@ -18,31 +22,99 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsQuery, lib: true do
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
metric_names
)
end
context
'some querie return results'
do
context
'some querie
s
return results'
do
before
do
expect
(
client
).
to
receive
(
:query_range
).
with
(
'query_range_a'
,
any_args
).
and_return
(
query_range_result
)
expect
(
client
).
to
receive
(
:query_range
).
with
(
'query_range_b'
,
any_args
).
and_return
(
query_range_result
)
expect
(
client
).
to
receive
(
:query_range
).
with
(
'query_range_empty'
,
any_args
).
and_return
([])
end
it
'return results only for queries with results'
do
expected
=
[
{
group:
'name'
,
priority:
1
,
metrics:
[
{
title:
'title'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_a'
,
result:
query_range_result
},
{
query_range:
'query_range_b'
,
label:
'label'
,
unit:
'unit'
,
result:
query_range_result
}
]
}
]
}
]
expect
(
query_result
).
to
eq
(
expected
)
end
end
end
context
'with two groups with one metric each'
do
let
(
:metrics
)
{
[
simple_metric
(
queries:
[
simple_query
])]
}
before
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
(
[
simple_metric_group
(
'group_a'
,
[
simple_metric
(
queries:
[
simple_query
])]),
simple_metric_group
(
'group_b'
,
[
simple_metric
(
title:
'title_b'
,
queries:
[
simple_query
(
'b'
)])])
])
allow
(
client
).
to
receive
(
:label_values
).
and_return
(
metric_names
)
end
context
'some queries return results'
do
before
do
expect
(
client
).
to
receive
(
:query_range
).
with
(
'query_range_a'
,
any_args
).
and_return
(
query_range_result
)
expect
(
client
).
to
receive
(
:query_range
).
with
(
'query_range_b'
,
any_args
).
and_return
(
query_range_result
)
end
it
'return results only for queries with results'
do
puts
query_result
expected
=
{
group:
'name'
,
priority:
1
,
metrics:
[
expected
=
[
{
group:
'group_a'
,
priority:
1
,
metrics:
[
{
title:
'title'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_a'
,
result:
[
{
metric:
{},
values:
[[
1488758662.506
,
'0.00002996364761904785'
],
[
1488758722.506
,
'0.00003090239047619091'
]]
}
]
}
]
}
]
},
{
group:
'group_b'
,
priority:
1
,
metrics:
[
{
title:
'title'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_a'
,
result:
query_range_result
},
{
query_range:
'query_range_b'
,
label:
'label'
,
unit:
'unit'
,
result:
query_range_result
}
title:
'title_b'
,
weight:
nil
,
y_label:
'Values'
,
queries:
[
{
query_range:
'query_range_b'
,
result:
[
{
metric:
{},
values:
[[
1488758662.506
,
'0.00002996364761904785'
],
[
1488758722.506
,
'0.00003090239047619091'
]]
}
]
}
]
}
]
}
}
]
expect
(
query_result
).
to
eq
(
[
expected
]
)
expect
(
query_result
).
to
eq
(
expected
)
end
end
end
...
...
spec/support/prometheus/additional_metrics_query_helper.rb
View file @
eaaad702
...
...
@@ -4,26 +4,6 @@ module Prometheus
%w{metric_a metric_b}
end
def
simple_queries
[{
query_range:
'query_range_a'
},
{
query_range:
'query_range_b'
,
label:
'label'
,
unit:
'unit'
}]
end
def
simple_query
(
suffix
=
'a'
)
[{
query_range:
"query_range_
#{
suffix
}
"
}]
end
def
simple_metrics
[
Gitlab
::
Prometheus
::
Metric
.
new
(
'title'
,
%w(metric_a metric_b)
,
nil
,
nil
,
simple_queries
),
Gitlab
::
Prometheus
::
Metric
.
new
(
'title'
,
%w{metric_a}
,
nil
,
nil
,
simple_query
(
'empty'
)),
Gitlab
::
Prometheus
::
Metric
.
new
(
'title'
,
%w{metric_c}
,
nil
,
nil
)
]
end
def
simple_metric_group
(
name
=
'name'
,
metrics
=
simple_metrics
)
Gitlab
::
Prometheus
::
MetricGroup
.
new
(
name
,
1
,
metrics
)
end
def
query_result
[
{
...
...
spec/support/prometheus/metric_builders.rb
0 → 100644
View file @
eaaad702
module
Prometheus
module
MetricBuilders
def
simple_query
(
suffix
=
'a'
,
**
opts
)
{
query_range:
"query_range_
#{
suffix
}
"
}.
merge
(
opts
)
end
def
simple_queries
[
simple_query
,
simple_query
(
'b'
,
label:
'label'
,
unit:
'unit'
)]
end
def
simple_metric
(
title:
'title'
,
required_metrics:
[],
queries:
[])
Gitlab
::
Prometheus
::
Metric
.
new
(
title
,
required_metrics
,
nil
,
nil
,
queries
)
end
def
simple_metrics
[
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{metric_c}
)
]
end
def
simple_metric_group
(
name
=
'name'
,
metrics
=
simple_metrics
)
Gitlab
::
Prometheus
::
MetricGroup
.
new
(
name
,
1
,
metrics
)
end
end
end
\ No newline at end of file
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