Skip to content

Add build tag to build without deprecated global name validation scheme #1834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Jul 14, 2025

Add build tag localvalidationscheme, to support building without the deprecated global metric/label name validation scheme (model.NameValidationScheme). This is to support building projects such as Prometheus and Grafana Mimir with a configurable metric/label name validation scheme, without changing the API unless said build tag is used.

Since model.NameValidationScheme is deprecated, the new build tag should eventually become the default, but I figure we should move in stages.

I'm also updating the CircleCI job matrix to exercise building with the new tag.

Question: Is there a way to mark the new build tag as experimental?

Depends on prometheus/common#804.

@aknuds1 aknuds1 force-pushed the arve/remove_global_name_validation branch from 23118f3 to c8493b4 Compare July 14, 2025 09:47
Signed-off-by: Arve Knudsen <[email protected]>
@aknuds1 aknuds1 force-pushed the arve/remove_global_name_validation branch from 34359a9 to 0c315b4 Compare July 14, 2025 10:25
@aknuds1 aknuds1 requested a review from Copilot July 14, 2025 12:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Introduce a new localvalidationscheme build tag to decouple the default global model.NameValidationScheme and enable configurable validation schemes. Core API methods and test utilities now uniformly accept a model.ValidationScheme parameter, with dual-file build-tag splits (_localvalidationscheme.go and _globalvalidationscheme.go) to preserve backward compatibility. CI and module dependencies are also updated to test both validation modes.

  • Add build-tag–guarded implementations for local vs. global validation schemes across timers, registries, metrics, counters, histograms, pushers, and HTTP instrumentation.
  • Refactor linting and registry code to propagate a model.ValidationScheme argument.
  • Update tests to wrap global calls (Lint(), Gather(), etc.) with helper functions that pass model.UTF8Validation.

Reviewed Changes

Copilot reviewed 73 out of 74 changed files in this pull request and generated no comments.

Show a summary per file
File Description
prometheus/value.go Extended newExemplar to accept a scheme parameter.
prometheus/timer.go Removed legacy inline ObserveDurationWithExemplar.
prometheus/timer_localvalidationscheme.go Added local build-tag version of ObserveDurationWithExemplar.
prometheus/timer_globalvalidationscheme.go Added global build-tag version of ObserveDurationWithExemplar.
prometheus/timer_test.go Updated test to use observeDurationWithExemplar(..., UTF8).
prometheus/registry.go Added nameValidationScheme field and threaded scheme through Gather.
prometheus/registry_localvalidationscheme.go Introduced options to pick a local validation scheme.
prometheus/registry_globalvalidationscheme.go Provided fallback to the global validation scheme.
prometheus/testutil/promlint/promlint.go Refactored Lint to take a scheme argument.
prometheus/testutil/promlint/promlint_localvalidationscheme.go Added local build-tag helper for Lint(scheme).
prometheus/testutil/promlint/promlint_globalvalidationscheme.go Added global build-tag helper for Lint().
prometheus/testutil/promlint/promlint_test.go Switched to lint(l) helper to inject scheme.
prometheus/testutil/lint_localvalidationscheme.go Added collectAndLint wrapper with scheme parameter.
prometheus/testutil/lint_globalvalidationscheme.go Added global wrapper for CollectAndLint.
prometheus/registry_test.go Updated to pass UTF8Validation in new newGatherers call.
prometheus/push/push.go Added validationScheme field and threaded through newGatherers.
prometheus/push/push_localvalidationscheme.go Exposed Option{NameValidationScheme} for pushers.
prometheus/push/push_globalvalidationscheme.go Kept legacy pusher API using global scheme.
prometheus/promhttp/option.go Added validationScheme default in options.
prometheus/promhttp/option_localvalidationscheme.go Exposed WithNameValidationScheme helper.
prometheus/promhttp/instrument_server.go Updated all observeWithExemplar and addWithExemplar calls to include scheme.
prometheus/promhttp/instrument_server_localvalidationscheme.go Added local build-tag versions with scheme parameter.
prometheus/promhttp/instrument_server_globalvalidationscheme.go Added global build-tag versions.
prometheus/promhttp/instrument_client.go Updated client instrumentation to pass scheme.
prometheus/histogram.go Extended updateExemplar to accept scheme.
prometheus/histogram_localvalidationscheme.go Added local build-tag ObserveWithExemplar implementation.
prometheus/histogram_globalvalidationscheme.go Added global build-tag ObserveWithExemplar fallback.
prometheus/metric.go Introduced newMetricWithExemplars with scheme parameter.
prometheus/metric_localvalidationscheme.go Exposed local helper for MustNewMetricWithExemplars.
prometheus/metric_globalvalidationscheme.go Kept legacy global-helper for metric exemplars.
prometheus/labels.go Removed old checkLabelName, delegated to scheme-specific files.
prometheus/labels_localvalidationscheme.go Introduced scheme-aware checkLabelName.
prometheus/labels_globalvalidationscheme.go Kept legacy checkLabelName.
prometheus/desc.go Refactored newDesc to accept scheme.
prometheus/desc_localvalidationscheme.go Added full V2 descriptor API with scheme options.
prometheus/desc_globalvalidationscheme.go Kept legacy global descriptor API.
prometheus/counter.go Extended updateExemplar with scheme.
prometheus/counter_localvalidationscheme.go Added local ExemplarAdder interface with scheme.
prometheus/counter_globalvalidationscheme.go Kept legacy global ExemplarAdder.
prometheus/counter_test.go Updated to use addToCounterWithExemplar(..., UTF8).
prometheus/counter_localvalidationscheme_test.go Added local build-tag wrapper for counter tests.
prometheus/counter_globalvalidationscheme_test.go Added global build-tag wrapper for counter tests.
examples/random/main.go Updated example to use observeWithExemplar(..., UTF8).
examples/random/main_localvalidationscheme.go Added local build-tag example wrapper.
examples/random/main_globalvalidationscheme.go Added global build-tag example wrapper.
examples/exemplars/main.go Updated example to use observeWithExemplar(..., UTF8).
examples/exemplars/main_localvalidationscheme.go Added local build-tag example wrapper.
examples/exemplars/main_globalvalidationscheme.go Added global build-tag example wrapper.
.github/workflows/go.yml Updated CI matrix to include validation_scheme and set build tags.
go.mod Bumped prometheus/common and other module versions.
Comments suppressed due to low confidence (4)

prometheus/value.go:246

  • The doc comment above newExemplar should be updated to describe the new 'scheme' parameter and how it influences label validation.
func newExemplar(value float64, ts time.Time, l Labels, scheme model.ValidationScheme) (*dto.Exemplar, error) {

prometheus/timer_test.go:73

  • [nitpick] The helper name observeDurationWithExemplar is close to the core API; consider renaming to observeWithDurationScheme or similar to avoid confusion.
		defer observeDurationWithExemplar(sumTimer, exemplar, model.UTF8Validation)

prometheus/timer_localvalidationscheme.go:14

  • [nitpick] There's extensive duplication between local vs global validation scheme files; consider unifying these by passing the scheme into a single implementation to reduce maintenance overhead.
//go:build localvalidationscheme

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