Skip to content

Commit

Permalink
feat(UMetrics): add prefix and nodejsMetricsEnabled options to facade
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodluckhf committed Oct 8, 2019
1 parent f1256ff commit dff12e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/UMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import Transport from './transport/Transport';
* @property {MetricRegistry} registry
*/
class UMetrics {
constructor(transport, { prefix, labels } = {}) {
constructor(
transport,
{ prefix = null, labels, nodejsMetricsEnabled = false } = {},
) {
if (!transport || !(transport instanceof Transport)) {
throw new Error(
'Transport must be provided and be instance of Transport',
);
}

this.nodejsMetricsEnabled = nodejsMetricsEnabled;
this.prefix = prefix;
this.transport = transport;
this.registry = new MetricRegistry({
prefix,
Expand Down
18 changes: 18 additions & 0 deletions src/UMetrics.server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,22 @@ describe('UMetrics facade', () => {
const realMetric = uMetrics.register(uMetrics.Metrics.Gauge, 'testMetric');
expect(uMetrics.testMetric).to.be.equals(realMetric);
});

it('Should have defaultMetrics disabled by default', () => {
const uMetrics = new UMetrics(new Transport(), { port: 1111 });
expect(uMetrics.nodejsMetricsEnabled).to.be.false;
});

it('Should have metricsPrefix options null by default', () => {
const uMetrics = new UMetrics(new Transport(), { port: 1111 });
expect(uMetrics.prefix).to.be.null;
});

it('Should change metricsPrefix options', () => {
const uMetrics = new UMetrics(new Transport(), {
port: 1111,
prefix: 'test',
});
expect(uMetrics.prefix).to.be.equals('test');
});
});

0 comments on commit dff12e7

Please sign in to comment.