opossum-prometheus
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,2 +5,22 @@ # Changelog | ||
## [0.2.0](https://github.com/lholmquist/opossum-prometheus/compare/v0.1.0...v0.2.0) (2020-04-23) | ||
### ⚠ BREAKING CHANGES | ||
* Options object is now used to configure custom registry and initial circuits | ||
* docs: Updates and adds documentation for options object configuration | ||
### Features | ||
* adds option for performance metrics so they can be disabled, default is enabled ([#20](https://github.com/lholmquist/opossum-prometheus/issues/20)) ([2437eca](https://github.com/lholmquist/opossum-prometheus/commit/2437eca65e7e5d55d3685f213c24e589827d2899)) | ||
* Use options object for all configuration ([#19](https://github.com/lholmquist/opossum-prometheus/issues/19)) ([b353a59](https://github.com/lholmquist/opossum-prometheus/commit/b353a5907212a5eabae420ff4ef06c105f953d3f)) | ||
### Bug Fixes | ||
* upgrade standard-version from 7.0.0 to 7.1.0 ([#17](https://github.com/lholmquist/opossum-prometheus/issues/17)) ([2b68517](https://github.com/lholmquist/opossum-prometheus/commit/2b68517ae6902837ff9d94cbcbab11621fba920d)) | ||
* upgrade tape from 4.11.0 to 4.13.2 ([#16](https://github.com/lholmquist/opossum-prometheus/issues/16)) ([6233d53](https://github.com/lholmquist/opossum-prometheus/commit/6233d53041727d8b44126b061a18cc411642bb34)) | ||
## [0.1.0](https://github.com/lholmquist/opossum-prometheus/compare/v0.0.4...v0.1.0) (2020-03-13) | ||
@@ -7,0 +27,0 @@ |
39
index.js
@@ -14,10 +14,6 @@ 'use strict'; | ||
class PrometheusMetrics { | ||
constructor (circuits, registry) { | ||
if (circuits instanceof client.Registry) { | ||
registry = circuits; | ||
circuits = undefined; | ||
} | ||
this._registry = registry || client.register; | ||
constructor (options = {}) { | ||
this._registry = options.registry || client.register; | ||
this._client = client; | ||
this._options = options; | ||
this._counter = new this._client.Counter({ | ||
@@ -30,10 +26,12 @@ name: `circuit`, | ||
this._summary = new this._client.Summary({ | ||
name: `circuit_perf`, | ||
help: `A summary of all circuit's events`, | ||
registers: [this._registry], | ||
labelNames: ['name', 'event'] | ||
}); | ||
if (this.exposePerformanceMetrics()) { | ||
this._summary = new this._client.Summary({ | ||
name: `circuit_perf`, | ||
help: `A summary of all circuit's events`, | ||
registers: [this._registry], | ||
labelNames: ['name', 'event'] | ||
}); | ||
} | ||
if (!registry) { | ||
if (!options.registry) { | ||
this.interval = this._client | ||
@@ -43,7 +41,13 @@ .collectDefaultMetrics({ prefix: 'opossum_', timeout: 5000 }); | ||
if (circuits) { | ||
this.add(circuits); | ||
if (options.circuits) { | ||
this.add(options.circuits); | ||
} | ||
} | ||
exposePerformanceMetrics () { | ||
return this._options === undefined || | ||
this._options.exposePerformanceMetrics === undefined || | ||
this._options.exposePerformanceMetrics; | ||
} | ||
add (circuits) { | ||
@@ -61,3 +65,4 @@ if (!circuits) { | ||
if (eventName === 'success' || eventName === 'failure') { | ||
if (this.exposePerformanceMetrics() && | ||
(eventName === 'success' || eventName === 'failure')) { | ||
// not the timeout event because runtime == timeout | ||
@@ -64,0 +69,0 @@ circuit.on(eventName, (result, runTime) => { |
{ | ||
"name": "opossum-prometheus", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Prometheus metrics for opossum circuit breaker", | ||
@@ -32,6 +32,6 @@ "main": "index.js", | ||
"opossum": "^5.0.0", | ||
"standard-version": "^7.0.0", | ||
"standard-version": "^7.1.0", | ||
"standardx": "^5.0.0", | ||
"tap-spec": "^5.0.0", | ||
"tape": "^4.11.0" | ||
"tape": "^4.13.2" | ||
}, | ||
@@ -38,0 +38,0 @@ "dependencies": { |
@@ -30,3 +30,3 @@ # Prometheus Metrics for Opossum Circuit Breaker | ||
// Provide them to the constructor | ||
const prometheus = new PrometheusMetrics([c1, c2]); | ||
const prometheus = new PrometheusMetrics({ circuits: [c1, c2] }); | ||
@@ -62,4 +62,17 @@ //... | ||
const circuit = new CircuitBreaker(functionThatMightFail); | ||
const metrics = new PrometheusMetrics(circuit, registry) | ||
const metrics = new PrometheusMetrics({ circuits: [circuit], registry: registry }) | ||
``` | ||
## Options | ||
The `PrometheusMetrics` constructor takes an options object as detailed below. | ||
```js | ||
const options = {}; | ||
new PrometheusMetrics(options) | ||
``` | ||
|Name |Description |Default | | ||
|--------------------------|------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| | ||
|`circuits` |A list or individual circuit breaker to create metrics for |No circuits | | ||
|`registry` |An existing registry to use for prometheus metrics |`undefined` - The default prometheus registry will be used and default system metrics will be collected| | ||
|`exposePerformanceMetrics`|Measure the performance of breakers and report them through the registry|true | |
@@ -36,3 +36,3 @@ 'use strict'; | ||
const c1 = new CircuitBreaker(passFail, { name: 'fred' }); | ||
const prometheus = new PrometheusMetrics(c1); | ||
const prometheus = new PrometheusMetrics({ circuits: c1 }); | ||
await c1.fire(1); | ||
@@ -51,3 +51,3 @@ t.equal(c1.name, 'fred'); | ||
const c2 = new CircuitBreaker(passFail, { name: 'bob' }); | ||
const prometheus = new PrometheusMetrics([c1, c2]); | ||
const prometheus = new PrometheusMetrics({ circuits: [c1, c2] }); | ||
await c1.fire(1); | ||
@@ -74,3 +74,6 @@ await c2.fire(1); | ||
}); | ||
const prometheus = new PrometheusMetrics([c1, c2], registry); | ||
const prometheus = new PrometheusMetrics({ | ||
circuits: [c1, c2], | ||
registry: registry | ||
}); | ||
await c1.fire(1); | ||
@@ -111,3 +114,3 @@ await c2.fire(1); | ||
const c3 = new CircuitBreaker(passFail, { name: 'foo' }); | ||
const prometheus = new PrometheusMetrics([c1]); | ||
const prometheus = new PrometheusMetrics({ circuits: [c1] }); | ||
prometheus.add([c2, c3]); | ||
@@ -144,3 +147,3 @@ await c1.fire(1); | ||
const failure = /circuit\{name="passFail",event="failure"\} 1/; | ||
const prometheus = new PrometheusMetrics([circuit]); | ||
const prometheus = new PrometheusMetrics({ circuits: [circuit] }); | ||
t.plan(3); | ||
@@ -164,3 +167,3 @@ circuit.fire(1) | ||
}; | ||
const prometheus = new PrometheusMetrics([circuit]); | ||
const prometheus = new PrometheusMetrics({ circuits: [circuit] }); | ||
const metrics = prometheus.metrics; | ||
@@ -178,3 +181,3 @@ t.plan(circuit.eventNames().length); | ||
const circuit = new CircuitBreaker(passFail); | ||
const prometheus = new PrometheusMetrics([circuit]); | ||
const prometheus = new PrometheusMetrics({ circuits: [circuit] }); | ||
const metrics = prometheus.metrics; | ||
@@ -202,3 +205,6 @@ const names = [ | ||
const circuit = new CircuitBreaker(passFail); | ||
const prometheus = new PrometheusMetrics([circuit], registry); | ||
const prometheus = new PrometheusMetrics({ | ||
circuits: [circuit], | ||
registry: registry | ||
}); | ||
const metrics = prometheus.metrics; | ||
@@ -225,3 +231,3 @@ const names = [ | ||
const registry = new Registry(); | ||
const prometheus = new PrometheusMetrics(registry); | ||
const prometheus = new PrometheusMetrics({ registry: registry }); | ||
const metrics = prometheus.metrics; | ||
@@ -258,3 +264,3 @@ const names = [ | ||
const circuit = new CircuitBreaker(passFail); | ||
const prometheus = new PrometheusMetrics([circuit]); | ||
const prometheus = new PrometheusMetrics({ circuits: [circuit] }); | ||
const metrics = prometheus.metrics; | ||
@@ -281,1 +287,46 @@ const names = [ | ||
}); | ||
test('Performance metrics are not created when disabled', | ||
async t => { | ||
t.plan(3); | ||
const c1 = new CircuitBreaker(passFail, { name: 'fred' }); | ||
const prometheus = new PrometheusMetrics({ | ||
circuits: [c1], | ||
exposePerformanceMetrics: false | ||
}); | ||
await c1.fire(1); | ||
t.equal(c1.name, 'fred'); | ||
t.ok(/circuit.*fred/.test(prometheus.metrics)); | ||
t.notOk(/circuit_perf.*fred/.test(prometheus.metrics)); | ||
prometheus.clear(); | ||
t.end(); | ||
}); | ||
test('Performance metrics are created when not configured in options', | ||
async t => { | ||
t.plan(3); | ||
const c1 = new CircuitBreaker(passFail, { name: 'fred' }); | ||
const prometheus = new PrometheusMetrics({ circuits: [c1] }); | ||
await c1.fire(1); | ||
t.equal(c1.name, 'fred'); | ||
t.ok(/circuit.*fred/.test(prometheus.metrics)); | ||
t.ok(/circuit_perf.*fred/.test(prometheus.metrics)); | ||
prometheus.clear(); | ||
t.end(); | ||
}); | ||
test('Performance metrics are created when enabled in options', | ||
async t => { | ||
t.plan(3); | ||
const c1 = new CircuitBreaker(passFail, { name: 'fred' }); | ||
const prometheus = new PrometheusMetrics({ | ||
circuits: [c1], | ||
exposePerformanceMetrics: true | ||
}); | ||
await c1.fire(1); | ||
t.equal(c1.name, 'fred'); | ||
t.ok(/circuit.*fred/.test(prometheus.metrics)); | ||
t.ok(/circuit_perf.*fred/.test(prometheus.metrics)); | ||
prometheus.clear(); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25782
373
76