Skip to content

Commit

Permalink
build(deps-dev): replace standard with neostandard (#242)
Browse files Browse the repository at this point in the history
* build(deps-dev): replace standard with neostandard

* chore: add eslint.config.js

* fix linting

---------

Co-authored-by: Aras Abbasi <[email protected]>
  • Loading branch information
Fdawgs and Uzlopak authored Dec 8, 2024
1 parent 2496149 commit ff839b0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/fastify/under-pressure/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/under-pressure/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/under-pressure.svg?style=flat)](https://www.npmjs.com/package/@fastify/under-pressure)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Measure process load with automatic handling of *"Service Unavailable"* plugin for Fastify.
It can check `maxEventLoopDelay`, `maxHeapUsedBytes`, `maxRssBytes` and `maxEventLoopUtilization` values.
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict'

module.exports = require('neostandard')({
ignores: require('neostandard').resolveIgnoresFromGitignore(),
ts: true
})
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"type": "commonjs",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard | snazzy",
"lint:fix": "standard --fix",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:unit": "tap",
"test:typescript": "tsd"
Expand Down Expand Up @@ -37,11 +37,10 @@
"@fastify/pre-commit": "^2.1.0",
"@types/node": "^22.0.0",
"fastify": "^5.0.0",
"neostandard": "^0.11.9",
"semver": "^7.6.0",
"simple-get": "^4.0.1",
"sinon": "^18.0.0",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"tap": "^18.7.2",
"tsd": "^0.31.0"
},
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
FastifyPluginAsync,
FastifyReply,
FastifyRequest
} from "fastify";
} from 'fastify'

declare module "fastify" {
declare module 'fastify' {
interface FastifyInstance {
memoryUsage(): { heapUsed: number; rssBytes: number; eventLoopDelay: number; eventLoopUtilized: number };
isUnderPressure(): boolean;
Expand Down Expand Up @@ -48,5 +48,5 @@ declare namespace fastifyUnderPressure {
export { fastifyUnderPressure as default }
}

declare function fastifyUnderPressure(...params: Parameters<FastifyUnderPressure>): ReturnType<FastifyUnderPressure>
declare function fastifyUnderPressure (...params: Parameters<FastifyUnderPressure>): ReturnType<FastifyUnderPressure>
export = fastifyUnderPressure
76 changes: 39 additions & 37 deletions types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,70 @@
import fastifyUnderPressure, { fastifyUnderPressure as namedFastifyUnderPressure, TYPE_EVENT_LOOP_DELAY, TYPE_EVENT_LOOP_UTILIZATION, TYPE_HEALTH_CHECK, TYPE_HEAP_USED_BYTES, TYPE_RSS_BYTES } from "..";
import fastify from "fastify";
import { expectType } from "tsd";
import fastifyUnderPressure, { fastifyUnderPressure as namedFastifyUnderPressure, TYPE_EVENT_LOOP_DELAY, TYPE_EVENT_LOOP_UTILIZATION, TYPE_HEALTH_CHECK, TYPE_HEAP_USED_BYTES, TYPE_RSS_BYTES } from '..'
import fastify from 'fastify'
import { expectType } from 'tsd'

const server = fastify();

() => {
{
const server = fastify()
server.register(fastifyUnderPressure, {
maxEventLoopDelay: 1000,
maxHeapUsedBytes: 100000000,
maxRssBytes: 100000000
});

server.register(fastifyUnderPressure);
})

server.get("/", (req, reply) => {
server.register(fastifyUnderPressure)

reply.send({ hello: "world", underPressure: server.isUnderPressure() });
});
server.get('/', (req, reply) => {
reply.send({ hello: 'world', underPressure: server.isUnderPressure() })
})

server.listen({port: 3000}, err => {
if (err) throw err;
});
server.listen({ port: 3000 }, err => {
if (err) throw err
})
};

() => {
{
const server = fastify()
server.register(fastifyUnderPressure, {
maxEventLoopDelay: 1000,
message: "Under pressure!",
message: 'Under pressure!',
retryAfter: 50
});
})
};

() => {
const memoryUsage = server.memoryUsage();
console.log(memoryUsage.heapUsed);
console.log(memoryUsage.rssBytes);
console.log(memoryUsage.eventLoopDelay);
{
const server = fastify()
const memoryUsage = server.memoryUsage()
console.log(memoryUsage.heapUsed)
console.log(memoryUsage.rssBytes)
console.log(memoryUsage.eventLoopDelay)
};

() => {
{
const server = fastify()
server.register(fastifyUnderPressure, {
healthCheck: async function (fastifyInstance) {
// do some magic to check if your db connection is healthy, etc...
return fastifyInstance.register === server.register;
return fastifyInstance.register === server.register
},
healthCheckInterval: 500
});
})
};

() => {
{
const server = fastify()
server.register(fastifyUnderPressure, {
sampleInterval: 10
});
})
}

() => {
{
const server = fastify()
server.register(fastifyUnderPressure, {
exposeStatusRoute: '/v2/status',
});
})

server.register(fastifyUnderPressure, {
exposeStatusRoute: true
});
})

server.register(fastifyUnderPressure, {
exposeStatusRoute: {
Expand All @@ -71,15 +74,15 @@ const server = fastify();
},
url: '/alive'
}
});
})

server.register(fastifyUnderPressure, {
exposeStatusRoute: {
routeOpts: {
logLevel: 'silent'
}
}
});
})

server.register(fastifyUnderPressure, {
exposeStatusRoute: {
Expand All @@ -94,7 +97,7 @@ const server = fastify();

server.register(fastifyUnderPressure, {
customError: new Error('custom error message')
});
})

class CustomError extends Error {
constructor () {
Expand All @@ -105,8 +108,8 @@ const server = fastify();

server.register(fastifyUnderPressure, {
customError: CustomError
});
};
})
}

expectType<'eventLoopDelay'>(fastifyUnderPressure.TYPE_EVENT_LOOP_DELAY)
expectType<'heapUsedBytes'>(fastifyUnderPressure.TYPE_HEAP_USED_BYTES)
Expand All @@ -125,4 +128,3 @@ expectType<'heapUsedBytes'>(TYPE_HEAP_USED_BYTES)
expectType<'rssBytes'>(TYPE_RSS_BYTES)
expectType<'healthCheck'>(TYPE_HEALTH_CHECK)
expectType<'eventLoopUtilization'>(TYPE_EVENT_LOOP_UTILIZATION)

0 comments on commit ff839b0

Please sign in to comment.