When trying to register a second instance with the same name, then just take the old one. Upgrade prom-client to 6.2.x. Bump 1.2.3

This commit is contained in:
Konstantin Pogorelov
2016-12-06 10:10:14 +01:00
parent c918b44c2b
commit 190bf0be31
3 changed files with 21 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "1.2.2",
"version": "1.2.3",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"keywords": [
@@ -16,7 +16,7 @@
"license": "MIT",
"dependencies": {
"on-finished": "^2.3.0",
"prom-client": "^6.1.2",
"prom-client": "^6.2.0",
"url-value-parser": "^1.0.0"
},
"devDependencies": {

View File

@@ -49,5 +49,17 @@ describe("PromFactory", () => {
expect(metric.help).toBe("help for test4");
expect(metric.percentiles).toEqual([0.1, 0.5]);
});
it("when regsitered with same name, just return old instance", () => {
const metric1 = factory.newSummary(
"test4",
"help for test4",
{percentiles: [0.1, 0.5]}
);
const metric2 = factory.newSummary(
"test4",
"help for test4",
{percentiles: [0.1, 0.5]}
);
expect(metric1).toBe(metric2);
});
});

View File

@@ -15,6 +15,12 @@ module.exports = class {
const applyParams = Array.prototype.slice.call(args);
const name = applyParams[0];
const realName = this.makeRealName(name);
const existing = this.promClient.register.getSingleMetric(realName);
if (existing) {
return existing;
}
applyParams[0] = realName;
applyParams.unshift(null); // add some dummy context for apply