Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.

Commit cd24cf7

Browse files
committed
Take AM feedbacks
1 parent 797ef31 commit cd24cf7

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

ops/health-check-route.s.md

+20-15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
# Why
66

7-
In order to monitor correctly their environments, some Cloud services require a HealthCheck route which returns a status depending on how the API is running.
7+
In order to monitor correctly their environments, backend services require a HealthCheck route which returns a status depending on how the API is running.
88

99
## Checks
1010

11-
- [ ] Do a call to every DB used by the API
11+
- [ ] Make a call to every database used by the API
1212
- [ ] Send a 2xx status code status in case of API running correctly and 5xx status code if not
13-
- [ ] Do the less data usage DB calls
14-
- [ ] Include a timestamp in order not to reduce the number of successive calls
13+
- [ ] Make the less data usage database calls: the health check route is likely to be called very often in short period of time
1514

1615
## Examples
1716

@@ -27,14 +26,13 @@ app.get("/health-check", (req, res) => {
2726

2827
- There is no call to any of the two databases
2928
- There is no 5xx status code if the API is not running
30-
- There is not timestamp hence the route may be called successively every seconds
3129

3230
### Example 2: Bad example
3331

3432
```javascript
3533
app.get("/health", async (req, res) => {
3634
try {
37-
await findAllDataCollectors(); // DataCollectors ~ 100 entries
35+
await RDS.getAllEntries();
3836
res.status(200).send({ status: "OK" });
3937
} catch (error) {
4038
res.status(503).send({ status: "KO" });
@@ -44,25 +42,32 @@ app.get("/health", async (req, res) => {
4442

4543
- There is a call to one of the database but not the other
4644
- The call is using too much data
47-
- There is no timestamp
4845
- There is a 503 if the DB is down
4946

5047
### Example 3: Good example
5148

5249
```javascript
5350
app.get("/health", async (req, res) => {
5451
try {
55-
if (nextFetchingDate && nextFetchingDate > Date.now()) {
56-
return res.status(200).send({ status: 200, message: "OK" });
57-
}
58-
59-
nextFetchingDate = Date.now() + TIME_CHECKING_INTERVAL;
60-
await Promise.all([AppsDynamoRepo.getDynamoHealth(), getHealth()]);
61-
52+
await Promise.all([DynamoDB.getDynamoHealth(), RDS.getHealth()]);
6253
res.status(200).send({ status: 200, message: "OK" });
6354
} catch (error) {
64-
nextFetchingDate = Date.now();
6555
handleError(res, error, { status: 503, error: error.message, message: "KO" });
6656
}
6757
});
58+
59+
RDS.getHealth = async () => {
60+
await knex.raw("select 1+1 as result");
61+
};
62+
63+
DynamoDB.getDynamoHealth = (): Promise<Array<Object>> => {
64+
return new Promise((resolve, reject) => {
65+
dynamodb.describeTable({ TableName: dynamodbTableName }, (error, data) => {
66+
if (error) {
67+
return reject(error);
68+
}
69+
resolve(data);
70+
});
71+
});
72+
};
6873
```

0 commit comments

Comments
 (0)