jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
303 stars 67 forks source link

ability to exclude incoming request from metrics #70

Closed yacineb closed 3 years ago

yacineb commented 3 years ago

Excluding routes by regexp is not handy. Using a filter lambda function is more powerful and generic. It enables instrumenting the api with custom criterias on requests (could be headers, routes etc) In production scenarios a public api is usually exposed to hackers who try to explore/scan routes, in few days the api has its registry full of 404, 403 metrics.

disjunction commented 3 years ago

The idea is good. I'm not sure if the API is intuitive enough. In arrays the .filter() method excludes those elements where filter results in false. In your API it's the opposite.

I would either rename the method to .bypass() so that it's clear: bypass if true, or reverse the logic and also explain it clearer in the readme.

@yacineb what do you think?

disjunction commented 3 years ago

btw in pr #41 there it is called excludeFn(), although i'd rather go your way and bypass the entire middleware.

Also we need to make sure the /metrics route remains no matter what the filter function says. One can remove it by a separate option.

yacineb commented 3 years ago

@disjunction you"re right, i've changed the wording, documentation and added a test case.

Hope it will be accepted, i need this feature ASAP.

Thks & Regards

disjunction commented 3 years ago

OK, thanks for the update. The test is broken, but I'll take it from here.

disjunction commented 3 years ago

I've just published it at npm as version 6.3.0 Cheers!