Skip to content

Alphabetize default metrics - #817

Merged
jdmarshall merged 3 commits into
prometheus:mainfrom
jonsuguiyama:alphabetize-default-metrics
Aug 26, 2026
Merged

jdmarshall merged 3 commits into
prometheus:mainfrom
jonsuguiyama:alphabetize-default-metrics

Conversation

@jonsuguiyama

Copy link
Copy Markdown
Contributor

Closes #810.

  • Reorder the metrics object in lib/defaultMetrics.js alphabetically by each module's Prometheus metric name.
  • In heapSizeAndUsed.js, move the shared collect() from the total gauge to the external gauge, since nodejs_external_memory_bytes now registers first alphabetically.
  • Add a test verifying default metric modules register in alphabetical order.
  • Update the existing heapSizeAndUsed test to read the external gauge first, since it now owns the shared collect.

@jdmarshall jdmarshall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm on my way out the door at the moment but looks promising. Thank you.

@jonsuguiyama
jonsuguiyama force-pushed the alphabetize-default-metrics branch from 6064bd5 to c3ce057 Compare August 23, 2026 17:04
@jonsuguiyama

Copy link
Copy Markdown
Contributor Author

Hi @jdmarshall, no rush - just flagging that the two required checks (Run Benchmarks and Run Checks) are still waiting on a maintainer to approve the workflow run, since this comes from a fork. Happy to rebase or adjust anything if needed.

@jdmarshall

Copy link
Copy Markdown
Contributor

Any PR that involves re-arranging things, as a rule of thumb should be prioritized to merge sooner rather than later to avoid conflicts with later initiatives.

Comment thread lib/defaultMetrics.js Outdated
heapSizeAndUsed,
gc,
heapSpacesSizeAndUsed,
version,

@jdmarshall jdmarshall Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do want to discuss one exception to the alphabetization rule.

node_version isn't really a stat, it's a configuration parameter that's part of either the build or the deployment. Having it buried like this, only someone who is really looking for it will find it, and this is, IME, one of a small number of pieces of data that people need to see more often than they believe they need to see it.

If the version is the first thing you see, then it is more likely to be seen. So I think this should be the exception to the alphabetical rule and should be at the top of the output.

@jdmarshall

jdmarshall commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Also a Changelog entry would be good, something like "organized the default metrics"

But we need a new section for it:


## [Unreleased]

### Breaking

### Changed

- Organized default metrics
 
### Added

## [0.16.0] - 2026-08-24

Register default metric modules in alphabetical order of their metric
name in defaultMetrics.js. Move the shared collect() in
heapSizeAndUsed from the total gauge to the external gauge, since
nodejs_external_memory_bytes now sorts first. Add a test asserting
module registration order is alphabetical.

Signed-off-by: Jon Suguiyama <[email protected]>
node_version describes build and deployment configuration rather than a
runtime statistic, so register it ahead of the alphabetized modules where
it is easier to spot. Document the exception at the call site and assert
it in the ordering test.

Signed-off-by: Jon Suguiyama <[email protected]>
@jonsuguiyama
jonsuguiyama force-pushed the alphabetize-default-metrics branch from c3ce057 to 8737760 Compare August 25, 2026 22:17
@jonsuguiyama

Copy link
Copy Markdown
Contributor Author

Good call on node_version, done. It now registers first, ahead of the alphabetized modules, and I left a note at the call site so the exception does not get "fixed" back later. The ordering test asserts version first, then alphabetical for the rest.

Changelog entry added in a new [Unreleased] section, using your wording.

Also rebased onto main to pick up 0.16.0, so this should merge clean.

Two CI notes, both independent of this PR:

  • The workflow runs are waiting on a maintainer to approve them again after the force-push, since this comes from a fork.
  • Changelog Reminder fails with HttpError: Resource not accessible by integration. The workflow requests pull-requests: write, but GITHUB_TOKEN is read-only on fork PRs, so the action cannot post or remove its comment. It will stay red on any fork PR regardless of whether the changelog was updated.

@jdmarshall

Copy link
Copy Markdown
Contributor

Alright, I'll try to merge this tonight.

@jdmarshall
jdmarshall merged commit 2743c6b into prometheus:main Aug 26, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alphabetize default metrics

2 participants