Skip to content

Commit

Permalink
Address comments and fix tests on PR: siimon#482
Browse files Browse the repository at this point in the history
  • Loading branch information
karlodwyer committed Mar 3, 2023
1 parent 17830bc commit ef89282
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 59 deletions.
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ interface MetricConfiguration<T extends string> {
name: string;
help: string;
labelNames?: T[] | readonly T[];
registers?: Registry<PrometheusContentType | OpenMetricsContentType>[];
registers?: (
| Registry<PrometheusContentType>
| Registry<OpenMetricsContentType>
)[];
aggregator?: Aggregator;
collect?: CollectFunction<any>;
enableExemplars?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Registry {
regContentType !== Registry.PROMETHEUS_CONTENT_TYPE &&
regContentType !== Registry.OPENMETRICS_CONTENT_TYPE
) {
throw new TypeError('Content type unsupported');
throw new TypeError(`Content type ${regContentType} is unsupported`);
}
this._contentType = regContentType;
}
Expand Down Expand Up @@ -225,7 +225,7 @@ class Registry {
) {
this._contentType = metricsContentType;
} else {
throw new Error('Content type unsupported');
throw new Error(`Content type ${metricsContentType} is unsupported`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"typescript": "^4.0.2"
},
"dependencies": {
"@opentelemetry/api": "^1.0.2",
"@opentelemetry/api": "^1.4.0",
"tdigest": "^0.1.1"
},
"types": "./index.d.ts",
Expand Down
76 changes: 38 additions & 38 deletions test/__snapshots__/registerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ counter_total 0
gauge 0
# HELP histogram help
# TYPE histogram histogram
histogram_bucket{le=\\"0.005\\"} 0
histogram_bucket{le=\\"0.01\\"} 0
histogram_bucket{le=\\"0.025\\"} 0
histogram_bucket{le=\\"0.05\\"} 0
histogram_bucket{le=\\"0.1\\"} 0
histogram_bucket{le=\\"0.25\\"} 0
histogram_bucket{le=\\"0.5\\"} 0
histogram_bucket{le=\\"1\\"} 0
histogram_bucket{le=\\"2.5\\"} 0
histogram_bucket{le=\\"5\\"} 0
histogram_bucket{le=\\"10\\"} 0
histogram_bucket{le=\\"+Inf\\"} 0
histogram_bucket{le="0.005"} 0
histogram_bucket{le="0.01"} 0
histogram_bucket{le="0.025"} 0
histogram_bucket{le="0.05"} 0
histogram_bucket{le="0.1"} 0
histogram_bucket{le="0.25"} 0
histogram_bucket{le="0.5"} 0
histogram_bucket{le="1"} 0
histogram_bucket{le="2.5"} 0
histogram_bucket{le="5"} 0
histogram_bucket{le="10"} 0
histogram_bucket{le="+Inf"} 0
histogram_sum 0
histogram_count 0
# HELP summary help
# TYPE summary summary
summary{quantile=\\"0.01\\"} 0
summary{quantile=\\"0.05\\"} 0
summary{quantile=\\"0.5\\"} 0
summary{quantile=\\"0.9\\"} 0
summary{quantile=\\"0.95\\"} 0
summary{quantile=\\"0.99\\"} 0
summary{quantile=\\"0.999\\"} 0
summary{quantile="0.01"} 0
summary{quantile="0.05"} 0
summary{quantile="0.5"} 0
summary{quantile="0.9"} 0
summary{quantile="0.95"} 0
summary{quantile="0.99"} 0
summary{quantile="0.999"} 0
summary_sum 0
summary_count 0
# EOF
Expand Down Expand Up @@ -77,30 +77,30 @@ gauge 0
# HELP histogram help
# TYPE histogram histogram
histogram_bucket{le=\\"0.005\\"} 0
histogram_bucket{le=\\"0.01\\"} 0
histogram_bucket{le=\\"0.025\\"} 0
histogram_bucket{le=\\"0.05\\"} 0
histogram_bucket{le=\\"0.1\\"} 0
histogram_bucket{le=\\"0.25\\"} 0
histogram_bucket{le=\\"0.5\\"} 0
histogram_bucket{le=\\"1\\"} 0
histogram_bucket{le=\\"2.5\\"} 0
histogram_bucket{le=\\"5\\"} 0
histogram_bucket{le=\\"10\\"} 0
histogram_bucket{le=\\"+Inf\\"} 0
histogram_bucket{le="0.005"} 0
histogram_bucket{le="0.01"} 0
histogram_bucket{le="0.025"} 0
histogram_bucket{le="0.05"} 0
histogram_bucket{le="0.1"} 0
histogram_bucket{le="0.25"} 0
histogram_bucket{le="0.5"} 0
histogram_bucket{le="1"} 0
histogram_bucket{le="2.5"} 0
histogram_bucket{le="5"} 0
histogram_bucket{le="10"} 0
histogram_bucket{le="+Inf"} 0
histogram_sum 0
histogram_count 0
# HELP summary help
# TYPE summary summary
summary{quantile=\\"0.01\\"} 0
summary{quantile=\\"0.05\\"} 0
summary{quantile=\\"0.5\\"} 0
summary{quantile=\\"0.9\\"} 0
summary{quantile=\\"0.95\\"} 0
summary{quantile=\\"0.99\\"} 0
summary{quantile=\\"0.999\\"} 0
summary{quantile="0.01"} 0
summary{quantile="0.05"} 0
summary{quantile="0.5"} 0
summary{quantile="0.9"} 0
summary{quantile="0.95"} 0
summary{quantile="0.99"} 0
summary{quantile="0.999"} 0
summary_sum 0
summary_count 0
"
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/summaryTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ exports[`summary with OpenMetrics registry global registry with param as object

exports[`summary with OpenMetrics registry global registry with param as object remove should throw error if label lengths does not match 1`] = `"Invalid number of arguments"`;

exports[`summary with OpenMetrics registry global registry with param as object should validate labels when observing 1`] = `"Added label \\"baz\\" is not included in initial labelset: [ 'foo' ]"`;
exports[`summary with OpenMetrics registry global registry with param as object should validate labels when observing 1`] = `"Added label "baz" is not included in initial labelset: [ 'foo' ]"`;

exports[`summary with Prometheus registry global registry with param as object labels should throw error if label lengths does not match 1`] = `"Invalid number of arguments"`;

exports[`summary with Prometheus registry global registry with param as object remove should throw error if label lengths does not match 1`] = `"Invalid number of arguments"`;

exports[`summary with Prometheus registry global registry with param as object should validate labels when observing 1`] = `"Added label \\"baz\\" is not included in initial labelset: [ 'foo' ]"`;
exports[`summary with Prometheus registry global registry with param as object should validate labels when observing 1`] = `"Added label "baz" is not included in initial labelset: [ 'foo' ]"`;
4 changes: 1 addition & 3 deletions test/metrics/eventLoopLagTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe.each([
register.clear();
});

it(`should add metric to the ${tag} registry`, async done => {
it(`should add metric to the ${tag} registry`, async () => {
expect(await register.getMetricsAsJSON()).toHaveLength(0);
eventLoopLag();

Expand Down Expand Up @@ -71,8 +71,6 @@ describe.each([
);
expect(metrics[7].type).toEqual('gauge');
expect(metrics[7].name).toEqual('nodejs_eventloop_lag_p99_seconds');

done();
});
});

Expand Down
5 changes: 1 addition & 4 deletions test/pushgatewayTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,7 @@ describe.each([
'Content-Encoding': 'gzip',
},
})
.post(
'/metrics/job/testJob',
gzipSync('# HELP test test\n# TYPE test counter\ntest 100\n'),
)
.post('/metrics/job/testJob', gzipSync(body))
.reply(200);

instance = new Pushgateway(
Expand Down
15 changes: 7 additions & 8 deletions test/registerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ const Registry = require('../index').Registry;
const register = require('../index').register;

describe('Register', () => {
const contentTypeTestStr =
'application/openmetrics-text; version=42.0.0; charset=utf-8';
const expectedContentTypeErrStr = `Content type ${contentTypeTestStr} is unsupported`;
it('should throw if set to an unsupported type', () => {
expect(() => {
register.setContentType(
'application/openmetrics-text; version=42.0.0; charset=utf-8',
);
}).toThrowError('Content type unsupported');
register.setContentType(contentTypeTestStr);
}).toThrowError(expectedContentTypeErrStr);
});

it('should throw if created with an unsupported type', () => {
expect(() => {
new Registry(
'application/openmetrics-text; version=42.0.0; charset=utf-8',
);
}).toThrowError('Content type unsupported');
new Registry(contentTypeTestStr);
}).toThrowError(expectedContentTypeErrStr);
});

describe.each([
Expand Down

0 comments on commit ef89282

Please sign in to comment.