Compare commits

...

16 Commits
4.2.1 ... 4.3.0

Author SHA1 Message Date
Konstantin Pogorelov
00b8369329 Merge branch 'develop' 2018-12-23 18:48:10 +01:00
Konstantin Pogorelov
59221f891b bump 4.3.0 2018-12-23 18:41:02 +01:00
Konstantin Pogorelov
3a0b2caf61 upgrade prom-cliet to 11.2.1 (latest) 2018-12-23 18:40:28 +01:00
Konstantin Pogorelov
e7d004f0cc rename metricsType -> metricType, move corresponding readme block 2 paragraphs lower 2018-12-23 16:45:38 +01:00
Chen Li
0dd3116f23 Feature/add metrics type summary (#24)
* add metric type summary

* add tests for percentile option

* throw errors for unknown metricType

* set histogram as default metrics type
2018-12-23 16:36:47 +01:00
Konstantin Pogorelov
6054824c67 Merge branch 'master' into develop 2018-08-25 14:43:58 +02:00
Konstantin Pogorelov
01c78bcc1d Merge branch 'master' into develop 2018-08-25 13:10:39 +02:00
Konstantin Pogorelov
bc65dc45cb #16 fix typo in docs 2018-08-25 12:57:15 +02:00
Konstantin Pogorelov
8cae5b6ef3 fix jasme path (again) 2018-08-25 12:52:38 +02:00
Konstantin Pogorelov
2003e7743f #16 fix unit test (cluster_metrics/metrics_cluster), cover the error branch 2018-08-25 12:44:24 +02:00
Konstantin Pogorelov
568c87216a #16 remove unnecessary check for existance after new, break on error with 500 2018-08-25 12:42:53 +02:00
Konstantin Pogorelov
98be36244e #16 make the cluster example runnable 2018-08-25 12:40:15 +02:00
Konstantin Pogorelov
6ff1204db4 revert way jasme was called, add npm run coverage 2018-08-25 09:49:28 +02:00
Konstantin Pogorelov
f71d837660 fix newlines in index.spec.js 2018-08-25 09:45:09 +02:00
Konstantin Pogorelov
4aa2bfa6ae update package-lock.json 2018-08-24 23:48:22 +02:00
Adam Yost
1fff877787 Add support for clusterMaster option re: #16 (#17)
* Add support for clusterMaster option re: #16
* Add Cluster instructions to README
* Use the approach recommended in PR
* use console.error for errors
* Update with new method signature
* add code coverage for new clusterMetrics middleware
2018-08-24 23:36:23 +02:00
5 changed files with 79 additions and 14 deletions

View File

@@ -9,7 +9,7 @@ Internally it uses **prom-client**. See: https://github.com/siimon/prom-client
Included metrics:
* `up`: normally is just 1
* `http_request_duration_seconds`: http latency histogram labeled with `status_code`, `method` and `path`
* `http_request_duration_seconds`: http latency histogram/summary labeled with `status_code`, `method` and `path`
## Install
@@ -62,9 +62,14 @@ Extra transformation callbacks:
* **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**
Metric type:
* **metricType**: two metric types are supported for `http_request_duration_seconds` metric: [histogram](https://prometheus.io/docs/concepts/metric_types/#histogram) and [summary](https://prometheus.io/docs/concepts/metric_types/#summary), default: **histogram**
Other options:
* **buckets**: buckets used for `http_request_duration_seconds` histogram
* **percentiles**: percentiles used for `http_request_duration_seconds` summary
* **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,

8
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "4.1.0",
"version": "4.2.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -1910,9 +1910,9 @@
"dev": true
},
"prom-client": {
"version": "11.1.1",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-11.1.1.tgz",
"integrity": "sha512-itUicyrq3Rko56v3ovQAMYwxEouK7lIylp26bjnlt1b/3fzn783riZnZn432I4udYmPsRgNx1F/u9RFvLyH7zA==",
"version": "11.2.1",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-11.2.1.tgz",
"integrity": "sha512-7VwtjrkQS50NvDoeYNn2z6wzXB5BMGzUlmMOeLPaITtJsTVXnPywRta7QFiV4pKr0fbRx9oDfUcx1xibabjSAg==",
"requires": {
"tdigest": "^0.1.1"
}

View File

@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "4.2.1",
"version": "4.3.0",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"keywords": [
@@ -18,7 +18,7 @@
"license": "MIT",
"dependencies": {
"on-finished": "^2.3.0",
"prom-client": "~11.1.1",
"prom-client": "~11.2.1",
"url-value-parser": "^2.0.0"
},
"devDependencies": {

View File

@@ -186,6 +186,54 @@ describe('index', () => {
});
});
it('metric type summary works', done => {
const app = express();
const bundled = bundle({
metricType: 'summary',
percentiles: [0.5, 0.85, 0.99],
});
app.use(bundled);
app.use('/test', (req, res) => res.send('it worked'));
const agent = supertest(app);
agent.get('/test').end(() => {
agent
.get('/metrics')
.end((err, res) => {
expect(res.status).toBe(200);
expect(res.text).toMatch(/quantile="0.85"/);
done();
});
});
});
it('metric type histogram works', done => {
const app = express();
const bundled = bundle({
metricType: 'histogram',
buckets: [10, 100],
});
app.use(bundled);
app.use('/test', (req, res) => res.send('it worked'));
const agent = supertest(app);
agent.get('/test').end(() => {
agent
.get('/metrics')
.end((err, res) => {
expect(res.status).toBe(200);
expect(res.text).toMatch(/le="100"/);
done();
});
});
});
it('throws on unknown metricType ', () => {
expect(() => {
bundle({metricType: 'hello'});
}).toThrow();
});
describe('usage of normalizePath()', () => {
it('normalizePath can be replaced gloablly', done => {

View File

@@ -62,6 +62,7 @@ function main(opts) {
includeStatusCode: true,
normalizePath: main.normalizePath,
formatStatusCode: main.normalizeStatusCode,
metricType: 'histogram',
promClient: {}
},
opts
@@ -106,13 +107,24 @@ function main(opts) {
if (opts.customLabels){
labels.push.apply(labels, Object.keys(opts.customLabels));
}
const metric = new promClient.Histogram({
name: httpMetricName,
help: 'duration histogram of http responses labeled with: ' + labels.join(', '),
labelNames: labels,
buckets: opts.buckets || [0.003, 0.03, 0.1, 0.3, 1.5, 10]
});
return metric;
if (opts.metricType === 'summary') {
return new promClient.Summary({
name: httpMetricName,
help: 'duration summary of http responses labeled with: ' + labels.join(', '),
labelNames: labels,
percentiles: opts.percentiles || [0.5, 0.75, 0.95, 0.98, 0.99, 0.999]
});
} else if (opts.metricType === 'histogram' || !opts.metricType) {
return new promClient.Histogram({
name: httpMetricName,
help: 'duration histogram of http responses labeled with: ' + labels.join(', '),
labelNames: labels,
buckets: opts.buckets || [0.003, 0.03, 0.1, 0.3, 1.5, 10]
});
} else {
throw new Error('metricType option must be histogram or summary');
}
}
};