Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@ project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

This release marks our first release under the Prometheus umbrella.
### Breaking

- Gauges no longer initialize to zero, even if they have no labels
- `reset()` changes that may require modifications to custom Metrics:
- it is no longer called in the middle of the constructor
- it now defaults to clearing the labelMap

### Changed

### Added

## [0.16.0] - 2026-08-??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got picked up from another PR that needs to land for v0.16.0


This release marks our first release as a Prometheus subproject.

The package is renamed from `prom-client` to `@prometheus-io/client`. Update your
dependencies and any `require()`/`import` statements accordingly.

### Breaking

- The package is renamed from `prom-client` to `@prometheus-io/client`. Update your
dependencies and any `require()`/`import` statements accordingly.
- The cluster and worker thread IPC message types are renamed from `prom-client:*`
to `@prometheus-io/client:*`. A cluster primary and its workers must therefore run
the same major version.
Expand Down
9 changes: 7 additions & 2 deletions lib/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'use strict';

const util = require('util');
const { isObject, getLabels, nowTimestamp, LabelMap } = require('./util');
const { isObject, getLabels, nowTimestamp } = require('./util');
const { Metric } = require('./metric');
const Exemplar = require('./exemplar');

Expand All @@ -35,6 +35,10 @@ class Counter extends Metric {
} else {
this.inc = this.incWithoutExemplar;
}

if (this.labelNames.length === 0) {
this.store.set({}, 0);
}
}

/**
Expand Down Expand Up @@ -102,7 +106,8 @@ class Counter extends Metric {
* @returns {void}
*/
reset() {
this.store = new LabelMap(this.labelNames);
this.store.clear();

if (this.labelNames.length === 0) {
this.store.set({}, 0);
}
Expand Down
13 changes: 1 addition & 12 deletions lib/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

const util = require('util');

const { getLabels, isObject, LabelMap } = require('./util');
const { getLabels, isObject } = require('./util');
const { Metric } = require('./metric');

class Gauge extends Metric {
Expand All @@ -40,17 +40,6 @@ class Gauge extends Metric {
set(this, labels, value);
}

/**
* Reset gauge.
* @returns {void}
*/
reset() {
this.store = new LabelMap(this.labelNames);
if (this.labelNames.length === 0) {
this.store.set({}, 0);
}
}

/**
* Increment a gauge value.
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
Expand Down
4 changes: 0 additions & 4 deletions lib/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ class Histogram extends Metric {
};
}

reset() {
this.store = new LabelMap(this.labelNames);
}

/**
* Initialize the metrics for the given combination of labels to zero.
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
Expand Down
11 changes: 7 additions & 4 deletions lib/metric.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const Registry = require('./registry');
const { isObject } = require('./util');
const { isObject, LabelMap } = require('./util');
const { validateMetricName, validateLabelName } = require('./validation');

/**
Expand Down Expand Up @@ -67,8 +67,7 @@ class Metric {
this.sortedLabelNames = [];
}

// TODO: Bad things happen when you call functions on half-initialized objects, yo
this.reset();
this.store = new LabelMap(this.labelNames);

for (const register of this.registers) {
if (
Expand All @@ -83,8 +82,12 @@ class Metric {
}
}

/**
* Reset the metric.
* @returns {void}
*/
reset() {
/* abstract */
this.store.clear();
}
}

Expand Down
26 changes: 12 additions & 14 deletions lib/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'use strict';

const util = require('util');
const { getLabels, LabelMap } = require('./util');
const { getLabels } = require('./util');
const { Metric } = require('./metric');
const timeWindowQuantiles = require('./timeWindowQuantiles');

Expand All @@ -29,24 +29,22 @@ class Summary extends Metric {
super(config, {
percentiles: [0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999],
compressCount: DEFAULT_COMPRESS_COUNT,
store: new LabelMap(),
});

if (this.labelNames.includes('quantile'))
throw new Error('quantile is a reserved label keyword');

this.type = 'summary';
this.store = new LabelMap(this.labelNames);

if (this.labelNames.includes('quantile')) {
throw new Error('quantile is a reserved label keyword');
}

if (this.labelNames.length === 0) {
this.store.set(
{},
{
td: new timeWindowQuantiles(this.maxAgeSeconds, this.ageBuckets),
count: 0,
sum: 0,
},
);
const initial = {
td: new timeWindowQuantiles(this.maxAgeSeconds, this.ageBuckets),
count: 0,
sum: 0,
};

this.store.set({}, initial);
}
}

Expand Down
2 changes: 0 additions & 2 deletions test/__snapshots__/registerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ exports[`Register with OpenMetrics type should output all initialized metrics at
counter_total 0
# HELP gauge help
# TYPE gauge gauge
gauge 0
# HELP histogram help
# TYPE histogram histogram
histogram_bucket{le="0.005"} 0
Expand Down Expand Up @@ -86,7 +85,6 @@ counter 0

# HELP gauge help
# TYPE gauge gauge
gauge 0

# HELP histogram help
# TYPE histogram histogram
Expand Down
8 changes: 5 additions & 3 deletions test/gaugeTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ describe.each([
expect(fn).toThrowErrorMatchingSnapshot();
});

it('should init to 0', async () => {
it('should not init to 0', async () => {
instance = new Gauge({
name: 'init_gauge',
help: 'somehelp',
});
await expectValue(0);

await expect(instance.get()).resolves.toBeEmpty;
});

describe('with labels', () => {
Expand Down Expand Up @@ -287,6 +288,7 @@ describe.each([
afterEach(() => {
globalRegistry.clear();
});

it('should reset labelless gauge', async () => {
const instance = new Gauge({
name: 'test_metric',
Expand All @@ -297,7 +299,7 @@ describe.each([
expect((await instance.get()).values[0].value).toEqual(12);

instance.reset();
expect((await instance.get()).values[0].value).toEqual(0);
expect(await instance.get()).toBeEmpty;

instance.set(10);
expect((await instance.get()).values[0].value).toEqual(10);
Expand Down
Loading