|
| 1 | +# v2.0.0 Release notes |
| 2 | + |
| 3 | +## Description |
| 4 | + |
| 5 | +This release is centered around removing global state. |
| 6 | + |
| 7 | +## tl;dr |
| 8 | + |
| 9 | +Changes in this release: |
| 10 | + |
| 11 | +- prom-client global state removed |
| 12 | +- .metrics() method added |
| 13 | +- .contentType() method added |
| 14 | +- lint fixing |
| 15 | + |
| 16 | +Usage of this module changes from: |
| 17 | + |
| 18 | +```js |
| 19 | +const promClient = require('prom-client'); |
| 20 | +const metricsConsumer = new PrometheusConsumer({ client: promClient }); |
| 21 | + |
| 22 | +client.pipe(metricsConsumer); |
| 23 | + |
| 24 | +app.get('/metrics', (req, res) => { |
| 25 | + res.set('Content-Type', promClient.register.contentType).send( |
| 26 | + promClient.register.metrics(), |
| 27 | + ); |
| 28 | +}); |
| 29 | +``` |
| 30 | + |
| 31 | +to: |
| 32 | + |
| 33 | +```js |
| 34 | +const promClient = require('prom-client'); |
| 35 | +const metricsConsumer = new PrometheusConsumer({ client: promClient }); |
| 36 | + |
| 37 | +client.pipe(metricsConsumer); |
| 38 | + |
| 39 | +app.get('/metrics', (req, res) => { |
| 40 | + res.set('Content-Type', metricsConsumer.contentType()).send( |
| 41 | + metricsConsumer.metrics(), |
| 42 | + ); |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +## Changes |
| 47 | + |
| 48 | +This release has the following changes |
| 49 | + |
| 50 | +### global state removal |
| 51 | + |
| 52 | +In previous versions, this module used prom-client's global registry to hold all collected metrics. This had the potential to collide with other usages of prom-client. |
| 53 | +In this version, a new isolated registry is created for each consumer instance. |
| 54 | + |
| 55 | +### .metrics() and .contentType() methods added |
| 56 | + |
| 57 | +In order to support using an isolated registry it was necessary to add a method to extract and render gathered metrics for scraping. |
| 58 | +Instead of rendering metrics out of the global registry you can call `.metrics()`. In order to set the correct content type for the content you can use `.contentType()` |
| 59 | + |
| 60 | +_Example_ |
| 61 | + |
| 62 | +```js |
| 63 | +app.get('/metrics', (req, res) => { |
| 64 | + res.set('Content-Type', consumer.contentType()).send(consumer.metrics()); |
| 65 | +}); |
| 66 | +``` |
| 67 | + |
| 68 | +### lint cleanup |
| 69 | + |
| 70 | +Several files were linted to AirBnB standard |
0 commit comments