fix(registry): default to summation for metrics without an aggregator - #820
Merged
jdmarshall merged 1 commit intoAug 23, 2026
Merged
Conversation
Both the README and the worker/cluster JSDoc state that metrics are
summed across workers when no explicit aggregator is configured. Two
regressions broke that contract:
- Registry.aggregate() threw "'undefined' is not a defined aggregator."
for snapshots lacking the property (e.g. metrics registered via
registerMetric() with a plain object), which crashes
clusterMetrics()/workerMetrics() entirely.
- getMetricsAsArray('sum') silently dropped those metrics, so their data
was lost on the shutdown flush path introduced for workers.
Restore the documented 'sum' fallback in both places.
jdmarshall
approved these changes
Aug 23, 2026
jdmarshall
left a comment
Contributor
There was a problem hiding this comment.
Hmmm.. I had code for this but then convinced myself it wasn't needed. :/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both the README ("Custom metrics are summed across workers by default") and the worker/cluster JSDoc ("or by summation if
aggregatoris undefined") promise a'sum'fallback for metrics without an explicitaggregator. Two recent changes broke that contract:Registry.aggregate()throws'undefined' is not a defined aggregator.when any snapshot lacks the property — snapshots produced byregisterMetric()with a plain object, or hand-written wrappers. This crashesclusterMetrics()/workerMetrics()entirely.getMetricsAsArray('sum')silently filters those metrics out (aggregator === metric.aggregatoris false when the property is missing), so their values are lost on the shutdown-flush path added for workers in ef1cea2.Reproduction on current main:
and:
Note that
new Counter({...})setsaggregator: 'sum'via the Metric constructor default, so built-in metric classes mask the issue; it only surfaces with wrapper/plain-object metrics, which is exactly what the aggregation and shutdown paths produce internally.Fix
Restore the documented
'sum'fallback in both places (metric.aggregator ?? 'sum').Testing
test/registerTest.js: aggregate() sums snapshots without an aggregator; getMetricsAsArray('sum') / getMetricsAsJSON('sum') include them