From: Daniel Swarbrick <dswarbrick@debian.org>
Date: Thu, 20 Feb 2025 14:54:23 +0100
Subject: Use legacy label name validation

Forwarded: not-needed
Last-Update: 2025-02-20

Due to a backwards-incompatible change in prometheus/common v0.62.0,
override the global models.NameValidationScheme variable to enforce
legacy (non-UTF-8) label names. This patch can be dropped once the
prometheus package is updated to one that supports UTF-8 label names,
i.e., v2.55.0 or later.
---
 model/labels/labels_common.go | 4 ++++
 model/relabel/relabel.go      | 4 ++++
 model/rulefmt/rulefmt.go      | 4 ++++
 storage/remote/codec.go       | 4 ++++
 4 files changed, 16 insertions(+)

diff --git a/model/labels/labels_common.go b/model/labels/labels_common.go
index f46321c..60b92c2 100644
--- a/model/labels/labels_common.go
+++ b/model/labels/labels_common.go
@@ -33,6 +33,10 @@ const (
 
 var seps = []byte{'\xff'}
 
+func init() {
+	model.NameValidationScheme = model.LegacyValidation
+}
+
 // Label is a key/value pair of strings.
 type Label struct {
 	Name, Value string
diff --git a/model/relabel/relabel.go b/model/relabel/relabel.go
index db2e6ce..3c51ab0 100644
--- a/model/relabel/relabel.go
+++ b/model/relabel/relabel.go
@@ -37,6 +37,10 @@ var (
 	}
 )
 
+func init() {
+	model.NameValidationScheme = model.LegacyValidation
+}
+
 // Action is the action to be performed on relabeling.
 type Action string
 
diff --git a/model/rulefmt/rulefmt.go b/model/rulefmt/rulefmt.go
index bfb85ce..fa1d264 100644
--- a/model/rulefmt/rulefmt.go
+++ b/model/rulefmt/rulefmt.go
@@ -32,6 +32,10 @@ import (
 	"github.com/prometheus/prometheus/template"
 )
 
+func init() {
+	model.NameValidationScheme = model.LegacyValidation
+}
+
 // Error represents semantic errors on parsing rule groups.
 type Error struct {
 	Group    string
diff --git a/storage/remote/codec.go b/storage/remote/codec.go
index 4893340..b32c8e5 100644
--- a/storage/remote/codec.go
+++ b/storage/remote/codec.go
@@ -41,6 +41,10 @@ import (
 // decodeReadLimit is the maximum size of a read request body in bytes.
 const decodeReadLimit = 32 * 1024 * 1024
 
+func init() {
+	model.NameValidationScheme = model.LegacyValidation
+}
+
 type HTTPError struct {
 	msg    string
 	status int
