Skip to content

Commit

Permalink
v1.3.0 Add Fastify support (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic authored Apr 19, 2024
1 parent 7fcec03 commit bda7894
Show file tree
Hide file tree
Showing 36 changed files with 24,790 additions and 108 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/bull.yml

This file was deleted.

49 changes: 38 additions & 11 deletions .github/workflows/express.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
name: Express Adapter
name: Express adapter tests

on:
push:
paths:
- 'express/**'
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
branches: [main]
pull_request: {}

jobs:
specs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: ArtiomTr/jest-coverage-report-action@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
# We can't use `cache: npm` because setup-node doesn't support our monorepo setup
node-version: ${{ matrix.node-version }}

- name: Cache node modules
uses: actions/cache@v2
with:
working-directory: ./express
annotations: none
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}

- name: Prepare local dependency
run: |
npm install
npm run build
npm link
working-directory: node-core

- name: Install dependencies & link local dependency
run: |
npm install
npm link judoscale-node-core
working-directory: express

- name: Run tests
run: npm test
working-directory: express
49 changes: 49 additions & 0 deletions .github/workflows/fastify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Fastify adapter tests

on:
push:
branches: [main]
pull_request: {}

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]
fastify-version: [3.x, 4.x]

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
# We can't use `cache: npm` because setup-node doesn't support our monorepo setup
node-version: ${{ matrix.node-version }}

- name: Cache node modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}

- name: Prepare local dependency
run: |
npm install
npm run build
npm link
working-directory: node-core

- name: Install dependencies & link local dependency
run: |
npm install
npm install fastify@${{ matrix.fastify-version }}
npm link judoscale-node-core
working-directory: fastify

- name: Run tests
run: npm test
working-directory: fastify
42 changes: 32 additions & 10 deletions .github/workflows/node-core.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
name: Node Core
name: Core adapter tests

on:
push:
paths:
- 'node-core/**'
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
pull_request: {}

jobs:
specs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]

defaults:
run:
working-directory: node-core

steps:
- uses: actions/checkout@v3
- uses: ArtiomTr/jest-coverage-report-action@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
working-directory: ./node-core
annotations: none
# We can't use `cache: npm` because setup-node doesn't support our monorepo setup
node-version: ${{ matrix.node-version }}

- name: Cache node modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
run: npm install
working-directory: node-core

- name: Run tests
run: npm test
working-directory: node-core
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Judoscale

These packages work together with the [Judoscale](https://judoscale.com) Heroku add-on to scale your web and worker dynos automatically. They gather a minimal set of metrics for each request or job queue, and periodically report this data asynchronously to the Judoscale API.
These packages work together with the [Judoscale](https://judoscale.com) autoscaling service to scale your web and worker services automatically. They gather a minimal set of metrics for each request or job queue, and periodically report this data asynchronously to the Judoscale API.

## Supported frameworks

- [Express](https://github.com/judoscale/judoscale-node/tree/main/express)
- [Fastify](https://github.com/judoscale/judoscale-node/tree/main/fastify)

## What data is collected?

The following data is submitted periodically to the Judoscale API:

- Node and framework versions
- Judoscale package versions
- Dyno name (example: web.1)
- Dyno or service name (example: web.1)
- PID
- Queue time metrics

Expand All @@ -32,7 +33,7 @@ In production, run `heroku logs -t | grep Judoscale`, and you should see somethi
If you don't see any Judoscale logging, check the following:

- Make sure "judoscale-express" is in your `Package.lock` file, and restart your app.
- Make sure a Judoscale package is present in your `Package.lock` file, and restart your app.
- Make sure Judoscale is one of the first middlewares for your app.

You can see more detailed (debug) logging by setting `JUDOSCALE_LOG_LEVEL` on your Heroku app:
Expand Down
26 changes: 26 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status.
set -e

# Print each command before executing it:
set -x

cd node-core
npm install
npm link
npm run build

cd ../express
npm link judoscale-node-core
npm install
npm run build

cd ../fastify
npm link judoscale-node-core
npm install

cd ../bull
npm link judoscale-node-core
npm install
npm run build
20 changes: 10 additions & 10 deletions bull/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions bull/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "judoscale-bull",
"version": "1.1.0",
"version": "1.3.0",
"description": "Bull adapter for the JudoScale autoscaling add-on for Heroku",
"main": "dist/index.js",
"scripts": {
Expand All @@ -13,8 +13,8 @@
"heroku",
"autoscale"
],
"author": "Carlos Marques",
"license": "ISC",
"author": "Adam McCrea",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.17.6",
"@babel/core": "^7.17.5",
Expand All @@ -29,7 +29,7 @@
"dependencies": {
"async": "^2.6.3",
"bull": "^4.8.1",
"judoscale-node-core": "^1.0.5",
"judoscale-node-core": "1.3.0",
"redis": "^4.0.6",
"unirest": "^0.6.0",
"winston": "^3.6.0"
Expand Down
12 changes: 2 additions & 10 deletions express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,18 @@ app.use(judoscale())
// custom configuration (see config options below)
app.use(
judoscale({
report_interval_seconds: 5,
log_level: 'debug',
})
)
```

## Configuration

Most Judoscale settings are handled via the Judoscale dashboard, but there a few ways you can configure the adapter in code:
Most Judoscale settings are handled via the Judoscale dashboard, but there are a few ways you can configure the adapter in code:

```javascript
app.use(
judoscale({
// Specify how frequently data is sent to Judoscale.
// Default: 10
report_interval_seconds: 5,

// Specify the API endpoint.
// Default: process.env.JUDOSCALE_URL
api_base_url: 'https://judoscale-node.requestcatcher.com',

// Use a custom logger instance
// Default: Winston logger instance (simple format)
logger: myLogger,
Expand Down
20 changes: 10 additions & 10 deletions express/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bda7894

Please sign in to comment.