prom-client
Advanced tools
Comparing version 13.2.0 to 14.0.0
@@ -16,2 +16,39 @@ # Changelog | ||
## [14.0.0] - 2021-09-18 | ||
### Breaking | ||
- changed: `linearBuckets` does not propagate rounding errors anymore. | ||
Fewer bucket bounds will be affected by rounding errors. Histogram bucket | ||
labels may change. [`6f1f3b2`](https://github.com/siimon/prom-client/commit/6f1f3b24c9c21311ff33e7d4b987b40c6b304e04) | ||
- changed: The push gateway methods `pushAdd()`, `push()` and `delete()` now | ||
return Promises instead of accepting a callback: | ||
```js | ||
// Old: | ||
gateway.pushAdd({ jobName: 'test' }, (err, resp, body) => {}); | ||
// New: | ||
gateway | ||
.pushAdd({ jobName: 'test' }) | ||
.then(({ resp, body }) => {}) | ||
.catch(err => {}); | ||
// or | ||
const { resp, body } = await gateway.pushAdd({ jobName: 'test' }); | ||
``` | ||
[`f177b1f`](https://github.com/siimon/prom-client/commit/f177b1fd3d4db5fc48fcb1ec02d94069fffcf144) | ||
- changed: The default `nodejs_eventloop_lag_*` metrics are now reset every time | ||
they are observed. This prevents these metrics from "stabilizing" over a long | ||
period of time and becoming insensitive to small changes. For more info, see | ||
[#370](https://github.com/siimon/prom-client/issues/370). [`0f444cd`](https://github.com/siimon/prom-client/commit/0f444cd38e4c7074991270106c270f731bafddb8) | ||
### Changed | ||
- Add missing `await`/`then`s to examples. [`074f339`](https://github.com/siimon/prom-client/commit/074f339914e5d71b5829cd4a949affae23dbc409) | ||
- Add missing type declaration for `client.contentType`. [`3b66641`](https://github.com/siimon/prom-client/commit/3b6664160bdd1555045b03d8f4c421022f30e1db) | ||
- Modernize some label processing code. [`c9bf1d8`](https://github.com/siimon/prom-client/commit/c9bf1d8e3db3b5fb97faf2df9ca9b9af670288f3) | ||
## [13.2.0] - 2021-08-08 | ||
@@ -18,0 +55,0 @@ |
@@ -82,2 +82,7 @@ // Type definitions for prom-client | ||
/** | ||
* The Content-Type of the metrics for use in the response headers. | ||
*/ | ||
export const contentType: string; | ||
export class AggregatorRegistry extends Registry { | ||
@@ -84,0 +89,0 @@ /** |
@@ -10,4 +10,3 @@ 'use strict'; | ||
for (let i = 0; i < count; i++) { | ||
buckets[i] = start; | ||
start += width; | ||
buckets[i] = start + i * width; | ||
} | ||
@@ -14,0 +13,0 @@ return buckets; |
@@ -73,4 +73,4 @@ /** | ||
remove() { | ||
const labels = getLabels(this.labelNames, arguments) || {}; | ||
remove(...args) { | ||
const labels = getLabels(this.labelNames, args) || {}; | ||
validateLabel(this.labelNames, labels); | ||
@@ -77,0 +77,0 @@ return removeLabels.call(this, this.hashMap, labels); |
@@ -120,4 +120,4 @@ /** | ||
labels() { | ||
const labels = getLabels(this.labelNames, arguments); | ||
labels(...args) { | ||
const labels = getLabels(this.labelNames, args); | ||
validateLabel(this.labelNames, labels); | ||
@@ -133,4 +133,4 @@ return { | ||
remove() { | ||
const labels = getLabels(this.labelNames, arguments); | ||
remove(...args) { | ||
const labels = getLabels(this.labelNames, args); | ||
validateLabel(this.labelNames, labels); | ||
@@ -137,0 +137,0 @@ removeLabels.call(this, this.hashMap, labels); |
@@ -104,4 +104,4 @@ /** | ||
labels() { | ||
const labels = getLabels(this.labelNames, arguments); | ||
labels(...args) { | ||
const labels = getLabels(this.labelNames, args); | ||
validateLabel(this.labelNames, labels); | ||
@@ -114,4 +114,4 @@ return { | ||
remove() { | ||
const labels = getLabels(this.labelNames, arguments); | ||
remove(...args) { | ||
const labels = getLabels(this.labelNames, args); | ||
validateLabel(this.labelNames, labels); | ||
@@ -118,0 +118,0 @@ removeLabels.call(this, this.hashMap, labels); |
@@ -63,2 +63,4 @@ 'use strict'; | ||
lagP99.set(labels, histogram.percentile(99) / 1e9); | ||
histogram.reset(); | ||
}; | ||
@@ -65,0 +67,0 @@ } |
@@ -18,3 +18,3 @@ 'use strict'; | ||
pushAdd(params, callback) { | ||
pushAdd(params) { | ||
if (!params || !params.jobName) { | ||
@@ -24,6 +24,6 @@ throw new Error('Missing jobName parameter'); | ||
useGateway.call(this, 'POST', params.jobName, params.groupings, callback); | ||
return useGateway.call(this, 'POST', params.jobName, params.groupings); | ||
} | ||
push(params, callback) { | ||
push(params) { | ||
if (!params || !params.jobName) { | ||
@@ -33,6 +33,6 @@ throw new Error('Missing jobName parameter'); | ||
useGateway.call(this, 'PUT', params.jobName, params.groupings, callback); | ||
return useGateway.call(this, 'PUT', params.jobName, params.groupings); | ||
} | ||
delete(params, callback) { | ||
delete(params) { | ||
if (!params || !params.jobName) { | ||
@@ -42,6 +42,6 @@ throw new Error('Missing jobName parameter'); | ||
useGateway.call(this, 'DELETE', params.jobName, params.groupings, callback); | ||
return useGateway.call(this, 'DELETE', params.jobName, params.groupings); | ||
} | ||
} | ||
function useGateway(method, job, groupings, callback) { | ||
async function useGateway(method, job, groupings) { | ||
// `URL` first added in v6.13.0 | ||
@@ -67,30 +67,31 @@ // eslint-disable-next-line node/no-deprecated-api | ||
const req = httpModule.request(options, res => { | ||
let body = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', chunk => { | ||
body += chunk; | ||
return new Promise((resolve, reject) => { | ||
const req = httpModule.request(options, resp => { | ||
let body = ''; | ||
resp.setEncoding('utf8'); | ||
resp.on('data', chunk => { | ||
body += chunk; | ||
}); | ||
resp.on('end', () => { | ||
resolve({ resp, body }); | ||
}); | ||
}); | ||
res.on('end', () => { | ||
callback(null, res, body); | ||
req.on('error', err => { | ||
reject(err); | ||
}); | ||
if (method !== 'DELETE') { | ||
this.registry | ||
.metrics() | ||
.then(metrics => { | ||
req.write(metrics); | ||
req.end(); | ||
}) | ||
.catch(err => { | ||
reject(err); | ||
}); | ||
} else { | ||
req.end(); | ||
} | ||
}); | ||
req.on('error', err => { | ||
callback(err); | ||
}); | ||
if (method !== 'DELETE') { | ||
this.registry | ||
.metrics() | ||
.then(metrics => { | ||
req.write(metrics); | ||
req.end(); | ||
}) | ||
.catch(err => { | ||
req.end(); | ||
callback(err); | ||
}); | ||
} else { | ||
req.end(); | ||
} | ||
} | ||
@@ -97,0 +98,0 @@ |
@@ -97,4 +97,4 @@ /** | ||
labels() { | ||
const labels = getLabels(this.labelNames, arguments); | ||
labels(...args) { | ||
const labels = getLabels(this.labelNames, args); | ||
validateLabel(this.labelNames, labels); | ||
@@ -107,4 +107,4 @@ return { | ||
remove() { | ||
const labels = getLabels(this.labelNames, arguments); | ||
remove(...args) { | ||
const labels = getLabels(this.labelNames, args); | ||
validateLabel(this.labelNames, labels); | ||
@@ -111,0 +111,0 @@ removeLabels.call(this, this.hashMap, labels); |
@@ -31,3 +31,2 @@ 'use strict'; | ||
// TODO: For node 6, use rest params | ||
exports.getLabels = function (labelNames, args) { | ||
@@ -42,7 +41,7 @@ if (typeof args[0] === 'object') { | ||
const argsAsArray = Array.prototype.slice.call(args); | ||
return labelNames.reduce((acc, label, index) => { | ||
acc[label] = argsAsArray[index]; | ||
return acc; | ||
}, {}); | ||
const acc = {}; | ||
for (let i = 0; i < labelNames.length; i++) { | ||
acc[labelNames[i]] = args[i]; | ||
} | ||
return acc; | ||
}; | ||
@@ -49,0 +48,0 @@ |
{ | ||
"name": "prom-client", | ||
"version": "13.2.0", | ||
"version": "14.0.0", | ||
"description": "Client for prometheus", | ||
@@ -43,2 +43,3 @@ "main": "index.js", | ||
"lint-staged": "^10.0.4", | ||
"nock": "^13.0.5", | ||
"prettier": "2.0.5", | ||
@@ -45,0 +46,0 @@ "typescript": "^4.0.2" |
@@ -493,12 +493,32 @@ # Prometheus client for node.js [![Actions Status](https://github.com/siimon/prom-client/workflows/Node.js%20CI/badge.svg?branch=master)](https://github.com/siimon/prom-client/actions) | ||
gateway.pushAdd({ jobName: 'test' }, function (err, resp, body) {}); //Add metric and overwrite old ones | ||
gateway.push({ jobName: 'test' }, function (err, resp, body) {}); //Overwrite all metrics (use PUT) | ||
gateway.delete({ jobName: 'test' }, function (err, resp, body) {}); //Delete all metrics for jobName | ||
gateway.pushAdd({ jobName: 'test' }) | ||
.then({resp, body} => { | ||
/* ... */ | ||
}) | ||
.catch(err => { | ||
/* ... */ | ||
})); //Add metric and overwrite old ones | ||
gateway.push({ jobName: 'test' }) | ||
.then({resp, body} => { | ||
/* ... */ | ||
}) | ||
.catch(err => { | ||
/* ... */ | ||
})); //Overwrite all metrics (use PUT) | ||
gateway.delete({ jobName: 'test' }) | ||
.then({resp, body} => { | ||
/* ... */ | ||
}) | ||
.catch(err => { | ||
/* ... */ | ||
})); //Delete all metrics for jobName | ||
//All gateway requests can have groupings on it | ||
gateway.pushAdd({ jobName: 'test', groupings: { key: 'value' } }, function ( | ||
err, | ||
resp, | ||
body, | ||
) {}); | ||
gateway.pushAdd({ jobName: 'test', groupings: { key: 'value' } }) | ||
.then({resp, body} => { | ||
/* ... */ | ||
}) | ||
.catch(err => { | ||
/* ... */ | ||
})); | ||
@@ -505,0 +525,0 @@ // It's possible to extend the Pushgateway with request options from nodes core |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118437
2583
566
12