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
Léo-Paul Géneau
gitlab-ce
Commits
22d44ae9
Commit
22d44ae9
authored
Jul 27, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use /-/health instead of breaking /-/liveness
parent
eb2bc7d9
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
101 additions
and
21 deletions
+101
-21
app/controllers/health_controller.rb
app/controllers/health_controller.rb
+3
-2
changelogs/unreleased/sh-simplify-liveness-check.yml
changelogs/unreleased/sh-simplify-liveness-check.yml
+3
-3
config/application.rb
config/application.rb
+1
-1
config/routes.rb
config/routes.rb
+2
-1
doc/user/admin_area/monitoring/health_check.md
doc/user/admin_area/monitoring/health_check.md
+33
-6
lib/gitlab/middleware/basic_health_check.rb
lib/gitlab/middleware/basic_health_check.rb
+4
-4
spec/controllers/health_controller_spec.rb
spec/controllers/health_controller_spec.rb
+51
-0
spec/lib/gitlab/middleware/basic_health_check_spec.rb
spec/lib/gitlab/middleware/basic_health_check_spec.rb
+4
-4
No files found.
app/controllers/health_controller.rb
View file @
22d44ae9
...
...
@@ -18,8 +18,9 @@ class HealthController < ActionController::Base
end
def
liveness
# This should never be called; it should be intercepted by LivenessHealthCheck middleware
head
:not_found
results
=
CHECKS
.
map
{
|
check
|
[
check
.
name
,
check
.
liveness
]
}
render_check_results
(
results
)
end
def
storage_check
...
...
changelogs/unreleased/sh-simplify-liveness-check.yml
View file @
22d44ae9
---
title
:
Simplify /-/liveness check to avoid connecting to the database
merge_request
:
title
:
Add /-/health basic health check endpoint
merge_request
:
20456
author
:
type
:
chang
ed
type
:
add
ed
config/application.rb
View file @
22d44ae9
...
...
@@ -156,7 +156,7 @@ module Gitlab
# This middleware needs to precede ActiveRecord::QueryCache and other middlewares that
# connect to the database.
config
.
middleware
.
insert_after
"Rails::Rack::Logger"
,
"Gitlab::Middleware::
Liveness
HealthCheck"
config
.
middleware
.
insert_after
"Rails::Rack::Logger"
,
"Gitlab::Middleware::
Basic
HealthCheck"
config
.
middleware
.
insert_after
Warden
::
Manager
,
Rack
::
Attack
...
...
config/routes.rb
View file @
22d44ae9
...
...
@@ -46,7 +46,8 @@ Rails.application.routes.draw do
get
'health_check(/:checks)'
=>
'health_check#index'
,
as: :health_check
scope
path:
'-'
do
get
'liveness'
=>
'health#liveness'
# Intercepted via Gitlab::Middleware::LivenessHealthCheck
# '/-/health' implemented by BasicHealthMiddleware
get
'liveness'
=>
'health#liveness'
get
'readiness'
=>
'health#readiness'
post
'storage_check'
=>
'health#storage_check'
resources
:metrics
,
only:
[
:index
]
...
...
doc/user/admin_area/monitoring/health_check.md
View file @
22d44ae9
...
...
@@ -20,14 +20,24 @@ To access monitoring resources, the client IP needs to be included in a whitelis
[
Read how to add IPs to a whitelist for the monitoring endpoints
][
admin
]
.
## Using the endpoint
## Using the endpoint
s
With default whitelist settings, the probes can be accessed from localhost:
-
`http://localhost/-/health`
-
`http://localhost/-/readiness`
-
`http://localhost/-/liveness`
The readiness endpoint will provide a report of system health in JSON format.
The first endpoint,
`/-/health/`
, only checks whether the application server is running. It does
-not verify the database or other services are running. A successful response with return
a 200 status code with the following message:
```
GitLab OK
```
The readiness and liveness probes will provide a report of system health in JSON format.
Readiness example output:
...
...
@@ -57,12 +67,29 @@ Readiness example output:
}
```
The liveness endpoint only checks whether the application server is running. It does
not verify the database or other services are running. A successful response with return
a 200 status code with the following message:
Liveness example output:
```
GitLab is alive
{
"fs_shards_check" : {
"status" : "ok"
},
"cache_check" : {
"status" : "ok"
},
"db_check" : {
"status" : "ok"
},
"redis_check" : {
"status" : "ok"
},
"queues_check" : {
"status" : "ok"
},
"shared_state_check" : {
"status" : "ok"
}
}
```
## Status
...
...
lib/gitlab/middleware/
liveness
_health_check.rb
→
lib/gitlab/middleware/
basic
_health_check.rb
View file @
22d44ae9
...
...
@@ -9,20 +9,20 @@
module
Gitlab
module
Middleware
class
Liveness
HealthCheck
class
Basic
HealthCheck
# This can't be frozen because Rails::Rack::Logger wraps the body
# rubocop:disable Style/MutableConstant
OK_RESPONSE
=
[
200
,
{
'Content-Type'
=>
'text/plain'
},
[
"GitLab
is alive
"
]]
OK_RESPONSE
=
[
200
,
{
'Content-Type'
=>
'text/plain'
},
[
"GitLab
OK
"
]]
EMPTY_RESPONSE
=
[
404
,
{
'Content-Type'
=>
'text/plain'
},
[
""
]]
# rubocop:enable Style/MutableConstant
LIVENESS_PATH
=
'/-/liveness
'
HEALTH_PATH
=
'/-/health
'
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
return
@app
.
call
(
env
)
unless
env
[
'PATH_INFO'
]
==
LIVENESS
_PATH
return
@app
.
call
(
env
)
unless
env
[
'PATH_INFO'
]
==
HEALTH
_PATH
request
=
Rack
::
Request
.
new
(
env
)
...
...
spec/controllers/health_controller_spec.rb
View file @
22d44ae9
...
...
@@ -109,4 +109,55 @@ describe HealthController do
end
end
end
describe
'#liveness'
do
shared_context
'endpoint responding with liveness data'
do
subject
{
get
:liveness
}
it
'responds with liveness checks data'
do
subject
expect
(
json_response
[
'db_check'
][
'status'
]).
to
eq
(
'ok'
)
expect
(
json_response
[
'cache_check'
][
'status'
]).
to
eq
(
'ok'
)
expect
(
json_response
[
'queues_check'
][
'status'
]).
to
eq
(
'ok'
)
expect
(
json_response
[
'shared_state_check'
][
'status'
]).
to
eq
(
'ok'
)
end
end
context
'accessed from whitelisted ip'
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
whitelisted_ip
)
end
it_behaves_like
'endpoint responding with liveness data'
end
context
'accessed from not whitelisted ip'
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
not_whitelisted_ip
)
end
it
'responds with resource not found'
do
get
:liveness
expect
(
response
.
status
).
to
eq
(
404
)
end
context
'accessed with valid token'
do
context
'token passed in request header'
do
before
do
request
.
headers
[
'TOKEN'
]
=
token
end
it_behaves_like
'endpoint responding with liveness data'
end
context
'token passed as URL param'
do
it_behaves_like
'endpoint responding with liveness data'
do
subject
{
get
:liveness
,
token:
token
}
end
end
end
end
end
end
spec/lib/gitlab/middleware/
liveness
_health_check_spec.rb
→
spec/lib/gitlab/middleware/
basic
_health_check_spec.rb
View file @
22d44ae9
require
'spec_helper'
describe
Gitlab
::
Middleware
::
Liveness
HealthCheck
do
describe
Gitlab
::
Middleware
::
Basic
HealthCheck
do
let
(
:app
)
{
double
(
:app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
let
(
:env
)
{
{}
}
...
...
@@ -12,7 +12,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
end
it
'returns a 404'
do
env
[
'PATH_INFO'
]
=
described_class
::
LIVENESS
_PATH
env
[
'PATH_INFO'
]
=
described_class
::
HEALTH
_PATH
response
=
middleware
.
call
(
env
)
...
...
@@ -34,7 +34,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
end
it
'returns 200 response when endpoint is hit'
do
env
[
'PATH_INFO'
]
=
described_class
::
LIVENESS
_PATH
env
[
'PATH_INFO'
]
=
described_class
::
HEALTH
_PATH
expect
(
app
).
not_to
receive
(
:call
)
...
...
@@ -42,7 +42,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
expect
(
response
[
0
]).
to
eq
(
200
)
expect
(
response
[
1
]).
to
eq
({
'Content-Type'
=>
'text/plain'
})
expect
(
response
[
2
]).
to
eq
([
'GitLab
is alive
'
])
expect
(
response
[
2
]).
to
eq
([
'GitLab
OK
'
])
end
it
'forwards the call for other paths'
do
...
...
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