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
62fe37e3
Commit
62fe37e3
authored
May 23, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move check if metrics are enabled to before action
parent
21561f34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
metrics_controller.rb
app/controllers/metrics_controller.rb
+6
-2
metrics_controller_spec.rb
spec/controllers/metrics_controller_spec.rb
+10
-0
No files found.
app/controllers/metrics_controller.rb
View file @
62fe37e3
...
@@ -3,6 +3,7 @@ require 'prometheus/client/formats/text'
...
@@ -3,6 +3,7 @@ require 'prometheus/client/formats/text'
class
MetricsController
<
ActionController
::
Base
class
MetricsController
<
ActionController
::
Base
protect_from_forgery
with: :exception
protect_from_forgery
with: :exception
include
RequiresHealthToken
include
RequiresHealthToken
before_action
:ensure_prometheus_metrics_are_enabled
CHECKS
=
[
CHECKS
=
[
Gitlab
::
HealthChecks
::
DbCheck
,
Gitlab
::
HealthChecks
::
DbCheck
,
...
@@ -10,9 +11,8 @@ class MetricsController < ActionController::Base
...
@@ -10,9 +11,8 @@ class MetricsController < ActionController::Base
Gitlab
::
HealthChecks
::
FsShardsCheck
Gitlab
::
HealthChecks
::
FsShardsCheck
].
freeze
].
freeze
def
metrics
return
render_404
unless
Gitlab
::
Metrics
.
prometheus_metrics_enabled?
def
metrics
metrics_text
=
Prometheus
::
Client
::
Formats
::
Text
.
marshal_multiprocess
(
multiprocess_metrics_path
)
metrics_text
=
Prometheus
::
Client
::
Formats
::
Text
.
marshal_multiprocess
(
multiprocess_metrics_path
)
response
=
health_metrics_text
+
"
\n
"
+
metrics_text
response
=
health_metrics_text
+
"
\n
"
+
metrics_text
...
@@ -21,6 +21,10 @@ class MetricsController < ActionController::Base
...
@@ -21,6 +21,10 @@ class MetricsController < ActionController::Base
private
private
def
ensure_prometheus_metrics_are_enabled
return
render_404
unless
Gitlab
::
Metrics
.
prometheus_metrics_enabled?
end
def
multiprocess_metrics_path
def
multiprocess_metrics_path
Rails
.
root
.
join
(
ENV
[
'prometheus_multiproc_dir'
])
Rails
.
root
.
join
(
ENV
[
'prometheus_multiproc_dir'
])
end
end
...
...
spec/controllers/metrics_controller_spec.rb
View file @
62fe37e3
...
@@ -48,6 +48,15 @@ describe MetricsController do
...
@@ -48,6 +48,15 @@ describe MetricsController do
expect
(
response
.
body
).
to
match
(
/^filesystem_read_latency{shard="default"} [0-9\.]+$/
)
expect
(
response
.
body
).
to
match
(
/^filesystem_read_latency{shard="default"} [0-9\.]+$/
)
expect
(
response
.
body
).
to
match
(
/^filesystem_readable{shard="default"} 1$/
)
expect
(
response
.
body
).
to
match
(
/^filesystem_readable{shard="default"} 1$/
)
end
end
context
'prometheus metrics are disabled'
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
:prometheus_metrics_enabled?
).
and_return
(
false
)
it
'returns proper response'
do
get
:metrics
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
end
context
'without authorization token'
do
context
'without authorization token'
do
...
@@ -56,5 +65,6 @@ describe MetricsController do
...
@@ -56,5 +65,6 @@ describe MetricsController do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
.
status
).
to
eq
(
404
)
end
end
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