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.5.1
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.5.2
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Jun 20, 2019

  1. fix: avoid mutation bug in registry (#273)

    Raynos authored and SimenB committed Jun 20, 2019
    Copy the full SHA
    2c0020f View commit details
  2. 11.5.2

    SimenB committed Jun 20, 2019
    Copy the full SHA
    50ce3db View commit details
Showing with 60 additions and 2 deletions.
  1. +12 −0 CHANGELOG.md
  2. +6 −0 lib/registry.js
  3. +1 −1 package-lock.json
  4. +1 −1 package.json
  5. +40 −0 test/registerTest.js
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,18 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Added

## [11.5.2] - 2019-06-20

### Changed

- fix: avoid mutation bug in registry

## [11.5.1] - 2019-06-13

### Changed

- fix: guard against missing constructor

## [11.5.0] - 2019-06-04

### Added
6 changes: 6 additions & 0 deletions lib/registry.js
Original file line number Diff line number Diff line change
@@ -36,6 +36,12 @@ class Registry {
let values = '';
for (const val of item.values || []) {
val.labels = val.labels || {};

if (defaultLabelNames.length > 0) {
// Make a copy before mutating
val.labels = Object.assign({}, val.labels);
}

for (const labelName of defaultLabelNames) {
val.labels[labelName] =
val.labels[labelName] || this._defaultLabels[labelName];
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prom-client",
"version": "11.5.1",
"version": "11.5.2",
"description": "Client for prometheus",
"main": "index.js",
"files": [
40 changes: 40 additions & 0 deletions test/registerTest.js
Original file line number Diff line number Diff line change
@@ -336,6 +336,46 @@ describe('register', () => {
});
});

describe('Registry with default labels', () => {
const Registry = require('../lib/registry');

it('should not throw with default labels', () => {
const r = new Registry();
r.setDefaultLabels({
env: 'development'
});

const hist = new Histogram({
name: 'my_histogram',
help: 'my histogram',
registers: [r],
labelNames: ['type']
});

const myHist = hist.labels('myType');

myHist.observe(1);

const metrics = r.metrics();
const lines = metrics.split('\n');
expect(
lines.indexOf(
'my_histogram_bucket{le="1",type="myType",env="development"} 1'
) >= 0
).toEqual(true);

myHist.observe(1);

const metrics2 = r.metrics();
const lines2 = metrics2.split('\n');
expect(
lines2.indexOf(
'my_histogram_bucket{le="1",type="myType",env="development"} 2'
) >= 0
).toEqual(true);
});
});

describe('merging', () => {
const Registry = require('../lib/registry');
let registryOne;