Skip to content

Ignore deprecation warnings about NameValidationScheme #6449

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

Merged
merged 9 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

> [!WARNING]
> This is the last version to support `model.LegacyValidation` for
> `go.opentelemetry.io/otel/exporters/prometheus`.
> The next version (v0.59.0) will only support the default `model.UTF8Validation`.
>
> See also [Change default validation scheme to UTF8Validation](https://github.com/prometheus/common/pull/724)
> in the prometheus repository.

### Removed

- Drop support for [Go 1.22]. (#6381, #6418)
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func WithoutScopeInfo() Option {
// have special behavior based on their name.
func WithNamespace(ns string) Option {
return optionFunc(func(cfg config) config {
if model.NameValidationScheme != model.UTF8Validation {
if model.NameValidationScheme != model.UTF8Validation { // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
// Only sanitize if prometheus does not support UTF-8.
ns = model.EscapeName(ns, model.NameEscapingScheme)
}
Expand Down
4 changes: 2 additions & 2 deletions exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func getAttrs(attrs attribute.Set) ([]string, []string) {
values := make([]string, 0, attrs.Len())
itr := attrs.Iter()

if model.NameValidationScheme == model.UTF8Validation {
if model.NameValidationScheme == model.UTF8Validation { // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
// Do not perform sanitization if prometheus supports UTF-8.
for itr.Next() {
kv := itr.Attribute()
Expand Down Expand Up @@ -413,7 +413,7 @@ var unitSuffixes = map[string]string{
// getName returns the sanitized name, prefixed with the namespace and suffixed with unit.
func (c *collector) getName(m metricdata.Metrics, typ *dto.MetricType) string {
name := m.Name
if model.NameValidationScheme != model.UTF8Validation {
if model.NameValidationScheme != model.UTF8Validation { // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
// Only sanitize if prometheus does not support UTF-8.
name = model.EscapeName(name, model.NameEscapingScheme)
}
Expand Down
10 changes: 5 additions & 5 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ func TestPrometheusExporter(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.disableUTF8 {
model.NameValidationScheme = model.LegacyValidation
model.NameValidationScheme = model.LegacyValidation // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
defer func() {
// Reset to defaults
model.NameValidationScheme = model.UTF8Validation
model.NameValidationScheme = model.UTF8Validation // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
}()
}
ctx := context.Background()
Expand Down Expand Up @@ -1029,13 +1029,13 @@ func TestExemplars(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
originalEscapingScheme := model.NameEscapingScheme
originalValidationScheme := model.NameValidationScheme
originalValidationScheme := model.NameValidationScheme // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
model.NameEscapingScheme = tc.escapingScheme
model.NameValidationScheme = tc.validationScheme
model.NameValidationScheme = tc.validationScheme // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
// Restore original value after the test is complete
defer func() {
model.NameEscapingScheme = originalEscapingScheme
model.NameValidationScheme = originalValidationScheme
model.NameValidationScheme = originalValidationScheme // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
}()
// initialize registry exporter
ctx := context.Background()
Expand Down
Loading