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
58313de4
Commit
58313de4
authored
May 23, 2018
by
Tiago Botelho
Committed by
Rémy Coutable
May 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render 404 when prometheus adapter is disabled in Prometheus metrics controller
parent
a2dbca4a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
26 deletions
+54
-26
app/controllers/projects/prometheus/metrics_controller.rb
app/controllers/projects/prometheus/metrics_controller.rb
+1
-1
changelogs/unreleased/46413-error-when-prometheus-adapter-is-disabled.yml
...eased/46413-error-when-prometheus-adapter-is-disabled.yml
+5
-0
spec/controllers/projects/prometheus/metrics_controller_spec.rb
...ontrollers/projects/prometheus/metrics_controller_spec.rb
+48
-25
No files found.
app/controllers/projects/prometheus/metrics_controller.rb
View file @
58313de4
...
@@ -25,7 +25,7 @@ module Projects
...
@@ -25,7 +25,7 @@ module Projects
end
end
def
require_prometheus_metrics!
def
require_prometheus_metrics!
render_404
unless
prometheus_adapter
.
can_query?
render_404
unless
prometheus_adapter
&
.
can_query?
end
end
end
end
end
end
...
...
changelogs/unreleased/46413-error-when-prometheus-adapter-is-disabled.yml
0 → 100644
View file @
58313de4
---
title
:
Render 404 when prometheus adapter is disabled in Prometheus metrics controller
merge_request
:
19110
author
:
type
:
fixed
spec/controllers/projects/prometheus/metrics_controller_spec.rb
View file @
58313de4
...
@@ -12,44 +12,67 @@ describe Projects::Prometheus::MetricsController do
...
@@ -12,44 +12,67 @@ describe Projects::Prometheus::MetricsController do
end
end
describe
'GET #active_common'
do
describe
'GET #active_common'
do
before
do
context
'when prometheus_adapter can query'
do
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
before
do
end
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
context
'when prometheus metrics are enabled'
do
context
'when prometheus metrics are enabled'
do
context
'when data is not present'
do
context
'when data is not present'
do
before
do
before
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
with
(
:matched_metrics
).
and_return
({})
allow
(
prometheus_adapter
).
to
receive
(
:query
).
with
(
:matched_metrics
).
and_return
({})
end
end
it
'returns no content response'
do
it
'returns no content response'
do
get
:active_common
,
project_params
(
format: :json
)
get
:active_common
,
project_params
(
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
204
)
expect
(
response
).
to
have_gitlab_http_status
(
204
)
end
end
end
end
context
'when data is available'
do
context
'when data is available'
do
let
(
:sample_response
)
{
{
some_data:
1
}
}
let
(
:sample_response
)
{
{
some_data:
1
}
}
before
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
with
(
:matched_metrics
).
and_return
(
sample_response
)
end
before
do
it
'returns no content response'
do
allow
(
prometheus_adapter
).
to
receive
(
:query
).
with
(
:matched_metrics
).
and_return
(
sample_response
)
get
:active_common
,
project_params
(
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
eq
(
sample_response
.
deep_stringify_keys
)
end
end
end
it
'returns no content response'
do
context
'when requesting non json response'
do
get
:active_common
,
project_params
(
format: :json
)
it
'returns not found response'
do
get
:active_common
,
project_params
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
e
xpect
(
json_response
).
to
eq
(
sample_response
.
deep_stringify_keys
)
e
nd
end
end
end
end
end
context
'when requesting non json response
'
do
context
'when prometheus_adapter cannot query
'
do
it
'returns not found response
'
do
it
'renders 404
'
do
get
:active_common
,
project_params
prometheus_adapter
=
double
(
'prometheus_adapter'
,
can_query?:
false
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
allow
(
controller
).
to
receive
(
:prometheus_adapter
).
and_return
(
prometheus_adapter
)
end
allow
(
prometheus_adapter
).
to
receive
(
:query
).
with
(
:matched_metrics
).
and_return
({})
get
:active_common
,
project_params
(
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
'when prometheus_adapter is disabled'
do
it
'renders 404'
do
get
:active_common
,
project_params
(
format: :json
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
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