Skip to content

Add registry option to skip metric sorting#2018

Open
ibobgunardi wants to merge 2 commits into
prometheus:mainfrom
ibobgunardi:bobi/disable-registry-metric-sorting
Open

Add registry option to skip metric sorting#2018
ibobgunardi wants to merge 2 commits into
prometheus:mainfrom
ibobgunardi:bobi/disable-registry-metric-sorting

Conversation

@ibobgunardi

Copy link
Copy Markdown

Fixes #483.

Adds RegistryOpts.DisableMetricSorting with option-aware constructors for vanilla and pedantic registries. The existing constructors keep the current sorted output; the new option skips the final MetricFamily/Metric sort for callers that can accept unspecified ordering.

Tests:

  • go test ./prometheus -run TestRegistryDisableMetricSorting -count=1
  • go test ./prometheus -run 'TestRegistry|TestRegisterUnregisterCollector|TestCollectorOnMetricPanic|TestCheckMetricConsistency|TestGatherDoesNotLeakGoroutines' -count=1
  • go test ./prometheus/internal -count=1

Note: go test ./prometheus -count=1 fails locally on Go 1.25.1 because the expected Go runtime metric set has 180 entries while this toolchain exposes 177.

Signed-off-by: Bobby <boby@codelabs.co.id>
@ibobgunardi ibobgunardi force-pushed the bobi/disable-registry-metric-sorting branch from ad02579 to 6cf8711 Compare June 4, 2026 13:35

@kakkoyun kakkoyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Really solid PR.

Comment thread prometheus/registry.go Outdated
@kakkoyun

kakkoyun commented Jun 4, 2026

Copy link
Copy Markdown
Member

I will wait for another maintainers' opinion before merging it @vesari @bwplotka

Signed-off-by: Bobby <boby@codelabs.co.id>

@bwplotka bwplotka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, solid PR, but we add bunch of new APIs and increase amount of options.

Do we know, for what exactly benefit? Can we add a quick micro benchmark to see how much we would really save in terms of time/memory?

The issue is #483 old - notably KSM moved to a hand coded exposition, so we don't need to support it? Curious how much benefit we have for 100 metric families vs 10k metric families.

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.

Consider optional disabling of metric sorting

3 participants