prom-client
Advanced tools
Comparing version 13.0.0 to 13.1.0
@@ -12,2 +12,23 @@ # Changelog | ||
### Changed | ||
### Added | ||
## [13.1.0] - 2021-01-24 | ||
### Changed | ||
- fix: push client attempting to write Promise (fixes [#390](https://github.com/siimon/prom-client/issues/390)) | ||
- types: improve type checking of labels | ||
- fix: Summary#observe should throw when adding additional labels to labelset (fixes [#262](https://github.com/siimon/prom-client/issues/262)) | ||
### Added | ||
- feat: added the ability to pass labels as an object to `labels()` and `remove()` | ||
- Added: More examples with commented output | ||
## [13.0.0] - 2020-12-16 | ||
### Breaking | ||
- changed: The following functions are now async (return a promise): | ||
@@ -14,0 +35,0 @@ `registry.metrics()` |
@@ -147,3 +147,3 @@ // Type definitions for prom-client | ||
help: string; | ||
labelNames?: T[]; | ||
labelNames?: T[] | readonly T[]; | ||
registers?: Registry[]; | ||
@@ -189,2 +189,9 @@ aggregator?: Aggregator; | ||
/** | ||
* Return the child for given labels | ||
* @param labels Object with label keys and values | ||
* @return Configured counter with given labels | ||
*/ | ||
labels(labels: LabelValues<T>): Counter.Internal; | ||
/** | ||
* Reset counter values | ||
@@ -199,2 +206,8 @@ */ | ||
remove(...values: string[]): void; | ||
/** | ||
* Remove metrics for the given label values | ||
* @param labels Object with label keys and values | ||
*/ | ||
remove(labels: LabelValues<T>): void; | ||
} | ||
@@ -286,2 +299,9 @@ | ||
/** | ||
* Return the child for given labels | ||
* @param labels Object with label keys and values | ||
* @return Configured counter with given labels | ||
*/ | ||
labels(labels: LabelValues<T>): Gauge.Internal<T>; | ||
/** | ||
* Reset gauge values | ||
@@ -296,2 +316,8 @@ */ | ||
remove(...values: string[]): void; | ||
/** | ||
* Remove metrics for the given label values | ||
* @param labels Object with label keys and values | ||
*/ | ||
remove(labels: LabelValues<T>): void; | ||
} | ||
@@ -379,2 +405,9 @@ | ||
/** | ||
* Return the child for given labels | ||
* @param labels Object with label keys and values | ||
* @return Configured counter with given labels | ||
*/ | ||
labels(labels: LabelValues<T>): Histogram.Internal<T>; | ||
/** | ||
* Remove metrics for the given label values | ||
@@ -384,2 +417,8 @@ * @param values Label values | ||
remove(...values: string[]): void; | ||
/** | ||
* Remove metrics for the given label values | ||
* @param labels Object with label keys and values | ||
*/ | ||
remove(labels: LabelValues<T>): void; | ||
} | ||
@@ -461,2 +500,9 @@ | ||
/** | ||
* Return the child for given labels | ||
* @param labels Object with label keys and values | ||
* @return Configured counter with given labels | ||
*/ | ||
labels(labels: LabelValues<T>): Summary.Internal<T>; | ||
/** | ||
* Remove metrics for the given label values | ||
@@ -466,2 +512,8 @@ * @param values Label values | ||
remove(...values: string[]): void; | ||
/** | ||
* Remove metrics for the given label values | ||
* @param labels Object with label keys and values | ||
*/ | ||
remove(labels: LabelValues<T>): void; | ||
} | ||
@@ -468,0 +520,0 @@ |
@@ -52,4 +52,4 @@ /** | ||
const labels = getLabels(this.labelNames, arguments) || {}; | ||
validateLabel(this.labelNames, labels); | ||
const hash = hashObject(labels); | ||
validateLabel(this.labelNames, labels); | ||
return { | ||
@@ -62,2 +62,3 @@ inc: inc.call(this, labels, hash), | ||
const labels = getLabels(this.labelNames, arguments) || {}; | ||
validateLabel(this.labelNames, labels); | ||
return removeLabels.call(this, this.hashMap, labels); | ||
@@ -64,0 +65,0 @@ } |
@@ -105,2 +105,3 @@ /** | ||
const labels = getLabels(this.labelNames, arguments); | ||
validateLabel(this.labelNames, labels); | ||
return { | ||
@@ -117,2 +118,3 @@ inc: inc.call(this, labels), | ||
const labels = getLabels(this.labelNames, arguments); | ||
validateLabel(this.labelNames, labels); | ||
removeLabels.call(this, this.hashMap, labels); | ||
@@ -119,0 +121,0 @@ } |
@@ -93,2 +93,3 @@ /** | ||
const labels = getLabels(this.labelNames, arguments); | ||
validateLabel(this.labelNames, labels); | ||
return { | ||
@@ -102,2 +103,3 @@ observe: observe.call(this, labels), | ||
const labels = getLabels(this.labelNames, arguments); | ||
validateLabel(this.labelNames, labels); | ||
removeLabels.call(this, this.hashMap, labels); | ||
@@ -104,0 +106,0 @@ } |
@@ -78,5 +78,15 @@ 'use strict'; | ||
if (method !== 'DELETE') { | ||
req.write(this.registry.metrics()); | ||
this.registry | ||
.metrics() | ||
.then(metrics => { | ||
req.write(metrics); | ||
req.end(); | ||
}) | ||
.catch(err => { | ||
req.end(); | ||
callback(err); | ||
}); | ||
} else { | ||
req.end(); | ||
} | ||
req.end(); | ||
} | ||
@@ -83,0 +93,0 @@ |
@@ -99,2 +99,3 @@ /** | ||
const labels = getLabels(this.labelNames, arguments); | ||
validateLabel(this.labelNames, labels); | ||
return { | ||
@@ -108,2 +109,3 @@ observe: observe.call(this, labels), | ||
const labels = getLabels(this.labelNames, arguments); | ||
validateLabel(this.labelNames, labels); | ||
removeLabels.call(this, this.hashMap, labels); | ||
@@ -158,3 +160,3 @@ } | ||
validateLabel(this.labelNames, this.labels); | ||
validateLabel(this.labelNames, labels); | ||
if (!Number.isFinite(labelValuePair.value)) { | ||
@@ -161,0 +163,0 @@ throw new TypeError( |
@@ -33,2 +33,6 @@ 'use strict'; | ||
exports.getLabels = function (labelNames, args) { | ||
if (typeof args[0] === 'object') { | ||
return args[0]; | ||
} | ||
if (labelNames.length !== args.length) { | ||
@@ -35,0 +39,0 @@ throw new Error('Invalid number of arguments'); |
{ | ||
"name": "prom-client", | ||
"version": "13.0.0", | ||
"version": "13.1.0", | ||
"description": "Client for prometheus", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -310,2 +310,4 @@ # 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) | ||
// 2nd version: Same effect as above | ||
gauge.labels({ method: 'GET', statusCode: '200' }).set(100); | ||
// 3nd version: And again the same effect as above | ||
gauge.labels('GET', '200').set(100); | ||
@@ -328,2 +330,24 @@ ``` | ||
#### Strongly typed Labels | ||
Typescript can also enforce label names using `as const` | ||
```typescript | ||
import * as client from 'prom-client'; | ||
const gauge = new client.Counter({ | ||
name: 'metric_name', | ||
help: 'metric_help', | ||
// add `as const` here to enforce label names | ||
labelNames: ['method'] as const, | ||
}); | ||
// Ok | ||
gauge.inc({ method: 1 }); | ||
// this is an error since `'methods'` is not a valid `labelName` | ||
// @ts-expect-error | ||
gauge.inc({ methods: 1 }); | ||
``` | ||
#### Default Labels (segmented by registry) | ||
@@ -462,4 +486,13 @@ | ||
//It's possible to extend the Pushgateway with request options from nodes core http/https library | ||
gateway = new client.Pushgateway('http://127.0.0.1:9091', { timeout: 5000 }); //Set the request timeout to 5000ms | ||
// It's possible to extend the Pushgateway with request options from nodes core | ||
// http/https library. In particular, you might want to provide an agent so that | ||
// TCP connections are reused. | ||
gateway = new client.Pushgateway('http://127.0.0.1:9091', { | ||
timeout: 5000, //Set the request timeout to 5000ms | ||
agent: new http.Agent({ | ||
keepAlive: true, | ||
keepAliveMsec: 10000, | ||
maxSockets: 5, | ||
}), | ||
}); | ||
``` | ||
@@ -466,0 +499,0 @@ |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
115134
2596
526
3