Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: siimon/prom-client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v11.1.2
Choose a base ref
...
head repository: siimon/prom-client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v11.1.3
Choose a head ref
  • 4 commits
  • 13 files changed
  • 2 contributors

Commits on Sep 20, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    24cf59a View commit details

Commits on Sep 21, 2018

  1. Copy the full SHA
    6674ada View commit details

Commits on Sep 22, 2018

  1. prepare for 11.1.3

    SimenB committed Sep 22, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    97ed179 View commit details
  2. 11.1.3

    SimenB committed Sep 22, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    SimenB Simen Bekkhus
    Copy the full SHA
    ac74915 View commit details
Showing with 1,187 additions and 1,533 deletions.
  1. +1 −1 .eslintrc
  2. +7 −0 CHANGELOG.md
  3. +3 −3 lib/cluster.js
  4. +22 −19 lib/counter.js
  5. +2 −3 lib/defaultMetrics.js
  6. +20 −17 lib/gauge.js
  7. +34 −34 lib/histogram.js
  8. +3 −3 lib/metricAggregators.js
  9. +1 −1 lib/pushgateway.js
  10. +46 −35 lib/registry.js
  11. +18 −15 lib/summary.js
  12. +1,023 −1,396 package-lock.json
  13. +7 −6 package.json
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"plugins": ["prettier"],
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "plugin:node/recommended"],
"env": {
"node": true,
"es6": true
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,13 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Added

## [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

### Changed
6 changes: 3 additions & 3 deletions lib/cluster.js
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@

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

const GET_METRICS_REQ = 'prom-client:getMetricsReq';
const GET_METRICS_RES = 'prom-client:getMetricsRes';
@@ -86,7 +86,7 @@ class AggregatorRegistry extends Registry {
*/
static aggregate(metricsArr) {
const aggregatedRegistry = new Registry();
const metricsByName = new util.Grouper();
const metricsByName = new Grouper();

// Gather by name
metricsArr.forEach(metrics => {
41 changes: 22 additions & 19 deletions lib/counter.js
Original file line number Diff line number Diff line change
@@ -4,19 +4,22 @@
'use strict';

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 getLabels = require('./util').getLabels;
const {
isDate,
getPropertiesFromObj,
hashObject,
isObject,
printDeprecationObjectConstructor,
getLabels
} = require('./util');

const {
validateLabel,
validateMetricName,
validateLabelName
} = require('./validation');

class Counter {
/**
@@ -59,7 +62,7 @@ class Counter {
throw new Error('Invalid metric name');
}

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

@@ -106,15 +109,15 @@ class Counter {
help: this.help,
name: this.name,
type,
values: getProperties(this.hashMap),
values: getPropertiesFromObj(this.hashMap),
aggregator: this.aggregator
};
}

labels() {
const labels = getLabels(this.labelNames, arguments) || {};
const hash = hashObject(labels);
validateLabels(this.labelNames, labels);
validateLabel(this.labelNames, labels);
return {
inc: inc.call(this, labels, hash)
};
@@ -125,7 +128,7 @@ const reset = function() {
this.hashMap = {};

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

@@ -144,15 +147,15 @@ const inc = function(labels, hash) {
}

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 || '';
timestamp = isDate(timestamp)
? timestamp.valueOf()
5 changes: 2 additions & 3 deletions lib/defaultMetrics.js
Original file line number Diff line number Diff line change
@@ -11,9 +11,8 @@ const processRequests = require('./metrics/processRequests');
const heapSizeAndUsed = require('./metrics/heapSizeAndUsed');
const heapSpacesSizeAndUsed = require('./metrics/heapSpacesSizeAndUsed');
const version = require('./metrics/version');
const globalRegistry = require('./registry').globalRegistry;
const printDeprecationCollectDefaultMetricsNumber = require('./util')
.printDeprecationCollectDefaultMetricsNumber;
const { globalRegistry } = require('./registry');
const { printDeprecationCollectDefaultMetricsNumber } = require('./util');

const metrics = {
processCpuTotal,
37 changes: 20 additions & 17 deletions lib/gauge.js
Original file line number Diff line number Diff line change
@@ -4,20 +4,23 @@
'use strict';

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');

class Gauge {
/**
@@ -58,7 +61,7 @@ class Gauge {
if (!validateMetricName(config.name)) {
throw new Error('Invalid metric name');
}
if (!validateLabelNames(config.labelNames)) {
if (!validateLabelName(config.labelNames)) {
throw new Error('Invalid label name');
}

@@ -145,7 +148,7 @@ class Gauge {
help: this.help,
name: this.name,
type,
values: getProperties(this.hashMap),
values: getPropertiesFromObj(this.hashMap),
aggregator: this.aggregator
};
}
@@ -226,16 +229,16 @@ function set(labels) {

labels = labels || {};

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

function reset() {
this.hashMap = {};

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

68 changes: 34 additions & 34 deletions lib/histogram.js
Original file line number Diff line number Diff line change
@@ -6,15 +6,18 @@
const util = require('util');
const globalRegistry = require('./registry').globalRegistry;
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');

class Histogram {
/**
@@ -105,7 +108,7 @@ class Histogram {
}

get() {
const data = getProperties(this.hashMap);
const data = getPropertiesFromObj(this.hashMap);
const values = data
.map(extractBucketValuesForExport(this))
.reduce(addSumAndCountForExport(this), []);
@@ -172,7 +175,7 @@ function validateInput(name, help, labels) {
throw new Error('Invalid metric name');
}

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

@@ -204,7 +207,7 @@ function sortAscending(x, y) {
return x - y;
}

function createValuePair(labels, value, metricName) {
function setValuePair(labels, value, metricName) {
return {
labels,
value,
@@ -226,7 +229,7 @@ function observe(labels) {
return value => {
const labelValuePair = convertLabelsAndValues(labels, value);

validateLabels(this.labelNames, labelValuePair.labels);
validateLabel(this.labelNames, labelValuePair.labels);
if (!Number.isFinite(labelValuePair.value)) {
throw new TypeError(
`Value is not a valid number: ${util.format(labelValuePair.value)}`
@@ -279,9 +282,17 @@ function convertLabelsAndValues(labels, value) {

function extractBucketValuesForExport(histogram) {
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 };
};
}
@@ -290,28 +301,17 @@ function addSumAndCountForExport(histogram) {
return (acc, d) => {
acc.push(...d.buckets);

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

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;
6 changes: 3 additions & 3 deletions lib/metricAggregators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const util = require('./util');
const { Grouper, hashObject } = require('./util');

/**
* Returns a new function that applies the `aggregatorFn` to the values.
@@ -18,10 +18,10 @@ function AggregatorFactory(aggregatorFn) {
aggregator: metrics[0].aggregator
};
// 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);
});
});
2 changes: 1 addition & 1 deletion lib/pushgateway.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
const url = require('url');
const http = require('http');
const https = require('https');
const globalRegistry = require('./registry').globalRegistry;
const { globalRegistry } = require('./registry');

class Pushgateway {
constructor(gatewayUrl, options, registry) {
Loading