Skip to content

Commit

Permalink
Allow to customize ringpop stats prefix (#320)
Browse files Browse the repository at this point in the history
Add a `statPrefix`-option to ringpop's constructor to override the `statPrefix` used for stats
  • Loading branch information
yulunli authored and mennopruijssers committed Apr 12, 2017
1 parent c08eb9b commit e5f092a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ function RingPop(options) {
this.serverRate = new metrics.Meter();
this.totalRate = new metrics.Meter();

// 10.30.8.26:20600 -> 10_30_8_26_20600
this.statHostPort = this.hostPort.replace(/\.|:/g, '_');
this.statPrefix = 'ringpop.' + this.statHostPort;
if (options.statPrefix) {
this.statPrefix = options.statPrefix;
} else {
// 10.30.8.26:20600 -> 10_30_8_26_20600
this.statHostPort = this.hostPort.replace(/\.|:/g, '_');
this.statPrefix = 'ringpop.' + this.statHostPort;
}
this.statKeys = {};
this.statsHooks = {};

Expand Down
14 changes: 14 additions & 0 deletions test/unit/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,17 @@ test('selfEvict initiates self evict sequence', function t(assert) {
ringpop.destroy();
assert.end();
});

test('statPrefix overrides default stats prefix', function t(assert) {
var ringpop = createRingpop();
assert.equals('ringpop.127_0_0_1_3000', ringpop.statPrefix, 'statPrefix is the default');
ringpop.destroy();

var customPrefix = 'random.prefix';
ringpop = createRingpop({
statPrefix: customPrefix
});
assert.equals(customPrefix, ringpop.statPrefix, 'statPrefix is customized');
ringpop.destroy();
assert.end();
});

0 comments on commit e5f092a

Please sign in to comment.