Compare commits

...

7 Commits
3.3.0 ... 4.0.0

Author SHA1 Message Date
Konstantin Pogorelov
d292dcab33 remove changelog from readme as it duplicates github releases function 2018-08-08 12:00:29 +02:00
Konstantin Pogorelov
84f99cc49c add urlValueParser option, update docs accordingly 2018-08-08 11:23:27 +02:00
Konstantin Pogorelov
fffe35ce5e update dependencies, use url-value-parser v2 2018-08-08 11:22:03 +02:00
Konstantin Pogorelov
06341c227a wip: 4.0.0, prom-client to v11, url-value-parser to v2 2018-08-07 17:55:25 +02:00
Konstantin Pogorelov
45b8f373be include collectDefaultMetrics in kraken example 2018-01-26 17:40:05 +01:00
Konstantin Pogorelov
4ee269faee make test more specific 2018-01-23 16:58:49 +01:00
Konstantin Pogorelov
e4d6113ff2 replace node 7 with node 8 in .travis.yml 2018-01-23 16:52:12 +01:00
7 changed files with 1417 additions and 1106 deletions

View File

@@ -1,4 +1,4 @@
language: node_js
node_js:
- "6"
- "7"
- "8"

View File

@@ -52,6 +52,9 @@ Which labels to include in `http_request_duration_seconds` metric:
Extra transformation callbacks:
* **urlValueParser**: options passed when instantiating [url-value-parser](https://github.com/disjunction/url-value-parser).
This is the easiest way to customize which parts of the URL should be replaced with "#val".
See the [docs](https://github.com/disjunction/url-value-parser) of url-value-parser module for details.
* **normalizePath**: `function(req)` generates path values from express `req` (see details below)
* **formatStatusCode**: `function(res)` producing final status code from express `res` object, e.g. you can combine `200`, `201` and `204` to just `2xx`.
* **transformLabels**: `function(labels, req, res)` transforms the **labels** object, e.g. setting dynamic values to **customLabels**
@@ -150,7 +153,9 @@ app.listen(3000);
## using with kraken.js
Here is meddleware config sample, which can be used in a standard **kraken.js** application:
Here is meddleware config sample, which can be used in a standard **kraken.js** application.
In this case the stats for URI paths and HTTP methods are collected separately,
while replacing all HEX values starting from 5 characters and all emails in the path as #val.
```json
{
@@ -163,7 +168,19 @@ Here is meddleware config sample, which can be used in a standard **kraken.js**
"arguments": [
{
"includeMethod": true,
"buckets": [0.1, 1, 5]
"includePath": true,
"buckets": [0.1, 1, 5],
"promClient": {
"collectDefaultMetrics": {
"timeout": 2000
}
},
"urlValueParser": {
"minHexLength": 5,
"extraMasks": [
"^[^@]+@[^@]+\\.[^@]+$"
]
}
}
]
}
@@ -172,50 +189,6 @@ Here is meddleware config sample, which can be used in a standard **kraken.js**
}
```
## Changelog
* **3.3.0**
* added option **promClient** to be able to call collectDefaultMetrics
* upgrade **prom-client** to ~10.2.2 (switch to semver "approximately")
* **3.2.0**
* added options **customLabels**, **transformLabels**
* upgrade **prom-client** to 10.1.0
* **3.1.0**
* upgrade **prom-client** to 10.0.0
* **3.0.0**
* upgrade dependencies, most notably **prom-client** to 9.0.0
* switch to koa v2 in koa unittest
* only node v6 or higher is supported (stop supporting node v4 and v5)
* switch to npm5 and use package-lock.json
* options added: includeStatusCode, formatStatusCode
* **2.1.0**
* deprecate **excludeRoutes**, use **req.originalUrl** instead of **req.path**
* **2.0.0**
* the reason for the version lift were:
* compliance to official naming recommendation: https://prometheus.io/docs/practices/naming/
* stopping promotion of an anti-pattern - see https://groups.google.com/d/msg/prometheus-developers/XjlOnDCK9qc/ovKzV3AIBwAJ
* dealing with **prom-client** being a singleton with a built-in registry
* main histogram metric renamed from `http_request_seconds` to `http_request_duration_seconds`
* options removed: **prefix**, **keepDefaultMetrics**
* factory removed (as the only reason of it was adding the prefix)
* upgrade prom-client to 6.3.0
* code style changed to the one closer to express
* **1.2.1**
* upgrade prom-client to 6.1.2
* add options: includeMethod, includePath, keepDefaultMetrics
## License
MIT

View File

@@ -15,6 +15,12 @@ const bundle = promBundle({
collectDefaultMetrics: {
timeout: 1000
}
},
urlValueParser: {
minHexLength: 5,
extraMasks: [
"^[^@]+@[^@]+\\.[^@]+$"
]
}
});
@@ -40,6 +46,7 @@ app.listen(3000, () => console.info( // eslint-disable-line
'listening on 3000\n'
+ 'test in shell console\n\n'
+ 'curl localhost:3000/foo/1234\n'
+ 'curl localhost:3000/foo/john%40example.com\n'
+ 'curl -X DELETE localhost:3000/foo/5432\n'
+ 'curl localhost:3000/bar\n'
+ 'curl localhost:3000/metrics\n'

2427
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "3.3.0",
"version": "4.0.0",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"keywords": [
@@ -17,16 +17,16 @@
"license": "MIT",
"dependencies": {
"on-finished": "^2.3.0",
"prom-client": "~10.2.2",
"url-value-parser": "^1.0.0"
"prom-client": "~11.1.1",
"url-value-parser": "^2.0.0"
},
"devDependencies": {
"coveralls": "^2.13.1",
"eslint": "^3.19.0",
"express": "^4.15.3",
"coveralls": "^3.0.2",
"eslint": "^5.3.0",
"express": "^4.16.3",
"istanbul": "^0.4.5",
"jasme": "^5.2.0",
"koa": "^2.2.0",
"koa": "^2.5.2",
"koa-connect": "^2.0.0",
"supertest": "^3.0.0",
"supertest-koa-agent": "^0.3.0"

View File

@@ -267,7 +267,7 @@ describe('index', () => {
.get('/metrics')
.end((err, res) => {
expect(res.status).toBe(200);
expect(res.text).not.toMatch(/200/);
expect(res.text).not.toMatch(/="200"/);
done();
});
});

View File

@@ -2,16 +2,18 @@
const UrlValueParser = require('url-value-parser');
const url = require('url');
// ATTENTION! urlValueParser is a singleton!
let urlValueParser;
module.exports = function(req) {
module.exports = function(req, opts) {
// originalUrl is taken, because url and path can be changed
// by middlewares such as 'router'. Note: this function is called onFinish
/// i.e. always in the tail of the middleware chain
const path = url.parse(req.originalUrl || req.url).pathname;
if (!urlValueParser) {
urlValueParser = new UrlValueParser();
urlValueParser = new UrlValueParser(opts && opts.urlValueParser);
}
return urlValueParser.replacePathValues(path);
};