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
1
Merge Requests
1
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
nexedi
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
...
@@ -18,8 +18,9 @@ class HealthController < ActionController::Base
end
end
def
liveness
def
liveness
# This should never be called; it should be intercepted by LivenessHealthCheck middleware
results
=
CHECKS
.
map
{
|
check
|
[
check
.
name
,
check
.
liveness
]
}
head
:not_found
render_check_results
(
results
)
end
end
def
storage_check
def
storage_check
...
...
changelogs/unreleased/sh-simplify-liveness-check.yml
View file @
22d44ae9
---
---
title
:
Simplify /-/liveness check to avoid connecting to the database
title
:
Add /-/health basic health check endpoint
merge_request
:
merge_request
:
20456
author
:
author
:
type
:
chang
ed
type
:
add
ed
config/application.rb
View file @
22d44ae9
...
@@ -156,7 +156,7 @@ module Gitlab
...
@@ -156,7 +156,7 @@ module Gitlab
# This middleware needs to precede ActiveRecord::QueryCache and other middlewares that
# This middleware needs to precede ActiveRecord::QueryCache and other middlewares that
# connect to the database.
# 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
.
middleware
.
insert_after
Warden
::
Manager
,
Rack
::
Attack
...
...
config/routes.rb
View file @
22d44ae9
...
@@ -46,7 +46,8 @@ Rails.application.routes.draw do
...
@@ -46,7 +46,8 @@ Rails.application.routes.draw do
get
'health_check(/:checks)'
=>
'health_check#index'
,
as: :health_check
get
'health_check(/:checks)'
=>
'health_check#index'
,
as: :health_check
scope
path:
'-'
do
scope
path:
'-'
do
get
'liveness'
=>
'health#liveness'
# Intercepted via Gitlab::Middleware::LivenessHealthCheck
# '/-/health' implemented by BasicHealthMiddleware
get
'liveness'
=>
'health#liveness'
get
'readiness'
=>
'health#readiness'
get
'readiness'
=>
'health#readiness'
post
'storage_check'
=>
'health#storage_check'
post
'storage_check'
=>
'health#storage_check'
resources
:metrics
,
only:
[
:index
]
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
...
@@ -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
]
.
[
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:
With default whitelist settings, the probes can be accessed from localhost:
-
`http://localhost/-/health`
-
`http://localhost/-/readiness`
-
`http://localhost/-/readiness`
-
`http://localhost/-/liveness`
-
`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:
Readiness example output:
...
@@ -57,12 +67,29 @@ Readiness example output:
...
@@ -57,12 +67,29 @@ Readiness example output:
}
}
```
```
The liveness endpoint only checks whether the application server is running. It does
Liveness example output:
not verify the database or other services are running. A successful response with return
a 200 status code with the following message:
```
```
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
## Status
...
...
lib/gitlab/middleware/
liveness
_health_check.rb
→
lib/gitlab/middleware/
basic
_health_check.rb
View file @
22d44ae9
...
@@ -9,20 +9,20 @@
...
@@ -9,20 +9,20 @@
module
Gitlab
module
Gitlab
module
Middleware
module
Middleware
class
Liveness
HealthCheck
class
Basic
HealthCheck
# This can't be frozen because Rails::Rack::Logger wraps the body
# This can't be frozen because Rails::Rack::Logger wraps the body
# rubocop:disable Style/MutableConstant
# 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'
},
[
""
]]
EMPTY_RESPONSE
=
[
404
,
{
'Content-Type'
=>
'text/plain'
},
[
""
]]
# rubocop:enable Style/MutableConstant
# rubocop:enable Style/MutableConstant
LIVENESS_PATH
=
'/-/liveness
'
HEALTH_PATH
=
'/-/health
'
def
initialize
(
app
)
def
initialize
(
app
)
@app
=
app
@app
=
app
end
end
def
call
(
env
)
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
)
request
=
Rack
::
Request
.
new
(
env
)
...
...
spec/controllers/health_controller_spec.rb
View file @
22d44ae9
...
@@ -109,4 +109,55 @@ describe HealthController do
...
@@ -109,4 +109,55 @@ describe HealthController do
end
end
end
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
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'
require
'spec_helper'
describe
Gitlab
::
Middleware
::
Liveness
HealthCheck
do
describe
Gitlab
::
Middleware
::
Basic
HealthCheck
do
let
(
:app
)
{
double
(
:app
)
}
let
(
:app
)
{
double
(
:app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
let
(
:env
)
{
{}
}
let
(
:env
)
{
{}
}
...
@@ -12,7 +12,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
...
@@ -12,7 +12,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
end
end
it
'returns a 404'
do
it
'returns a 404'
do
env
[
'PATH_INFO'
]
=
described_class
::
LIVENESS
_PATH
env
[
'PATH_INFO'
]
=
described_class
::
HEALTH
_PATH
response
=
middleware
.
call
(
env
)
response
=
middleware
.
call
(
env
)
...
@@ -34,7 +34,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
...
@@ -34,7 +34,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
end
end
it
'returns 200 response when endpoint is hit'
do
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
)
expect
(
app
).
not_to
receive
(
:call
)
...
@@ -42,7 +42,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
...
@@ -42,7 +42,7 @@ describe Gitlab::Middleware::LivenessHealthCheck do
expect
(
response
[
0
]).
to
eq
(
200
)
expect
(
response
[
0
]).
to
eq
(
200
)
expect
(
response
[
1
]).
to
eq
({
'Content-Type'
=>
'text/plain'
})
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
end
it
'forwards the call for other paths'
do
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