Skip to content

Commit

Permalink
add promClient option for smuggling collectDefaultMetrics, upgrade pr…
Browse files Browse the repository at this point in the history
…om-client to ~10.2.2, version 3.3.0
  • Loading branch information
disjunction committed Jan 23, 2018
1 parent c8996a7 commit 06f55c9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Other options:

* **buckets**: buckets used for `http_request_duration_seconds` histogram
* **autoregister**: if `/metrics` endpoint should be registered. (Default: **true**)
* **promClient**: options for promClient startup, e.g. **collectDefaultMetrics**. This option was added
to keep `express-prom-bundle` runnable using confit (e.g. with kraken.js) without writing any JS code,
see [advanced example](https://github.com/jochen-schweizer/express-prom-bundle/blob/master/advanced-example.js)

Deprecated:

Expand Down Expand Up @@ -171,19 +174,32 @@ 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/
Expand Down
9 changes: 7 additions & 2 deletions advanced-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ const bundle = promBundle({
includeMethod: true,
includePath: true,
customLabels: {year: null},
transformLabels: labels => Object.assign(labels, {year: new Date().getFullYear()})
transformLabels: labels => Object.assign(labels, {year: new Date().getFullYear()}),
promClient: {
collectDefaultMetrics: {
timeout: 1000
}
}
});

app.use(bundle);

// native prom-client metric (no prefix)
const c1 = new bundle.promClient.Counter('c1', 'c1 help');
const c1 = new bundle.promClient.Counter({name: 'c1', help: 'c1 help'});
c1.inc(10);

app.get('/foo/:id', (req, res) => {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "3.2.1",
"version": "3.3.0",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"keywords": [
Expand All @@ -17,7 +17,7 @@
"license": "MIT",
"dependencies": {
"on-finished": "^2.3.0",
"prom-client": "^10.1.0",
"prom-client": "~10.2.2",
"url-value-parser": "^1.0.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,16 @@ describe('index', () => {
});
});
});

it('calls promClient.collectDefaultMetrics', () => {
const spy = spyOn(promClient, 'collectDefaultMetrics');
bundle({
promClient: {
collectDefaultMetrics: {
timeout: 3000
}
}
});
expect(spy).toHaveBeenCalledWith({timeout: 3000});
});
});
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function main(opts) {
autoregister: true,
includeStatusCode: true,
normalizePath: main.normalizePath,
formatStatusCode: main.normalizeStatusCode
formatStatusCode: main.normalizeStatusCode,
promClient: {}
},
opts
);
Expand All @@ -66,6 +67,10 @@ function main(opts) {
);
}

if (opts.promClient.collectDefaultMetrics) {
promClient.collectDefaultMetrics(opts.promClient.collectDefaultMetrics);
}

const httpMetricName = opts.httpDurationMetricName || 'http_request_duration_seconds';

const metricTemplates = {
Expand Down

0 comments on commit 06f55c9

Please sign in to comment.