Skip to content

Commit

Permalink
change: add "collect" fn, make scrape fns async, ...
Browse files Browse the repository at this point in the history
* Adds a `collect` fn, which may be async, to each metric type. This provides a cleaner interface than registering collectors, and allows the collector to do asynchronous work. (Previously it would be one scrape behind if it had to do async work.)

* In turn, makes `registry.metrics()` and `registry.get...` async, and removes the `collectors`/`registerCollector` functions.

* Fixes `process_max_fds` and `process_start_time_seconds` so that they have values after the registry is reset (same vein as #238)

* Cleans up the readme a bit (removes some out-of-date info)
  • Loading branch information
zbjornson committed Jul 4, 2020
1 parent 20ec702 commit 2e94b01
Show file tree
Hide file tree
Showing 44 changed files with 880 additions and 822 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,38 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Breaking

- changed: The following functions are now async (return a promise):
`registry.metrics()`
`registry.getMetricsAsJSON()`
`registry.getMetricsAsArray()`
`registry.getSingleMetricAsString()`

If your metrics server has a line like `res.send(register.metrics())`, you
should change it to `res.send(await register.metrics())`.

Additionally, all metric types now accept an optional `collect` function,
which is called when the metric's value should be collected and within which
you should set the metric's value. You should provide a `collect` function for
point-in-time metrics (e.g. current memory usage, as opposed to HTTP request
durations that are continuously logged in a histogram).

- changed: `register.clusterMetrics()` no longer accepts a callback; it only
returns a promise.

- removed: v12.0.0 added the undocumented functions `registry.registerCollector`
and `registry.collectors()`. These have been removed. If you were using them,
you should instead provide a `collect` function as described above.

### Changed

- fix: provide nodejs_version_info metrics after calling `registry.resetMetrics()` (#238)
- fix: provide nodejs_version_info metric value after calling `registry.resetMetrics()` (#238)
- fix: provide process_max_fds metric value after calling `registry.resetMetrics()`
- fix: provide process_start_time_seconds metric value after calling `registry.resetMetrics()`
- chore: improve performance of `registry.getMetricAsPrometheusString`
- chore: refactor metrics to reduce code duplication
- chore: replace `utils.getPropertiesFromObj` with `Object.values`
- chore: remove unused `catch` bindings
- chore: upgrade Prettier to 2.x

### Added

Expand Down
Loading

0 comments on commit 2e94b01

Please sign in to comment.