mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-03-18 21:30:38 +01:00
minor dep. upgrade, do not remove initial metrics if they match the requested prefix (i.e. recognized as own metrics), bump 1.2.2
This commit is contained in:
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "express-prom-bundle",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "express middleware with popular prometheus metrics in one bundle",
|
||||
"main": "src/index.js",
|
||||
"keywords": [
|
||||
@@ -20,10 +20,10 @@
|
||||
"url-value-parser": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^2.11.12",
|
||||
"eslint": "^3.11.0",
|
||||
"express": "^4.13.4",
|
||||
"istanbul": "^0.4.4",
|
||||
"coveralls": "^2.11.15",
|
||||
"eslint": "^3.11.1",
|
||||
"express": "^4.14.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"jasme": "^5.2.0",
|
||||
"koa": "^1.2.4",
|
||||
"koa-connect": "^1.0.0",
|
||||
|
||||
@@ -9,6 +9,17 @@ const c2k = require("koa-connect");
|
||||
const supertestKoa = require("supertest-koa-agent");
|
||||
const promClient = require("prom-client");
|
||||
|
||||
// had to reinvent, because getSingleMetric() is still not in npm
|
||||
function myGetSingleMetric(name) {
|
||||
let returnMetric;
|
||||
promClient.register.getMetricsAsJSON().forEach(metric => {
|
||||
if (metric.name === name) {
|
||||
returnMetric = metric;
|
||||
}
|
||||
});
|
||||
return returnMetric;
|
||||
}
|
||||
|
||||
describe("index", () => {
|
||||
beforeEach(() => {
|
||||
promClient.register.clear();
|
||||
@@ -146,6 +157,29 @@ describe("index", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("initial metrics removal", () => {
|
||||
it("removes unexpected metrics on start with no prefix", () => {
|
||||
new promClient.Counter("foo", "bar");
|
||||
expect(myGetSingleMetric("foo")).toBeDefined();
|
||||
bundle();
|
||||
expect(myGetSingleMetric("foo")).not.toBeDefined();
|
||||
});
|
||||
|
||||
it("removes unexpected metrics on start with a prefix", () => {
|
||||
new promClient.Counter("foo", "bar");
|
||||
expect(myGetSingleMetric("foo")).toBeDefined();
|
||||
bundle({prefix: "some_test_"});
|
||||
expect(myGetSingleMetric("foo")).not.toBeDefined();
|
||||
});
|
||||
|
||||
it("doesnt remove metrics with matched prefix", () => {
|
||||
new promClient.Counter("some_test_foo", "bar");
|
||||
expect(myGetSingleMetric("some_test_foo")).toBeDefined();
|
||||
bundle({prefix: "some_test_"});
|
||||
expect(myGetSingleMetric("some_test_foo")).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("tolerates includePath, includeMethod and keepDefaultMetrics", done => {
|
||||
const app = express();
|
||||
const instance = bundle({
|
||||
|
||||
10
src/index.js
10
src/index.js
@@ -51,10 +51,16 @@ function main(opts) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove default metrics provided by prom-client
|
||||
// this is a really messy hack but needed for compatibility with v1
|
||||
// will be completely removed in v2
|
||||
if (!opts.keepDefaultMetrics) {
|
||||
const metrics = promClient.register.getMetricsAsJSON();
|
||||
clearInterval(promClient.defaultMetrics());
|
||||
promClient.register.clear();
|
||||
metrics.forEach(metric => {
|
||||
if (!opts.prefix || metric.name.substr(0, opts.prefix.length) != opts.prefix) {
|
||||
promClient.register.removeSingleMetric(metric.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const factory = new PromFactory(opts);
|
||||
|
||||
Reference in New Issue
Block a user