Skip to content

Commit

Permalink
Merge pull request #38 from SkynetLabs/clean-up-codebase
Browse files Browse the repository at this point in the history
refactor async code and skynet-js
  • Loading branch information
kwypchlo authored Oct 5, 2022
2 parents 493eecb + 496dcf2 commit 0208b24
Show file tree
Hide file tree
Showing 15 changed files with 2,385 additions and 2,996 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,44 @@
# Webportal Health Check

This repo contains the health checks that are run on the Skynet Webportals

## Services composition

### HTTP API server

This service includes a standalone HTTP server that exposes health check API endpoints.

> executing `node src` runs the server
By default the server runs on 0.0.0.0 port 3100 but you can configure those settings with environment variables `HOSTNAME` and `PORT`.

#### API endpoints

- `/health-check` returns current health check status (shows only failed checks if any), response code will be 200 when status is up and 503 otherwise
- `/health-check/critical` returns critical checks (last 24 hours)
- `/health-check/extended` returns extended checks (last 24 hours)
- `/health-check/disabled` returns information whether server is set to disabled

### Checks

There are 2 types of checks in this service:

- [critical](src/checks/critical.js): quick and cheap to run, failure of those checks should result in server being marked as failing (disabled)
- [extended](src/checks/extended.js): set of popular or common skylinks that should be checked against less frequently to ensure server is in good condition

### CLI

This service includes a [cli](bin/cli) binary that is accessible from `bin` directory and exposes some of the service' functionalities.

- `bin/cli` displays available commands
- `bin/cli run [critical|extended]` executes health checks of given type
- `bin/cli enable` toggles the health check `disabled` flag to `false`
- `bin/cli disable <reason>` toggles the health check `disabled` flag on with a given reason (ie. "down for maintenance")

There are also cli scripts in `cli` directory but those should be considered deprecated and are kept only for backwards compatibility.

## Docker image

Image of this service is available on [dockerhub](https://hub.docker.com/repository/docker/skynetlabs/webportal-health-check) and is built from Dockerfile file found in root directory of this repository.

Docker image includes running HTTP API server in foreground and crontab configuration for running critical checks every 5 minutes and extended checks every 60 minutes. It also exposes `cli` binary directly on the container so you can use it like `docker exec health-check cli enable`.
3 changes: 2 additions & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ require("yargs/yargs")(process.argv.slice(2))

const entry = {
date: new Date().toISOString(),
checks: (await Promise.all(checks.map((check) => new Promise(check)))).filter(Boolean).map(middleware),
// run all checks, filter empty responses (skipped) and pass the response through the middleware
checks: (await Promise.all(checks.map((check) => check()))).filter(Boolean).map(middleware),
};

db.read() // read before writing to make sure no external changes are overwritten
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"blakejs": "^1.2.1",
"deep-object-diff": "^1.1.7",
"express": "^4.18.1",
"form-data": "^4.0.0",
"got": "^11.8.2",
"got": "^11.8.3",
"graceful-fs": "^4.2.10",
"hasha": "^5.2.2",
"http-status-codes": "^2.2.0",
"lodash": "^4.17.21",
"lowdb": "^1.0.0",
"skynet-js": "^4.3.0",
"tus-js-client": "^3.0.0",
"pbkdf2-hmac": "^1.0.4",
"tus-js-client": "^3.0.1",
"tweetnacl": "^1.0.3",
"write-file-atomic": "^4.0.1",
"yargs": "^17.5.1"
"yargs": "^17.6.0"
},
"devDependencies": {
"jest": "^29.0.1",
"jest": "^29.1.2",
"prettier": "^2.7.1"
},
"scripts": {
Expand Down
Loading

0 comments on commit 0208b24

Please sign in to comment.