From cf5f48f181f5270eeac48e077e974ba0e00f5c58 Mon Sep 17 00:00:00 2001 From: Owen Williams Date: Thu, 5 Dec 2024 03:59:06 -0500 Subject: [PATCH] Change default validation scheme to UTF8Validation (#724) fixes https://github.com/prometheus/common/issues/723 Signed-off-by: Owen Williams --- model/alert_test.go | 5 +++++ model/metric.go | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/model/alert_test.go b/model/alert_test.go index 2a8d7bba..fc3eaf10 100644 --- a/model/alert_test.go +++ b/model/alert_test.go @@ -22,6 +22,11 @@ import ( ) func TestAlertValidate(t *testing.T) { + oldScheme := NameValidationScheme + NameValidationScheme = LegacyValidation + defer func() { + NameValidationScheme = oldScheme + }() ts := time.Now() cases := []struct { diff --git a/model/metric.go b/model/metric.go index 0daca836..5766107c 100644 --- a/model/metric.go +++ b/model/metric.go @@ -28,13 +28,13 @@ import ( var ( // NameValidationScheme determines the method of name validation to be used by - // all calls to IsValidMetricName() and LabelName IsValid(). Setting UTF-8 mode - // in isolation from other components that don't support UTF-8 may result in - // bugs or other undefined behavior. This value is intended to be set by - // UTF-8-aware binaries as part of their startup. To avoid need for locking, - // this value should be set once, ideally in an init(), before multiple - // goroutines are started. - NameValidationScheme = LegacyValidation + // all calls to IsValidMetricName() and LabelName IsValid(). Setting UTF-8 + // mode in isolation from other components that don't support UTF-8 may result + // in bugs or other undefined behavior. This value can be set to + // LegacyValidation during startup if a binary is not UTF-8-aware binaries. To + // avoid need for locking, this value should be set once, ideally in an + // init(), before multiple goroutines are started. + NameValidationScheme = UTF8Validation // NameEscapingScheme defines the default way that names will be escaped when // presented to systems that do not support UTF-8 names. If the Content-Type