BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
1ea2a85c
Commit
1ea2a85c
authored
Sep 25, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Prometheus metrics endpoint return empty response when metrics are disabled
parent
b83dcd3a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
metrics_controller.rb
app/controllers/metrics_controller.rb
+9
-7
metrics_controller_spec.rb
spec/controllers/metrics_controller_spec.rb
+2
-1
No files found.
app/controllers/metrics_controller.rb
View file @
1ea2a85c
...
@@ -3,10 +3,16 @@ class MetricsController < ActionController::Base
...
@@ -3,10 +3,16 @@ class MetricsController < ActionController::Base
protect_from_forgery
with: :exception
protect_from_forgery
with: :exception
before_action
:validate_prometheus_metrics
def
index
def
index
render
text:
metrics_service
.
metrics_text
,
content_type:
'text/plain; version=0.0.4'
response
=
if
Gitlab
::
Metrics
.
prometheus_metrics_enabled?
metrics_service
.
metrics_text
else
help_page
=
help_page_url
(
'administration/monitoring/prometheus/gitlab_metrics'
,
anchor:
'gitlab-prometheus-metrics'
)
"# Metrics are disabled, see:
#{
help_page
}
\n
"
end
render
text:
response
,
content_type:
'text/plain; version=0.0.4'
end
end
private
private
...
@@ -14,8 +20,4 @@ class MetricsController < ActionController::Base
...
@@ -14,8 +20,4 @@ class MetricsController < ActionController::Base
def
metrics_service
def
metrics_service
@metrics_service
||=
MetricsService
.
new
@metrics_service
||=
MetricsService
.
new
end
end
def
validate_prometheus_metrics
render_404
unless
Gitlab
::
Metrics
.
prometheus_metrics_enabled?
end
end
end
spec/controllers/metrics_controller_spec.rb
View file @
1ea2a85c
...
@@ -78,7 +78,8 @@ describe MetricsController do
...
@@ -78,7 +78,8 @@ describe MetricsController do
it
'returns proper response'
do
it
'returns proper response'
do
get
:index
get
:index
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
body
).
to
eq
(
"# Metrics are disabled, see: http://test.host/help/administration/monitoring/prometheus/gitlab_metrics#gitlab-prometheus-metrics
\n
"
)
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