Skip to content

Commit 905684c

Browse files
authored
Ignore deprecation warnings about NameValidationScheme (#6449)
In 0.63.0, prometheus deprecates the `model.NameValidationScheme` attribute. https://github.com/open-telemetry/opentelemetry-go/actions/runs/13885046847/job/38848614767?pr=6442 > Error: exporter_test.go:478:6: SA1019: model.NameValidationScheme is deprecated: This variable should not be used and might be removed in the far future. If you wish to stick to the legacy name validation use `IsValidLegacyMetricName()` and `LabelName.IsValidLegacy()` methods instead. This variable is here as an escape hatch for emergency cases, given the recent change from `LegacyValidation` to `UTF8Validation`, e.g., to delay UTF-8 migrations in time or aid in debugging unforeseen results of the change. In such a case, a temporary assignment to `LegacyValidation` value in the `init()` function in your main.go or so, could be considered. (staticcheck) We probably want to keep supporting this scheme in the near future though. So this ignores those deprecations, so we can upgrade the package. Unblocks #6442
1 parent f0ca595 commit 905684c

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
88

99
## [Unreleased]
1010

11+
> [!WARNING]
12+
> This is the last version to support `model.LegacyValidation` for
13+
> `go.opentelemetry.io/otel/exporters/prometheus`.
14+
> The next version (v0.59.0) will only support the default `model.UTF8Validation`.
15+
>
16+
> See also [Change default validation scheme to UTF8Validation](https://github.com/prometheus/common/pull/724)
17+
> in the prometheus repository.
18+
1119
### Added
1220

1321
- The `go.opentelemetry.io/otel/semconv/v1.31.0` package.
@@ -29,6 +37,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2937
- `go.opentelemetry.io/otel/log/logtest` is now a separate Go module. (#6465)
3038
- `go.opentelemetry.io/otel/sdk/log/logtest` is now a separate Go module. (#6466)
3139

40+
### Deprecated
41+
42+
- Deprecate support for `model.LegacyValidation` for `go.opentelemetry.io/otel/exporters/prometheus`. (#6449)
43+
3244
### Fixes
3345

3446
- Stop percent encoding header environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` and `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#6392)

exporters/prometheus/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ package prometheus // import "go.opentelemetry.io/otel/exporters/prometheus"
55

66
import (
77
"strings"
8+
"sync"
89

910
"github.com/prometheus/client_golang/prometheus"
1011
"github.com/prometheus/common/model"
1112

1213
"go.opentelemetry.io/otel/attribute"
14+
"go.opentelemetry.io/otel/internal/global"
1315
"go.opentelemetry.io/otel/sdk/metric"
1416
)
1517

@@ -25,6 +27,10 @@ type config struct {
2527
resourceAttributesFilter attribute.Filter
2628
}
2729

30+
var logDeprecatedLegacyScheme = sync.OnceFunc(func() {
31+
global.Warn("prometheus exporter legacy scheme deprecated: support for the legacy NameValidationScheme will be removed in the next release")
32+
})
33+
2834
// newConfig creates a validated config configured with options.
2935
func newConfig(opts ...Option) config {
3036
cfg := config{}
@@ -132,7 +138,8 @@ func WithoutScopeInfo() Option {
132138
// have special behavior based on their name.
133139
func WithNamespace(ns string) Option {
134140
return optionFunc(func(cfg config) config {
135-
if model.NameValidationScheme != model.UTF8Validation {
141+
if model.NameValidationScheme != model.UTF8Validation { // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
142+
logDeprecatedLegacyScheme()
136143
// Only sanitize if prometheus does not support UTF-8.
137144
ns = model.EscapeName(ns, model.NameEscapingScheme)
138145
}

exporters/prometheus/exporter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func getAttrs(attrs attribute.Set) ([]string, []string) {
327327
values := make([]string, 0, attrs.Len())
328328
itr := attrs.Iter()
329329

330-
if model.NameValidationScheme == model.UTF8Validation {
330+
if model.NameValidationScheme == model.UTF8Validation { // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
331331
// Do not perform sanitization if prometheus supports UTF-8.
332332
for itr.Next() {
333333
kv := itr.Attribute()
@@ -413,8 +413,9 @@ var unitSuffixes = map[string]string{
413413
// getName returns the sanitized name, prefixed with the namespace and suffixed with unit.
414414
func (c *collector) getName(m metricdata.Metrics, typ *dto.MetricType) string {
415415
name := m.Name
416-
if model.NameValidationScheme != model.UTF8Validation {
416+
if model.NameValidationScheme != model.UTF8Validation { // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
417417
// Only sanitize if prometheus does not support UTF-8.
418+
logDeprecatedLegacyScheme()
418419
name = model.EscapeName(name, model.NameEscapingScheme)
419420
}
420421
addCounterSuffix := !c.withoutCounterSuffixes && *typ == dto.MetricType_COUNTER

exporters/prometheus/exporter_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,10 @@ func TestPrometheusExporter(t *testing.T) {
472472
for _, tc := range testCases {
473473
t.Run(tc.name, func(t *testing.T) {
474474
if tc.disableUTF8 {
475-
model.NameValidationScheme = model.LegacyValidation
475+
model.NameValidationScheme = model.LegacyValidation // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
476476
defer func() {
477477
// Reset to defaults
478-
model.NameValidationScheme = model.UTF8Validation
478+
model.NameValidationScheme = model.UTF8Validation // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
479479
}()
480480
}
481481
ctx := context.Background()
@@ -1029,13 +1029,13 @@ func TestExemplars(t *testing.T) {
10291029
} {
10301030
t.Run(tc.name, func(t *testing.T) {
10311031
originalEscapingScheme := model.NameEscapingScheme
1032-
originalValidationScheme := model.NameValidationScheme
1032+
originalValidationScheme := model.NameValidationScheme // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
10331033
model.NameEscapingScheme = tc.escapingScheme
1034-
model.NameValidationScheme = tc.validationScheme
1034+
model.NameValidationScheme = tc.validationScheme // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
10351035
// Restore original value after the test is complete
10361036
defer func() {
10371037
model.NameEscapingScheme = originalEscapingScheme
1038-
model.NameValidationScheme = originalValidationScheme
1038+
model.NameValidationScheme = originalValidationScheme // nolint:staticcheck // We need this check to keep supporting the legacy scheme.
10391039
}()
10401040
// initialize registry exporter
10411041
ctx := context.Background()

0 commit comments

Comments
 (0)