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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
c8f23bd2
Commit
c8f23bd2
authored
May 11, 2016
by
DJ Mountney
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support token header for health check token, and general cleanup of the health_check feature.
parent
0e0caf4d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
20 deletions
+50
-20
app/controllers/health_check_controller.rb
app/controllers/health_check_controller.rb
+12
-3
app/views/admin/health_check/show.html.haml
app/views/admin/health_check/show.html.haml
+21
-15
config/initializers/health_check.rb
config/initializers/health_check.rb
+1
-1
config/routes.rb
config/routes.rb
+1
-1
spec/controllers/health_check_controller_spec.rb
spec/controllers/health_check_controller_spec.rb
+15
-0
No files found.
app/controllers/health_check_controller.rb
View file @
c8f23bd2
class
HealthCheckController
<
HealthCheck
::
HealthCheckController
class
HealthCheckController
<
HealthCheck
::
HealthCheckController
before_action
:validate_health_check_access!
before_action
:validate_health_check_access!
pr
otected
pr
ivate
def
validate_health_check_access!
def
validate_health_check_access!
return
render_404
unless
params
[
:token
].
presence
&&
params
[
:token
]
==
current_application_settings
.
health_check_access_token
render_404
unless
token_valid?
end
def
token_valid?
token
=
params
[
:token
].
presence
||
request
.
headers
[
'TOKEN'
]
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
token
,
current_application_settings
.
health_check_access_token
)
end
end
def
render_404
def
render_404
render
file:
Rails
.
root
.
join
(
"public"
,
"404"
),
layout:
false
,
status:
"404"
render
file:
Rails
.
root
.
join
(
'public'
,
'404'
),
layout:
false
,
status:
'404'
end
end
end
end
app/views/admin/health_check/show.html.haml
View file @
c8f23bd2
...
@@ -2,29 +2,35 @@
...
@@ -2,29 +2,35 @@
%h3
.page-title
%h3
.page-title
Health Check
Health Check
%p
.light
Access token is
%code
{
id
:'health-check-token'
}=
"
#{
current_application_settings
.
health_check_access_token
}
"
%p
.light
Health information can be reteived as plain text, json, or xml using:
%ul
%li
%code
=
"/health_check?token=
#{
current_application_settings
.
health_check_access_token
}
"
%li
%code
=
"/health_check.json?token=
#{
current_application_settings
.
health_check_access_token
}
"
%li
%code
=
"/health_check.xml?token=
#{
current_application_settings
.
health_check_access_token
}
"
.bs-callout.clearfix
.bs-callout.clearfix
.pull-left
.pull-left
%p
%p
You can reset the health check access token by pressing the button below.
Access token is
%p
%code
#health-check-token
=
current_application_settings
.
health_check_access_token
=
button_to
reset_health_check_token_admin_application_settings_path
,
=
button_to
reset_health_check_token_admin_application_settings_path
,
method: :put
,
class:
'btn btn-default'
,
method: :put
,
class:
'btn btn-default'
,
data:
{
confirm:
'Are you sure you want to reset the health check token?'
}
do
data:
{
confirm:
'Are you sure you want to reset the health check token?'
}
do
=
icon
(
'refresh'
)
=
icon
(
'refresh'
)
Reset health check access token
Reset health check access token
%p
.light
Health information can be reteived as plain text, json, or xml using:
%ul
%li
%code
=
health_check_url
(
token
:current_application_settings
.
health_check_access_token
)
%li
%code
=
health_check_url
(
token
:current_application_settings
.
health_check_access_token
,
format: :json
)
%li
%code
=
health_check_url
(
token
:current_application_settings
.
health_check_access_token
,
format: :xml
)
%p
.light
You can also ask for the status of specific services:
%ul
%li
%code
=
health_check_url
(
token
:current_application_settings
.
health_check_access_token
,
checks: :cache
)
%li
%code
=
health_check_url
(
token
:current_application_settings
.
health_check_access_token
,
checks: :database
)
%li
%code
=
health_check_url
(
token
:current_application_settings
.
health_check_access_token
,
checks: :migrations
)
%hr
%hr
.panel.panel-default
.panel.panel-default
...
...
config/initializers/health_check.rb
View file @
c8f23bd2
HealthCheck
.
setup
do
|
config
|
HealthCheck
.
setup
do
|
config
|
config
.
standard_checks
=
[
'database'
,
'migrations'
,
'cache'
]
config
.
standard_checks
=
[
'database'
,
'migrations'
,
'cache'
]
end
end
config/routes.rb
View file @
c8f23bd2
...
@@ -74,7 +74,7 @@ Rails.application.routes.draw do
...
@@ -74,7 +74,7 @@ Rails.application.routes.draw do
end
end
# Health check
# Health check
get
'health_check(/:checks)
(.:format)'
=>
'health_check#index'
get
'health_check(/:checks)
'
=>
'health_check#index'
,
as: :health_check
# Enable Grack support
# Enable Grack support
mount
Grack
::
AuthSpawner
,
at:
'/'
,
constraints:
lambda
{
|
request
|
/[-\/\w\.]+\.git\//
.
match
(
request
.
path_info
)
},
via:
[
:get
,
:post
,
:put
]
mount
Grack
::
AuthSpawner
,
at:
'/'
,
constraints:
lambda
{
|
request
|
/[-\/\w\.]+\.git\//
.
match
(
request
.
path_info
)
},
via:
[
:get
,
:post
,
:put
]
...
...
spec/controllers/health_check_controller_spec.rb
View file @
c8f23bd2
...
@@ -14,6 +14,13 @@ describe HealthCheckController do
...
@@ -14,6 +14,13 @@ describe HealthCheckController do
end
end
context
'when services are up and an access token is provided'
do
context
'when services are up and an access token is provided'
do
it
'supports passing the token in the header'
do
request
.
headers
[
'TOKEN'
]
=
token
get
:index
expect
(
response
).
to
be_success
expect
(
response
.
content_type
).
to
eq
'text/plain'
end
it
'supports successful plaintest response'
do
it
'supports successful plaintest response'
do
get
:index
,
token:
token
get
:index
,
token:
token
expect
(
response
).
to
be_success
expect
(
response
).
to
be_success
...
@@ -55,6 +62,14 @@ describe HealthCheckController do
...
@@ -55,6 +62,14 @@ describe HealthCheckController do
allow
(
HealthCheck
::
Utils
).
to
receive
(
:process_checks
).
with
(
'email'
).
and_return
(
'Email is on fire'
)
allow
(
HealthCheck
::
Utils
).
to
receive
(
:process_checks
).
with
(
'email'
).
and_return
(
'Email is on fire'
)
end
end
it
'supports passing the token in the header'
do
request
.
headers
[
'TOKEN'
]
=
token
get
:index
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
content_type
).
to
eq
'text/plain'
expect
(
response
.
body
).
to
include
(
'The server is on fire'
)
end
it
'supports failure plaintest response'
do
it
'supports failure plaintest response'
do
get
:index
,
token:
token
get
:index
,
token:
token
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
.
status
).
to
eq
(
500
)
...
...
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