mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-01-18 16:27:28 +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:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user