Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

opossum-prometheus

Package Overview
Dependencies
Maintainers
10
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opossum-prometheus - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

.github/workflows/nodejs-ci-action.yml

36

CHANGELOG.md

@@ -5,2 +5,38 @@ # Changelog

## [0.4.0](https://github.com/nodeshift/opossum-prometheus/compare/v0.3.0...v0.4.0) (2024-04-08)
### ⚠ BREAKING CHANGES
* Drop support for Node.js v14
Update prom-client to v15
metrics is now an async function
* drop Node.js 12
### Features
* support Node.js v20 ([#78](https://github.com/nodeshift/opossum-prometheus/issues/78)) ([1f3e050](https://github.com/nodeshift/opossum-prometheus/commit/1f3e0503c616a57b77eef8e8e31634e2ae79f598))
* upgrade opossum from 5.1.3 to 6.2.1 ([#62](https://github.com/nodeshift/opossum-prometheus/issues/62)) ([88e13d5](https://github.com/nodeshift/opossum-prometheus/commit/88e13d5a1e3f4a9cb87375e97c1be8f5742de522))
* using semistandard and greenkeeper badge removed ([bdfe980](https://github.com/nodeshift/opossum-prometheus/commit/bdfe9809dd46eac7d8cc4161ef2c21f4b5a1029f))
### Bug Fixes
* package.json & package-lock.json to reduce vulnerabilities ([#56](https://github.com/nodeshift/opossum-prometheus/issues/56)) ([5c57b1e](https://github.com/nodeshift/opossum-prometheus/commit/5c57b1e22a1147355c9cf983dcfc06ac4fd7cf7a))
* upgrade coveralls from 3.1.0 to 3.1.1 ([#51](https://github.com/nodeshift/opossum-prometheus/issues/51)) ([1bcbaae](https://github.com/nodeshift/opossum-prometheus/commit/1bcbaae923eea55c2e4b6159f2612c9890c54669))
* upgrade opossum from 5.0.0 to 5.0.1 ([#33](https://github.com/nodeshift/opossum-prometheus/issues/33)) ([e9e700a](https://github.com/nodeshift/opossum-prometheus/commit/e9e700ad77c7919c7de51234c3ce43ad5e26ee9f))
* upgrade opossum from 5.0.1 to 5.0.2 ([#36](https://github.com/nodeshift/opossum-prometheus/issues/36)) ([c45d4b1](https://github.com/nodeshift/opossum-prometheus/commit/c45d4b14970734474c78b31a6470a3073a79b3e7))
* upgrade opossum from 5.0.2 to 5.1.0 ([#38](https://github.com/nodeshift/opossum-prometheus/issues/38)) ([d3f509d](https://github.com/nodeshift/opossum-prometheus/commit/d3f509d313268548c6c5c362548c322d5abb673e))
* upgrade opossum from 5.1.0 to 5.1.1 ([#39](https://github.com/nodeshift/opossum-prometheus/issues/39)) ([ae9f69b](https://github.com/nodeshift/opossum-prometheus/commit/ae9f69b07f35ff07230ef15d7efa14fdbd272301))
* upgrade opossum from 5.1.1 to 5.1.2 ([#43](https://github.com/nodeshift/opossum-prometheus/issues/43)) ([f0c00fe](https://github.com/nodeshift/opossum-prometheus/commit/f0c00fe04518b100fc18f0be32fe7e6fd4cb530e))
* upgrade opossum from 5.1.2 to 5.1.3 ([#44](https://github.com/nodeshift/opossum-prometheus/issues/44)) ([78c826b](https://github.com/nodeshift/opossum-prometheus/commit/78c826b0b941f6a8a8dab142b2c27f3264b6f855))
* upgrade standard-version from 9.0.0 to 9.1.0 ([#40](https://github.com/nodeshift/opossum-prometheus/issues/40)) ([6c694ed](https://github.com/nodeshift/opossum-prometheus/commit/6c694eda67f0e7743c4dcf5001daa1f5955e6106))
* upgrade standard-version from 9.1.0 to 9.3.0 ([#49](https://github.com/nodeshift/opossum-prometheus/issues/49)) ([d29b608](https://github.com/nodeshift/opossum-prometheus/commit/d29b60878b76133bcda3be3d57328993b5c94441))
* upgrade tape from 5.0.1 to 5.1.0 ([#41](https://github.com/nodeshift/opossum-prometheus/issues/41)) ([c51f9d3](https://github.com/nodeshift/opossum-prometheus/commit/c51f9d3e8263b4f47cc7de0a3cd5009152c7ccd4))
* upgrade tape from 5.1.0 to 5.1.1 ([#42](https://github.com/nodeshift/opossum-prometheus/issues/42)) ([d45e86a](https://github.com/nodeshift/opossum-prometheus/commit/d45e86aa0b83d9b333f73f8f4407e43b16cd9452))
* upgrade tape from 5.1.1 to 5.2.2 ([#50](https://github.com/nodeshift/opossum-prometheus/issues/50)) ([ebeeed4](https://github.com/nodeshift/opossum-prometheus/commit/ebeeed431aa4589054d496616898a5241d39ce74))
* drop Node.js 12 ([b14eca3](https://github.com/nodeshift/opossum-prometheus/commit/b14eca32fc996d46f97b3055c295fb77e436b8fb))
## [0.3.0](https://github.com/lholmquist/opossum-prometheus/compare/v0.2.0...v0.3.0) (2020-09-02)

@@ -7,0 +43,0 @@

12

index.js

@@ -36,7 +36,6 @@ 'use strict';

if (!options.registry) {
this.interval = this._client
.collectDefaultMetrics({
prefix: `${this._metricPrefix}opossum_`,
timeout: 5000
});
this._client.collectDefaultMetrics({
prefix: `${this._metricPrefix}opossum_`,
register: this._registry
});
}

@@ -79,7 +78,6 @@

clear () {
clearInterval(this.interval);
this._registry.clear();
}
get metrics () {
metrics () {
return this._registry.metrics();

@@ -86,0 +84,0 @@ }

{
"name": "opossum-prometheus",
"version": "0.3.0",
"version": "0.4.0",
"description": "Prometheus metrics for opossum circuit breaker",
"main": "index.js",
"scripts": {
"prepare": "husky || true",
"lint": "eslint --ignore-path .gitignore .",
"pretest": "npm run lint",
"test": "nyc tape test/*.js | tap-spec",
"coverage": "nyc report && if [ $CODACY_PROJECT_TOKEN'' != '' ] ; then nyc report --reporter=text-lcov | codacy-coverage; fi",
"ci": "npm run test && npm run coverage",
"prerelease": "npm run ci",
"release": "standard-version -s -a",
"lint": "standardx test/*.js index.js"
"prerelease": "npm run test",
"release": "standard-version -a"
},
"repository": {
"type": "git",
"url": "git://github.com/nodeshift/opossum-prometheus.git"
},
"bugs": {
"url": "https://github.com/nodeshift/opossum-prometheus/issues"
},
"support": {

@@ -29,13 +35,22 @@ "target": "LTS",

"devDependencies": {
"codacy-coverage": "^3.4.0",
"coveralls": "^3.1.1",
"eslint": "^8.57.0",
"eslint-config-semistandard": "^17.0.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"husky": "^9.0.11",
"nyc": "^15.1.0",
"opossum": "^5.0.0",
"standard-version": "^9.0.0",
"standardx": "^5.0.0",
"opossum": "^8.1.3",
"standard-version": "^9.5.0",
"tap-spec": "^5.0.0",
"tape": "^5.0.1"
"tape": "^5.7.5"
},
"dependencies": {
"prom-client": "^12.0.0"
"prom-client": "^15.1.0"
},
"engines": {
"node": "^21 || ^20 || ^18 || ^16"
}
}
# Prometheus Metrics for Opossum Circuit Breaker
[![CircleCI](https://circleci.com/gh/nodeshift/opossum-prometheus.svg?style=svg)](https://circleci.com/gh/nodeshift/opossum-prometheus)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6dcbcd9e5a6649faafb5b00ceeecb4db)](https://www.codacy.com/app/nodeshift/opossum-prometheus?utm_source=github.com&utm_medium=referral&utm_content=nodeshift/opossum-prometheus&utm_campaign=Badge_Grade)
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/6dcbcd9e5a6649faafb5b00ceeecb4db)](https://www.codacy.com/app/nodeshift/opossum-prometheus?utm_source=github.com&utm_medium=referral&utm_content=nodeshift/opossum-prometheus&utm_campaign=Badge_Coverage)
[![dependencies Status](https://david-dm.org/nodeshift/opossum-prometheus/status.svg)](https://david-dm.org/nodeshift/opossum-prometheus)
[![Known Vulnerabilities](https://snyk.io/test/npm/opossum-prometheus/badge.svg)](https://snyk.io/test/npm/opossum-prometheus) [![Greenkeeper badge](https://badges.greenkeeper.io/nodeshift/opossum-prometheus.svg)](https://greenkeeper.io/)
![Node.js CI](https://github.com/nodeshift/opossum-prometheus/workflows/Node.js%20CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/nodeshift/opossum-prometheus/badge.svg?branch=main)](https://coveralls.io/github/nodeshift/opossum-prometheus?branch=main)
[![Known Vulnerabilities](https://snyk.io/test/npm/opossum-prometheus/badge.svg)](https://snyk.io/test/npm/opossum-prometheus)

@@ -27,3 +25,3 @@ This module provides [Prometheus](https://prometheus.io/) metrics for

const c1 = new CircuitBreaker(someFunction);
const c2 = new CircuitBreaker(someOtherfunction);
const c2 = new CircuitBreaker(someOtherFunction);

@@ -35,7 +33,7 @@ // Provide them to the constructor

// Provide other circuit breaker later
const c3 = new CircuitBreaker(someOtherfunction3);
prometheus.add([C3]);
const c3 = new CircuitBreaker(someOtherFunction3);
prometheus.add([c3]);
// Write metrics to the console
console.log(prometheus.metrics);
console.log(await prometheus.metrics());
```

@@ -42,0 +40,0 @@

@@ -27,4 +27,4 @@ 'use strict';

const prometheus = new PrometheusMetrics();
t.teardown(() => prometheus.clear());
t.ok(prometheus);
prometheus.clear();

@@ -39,7 +39,8 @@ t.end();

const prometheus = new PrometheusMetrics({ circuits: c1 });
t.teardown(() => prometheus.clear());
await c1.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.ok(/circuit.*fred/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(metrics));
t.ok(/circuit_perf.*fred/.test(metrics));
t.end();

@@ -54,11 +55,12 @@ });

const prometheus = new PrometheusMetrics({ circuits: [c1, c2] });
t.teardown(() => prometheus.clear());
await c1.fire(1);
await c2.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.equal(c2.name, 'bob');
t.ok(/circuit.*fred/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred/.test(prometheus.metrics));
t.ok(/circuit.*bob/.test(prometheus.metrics));
t.ok(/circuit_perf.*bob/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(metrics));
t.ok(/circuit_perf.*fred/.test(metrics));
t.ok(/circuit.*bob/.test(metrics));
t.ok(/circuit_perf.*bob/.test(metrics));
t.end();

@@ -78,17 +80,19 @@ });

circuits: [c1, c2],
registry: registry
registry
});
t.teardown(() => prometheus.clear());
await c1.fire(1);
await c2.fire(1);
const rMetrics = await registry.metrics();
const pMetrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.equal(c2.name, 'bob');
t.ok(/circuit.*fred/.test(registry.metrics()));
t.ok(/circuit_perf.*fred/.test(registry.metrics()));
t.ok(/circuit.*bob/.test(registry.metrics()));
t.ok(/circuit_perf.*bob/.test(registry.metrics()));
t.ok(/circuit.*bob/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred/.test(prometheus.metrics));
t.ok(/circuit.*bob/.test(prometheus.metrics));
t.ok(/circuit_perf.*bob/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(rMetrics));
t.ok(/circuit_perf.*fred/.test(rMetrics));
t.ok(/circuit.*bob/.test(rMetrics));
t.ok(/circuit_perf.*bob/.test(rMetrics));
t.ok(/circuit.*bob/.test(pMetrics));
t.ok(/circuit_perf.*fred/.test(pMetrics));
t.ok(/circuit.*bob/.test(pMetrics));
t.ok(/circuit_perf.*bob/.test(pMetrics));
t.end();

@@ -101,8 +105,9 @@ });

const prometheus = new PrometheusMetrics();
t.teardown(() => prometheus.clear());
prometheus.add(c1);
await c1.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.ok(/circuit.*fred.*/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred.*/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred.*/.test(metrics));
t.ok(/circuit_perf.*fred.*/.test(metrics));
t.end();

@@ -118,2 +123,3 @@ });

const prometheus = new PrometheusMetrics({ circuits: [c1] });
t.teardown(() => prometheus.clear());
prometheus.add([c2, c3]);

@@ -123,25 +129,25 @@ await c1.fire(1);

await c3.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.equal(c2.name, 'bob');
t.equal(c3.name, 'foo');
t.ok(/circuit.*fred/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred/.test(prometheus.metrics));
t.ok(/circuit.*bob/.test(prometheus.metrics));
t.ok(/circuit_perf.*bob/.test(prometheus.metrics));
t.ok(/circuit.*foo/.test(prometheus.metrics));
t.ok(/circuit_perf.*foo/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(metrics));
t.ok(/circuit_perf.*fred/.test(metrics));
t.ok(/circuit.*bob/.test(metrics));
t.ok(/circuit_perf.*bob/.test(metrics));
t.ok(/circuit.*foo/.test(metrics));
t.ok(/circuit_perf.*foo/.test(metrics));
t.end();
});
test('The add function called without parameter do nothing', t => {
test('The add function called without parameter do nothing', async t => {
t.plan(1);
const prometheus = new PrometheusMetrics();
t.teardown(() => prometheus.clear());
prometheus.add();
t.ok(/circuit/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit/.test(await prometheus.metrics()));
t.end();
});
test('Circuit fire/success/failure are counted', t => {
test('Circuit fire/success/failure are counted', async t => {
const circuit = new CircuitBreaker(passFail);

@@ -152,16 +158,17 @@ const fire = /circuit\{name="passFail",event="fire"\} 2/;

const prometheus = new PrometheusMetrics({ circuits: [circuit] });
t.teardown(() => prometheus.clear());
t.plan(3);
circuit.fire(1)
.then(_ => circuit.fire(-1))
.catch(_ => {
const metrics = prometheus.metrics;
t.ok(fire.test(metrics), fire);
t.ok(success.test(metrics), success);
t.ok(failure.test(metrics), failure);
prometheus.clear();
t.end();
});
try {
await circuit.fire(1);
await circuit.fire(-1);
} catch (e) {
const metrics = await prometheus.metrics();
t.ok(fire.test(metrics), fire);
t.ok(success.test(metrics), success);
t.ok(failure.test(metrics), failure);
t.end();
}
});
test('Metrics are enabled for all circuit events', t => {
test('Metrics are enabled for all circuit events', async t => {
const circuit = new CircuitBreaker(passFail);

@@ -172,3 +179,4 @@ circuit.on = (event, callback) => {

const prometheus = new PrometheusMetrics({ circuits: [circuit] });
const metrics = prometheus.metrics;
t.teardown(() => prometheus.clear());
const metrics = await prometheus.metrics();
t.plan(circuit.eventNames().length);

@@ -179,19 +187,23 @@ for (const name of circuit.eventNames()) {

}
prometheus.clear();
t.end();
});
test('Default prometheus metrics are enabled', t => {
test('Default prometheus metrics are enabled', async t => {
const circuit = new CircuitBreaker(passFail);
const prometheus = new PrometheusMetrics({ circuits: [circuit] });
const metrics = prometheus.metrics;
t.teardown(() => prometheus.clear());
const metrics = await prometheus.metrics();
const names = [
'process_cpu_seconds_total',
'process_open_fds',
'process_max_fds',
'process_virtual_memory_bytes',
'process_resident_memory_bytes',
'process_heap_bytes',
'process_start_time_seconds'
];
if (process.platform === 'linux') {
names.concat([
'process_virtual_memory_bytes',
'process_heap_bytes',
'process_open_fds',
'process_max_fds'
]);
}
t.plan(names.length);

@@ -202,7 +214,6 @@ for (const name of names) {

}
prometheus.clear();
t.end();
});
test('Should not add default metrics to custom registry', t => {
test('Should not add default metrics to custom registry', async t => {
const registry = new Registry();

@@ -212,5 +223,6 @@ const circuit = new CircuitBreaker(passFail);

circuits: [circuit],
registry: registry
registry
});
const metrics = prometheus.metrics;
t.teardown(() => prometheus.clear());
const metrics = await prometheus.metrics();
const names = [

@@ -230,10 +242,10 @@ 'process_cpu_seconds_total',

}
prometheus.clear();
t.end();
});
test('Default prometheus metrics are enabled without circuit', t => {
test('Default prometheus metrics are enabled without circuit', async t => {
const registry = new Registry();
const prometheus = new PrometheusMetrics({ registry: registry });
const metrics = prometheus.metrics;
const prometheus = new PrometheusMetrics({ registry });
t.teardown(() => prometheus.clear());
const metrics = await prometheus.metrics();
const names = [

@@ -263,10 +275,10 @@ 'nodejs_eventloop_lag',

}
prometheus.clear();
t.end();
});
test('Node.js specific metrics are enabled', t => {
test('Node.js specific metrics are enabled', async t => {
const circuit = new CircuitBreaker(passFail);
const prometheus = new PrometheusMetrics({ circuits: [circuit] });
const metrics = prometheus.metrics;
t.teardown(() => prometheus.clear());
const metrics = await prometheus.metrics();
const names = [

@@ -289,3 +301,2 @@ 'nodejs_eventloop_lag',

}
prometheus.clear();
t.end();

@@ -302,7 +313,8 @@ });

});
t.teardown(() => prometheus.clear());
await c1.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.ok(/circuit.*fred/.test(prometheus.metrics));
t.notOk(/circuit_perf.*fred/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(metrics));
t.notOk(/circuit_perf.*fred/.test(metrics));
t.end();

@@ -316,7 +328,8 @@ });

const prometheus = new PrometheusMetrics({ circuits: [c1] });
t.teardown(() => prometheus.clear());
await c1.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.ok(/circuit.*fred/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(metrics));
t.ok(/circuit_perf.*fred/.test(metrics));
t.end();

@@ -333,7 +346,8 @@ });

});
t.teardown(() => prometheus.clear());
await c1.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.ok(/circuit.*fred/.test(prometheus.metrics));
t.ok(/circuit_perf.*fred/.test(prometheus.metrics));
prometheus.clear();
t.ok(/circuit.*fred/.test(metrics));
t.ok(/circuit_perf.*fred/.test(metrics));
t.end();

@@ -351,12 +365,13 @@ });

});
t.teardown(() => prometheus.clear());
await c1.fire(1);
await c2.fire(1);
const metrics = await prometheus.metrics();
t.equal(c1.name, 'fred');
t.equal(c2.name, 'bob');
t.ok(/some_prefix_circuit.*fred/.test(prometheus.metrics));
t.ok(/some_prefix_circuit_perf.*fred/.test(prometheus.metrics));
t.ok(/some_prefix_circuit.*bob/.test(prometheus.metrics));
t.ok(/some_prefix_circuit_perf.*bob/.test(prometheus.metrics));
prometheus.clear();
t.ok(/some_prefix_circuit.*fred/.test(metrics));
t.ok(/some_prefix_circuit_perf.*fred/.test(metrics));
t.ok(/some_prefix_circuit.*bob/.test(metrics));
t.ok(/some_prefix_circuit_perf.*bob/.test(metrics));
t.end();
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc