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
48778ac5
Commit
48778ac5
authored
Jul 31, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for query context variables
parent
6df5bd8b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
18 deletions
+34
-18
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+0
-5
spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb
...heus/queries/additional_metrics_environment_query_spec.rb
+1
-1
spec/support/prometheus/additional_metrics_shared_examples.rb
.../support/prometheus/additional_metrics_shared_examples.rb
+33
-12
No files found.
app/models/project_services/prometheus_service.rb
View file @
48778ac5
...
@@ -75,11 +75,6 @@ class PrometheusService < MonitoringService
...
@@ -75,11 +75,6 @@ class PrometheusService < MonitoringService
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
.
name
,
&
:itself
)
with_reactive_cache
(
Gitlab
::
Prometheus
::
Queries
::
MatchedMetricsQuery
.
name
,
&
:itself
)
end
end
def
with_reactive_cache
(
name
,
*
args
,
&
block
)
vals
=
args
.
map
(
&
:to_s
)
yield
calculate_reactive_cache
(
name
,
*
vals
)
end
# Cache metrics for specific environment
# Cache metrics for specific environment
def
calculate_reactive_cache
(
query_class_name
,
*
args
)
def
calculate_reactive_cache
(
query_class_name
,
*
args
)
return
unless
active?
&&
project
&&
!
project
.
pending_delete?
return
unless
active?
&&
project
&&
!
project
.
pending_delete?
...
...
spec/lib/gitlab/prometheus/queries/additional_metrics_environment_query_spec.rb
View file @
48778ac5
...
@@ -6,11 +6,11 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do
...
@@ -6,11 +6,11 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do
end
end
include_examples
'additional metrics query'
do
include_examples
'additional metrics query'
do
let
(
:query_result
)
{
described_class
.
new
(
client
).
query
(
environment
.
id
)
}
let
(
:query_params
)
{
[
environment
.
id
]
}
let
(
:query_params
)
{
[
environment
.
id
]
}
it
'queries using specific time'
do
it
'queries using specific time'
do
expect
(
client
).
to
receive
(
:query_range
).
with
(
anything
,
start:
8
.
hours
.
ago
.
to_f
,
stop:
Time
.
now
.
to_f
)
expect
(
client
).
to
receive
(
:query_range
).
with
(
anything
,
start:
8
.
hours
.
ago
.
to_f
,
stop:
Time
.
now
.
to_f
)
expect
(
query_result
).
not_to
be_nil
expect
(
query_result
).
not_to
be_nil
end
end
end
end
...
...
spec/support/prometheus/additional_metrics_shared_examples.rb
View file @
48778ac5
...
@@ -11,6 +11,7 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -11,6 +11,7 @@ RSpec.shared_examples 'additional metrics query' do
end
end
let
(
:client
)
{
double
(
'prometheus_client'
)
}
let
(
:client
)
{
double
(
'prometheus_client'
)
}
let
(
:query_result
)
{
described_class
.
new
(
client
).
query
(
*
query_params
)
}
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
)
}
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
)
}
before
do
before
do
...
@@ -18,31 +19,52 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -18,31 +19,52 @@ RSpec.shared_examples 'additional metrics query' do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
(
metrics:
[
simple_metric
])])
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
(
metrics:
[
simple_metric
])])
end
end
context
'metrics
rendering
'
do
context
'metrics
query context
'
do
subject!
{
described_class
.
new
(
client
)
}
subject!
{
described_class
.
new
(
client
)
}
before
do
shared_examples
'query context containing environment slug and filter'
do
it
'query context contains ci_environment_slug'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
hash_including
(
ci_environment_slug:
environment
.
slug
))
subject
.
query
(
*
query_params
)
end
end
describe
'project has kubernetes service'
do
it
'query context contains environment filter'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
hash_including
(
environment_filter:
"container_name!=
\"
POD
\"
,environment=
\"
#{
environment
.
slug
}
\"
"
)
)
subject
.
query
(
*
query_params
)
end
end
describe
'project has Kubernetes service'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
let
(
:project
)
{
create
(
:kubernetes_project
)
}
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
,
project:
project
)
}
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
,
project:
project
)
}
let
(
:kube_namespace
)
{
project
.
kubernetes_service
.
actual_namespace
}
let
(
:kube_namespace
)
{
project
.
kubernetes_service
.
actual_namespace
}
it
'query context contains kube namespace'
do
it_behaves_like
'query context containing environment slug and filter'
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
hash_including
(
it
'query context contains kube_namespace'
do
kube_namespace:
kube_namespace
)
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
hash_including
(
kube_namespace:
kube_namespace
))
)
subject
.
query
(
*
query_params
)
end
end
describe
'project without Kubernetes service'
do
it_behaves_like
'query context containing environment slug and filter'
it
'query context contains empty kube_namespace'
do
expect
(
subject
).
to
receive
(
:query_metrics
).
with
(
hash_including
(
kube_namespace:
''
))
subject
.
query
(
*
query_params
)
subject
.
query
(
*
query_params
)
end
end
end
end
end
end
context
'with one group where two metrics is found'
do
context
'with one group where two metrics is found'
do
let
(
:query_result
)
{
described_class
.
new
(
client
).
query
(
*
query_params
)
}
before
do
before
do
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
allow
(
metric_group_class
).
to
receive
(
:all
).
and_return
([
simple_metric_group
])
end
end
...
@@ -77,7 +99,6 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -77,7 +99,6 @@ RSpec.shared_examples 'additional metrics query' do
end
end
context
'with two groups with one metric each'
do
context
'with two groups with one metric each'
do
let
(
:query_result
)
{
described_class
.
new
(
client
).
query
(
*
query_params
)
}
let
(
:metrics
)
{
[
simple_metric
(
queries:
[
simple_query
])]
}
let
(
:metrics
)
{
[
simple_metric
(
queries:
[
simple_query
])]
}
before
do
before
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