Skip to content

Commit

Permalink
[server] Add a liveness and readiness urls
Browse files Browse the repository at this point in the history
Add 2 new url endpoints:
 - `localhost:8001/live`: simply say that the server is running. In case of succes it will response with 200 status code and a `CODECHECKER_SERVER_IS_LIVE` message.
 - `localhost:8001/ready`: it will run a simple query on the database. In case of success it will response with 200 status code and a `CODECHECKER_SERVER_IS_READY` message. In case of error it will response with 500 error code and a `CODECHECKER_SERVER_IS_NOT_READY` error message.
  • Loading branch information
csordasmarton committed Oct 30, 2019
1 parent 10d5902 commit d64471c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
Binary file added docs/images/kubernetes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions docs/web/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ packaged with all its dependencies and libraries.
To see how you can run a CodeChecker server in Docker read the following
sections.

## Table of Contents
* [Build Docker image](#build-docker-image)
* [Pre-built CodeChecker Docker images](#pre-built-codechecker-docker-images)
* [Usage](#usage)
* [Docker compose](#docker-compose)
* [docker-compose.yml](#docker-composeyml)
* [Sqlite setup](#sqlite-setup)
* [PostgreSQL setup](#postgresql-setup)
* [PostgreSQL (no authentication)](#postgresql-no-authentication)
* [PostgreSQL (authentication)](#postgresql-authentication)
* [Running your app](#running-your-app)
* [Kubernetes](#kubernetes)

## Build Docker image
You can create a Docker image by running the following command in the root
directory of this repository:
Expand Down Expand Up @@ -110,3 +123,20 @@ previously created password files for secrets.
### Running your app
Run `docker-compose -f web/docker/services/<service-yml-file> up -d` and
Compose starts and runs your entire app.

## Kubernetes
[![Kubernetes](../images/kubernetes.png)](https://kubernetes.io/)

CodeChecker supports to configure liveness, readiness and startup probes for
containers when using
[Kubernetes]( https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/).

If your server is running on `my.company.org` at `8080` port then two URL
endpoints will be available for you:
* `my.company.org:8080/live`: simply say that the server is running. In case of
succes it will response with `200` status code and a
`CODECHECKER_SERVER_IS_LIVE` message.
* `my.company.org:8080/ready`: it will run a simple query on the database. In
case of success it will response with `200` status code and a
`CODECHECKER_SERVER_IS_READY` message. In case of error it will response with
`500` error code and a `CODECHECKER_SERVER_IS_NOT_READY` error message.
4 changes: 3 additions & 1 deletion web/server/codechecker_server/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
'scripts',
'style',
'userguide',
'docs']
'docs',
'live',
'ready']

# A list of top-level path elements in requests (such as Thrift endpoints)
# which should not be considered as a product route.
Expand Down
35 changes: 34 additions & 1 deletion web/server/codechecker_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
from .api.report_server import ThriftRequestHandler as ReportHandler_v6
from .database import database
from .database import db_cleanup
from .database.config_db_model import Product as ORMProduct
from .database.config_db_model import Product as ORMProduct, \
Configuration as ORMConfiguration
from .database.run_db_model import IDENTIFIER as RUN_META, Run, RunLock

LOG = get_logger('server')
Expand Down Expand Up @@ -154,6 +155,30 @@ def __has_access_permission(self, product):
perm_args,
self.auth_session)

def __handle_readiness(self):
""" Handle readiness probe. """
try:
cfg_sess = self.server.config_session()
cfg_sess.query(ORMConfiguration).count()

self.send_response(200)
self.end_headers()
self.wfile.write('CODECHECKER_SERVER_IS_READY')
except Exception:
self.send_response(500)
self.end_headers()
self.wfile.write('CODECHECKER_SERVER_IS_NOT_READY')
finally:
if cfg_sess:
cfg_sess.close()
cfg_sess.commit()

def __handle_liveness(self):
""" Handle liveness probe. """
self.send_response(200)
self.end_headers()
self.wfile.write('CODECHECKER_SERVER_IS_LIVE')

def end_headers(self):
# Sending the authentication cookie
# in every response if any.
Expand Down Expand Up @@ -189,6 +214,14 @@ def do_GET(self):

product_endpoint, path = routing.split_client_GET_request(self.path)

if self.path == '/live':
self.__handle_liveness()
return

if self.path == '/ready':
self.__handle_readiness()
return

if self.server.manager.is_enabled and not self.auth_session \
and routing.is_protected_GET_entrypoint(path):
# If necessary, prompt the user for authentication.
Expand Down

0 comments on commit d64471c

Please sign in to comment.