Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new custom configuration for routes #25

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,20 @@ jobs:
run: npm run lint
- name: Build
run: npm run build

test:
runs-on: ubuntu-latest
name: Test
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install with npm
run: npm install
- name: Test
run: npm run test
11 changes: 0 additions & 11 deletions .prettierrc

This file was deleted.

106 changes: 81 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,119 @@
</div>

## Installation
__Note: Arecibo version 1 supports version 2 of Fastify. Arecibo version 2 supports version 3 of Fastify.__

__Note: Arecibo version 2 supports Fastify versions 3 and 4.__

| Arecibo version | Fastify version | Branch |
| -- | -- | -- |
| [v2](https://github.com/ducktors/arecibo/releases/tag/v2.2.0) | Fastify 3 & 4 | [master](https://github.com/ducktors/arecibo/tree/master) |
| [v1.1.0](https://github.com/ducktors/arecibo/releases/tag/v1.1.0) | Fastify 2 | deprecated |

| [v1.1.0](https://github.com/ducktors/arecibo/releases/tag/v1.1.0) | Fastify 2 | deprecated |

```bash
npm i arecibo
```

## Usage in Node.js

Arecibo now supports two configurations: basic and specific.

### Basic Configuration

The basic configuration provides a single `/healthz` route for general health checks.

```javascript
const fastify = require('fastify')()
const arecibo = require('arecibo')
// or import arecibo from 'arecibo'
// or import * as arecibo from 'arecibo'

fastify.register(arecibo, {
message: 'Put here your custom message', // optional, default to original arecibo message
readinessURL: '/put/here/your/custom/url', // optional, deafult to /arecibo/readiness
livenessURL: '/put/here/your/custom/url', // optional, deafult to /arecibo/liveness
readinessCallback: (req, reply) => reply.type('text/html').send('Put here your custom message'), // optional
livenessCallback: (req, reply) => reply.type('text/html').send('Put here your custom message'), // optional
logLevel: 'error', // optional, defaults to 'info'; can be trace, debug, info, warn, error, and fatal
probeType: 'basic', // Use basic configuration
message: 'Custom health check message', // optional
healthzURL: '/custom-healthz', // optional, default is '/healthz'
healthzCallback: (req, reply) => reply.type('text/html').send('Custom health check response'), // optional
logLevel: 'error', // optional, defaults to 'info'
})
```

### Specific Configuration

The specific configuration provides separate routes for readiness, liveness, and startup probes.

```javascript
const fastify = require('fastify')()
const arecibo = require('arecibo')

fastify.register(arecibo, {
probeType: 'specific', // Use specific configuration
message: 'Custom probe message', // optional
readinessURL: '/custom-readiness', // optional, default is '/arecibo/readiness'
livenessURL: '/custom-liveness', // optional, default is '/arecibo/liveness'
startupURL: '/custom-startup', // optional, default is '/arecibo/startup'
readinessCallback: (req, reply) => reply.type('text/html').send('Custom readiness response'), // optional
livenessCallback: (req, reply) => reply.type('text/html').send('Custom liveness response'), // optional
startupCallback: (req, reply) => reply.type('text/html').send('Custom startup response'), // optional
logLevel: 'error', // optional, defaults to 'info'
})
```
### Note for typescript users

If you set `"esModuleInterop": true` you must import this module using `import arecibo from 'arecibo'`.
### Options

- `probeType`: 'basic' or 'specific' (required)
- `message`: Custom message for all probes (optional)
- `healthzURL`: Custom URL for the health check in basic configuration (optional)
- `readinessURL`: Custom URL for the readiness probe (optional)
- `livenessURL`: Custom URL for the liveness probe (optional)
- `startupURL`: Custom URL for the startup probe (optional)
- `healthzCallback`: Custom callback for the health check (optional)
- `readinessCallback`: Custom callback for the readiness probe (optional)
- `livenessCallback`: Custom callback for the liveness probe (optional)
- `startupCallback`: Custom callback for the startup probe (optional)
- `logLevel`: Log level for the routes (optional, defaults to 'info')

## On Kubernetes add deployment manifest
### Note for TypeScript users

If you set `"esModuleInterop": true` in your `tsconfig.json`, you must import this module using `import arecibo from 'arecibo'`.

## Kubernetes Deployment Manifest

For the basic configuration:

```yaml
...
livenessProbe:
httpGet:
path: /healthz
port: 80
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 15
...
```

For the specific configuration:

```yaml
...
livenessProbe:
httpGet:
path: /arecibo/liveness
port: 80
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 15
timeoutSeconds: 1
periodSeconds: 15
readinessProbe:
httpGet:
path: /arecibo/readiness
port: 80
httpHeaders:
- name: X-Custom-Header
value: Awesome
initialDelaySeconds: 5
timeoutSeconds: 1
periodSeconds: 15

startupProbe:
httpGet:
path: /arecibo/startup
port: 80
initialDelaySeconds: 5
failureThreshold: 30
periodSeconds: 10
...
```

Expand All @@ -92,11 +146,13 @@ feat: new feature ---> 1.x.0
fix: fix a bug ---> 1.0.x
```


## Reference
* <a href="https://github.com/fastify/fastify">Fastify</a>
* <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/">Configure Liveness and Readiness Probes</a>
* <a href="https://www.youtube.com/watch?v=mxEvAPQRwhw">Kubernetes Health Checks with Readiness and Liveness Probes (Kubernetes Best Practices)</a>

- [Fastify](https://github.com/fastify/fastify)

- [Configure Liveness, Readiness and Startup Probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)
- [Kubernetes Health Checks with Readiness and Liveness Probes (Kubernetes Best Practices)](https://www.youtube.com/watch?v=mxEvAPQRwhw)

## Fun fact: where does the name come from?

The name is inspired by the Arecibo message, a 1974 interstellar radio message carrying basic information about humanity and Earth sent to globular star cluster M13 in the hope that extraterrestrial intelligence might receive and decipher it. The message was broadcast into space a single time via frequency modulated radio waves at a ceremony to mark the remodelling of the Arecibo radio telescope in Puerto Rico on 16 November 1974.
182 changes: 182 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"formatter": {
"ignore": [
".vscode",
"lib/**"
],
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto"
},
"organizeImports": {
"ignore": [
".vscode",
"lib/**"
],
"enabled": true
},
"linter": {
"ignore": [
".vscode",
"lib/**"
],
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"noBannedTypes": "error",
"noUselessThisAlias": "error",
"noUselessTypeConstraint": "error",
"useLiteralKeys": "off",
"noForEach": "off",
"useOptionalChain": "off",
"noUselessTernary": "off",
"useArrowFunction": "off"
},
"correctness": {
"noPrecisionLoss": "error",
"noUnusedImports": "error",
"noUnusedVariables": "off",
"noConstAssign": "off",
"noGlobalObjectCalls": "off",
"noInvalidConstructorSuper": "off",
"noNewSymbol": "off",
"noSetterReturn": "off",
"noUndeclaredVariables": "off",
"noUnreachable": "off",
"noUnreachableSuper": "off",
"noUnnecessaryContinue": "off"
},
"performance": {
"noDelete": "off",
"noAccumulatingSpread": "off"
},
"style": {
"noDefaultExport": "error",
"noNamespace": "error",
"useAsConstAssertion": "error",
"noArguments": "error",
"noVar": "error",
"useConst": "error",
"noInferrableTypes": "off",
"noNonNullAssertion": "off",
"useBlockStatements": "off",
"useImportType": "off",
"useTemplate": "off",
"noUnusedTemplateLiteral": "off",
"useNodejsImportProtocol": "off",
"useNumberNamespace": "off"
},
"suspicious": {
"noExtraNonNullAssertion": "error",
"noMisleadingInstantiator": "error",
"noUnsafeDeclarationMerging": "error",
"noExplicitAny": "off",
"noImplicitAnyLet": "off",
"noDuplicateClassMembers": "off",
"noDuplicateObjectKeys": "off",
"noDuplicateParameters": "off",
"noFunctionAssign": "off",
"noImportAssign": "off",
"noRedeclare": "off",
"noUnsafeNegation": "off",
"useGetterReturn": "off",
"noGlobalIsNan": "off"
},
"nursery": {
"useImportExtensions": {
"level": "error",
"fix": "none"
}
}
}
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
},
"css": {
"formatter": {
"enabled": true
}
},
"overrides": [
{
"include": [
"src/**"
],
"linter": {
"rules": {
"performance": {
"noBarrelFile": "off"
},
"complexity": {
"noStaticOnlyClass": "off",
"noExtraBooleanCast": "off",
"useRegexLiterals": "off"
},
"correctness": {
"noSwitchDeclarations": "off",
"noUnsafeOptionalChaining": "off",
"noSelfAssign": "off",
"noVoidTypeReturn": "off",
"noEmptyPattern": "off"
},
"style": {
"noUselessElse": "off",
"noParameterAssign": "off",
"useDefaultParameterLast": "off",
"noCommaOperator": "off"
},
"suspicious": {
"noAssignInExpressions": "off",
"noDoubleEquals": "off",
"noThenProperty": "off",
"noDuplicateCase": "off",
"noSelfCompare": "off"
}
}
}
},
{
"include": [
"*.json"
],
"json": {
"formatter": {
"lineWidth": 2
}
}
},
{
"include": [
"*.yaml",
"*.yml"
],
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
]
}
7 changes: 7 additions & 0 deletions extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"biomejs.biome",
"redhat.vscode-yaml",
"aaron-bond.better-comments"
]
}
Loading