#7 upgrade dependencies, workaround for koa-connect, update docs

This commit is contained in:
Konstantin Pogorelov
2017-05-31 15:27:08 +02:00
parent 5b1aa494cb
commit 5b1517ca91
6 changed files with 22 additions and 27 deletions

View File

@@ -2,7 +2,7 @@
# express prometheus bundle
Express middleware with popular prometheus metrics in one bundle. It's also compatible with koa v1 (see below).
Express middleware with popular prometheus metrics in one bundle. It's also compatible with koa v1 and v2 (see below).
Internally it uses **prom-client**. See: https://github.com/siimon/prom-client
@@ -116,15 +116,15 @@ app.listen(3000);
See an [advanced example on github](https://github.com/jochen-schweizer/express-prom-bundle/blob/master/advanced-example.js)
## koa v1 example
## koa v2 example
```javascript
const promBundle = require("express-prom-bundle");
const koa = require("koa");
const Koa = require("koa");
const c2k = require("koa-connect");
const metricsMiddleware = promBundle({/* options */ });
const app = koa();
const app = new Koa();
app.use(c2k(metricsMiddleware));
app.use(/* your middleware */);
@@ -157,8 +157,11 @@ Here is meddleware config sample, which can be used in a standard **kraken.js**
## Changelog
* **3.0.0**
* upgrade dependencies, most notably **prom-client** to 9.0.0
* switch to koa v2 in koa unittest
* **2.1.0**
* deprecate **excludeRoutes**, use **req.originalPath** instead of **req.path**
* 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/

View File

@@ -4,11 +4,6 @@ const express = require('express');
const app = express();
const promBundle = require('express-prom-bundle');
// here we want to remove default metrics provided in prom-client
// this must be done before initializing promBundle
clearInterval(promBundle.promClient.defaultMetrics());
promBundle.promClient.register.clear();
const bundle = promBundle({
blacklist: [/up/],
buckets: [0.1, 0.4, 0.7],

View File

@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "2.2.0",
"version": "3.0.0",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"keywords": [
@@ -17,18 +17,18 @@
"license": "MIT",
"dependencies": {
"on-finished": "^2.3.0",
"prom-client": "^6.3.0",
"prom-client": "^9.0.0",
"url-value-parser": "^1.0.0"
},
"devDependencies": {
"coveralls": "^2.11.15",
"eslint": "^3.11.1",
"express": "^4.14.0",
"coveralls": "^2.13.1",
"eslint": "^3.19.0",
"express": "^4.15.3",
"istanbul": "^0.4.5",
"jasme": "^5.2.0",
"koa": "^1.2.4",
"koa-connect": "^1.0.0",
"supertest": "^2.0.1",
"koa": "^2.2.0",
"koa-connect": "^2.0.0",
"supertest": "^3.0.0",
"supertest-koa-agent": "^0.3.0"
},
"repository": {

View File

@@ -4,7 +4,7 @@
const express = require('express');
const supertest = require('supertest');
const bundle = require('../');
const koa = require('koa');
const Koa = require('koa');
const c2k = require('koa-connect');
const supertestKoa = require('supertest-koa-agent');
const promClient = require('prom-client');
@@ -194,17 +194,14 @@ describe('index', () => {
});
it('Koa: metrics returns up=1', done => {
const app = koa();
const app = new Koa();
const bundled = bundle({
whitelist: ['up']
});
app.use(c2k(bundled));
app.use(function*(next) {
if (this.path !== 'test') {
return yield next;
}
this.body = 'it worked';
app.use(function(ctx, next) {
return next().then(() => ctx.body = 'it worked');
});
const agent = supertestKoa(app);

View File

@@ -102,7 +102,7 @@ function main(opts) {
};
const middleware = function (req, res, next) {
const path = req.originalUrl;
const path = req.originalUrl || req.url; // originalUrl gets lost in koa-connect?
let labels;
if (opts.autoregister && path.match(/^\/metrics\/?$/)) {

View File

@@ -10,7 +10,7 @@ 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).pathname;
const path = url.parse(req.originalUrl || req.url).pathname;
if (opts.normalizePath !== undefined && !opts.normalizePath) {
return path;