Skip to content

Commit

Permalink
feat: add prom-client 13 and 14 to peer deps (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Sep 6, 2023
1 parent 332e811 commit 563d07d
Show file tree
Hide file tree
Showing 7 changed files with 904 additions and 34 deletions.
12 changes: 10 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ workflows:
- test:
matrix:
parameters:
node-version: ['6', '8', '10', '12', '14', '16', '18', '19']
prom-client-version: ['10', '11', '12']
node-version: ['6', '8', '10', '12', '14', '16', '18', '19', '20']
prom-client-version: ['10', '11', '12', '13', '14']
exclude:
- node-version: '6'
prom-client-version: '12'
- node-version: '6'
prom-client-version: '13'
- node-version: '6'
prom-client-version: '14'
- node-version: '8'
prom-client-version: '13'
- node-version: '8'
prom-client-version: '14'
orbs:
node: circleci/[email protected]
version: 2.1
Expand Down
17 changes: 15 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
{
"extends": ["simenb-base", "simenb-node", "simenb-jest"],
"extends": [
"simenb-base",
"simenb-node",
"simenb-jest"
],
"rules": {
// Not supported in node 4
"prefer-destructuring": "off"
}
},
"overrides": [
{
"files": "test.js",
"rules": {
// Jest transpiles
"node/no-unsupported-features/es-syntax": "off"
}
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Usage

This module has a peer dependency on [`prom-client`](https://github.com/siimon/prom-client). Currently, 10 is supported.
This module has a peer dependency on [`prom-client`](https://github.com/siimon/prom-client). Currently, 10-14 is supported.

This module follows the same API as the core default metrics. To start collection GC stats, invoke the exported function to create the
metrics, then invoke the returned function to start the collecting.
Expand Down
5 changes: 5 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@
"optional": "^0.1.3"
},
"peerDependencies": {
"prom-client": ">= 10 <= 12"
"prom-client": ">= 10 <= 14"
},
"devDependencies": {
"@babel/core": "^7.22.15",
"@babel/preset-env": "^7.22.15",
"babel-jest": "^24.0.0",
"eslint": "^5.6.0",
"eslint-config-simenb-base": "^15.0.0",
"eslint-config-simenb-jest": "^3.0.0",
"eslint-config-simenb-node": "^2.0.0",
"jest": "^24.0.0",
"prettier": "^1.4.4",
"prom-client": "^12.0.0"
"prom-client": "^14.0.0"
},
"jest": {
"testEnvironment": "node"
Expand Down
25 changes: 13 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,35 @@ afterEach(() => {
promRegister.clear();
});

test('register metrics', () => {
expect(promRegister.getMetricsAsJSON()).toHaveLength(0);
test('register metrics', async () => {
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);

gcMetrics();

expect(promRegister.getMetricsAsJSON()).toHaveLength(3);
expect(await promRegister.getMetricsAsJSON()).toHaveLength(3);
});

test('register metrics to custom register', () => {
test('register metrics to custom register', async () => {
const register = new PromRegistry();

expect(promRegister.getMetricsAsJSON()).toHaveLength(0);
expect(register.getMetricsAsJSON()).toHaveLength(0);
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);
expect(await register.getMetricsAsJSON()).toHaveLength(0);

gcMetrics(register);

expect(promRegister.getMetricsAsJSON()).toHaveLength(0);
expect(register.getMetricsAsJSON()).toHaveLength(3);
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);
expect(await register.getMetricsAsJSON()).toHaveLength(3);
});

test('include prefix', () => {
expect(promRegister.getMetricsAsJSON()).toHaveLength(0);
test('include prefix', async () => {
expect(await promRegister.getMetricsAsJSON()).toHaveLength(0);

gcMetrics(undefined, { prefix: 'prefix_' });

expect(promRegister.getMetricsAsJSON()).toHaveLength(3);
const metricsAsJson = await promRegister.getMetricsAsJSON();
expect(metricsAsJson).toHaveLength(3);

expect(promRegister.getMetricsAsJSON().map(metric => metric.name)).toEqual([
expect(metricsAsJson.map(metric => metric.name)).toEqual([
'prefix_nodejs_gc_runs_total',
'prefix_nodejs_gc_pause_seconds_total',
'prefix_nodejs_gc_reclaimed_bytes_total',
Expand Down
Loading

0 comments on commit 563d07d

Please sign in to comment.