Skip to content

feat: add normalizeMetricName helper#2098

Merged
jaydeluca merged 2 commits intoprometheus:copilot/fix-inference-issue-untyped-metricsfrom
zeitlinger:stacked/normalize-metric-name
May 5, 2026
Merged

feat: add normalizeMetricName helper#2098
jaydeluca merged 2 commits intoprometheus:copilot/fix-inference-issue-untyped-metricsfrom
zeitlinger:stacked/normalize-metric-name

Conversation

@zeitlinger
Copy link
Copy Markdown
Member

Summary

Adds a new permissive normalization API on top of #2094.

sanitizeMetricName() keeps the restored compatibility behavior from that PR:
it strips reserved suffixes such as _total, _created, _bucket, and
_info (plus dot variants).

This PR adds normalizeMetricName() as the explicit opt-in for the newer
1.6.x-style permissive behavior:

  • keep the original metric name unchanged
  • allow reserved suffixes to remain in the normalized name
  • still append units when requested

That gives downstream integrations a clear API split:

  • sanitizeMetricName(...) for compatibility-preserving suffix stripping
  • normalizeMetricName(...) for permissive normalization

Changes

  • add PrometheusNaming.normalizeMetricName(String)
  • add PrometheusNaming.normalizeMetricName(String, Unit)
  • extend PrometheusNamingTest to cover the new helper and its unit overload
  • clarify the class-level Javadoc around when to use sanitizeMetricName()
    vs normalizeMetricName()

Why stacked

This is intended to sit on top of #2094.

Test plan

  • mise run build
  • ./mvnw test -pl prometheus-metrics-model -am -Dtest=PrometheusNamingTest,MetricMetadataTest -Dsurefire.failIfNoSpecifiedTests=false -Dcoverage.skip=true -Dcheckstyle.skip=true

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
@jaydeluca jaydeluca merged commit 3816ccc into prometheus:copilot/fix-inference-issue-untyped-metrics May 5, 2026
8 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.

2 participants