Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: siimon/prom-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.2.0
Choose a base ref
...
head repository: siimon/prom-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.2.1
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 27, 2017

  1. Copy the full SHA
    dbaac7b View commit details
  2. Update changelog for release

    SimenB committed Oct 27, 2017

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3c522d3 View commit details
  3. 10.2.1

    SimenB committed Oct 27, 2017

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    5e5c8cf View commit details
Showing with 23 additions and 29 deletions.
  1. +6 −1 CHANGELOG.md
  2. +14 −13 lib/cluster.js
  3. +1 −1 package.json
  4. +2 −14 test/clusterTest.js
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Changed
### Added

## [10.2.1] - 2017-10-27
### Changed
- Only resolve/reject `clusterMetrics` promise if no callback is provided

## [10.2.0] - 2017-10-16
### Changed
- Don't add event listeners if cluster module is not used.
@@ -84,7 +88,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Creating metrics with one argument per parameter - use object literals instead.


[Unreleased]: https://github.com/siimon/prom-client/compare/v10.2.0...HEAD
[Unreleased]: https://github.com/siimon/prom-client/compare/v10.2.1...HEAD
[10.2.1]: https://github.com/siimon/prom-client/compare/v10.2.0...v10.2.1
[10.2.0]: https://github.com/siimon/prom-client/compare/v10.1.1...v10.2.0
[10.1.1]: https://github.com/siimon/prom-client/compare/v10.1.0...v10.1.1
[10.1.0]: https://github.com/siimon/prom-client/compare/v10.0.4...v10.1.0
27 changes: 14 additions & 13 deletions lib/cluster.js
Original file line number Diff line number Diff line change
@@ -37,29 +37,31 @@ class AggregatorRegistry extends Registry {
clusterMetrics(callback) {
const requestId = requestCtr++;

callback = callback || function() {};

return new Promise((resolve, reject) => {
const nWorkers = Object.keys(cluster.workers).length;

function done(err, result) {
// Don't resolve/reject the promise if a callback is provided
if (typeof callback === 'function') {
callback(err, result);
} else {
if (err) reject(err);
else resolve(result);
}
}

if (nWorkers === 0) {
return process.nextTick(() => {
callback(null, '');
resolve('');
});
return process.nextTick(() => done(null, ''));
}

const request = {
responses: [],
pending: nWorkers,
callback,
resolve,
reject,
done,
errorTimeout: setTimeout(() => {
request.failed = true;
const err = new Error('Operation timed out.');
request.callback(err);
reject(err);
request.done(err);
}, 5000),
failed: false
};
@@ -166,8 +168,7 @@ function addListeners() {

const registry = AggregatorRegistry.aggregate(request.responses);
const promString = registry.metrics();
request.callback(null, promString);
request.resolve(promString);
request.done(null, promString);
}
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prom-client",
"version": "10.2.0",
"version": "10.2.1",
"description": "Client for prometheus",
"main": "index.js",
"files": [
16 changes: 2 additions & 14 deletions test/clusterTest.js
Original file line number Diff line number Diff line change
@@ -21,27 +21,15 @@ describe('AggregatorRegistry', () => {
it('works properly if there are no cluster workers', done => {
const AggregatorRegistry = require('../lib/cluster');
const ar = new AggregatorRegistry();
let cbCalled = false;
let promiseResolved = false;
let tickElapsed = false;
process.nextTick(() => {
tickElapsed = true;
});
const maybeDone = () => {
if (cbCalled && promiseResolved) done();
};
const ret = ar.clusterMetrics((err, metrics) => {
cbCalled = true;
ar.clusterMetrics((err, metrics) => {
expect(tickElapsed).toBe(true);
expect(err).toBeNull();
expect(metrics).toEqual('');
maybeDone();
});
ret.then(metrics => {
promiseResolved = true;
expect(tickElapsed).toBe(true);
expect(metrics).toEqual('');
maybeDone();
done();
});
});
});