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
b5335654
Commit
b5335654
authored
Mar 05, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if prometheus_adapter is properly called
parent
5ceec83a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
32 deletions
+21
-32
app/controllers/projects/prometheus/metrics_controller.rb
app/controllers/projects/prometheus/metrics_controller.rb
+2
-1
spec/controllers/projects/prometheus/metrics_controller_spec.rb
...ontrollers/projects/prometheus/metrics_controller_spec.rb
+16
-2
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+3
-29
No files found.
app/controllers/projects/prometheus/metrics_controller.rb
View file @
b5335654
...
...
@@ -21,9 +21,10 @@ module Projects
private
def
prometheus_adapter
@prometheus_adapter
||=
Prometheus
::
AdapterService
.
new
(
project
).
prometheus_adapter
@prometheus_adapter
||=
::
Prometheus
::
AdapterService
.
new
(
project
).
prometheus_adapter
end
def
require_prometheus_metrics!
render_404
unless
prometheus_adapter
.
can_query?
end
...
...
spec/controllers/projects/prometheus/metrics_controller_spec.rb
View file @
b5335654
...
...
@@ -7,13 +7,15 @@ describe Projects::Prometheus::MetricsController do
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
)
}
before
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
project
.
add_master
(
user
)
sign_in
(
user
)
end
describe
'GET #active_common'
do
before
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
context
'when prometheus metrics are enabled'
do
context
'when data is not present'
do
before
do
...
...
@@ -52,6 +54,18 @@ describe Projects::Prometheus::MetricsController do
end
end
describe
'#prometheus_adapter'
do
before
do
allow
(
controller
).
to
receive
(
:project
).
and_return
(
project
)
end
it
'calls prometheus adapter service'
do
expect_any_instance_of
(
::
Prometheus
::
AdapterService
).
to
receive
(
:prometheus_adapter
)
subject
.
__send__
(
:prometheus_adapter
)
end
end
def
project_params
(
opts
=
{})
opts
.
reverse_merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
...
...
spec/models/environment_spec.rb
View file @
b5335654
...
...
@@ -623,36 +623,10 @@ describe Environment do
end
describe
'#prometheus_adapter'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
environment_scope:
'*'
,
projects:
[
project
])
}
it
'calls prometheus adapter service'
do
expect_any_instance_of
(
Prometheus
::
AdapterService
).
to
receive
(
:prometheus_adapter
)
context
'prometheus service can execute queries'
do
let
(
:prometheus_service
)
{
double
(
:prometheus_service
,
can_query?:
true
)
}
before
do
allow
(
environment
.
project
).
to
receive
(
:find_or_initialize_service
).
with
(
'prometheus'
).
and_return
prometheus_service
end
it
'return prometheus service as prometheus adapter'
do
expect
(
environment
.
prometheus_adapter
).
to
eq
(
prometheus_service
)
end
end
context
"prometheus service can't execute queries"
do
let
(
:prometheus_service
)
{
double
(
:prometheus_service
,
can_query?:
false
)
}
context
'with cluster with prometheus installed'
do
let!
(
:prometheus
)
{
create
(
:clusters_applications_prometheus
,
:installed
,
cluster:
cluster
)
}
it
'returns application handling all environments'
do
expect
(
environment
.
prometheus_adapter
).
to
eq
(
prometheus
)
end
end
context
'with cluster without prometheus installed'
do
it
'returns nil'
do
expect
(
environment
.
prometheus_adapter
).
to
be_nil
end
end
subject
.
prometheus_adapter
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