This repository was archived by the owner on Jan 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Write HealthCheck route #154
Open
Arlevoy
wants to merge
4
commits into
master
Choose a base branch
from
health-check-route
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # [Standard] Writing a health check route | ||
|
|
||
| ## Owner: Arthur Levoyer | ||
|
|
||
| # Why | ||
|
|
||
| In order to monitor correctly their environments, backend services require a HealthCheck route which returns a status depending on how the API is running. | ||
|
|
||
| ## Checks | ||
|
|
||
| - [ ] Make a call to every database used by the API | ||
| - [ ] Send a 2xx status code status in case of API running correctly and 5xx status code if not | ||
| - [ ] Make the less data usage database calls: the health check route is likely to be called very often in short period of time | ||
|
||
|
|
||
| ## Examples | ||
|
|
||
| In the examples below the API is concentrating calls to one database RDS and one DynamoDB | ||
|
||
|
|
||
| ### Example 1: Bad example | ||
|
|
||
| ```javascript | ||
| app.get("/health-check", (req, res) => { | ||
| res.status(200).send({ status: "OK" }); | ||
| }); | ||
| ``` | ||
|
|
||
| - There is no call to any of the two databases | ||
| - There is no 5xx status code if the API is not running | ||
|
|
||
| ### Example 2: Bad example | ||
|
|
||
| ```javascript | ||
| app.get("/health", async (req, res) => { | ||
| try { | ||
| await RDS.getAllEntries(); | ||
| res.status(200).send({ status: "OK" }); | ||
| } catch (error) { | ||
| res.status(503).send({ status: "KO" }); | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| - There is a call to one of the database but not the other | ||
| - The call is using too much data | ||
| - There is a 503 if the DB is down | ||
|
||
|
|
||
| ### Example 3: Good example | ||
|
|
||
| ```javascript | ||
| app.get("/health", async (req, res) => { | ||
| try { | ||
| await Promise.all([DynamoDB.getDynamoHealth(), RDS.getHealth()]); | ||
| res.status(200).send({ status: 200, message: "OK" }); | ||
| } catch (error) { | ||
| handleError(res, error, { status: 503, error: error.message, message: "KO" }); | ||
| } | ||
| }); | ||
|
|
||
| RDS.getHealth = async () => { | ||
| await knex.raw("select 1+1 as result"); | ||
| }; | ||
|
|
||
| DynamoDB.getDynamoHealth = (): Promise<Array<Object>> => { | ||
|
||
| return new Promise((resolve, reject) => { | ||
| dynamodb.describeTable({ TableName: dynamodbTableName }, (error, data) => { | ||
| if (error) { | ||
| return reject(error); | ||
| } | ||
| resolve(data); | ||
| }); | ||
| }); | ||
| }; | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send a 2xx status code status if the API is running correctly, 5xx status code if not