Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
- fix: Correct content type exported for cluster and worker mode.
- perf: Remove truthy conditionals from default metric collectors
- fix: Preserve zero-valued Counter exemplars
- perf: Remove object and array fallback truthiness from core metric paths

### Added

Expand Down
4 changes: 2 additions & 2 deletions lib/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ class Counter extends Metric {
}

labels(...args) {
const labels = getLabels(this.labelNames, args) || {};
const labels = getLabels(this.labelNames, args) ?? {};
return {
inc: this.inc.bind(this, labels),
};
}

remove(...args) {
const labels = getLabels(this.labelNames, args) || {};
const labels = getLabels(this.labelNames, args) ?? {};
this.store.validate(labels); //TODO: this isn't really necessary is it?
this.store.remove(labels);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ class Histogram extends Metric {
* @returns {void}
*/
observeWithoutExemplar(labels, value) {
observe(this, labels === 0 ? 0 : labels || {}, value);
observe(this, labels === 0 ? 0 : (labels ?? {}), value);
}

observeWithExemplar({
labels = this.defaultLabels,
value,
exemplarLabels = this.defaultExemplarLabelSet,
} = {}) {
observe(this, labels === 0 ? 0 : labels || {}, value);
observe(this, labels === 0 ? 0 : (labels ?? {}), value);
this.updateExemplar(labels, value, exemplarLabels);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/helpers/processMetricsHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function aggregateByObjectName(list) {
function updateMetrics(gauge, data, labels) {
gauge.reset();
for (const key in data) {
gauge.set(Object.assign({ type: key }, labels || {}), data[key]);
gauge.set(Object.assign({ type: key }, labels ?? {}), data[key]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Registry {
const isOpenMetrics =
this.contentType === Registry.OPENMETRICS_CONTENT_TYPE;

for (const val of metric.values || []) {
for (const val of metric.values ?? []) {
const { metricName = name, labels = {}, sharedLabels } = val;
const seriesName =
isOpenMetrics && metric.type === 'counter'
Expand Down
2 changes: 1 addition & 1 deletion lib/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Summary extends Metric {
* @returns {void}
*/
observe(labels, value) {
observe.call(this, labels === 0 ? 0 : labels || {})(value);
observe.call(this, labels === 0 ? 0 : (labels ?? {}))(value);
}

async get() {
Expand Down
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ exports.setValue = function setValue(hashMap, value, labels) {
const hash = hashObject(labels);
hashMap.set(hash, {
value: typeof value === 'number' ? value : 0,
labels: labels || {},
labels: labels ?? {},
});
return hashMap;
};
Expand Down
Loading