Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
b172f419c463
Commit
c8f23bd2
authored
May 11, 2016
by
DJ Mountney
Browse files
Support token header for health check token, and general cleanup of the health_check feature.
parent
4ab056021363
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/controllers/health_check_controller.rb
View file @
b172f419
class
HealthCheckController
<
HealthCheck
::
HealthCheckController
before_action
:validate_health_check_access!
pr
otec
te
d
pr
iva
te
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
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
app/views/admin/health_check/show.html.haml
View file @
b172f419
...
...
@@ -2,29 +2,35 @@
%h3
.page-title
Health Check
%p
.light
.bs-callout.clearfix
.pull-left
%p
Access token is
%code
{
id
:'health-check-token'
}=
"
#{
current_application_settings
.
health_check_access_token
}
"
%code
#health-check-token
=
current_application_settings
.
health_check_access_token
=
button_to
reset_health_check_token_admin_application_settings_path
,
method: :put
,
class:
'btn btn-default'
,
data:
{
confirm:
'Are you sure you want to reset the health check token?'
}
do
=
icon
(
'refresh'
)
Reset 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
}
"
%code
=
health_check
_url
(
token
:
current_application_settings
.
health_check_access_token
)
%li
%code
=
"/
health_check
.json?
token
=
#{
current_application_settings
.
health_check_access_token
}
"
%code
=
health_check
_url
(
token
:
current_application_settings
.
health_check_access_token
,
format: :json
)
%li
%code
=
"/
health_check
.xml?
token
=
#{
current_application_settings
.
health_check_access_token
}
"
%code
=
health_check
_url
(
token
:
current_application_settings
.
health_check_access_token
,
format: :xml
)
.bs-callout.clearfix
.pull-left
%p
You can reset the health check access token by pressing the button below.
%p
=
button_to
reset_health_check_token_admin_application_settings_path
,
method: :put
,
class:
'btn btn-default'
,
data:
{
confirm:
'Are you sure you want to reset the health check token?'
}
do
=
icon
(
'refresh'
)
Reset health check access token
%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
.panel.panel-default
...
...
config/initializers/health_check.rb
View file @
b172f419
HealthCheck
.
setup
do
|
config
|
config
.
standard_checks
=
[
'database'
,
'migrations'
,
'cache'
]
config
.
standard_checks
=
[
'database'
,
'migrations'
,
'cache'
]
end
config/routes.rb
View file @
b172f419
...
...
@@ -74,7 +74,7 @@
end
# Health check
get
'health_check(/:checks)
(.:format)
'
=>
'health_check#index'
get
'health_check(/:checks)'
=>
'health_check#index'
,
as: :health_check
# Enable Grack support
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 @
b172f419
...
...
@@ -14,6 +14,13 @@
end
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
get
:index
,
token:
token
expect
(
response
).
to
be_success
...
...
@@ -55,6 +62,14 @@
allow
(
HealthCheck
::
Utils
).
to
receive
(
:process_checks
).
with
(
'email'
).
and_return
(
'Email is on fire'
)
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
get
:index
,
token:
token
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