Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prom-client

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prom-client - npm Package Compare versions

Comparing version 11.1.2 to 11.1.3

7

CHANGELOG.md

@@ -16,2 +16,9 @@ # Changelog

## [11.1.3] - 2018-09-22
### Changed
- Fixed performance by avoiding `Object.assign` on hot paths, as well as
mutating objects when appropriate.
## [11.1.2] - 2018-09-19

@@ -18,0 +25,0 @@

6

lib/cluster.js

@@ -13,4 +13,4 @@ 'use strict';

const Registry = require('./registry');
const util = require('./util');
const aggregators = require('./metricAggregators').aggregators;
const { Grouper } = require('./util');
const { aggregators } = require('./metricAggregators');

@@ -90,3 +90,3 @@ const GET_METRICS_REQ = 'prom-client:getMetricsReq';

const aggregatedRegistry = new Registry();
const metricsByName = new util.Grouper();
const metricsByName = new Grouper();

@@ -93,0 +93,0 @@ // Gather by name

@@ -7,15 +7,18 @@ /**

const util = require('util');
const globalRegistry = require('./registry').globalRegistry;
const { globalRegistry } = require('./registry');
const type = 'counter';
const isDate = require('./util').isDate;
const getProperties = require('./util').getPropertiesFromObj;
const hashObject = require('./util').hashObject;
const validateLabels = require('./validation').validateLabel;
const validateMetricName = require('./validation').validateMetricName;
const validateLabelNames = require('./validation').validateLabelName;
const isObject = require('./util').isObject;
const printDeprecationObjectConstructor = require('./util')
.printDeprecationObjectConstructor;
const {
isDate,
getPropertiesFromObj,
hashObject,
isObject,
printDeprecationObjectConstructor,
getLabels
} = require('./util');
const getLabels = require('./util').getLabels;
const {
validateLabel,
validateMetricName,
validateLabelName
} = require('./validation');

@@ -63,3 +66,3 @@ class Counter {

if (!validateLabelNames(config.labelNames)) {
if (!validateLabelName(config.labelNames)) {
throw new Error('Invalid label name');

@@ -111,3 +114,3 @@ }

type,
values: getProperties(this.hashMap),
values: getPropertiesFromObj(this.hashMap),
aggregator: this.aggregator

@@ -120,3 +123,3 @@ };

const hash = hashObject(labels);
validateLabels(this.labelNames, labels);
validateLabel(this.labelNames, labels);
return {

@@ -132,3 +135,3 @@ inc: inc.call(this, labels, hash)

if (this.labelNames.length === 0) {
this.hashMap = createValue({}, 0);
this.hashMap = setValue({}, 0);
}

@@ -152,11 +155,11 @@ };

labels = labels || {};
validateLabels(this.labelNames, labels);
validateLabel(this.labelNames, labels);
const incValue = value === null || value === undefined ? 1 : value;
this.hashMap = createValue(this.hashMap, incValue, timestamp, labels, hash);
this.hashMap = setValue(this.hashMap, incValue, timestamp, labels, hash);
};
};
function createValue(hashMap, value, timestamp, labels, hash) {
function setValue(hashMap, value, timestamp, labels, hash) {
hash = hash || '';

@@ -163,0 +166,0 @@ timestamp = isDate(timestamp)

@@ -14,5 +14,4 @@ 'use strict';

const version = require('./metrics/version');
const globalRegistry = require('./registry').globalRegistry;
const printDeprecationCollectDefaultMetricsNumber = require('./util')
.printDeprecationCollectDefaultMetricsNumber;
const { globalRegistry } = require('./registry');
const { printDeprecationCollectDefaultMetricsNumber } = require('./util');

@@ -19,0 +18,0 @@ const metrics = {

@@ -7,16 +7,19 @@ /**

const util = require('util');
const globalRegistry = require('./registry').globalRegistry;
const { globalRegistry } = require('./registry');
const type = 'gauge';
const isDate = require('./util').isDate;
const createValue = require('./util').setValue;
const getProperties = require('./util').getPropertiesFromObj;
const getLabels = require('./util').getLabels;
const hashObject = require('./util').hashObject;
const validateMetricName = require('./validation').validateMetricName;
const validateLabels = require('./validation').validateLabel;
const validateLabelNames = require('./validation').validateLabelName;
const isObject = require('./util').isObject;
const printDeprecationObjectConstructor = require('./util')
.printDeprecationObjectConstructor;
const {
isDate,
setValue,
getPropertiesFromObj,
getLabels,
hashObject,
isObject,
printDeprecationObjectConstructor
} = require('./util');
const {
validateMetricName,
validateLabel,
validateLabelName
} = require('./validation');

@@ -62,3 +65,3 @@ class Gauge {

}
if (!validateLabelNames(config.labelNames)) {
if (!validateLabelName(config.labelNames)) {
throw new Error('Invalid label name');

@@ -150,3 +153,3 @@ }

type,
values: getProperties(this.hashMap),
values: getPropertiesFromObj(this.hashMap),
aggregator: this.aggregator

@@ -232,4 +235,4 @@ };

validateLabels(this.labelNames, labels);
this.hashMap = createValue(this.hashMap, value, labels, timestamp);
validateLabel(this.labelNames, labels);
this.hashMap = setValue(this.hashMap, value, labels, timestamp);
};

@@ -242,3 +245,3 @@ }

if (this.labelNames.length === 0) {
this.hashMap = createValue({}, 0, {});
this.hashMap = setValue({}, 0, {});
}

@@ -245,0 +248,0 @@ }

@@ -9,11 +9,14 @@ /**

const type = 'histogram';
const getProperties = require('./util').getPropertiesFromObj;
const getLabels = require('./util').getLabels;
const hashObject = require('./util').hashObject;
const validateLabels = require('./validation').validateLabel;
const validateMetricName = require('./validation').validateMetricName;
const validateLabelNames = require('./validation').validateLabelName;
const isObject = require('./util').isObject;
const printDeprecationObjectConstructor = require('./util')
.printDeprecationObjectConstructor;
const {
getPropertiesFromObj,
getLabels,
hashObject,
isObject,
printDeprecationObjectConstructor
} = require('./util');
const {
validateMetricName,
validateLabel,
validateLabelName
} = require('./validation');

@@ -109,3 +112,3 @@ class Histogram {

get() {
const data = getProperties(this.hashMap);
const data = getPropertiesFromObj(this.hashMap);
const values = data

@@ -177,3 +180,3 @@ .map(extractBucketValuesForExport(this))

if (!validateLabelNames(labels)) {
if (!validateLabelName(labels)) {
throw new Error('Invalid label name');

@@ -210,3 +213,3 @@ }

function createValuePair(labels, value, metricName) {
function setValuePair(labels, value, metricName) {
return {

@@ -233,3 +236,3 @@ labels,

validateLabels(this.labelNames, labelValuePair.labels);
validateLabel(this.labelNames, labelValuePair.labels);
if (!Number.isFinite(labelValuePair.value)) {

@@ -287,5 +290,13 @@ throw new TypeError(

return bucketData => {
const buckets = histogram.upperBounds.map(
createBucketValues(bucketData, histogram)
);
const buckets = [];
const bucketLabelNames = Object.keys(bucketData.labels);
let acc = 0;
for (const upperBound of histogram.upperBounds) {
acc += bucketData.bucketValues[upperBound];
const lbls = { le: upperBound };
for (const labelName of bucketLabelNames) {
lbls[labelName] = bucketData.labels[labelName];
}
buckets.push(setValuePair(lbls, acc, `${histogram.name}_bucket`));
}
return { buckets, data: bucketData };

@@ -299,12 +310,11 @@ };

const infLabel = Object.assign({ le: '+Inf' }, d.data.labels);
const infLabel = { le: '+Inf' };
for (const label of Object.keys(d.data.labels)) {
infLabel[label] = d.data.labels[label];
}
acc.push(
createValuePair(infLabel, d.data.count, `${histogram.name}_bucket`)
setValuePair(infLabel, d.data.count, `${histogram.name}_bucket`),
setValuePair(d.data.labels, d.data.sum, `${histogram.name}_sum`),
setValuePair(d.data.labels, d.data.count, `${histogram.name}_count`)
);
acc.push(
createValuePair(d.data.labels, d.data.sum, `${histogram.name}_sum`)
);
acc.push(
createValuePair(d.data.labels, d.data.count, `${histogram.name}_count`)
);
return acc;

@@ -314,12 +324,2 @@ };

function createBucketValues(bucket, histogram) {
let acc = 0;
return upperBound => {
acc += bucket.bucketValues[upperBound];
const lbls = Object.assign({ le: upperBound }, bucket.labels);
const valuePair = createValuePair(lbls, acc, `${histogram.name}_bucket`);
return valuePair;
};
}
module.exports = Histogram;
'use strict';
const util = require('./util');
const { Grouper, hashObject } = require('./util');

@@ -21,6 +21,6 @@ /**

// Gather metrics by metricName and labels.
const byLabels = new util.Grouper();
const byLabels = new Grouper();
metrics.forEach(metric => {
metric.values.forEach(value => {
const key = util.hashObject(value.labels);
const key = hashObject(value.labels);
byLabels.add(`${value.metricName}_${key}`, value);

@@ -27,0 +27,0 @@ });

@@ -6,3 +6,3 @@ 'use strict';

const https = require('https');
const globalRegistry = require('./registry').globalRegistry;
const { globalRegistry } = require('./registry');

@@ -9,0 +9,0 @@ class Pushgateway {

'use strict';
const getValueAsString = require('./util').getValueAsString;
const { getValueAsString } = require('./util');

@@ -32,35 +32,42 @@ function escapeString(str) {

const name = escapeString(item.name);
let help = escapeString(item.help);
help = ['#', 'HELP', name, help].join(' ');
const type = ['#', 'TYPE', name, item.type].join(' ');
const help = `# HELP ${name} ${escapeString(item.help)}`;
const type = `# TYPE ${name} ${item.type}`;
const defaultLabelNames = Object.keys(this._defaultLabels);
const values = (item.values || []).reduce((valAcc, val) => {
const merged = Object.assign({}, this._defaultLabels, val.labels);
let values = '';
for (const val of item.values || []) {
val.labels = val.labels || {};
for (const labelName of defaultLabelNames) {
val.labels[labelName] =
val.labels[labelName] || this._defaultLabels[labelName];
}
const labels = Object.keys(merged).map(
key => `${key}="${escapeLabelValue(merged[key])}"`
);
let labels = '';
for (const key of Object.keys(val.labels)) {
labels += `${key}="${escapeLabelValue(val.labels[key])}",`;
}
let metricName = val.metricName || item.name;
if (labels.length) {
metricName += `{${labels.join(',')}}`;
if (labels) {
metricName += `{${labels.replace(/,$/, '')}}`;
}
const line = [metricName, getValueAsString(val.value)];
if (opts.timestamps) {
line.push(val.timestamp);
let line = `${metricName} ${getValueAsString(val.value)}`;
if (opts.timestamps && val.timestamp) {
line += ` ${val.timestamp}`;
}
valAcc += line.join(' ').trim();
valAcc += '\n';
return valAcc;
}, '');
values += `${line.trim()}\n`;
}
const acc = [help, type, values].join('\n');
return acc;
return `${help}\n${type}\n${values}`.trim();
}
metrics(opts) {
return this.getMetricsAsArray()
.map(metric => this.getMetricAsPrometheusString(metric, opts))
.join('\n');
let metrics = '';
for (const metric of this.getMetricsAsArray()) {
metrics += `${this.getMetricAsPrometheusString(metric, opts)}\n\n`;
}
return metrics.replace(/\n$/, '');
}

@@ -87,17 +94,21 @@

getMetricsAsJSON() {
return this.getMetricsAsArray().map(metric => {
const metrics = [];
const defaultLabelNames = Object.keys(this._defaultLabels);
for (const metric of this.getMetricsAsArray()) {
const item = metric.get();
if (!item.values) {
return item;
if (item.values) {
for (const val of item.values) {
for (const labelName of defaultLabelNames) {
val.labels[labelName] =
val.labels[labelName] || this._defaultLabels[labelName];
}
}
}
item.values = item.values.map(val =>
// Avoid mutation and merge metric labels with registry default labels
Object.assign({}, val, {
labels: Object.assign({}, this._defaultLabels, val.labels)
})
);
metrics.push(item);
}
return item;
});
return metrics;
}

@@ -104,0 +115,0 @@

@@ -7,14 +7,17 @@ /**

const util = require('util');
const globalRegistry = require('./registry').globalRegistry;
const { globalRegistry } = require('./registry');
const type = 'summary';
const getProperties = require('./util').getPropertiesFromObj;
const getLabels = require('./util').getLabels;
const hashObject = require('./util').hashObject;
const validateLabels = require('./validation').validateLabel;
const validateMetricName = require('./validation').validateMetricName;
const validateLabelNames = require('./validation').validateLabelName;
const TDigest = require('tdigest').TDigest;
const isObject = require('util').isObject;
const printDeprecationObjectConstructor = require('./util')
.printDeprecationObjectConstructor;
const {
getPropertiesFromObj,
getLabels,
hashObject,
isObject,
printDeprecationObjectConstructor
} = require('./util');
const {
validateLabel,
validateMetricName,
validateLabelName
} = require('./validation');
const { TDigest } = require('tdigest');

@@ -102,3 +105,3 @@ class Summary {

get() {
const data = getProperties(this.hashMap);
const data = getPropertiesFromObj(this.hashMap);
const values = [];

@@ -123,3 +126,3 @@ data.forEach(s => {

reset() {
const data = getProperties(this.hashMap);
const data = getPropertiesFromObj(this.hashMap);
data.forEach(s => {

@@ -208,3 +211,3 @@ s.td.reset();

if (!validateLabelNames(labels)) {
if (!validateLabelName(labels)) {
throw new Error('Invalid label name');

@@ -235,3 +238,3 @@ }

validateLabels(this.labelNames, this.labels);
validateLabel(this.labelNames, this.labels);
if (!Number.isFinite(labelValuePair.value)) {

@@ -238,0 +241,0 @@ throw new TypeError(

{
"name": "prom-client",
"version": "11.1.2",
"version": "11.1.3",
"description": "Client for prometheus",

@@ -12,3 +12,3 @@ "main": "index.js",

"engines": {
"node": ">=6"
"node": ">=6.1"
},

@@ -35,11 +35,12 @@ "scripts": {

"devDependencies": {
"eslint": "^4.1.1",
"eslint": "^5.6.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-prettier": "^2.1.2",
"express": "^4.13.3",
"husky": "^0.14.3",
"jest": "^22.4.2",
"jest": "^23.6.0",
"lint-staged": "^7.0.0",
"lolex": "^2.1.3",
"prettier": "1.14.2",
"typescript": "^2.5.2"
"prettier": "1.14.3",
"typescript": "^3.0.3"
},

@@ -46,0 +47,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc