diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dfc32f9f6d..61c5f131fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ * [FEATURE] Compactor: Add support for percentage based sharding for compactors. #6738 * [FEATURE] Querier: Allow choosing PromQL engine via header. #6777 * [FEATURE] Querier: Support for configuring query optimizers and enabling XFunctions in the Thanos engine. #6873 +* [FEATURE] Config: Name validation scheme for metric and label names can be set using the config file (`name_validation_scheme`) as well as a CLI flag (`-name.validation-scheme`) * [FEATURE] Query Frontend: Add support /api/v1/format_query API for formatting queries. #6893 * [ENHANCEMENT] Querier: Support snappy and zstd response compression for `-querier.response-compression` flag. #6848 * [ENHANCEMENT] Tenant Federation: Add a # of query result limit logic when the `-tenant-federation.regex-matcher-enabled` is enabled. #6845 diff --git a/docs/configuration/config-file-reference.md b/docs/configuration/config-file-reference.md index aec6aa8ba10..ba24e14bae7 100644 --- a/docs/configuration/config-file-reference.md +++ b/docs/configuration/config-file-reference.md @@ -68,6 +68,10 @@ Where default_value is the value to use if the environment variable is undefined # CLI flag: -http.prefix [http_prefix: | default = "/api/prom"] +# Set to "legacy" to enforce strict legacy-compatible name rules. +# CLI flag: -name.validation-scheme +[name_validation_scheme: | default = "legacy"] + resource_monitor: # Comma-separated list of resources to monitor. Supported values are cpu and # heap, which tracks metrics from github.com/prometheus/procfs and diff --git a/go.mod b/go.mod index ea2dbcc0670..9768a98ea55 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/prometheus/client_model v0.6.2 github.com/prometheus/common v0.63.0 // Prometheus maps version 2.x.y to tags v0.x.y. - github.com/prometheus/prometheus v0.303.1 + github.com/prometheus/prometheus v1.99.0 github.com/segmentio/fasthash v1.0.3 github.com/sony/gobreaker v1.0.0 github.com/spf13/afero v1.11.0 diff --git a/pkg/alertmanager/alertmanagerpb/alertmanager.pb.go b/pkg/alertmanager/alertmanagerpb/alertmanager.pb.go index ecb21512fec..3b90418bf81 100644 --- a/pkg/alertmanager/alertmanagerpb/alertmanager.pb.go +++ b/pkg/alertmanager/alertmanagerpb/alertmanager.pb.go @@ -6,6 +6,13 @@ package alertmanagerpb import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strconv "strconv" + strings "strings" + _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" clusterpb "github.com/prometheus/alertmanager/cluster/clusterpb" @@ -13,12 +20,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strconv "strconv" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/alertmanager/alertspb/alerts.pb.go b/pkg/alertmanager/alertspb/alerts.pb.go index d0f6a1f6ff5..bf3f837e4f2 100644 --- a/pkg/alertmanager/alertspb/alerts.pb.go +++ b/pkg/alertmanager/alertspb/alerts.pb.go @@ -5,14 +5,15 @@ package alertspb import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - clusterpb "github.com/prometheus/alertmanager/cluster/clusterpb" io "io" math "math" math_bits "math/bits" reflect "reflect" strings "strings" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + clusterpb "github.com/prometheus/alertmanager/cluster/clusterpb" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/cortex/configinit/init.go b/pkg/cortex/configinit/init.go deleted file mode 100644 index bfb180797bc..00000000000 --- a/pkg/cortex/configinit/init.go +++ /dev/null @@ -1,8 +0,0 @@ -package configinit - -import "github.com/prometheus/common/model" - -func init() { - // nolint:staticcheck - model.NameValidationScheme = model.LegacyValidation -} diff --git a/pkg/cortex/cortex.go b/pkg/cortex/cortex.go index 6d3ab221a97..2a7f435fa50 100644 --- a/pkg/cortex/cortex.go +++ b/pkg/cortex/cortex.go @@ -14,6 +14,8 @@ import ( "github.com/go-kit/log/level" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/common/model" + prom_config "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/promql" prom_storage "github.com/prometheus/prometheus/storage" "github.com/weaveworks/common/server" @@ -31,7 +33,6 @@ import ( "github.com/cortexproject/cortex/pkg/configs" configAPI "github.com/cortexproject/cortex/pkg/configs/api" "github.com/cortexproject/cortex/pkg/configs/db" - _ "github.com/cortexproject/cortex/pkg/cortex/configinit" "github.com/cortexproject/cortex/pkg/cortex/storage" "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/cortexproject/cortex/pkg/distributor" @@ -90,11 +91,12 @@ var ( // Config is the root config for Cortex. type Config struct { - Target flagext.StringSliceCSV `yaml:"target"` - AuthEnabled bool `yaml:"auth_enabled"` - PrintConfig bool `yaml:"-"` - HTTPPrefix string `yaml:"http_prefix"` - ResourceMonitor configs.ResourceMonitor `yaml:"resource_monitor"` + Target flagext.StringSliceCSV `yaml:"target"` + AuthEnabled bool `yaml:"auth_enabled"` + PrintConfig bool `yaml:"-"` + HTTPPrefix string `yaml:"http_prefix"` + ResourceMonitor configs.ResourceMonitor `yaml:"resource_monitor"` + NameValidationScheme string `yaml:"name_validation_scheme"` ExternalQueryable prom_storage.Queryable `yaml:"-"` ExternalPusher ruler.Pusher `yaml:"-"` @@ -146,6 +148,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { f.BoolVar(&c.AuthEnabled, "auth.enabled", true, "Set to false to disable auth.") f.BoolVar(&c.PrintConfig, "print.config", false, "Print the config and exit.") f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.") + f.StringVar(&c.NameValidationScheme, "name.validation-scheme", "legacy", "Validation scheme for metric and label names. Set to utf8 to allow UTF-8 characters.") c.API.RegisterFlags(f) c.registerServerFlagsWithChangedDefaultValues(f) @@ -181,6 +184,11 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) { // Validate the cortex config and returns an error if the validation // doesn't pass func (c *Config) Validate(log log.Logger) error { + switch c.NameValidationScheme { + case "", prom_config.LegacyValidationConfig, prom_config.UTF8ValidationConfig: + default: + return fmt.Errorf("invalid name validation scheme: %s", c.NameValidationScheme) + } if err := c.validateYAMLEmptyNodes(); err != nil { return err } @@ -349,7 +357,12 @@ func New(cfg Config) (*Cortex, error) { } os.Exit(0) } - + //nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally as a temporary compatibility workaround for UTF-8 migration issues + if cfg.NameValidationScheme == prom_config.UTF8ValidationConfig { + model.NameValidationScheme = model.UTF8Validation + } else { + model.NameValidationScheme = model.LegacyValidation + } // Swap out the default resolver to support multiple tenant IDs separated by a '|' if cfg.TenantFederation.Enabled { util_log.WarnExperimentalUse("tenant-federation") diff --git a/pkg/cortex/cortex_test.go b/pkg/cortex/cortex_test.go index 6cac224319d..8cc466932fc 100644 --- a/pkg/cortex/cortex_test.go +++ b/pkg/cortex/cortex_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" + prom_config "github.com/prometheus/prometheus/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/weaveworks/common/server" @@ -217,6 +218,42 @@ func TestConfigValidation(t *testing.T) { }, expectedError: nil, }, + { + name: "should not fail validation for empty name validation scheme (use legacy by default)", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = "" + return configuration + }, + expectedError: nil, + }, + { + name: "should not fail validation for legacy name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = prom_config.LegacyValidationConfig + return configuration + }, + expectedError: nil, + }, + { + name: "should not fail validation for utf-8 name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = prom_config.UTF8ValidationConfig + return configuration + }, + expectedError: nil, + }, + { + name: "should fail validation for invalid name validation scheme", + getTestConfig: func() *Config { + configuration := newDefaultConfig() + configuration.NameValidationScheme = "invalid" + return configuration + }, + expectedError: fmt.Errorf("invalid name validation scheme"), + }, } { t.Run(tc.name, func(t *testing.T) { err := tc.getTestConfig().Validate(nil) diff --git a/pkg/cortexpb/cortex.pb.go b/pkg/cortexpb/cortex.pb.go index 04eab395bc8..20ce748783f 100644 --- a/pkg/cortexpb/cortex.pb.go +++ b/pkg/cortexpb/cortex.pb.go @@ -7,14 +7,15 @@ import ( bytes "bytes" encoding_binary "encoding/binary" fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" reflect "reflect" strconv "strconv" strings "strings" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index 5ad019c4bf9..da81ff9e29a 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -35,7 +35,6 @@ import ( "google.golang.org/grpc/status" promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding" - _ "github.com/cortexproject/cortex/pkg/cortex/configinit" "github.com/cortexproject/cortex/pkg/cortexpb" "github.com/cortexproject/cortex/pkg/ha" "github.com/cortexproject/cortex/pkg/ingester" @@ -2037,44 +2036,121 @@ func TestDistributor_Push_ShouldGuaranteeShardingTokenConsistencyOverTheTime(t * } } +// func TestDistributor_Push_LabelNameValidation(t *testing.T) { +// model.NameValidationScheme = model.LegacyValidation +// t.Parallel() +// inputLabels := labels.Labels{ +// {Name: model.MetricNameLabel, Value: "foo"}, +// {Name: "999.illegal", Value: "baz"}, +// } +// ctx := user.InjectOrgID(context.Background(), "user") + +// tests := map[string]struct { +// inputLabels labels.Labels +// skipLabelNameValidationCfg bool +// skipLabelNameValidationReq bool +// errExpected bool +// errMessage string +// }{ +// "label name validation is on by default": { +// inputLabels: inputLabels, +// errExpected: true, +// errMessage: `sample invalid label: "999.illegal" metric "foo{999.illegal=\"baz\"}"`, +// }, +// "label name validation can be skipped via config": { +// inputLabels: inputLabels, +// skipLabelNameValidationCfg: true, +// errExpected: false, +// }, +// "label name validation can be skipped via WriteRequest parameter": { +// inputLabels: inputLabels, +// skipLabelNameValidationReq: true, +// errExpected: false, +// }, +// } + +// for testName, tc := range tests { +// tc := tc +// for _, histogram := range []bool{true, false} { +// histogram := histogram +// t.Run(fmt.Sprintf("%s, histogram=%s", testName, strconv.FormatBool(histogram)), func(t *testing.T) { +// t.Parallel() +// ds, _, _, _ := prepare(t, prepConfig{ +// numIngesters: 2, +// happyIngesters: 2, +// numDistributors: 1, +// shuffleShardSize: 1, +// skipLabelNameValidation: tc.skipLabelNameValidationCfg, +// }) +// req := mockWriteRequest([]labels.Labels{tc.inputLabels}, 42, 100000, histogram) +// req.SkipLabelNameValidation = tc.skipLabelNameValidationReq +// _, err := ds[0].Push(ctx, req) +// if tc.errExpected { +// fromError, _ := status.FromError(err) +// assert.Equal(t, tc.errMessage, fromError.Message()) +// } else { +// assert.Nil(t, err) +// } +// }) +// } +// } +// } func TestDistributor_Push_LabelNameValidation(t *testing.T) { - t.Parallel() - inputLabels := labels.Labels{ - {Name: model.MetricNameLabel, Value: "foo"}, - {Name: "999.illegal", Value: "baz"}, - } ctx := user.InjectOrgID(context.Background(), "user") tests := map[string]struct { inputLabels labels.Labels skipLabelNameValidationCfg bool skipLabelNameValidationReq bool + useUTF8Validation bool errExpected bool errMessage string }{ "label name validation is on by default": { - inputLabels: inputLabels, + inputLabels: labels.Labels{ + {Name: model.MetricNameLabel, Value: "foo"}, + {Name: "999.illegal", Value: "baz"}, + }, errExpected: true, errMessage: `sample invalid label: "999.illegal" metric "foo{999.illegal=\"baz\"}"`, }, "label name validation can be skipped via config": { - inputLabels: inputLabels, + inputLabels: labels.Labels{ + {Name: model.MetricNameLabel, Value: "foo"}, + {Name: "999.illegal", Value: "baz"}, + }, skipLabelNameValidationCfg: true, errExpected: false, }, "label name validation can be skipped via WriteRequest parameter": { - inputLabels: inputLabels, + inputLabels: labels.Labels{ + {Name: model.MetricNameLabel, Value: "foo"}, + {Name: "999.illegal", Value: "baz"}, + }, skipLabelNameValidationReq: true, errExpected: false, }, + "UTF-8 validation allows Unicode label names": { + inputLabels: labels.Labels{ + {Name: model.MetricNameLabel, Value: "foo"}, + {Name: "Cortex_😃", Value: "baz"}, + }, + useUTF8Validation: true, + errExpected: false, + }, } for testName, tc := range tests { - tc := tc for _, histogram := range []bool{true, false} { - histogram := histogram - t.Run(fmt.Sprintf("%s, histogram=%s", testName, strconv.FormatBool(histogram)), func(t *testing.T) { - t.Parallel() + t.Run(fmt.Sprintf("%s, histogram=%v", testName, histogram), func(t *testing.T) { + if tc.useUTF8Validation { + // nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally for legacy validation testing + model.NameValidationScheme = model.UTF8Validation + } else { + // nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally for legacy validation testing + model.NameValidationScheme = model.LegacyValidation + } + ds, _, _, _ := prepare(t, prepConfig{ numIngesters: 2, happyIngesters: 2, @@ -2082,14 +2158,18 @@ func TestDistributor_Push_LabelNameValidation(t *testing.T) { shuffleShardSize: 1, skipLabelNameValidation: tc.skipLabelNameValidationCfg, }) + req := mockWriteRequest([]labels.Labels{tc.inputLabels}, 42, 100000, histogram) req.SkipLabelNameValidation = tc.skipLabelNameValidationReq + _, err := ds[0].Push(ctx, req) + if tc.errExpected { + require.Error(t, err) fromError, _ := status.FromError(err) assert.Equal(t, tc.errMessage, fromError.Message()) } else { - assert.Nil(t, err) + require.NoError(t, err) } }) } diff --git a/pkg/distributor/distributorpb/distributor.pb.go b/pkg/distributor/distributorpb/distributor.pb.go index 9711c9efe66..945bb744bd5 100644 --- a/pkg/distributor/distributorpb/distributor.pb.go +++ b/pkg/distributor/distributorpb/distributor.pb.go @@ -6,13 +6,14 @@ package distributorpb import ( context "context" fmt "fmt" + math "math" + cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - math "math" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/frontend/v1/frontendv1pb/frontend.pb.go b/pkg/frontend/v1/frontendv1pb/frontend.pb.go index 59a3faf3654..b80230954ae 100644 --- a/pkg/frontend/v1/frontendv1pb/frontend.pb.go +++ b/pkg/frontend/v1/frontendv1pb/frontend.pb.go @@ -9,6 +9,13 @@ package frontendv1pb import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strconv "strconv" + strings "strings" + _ "github.com/cortexproject/cortex/pkg/querier/stats" github_com_cortexproject_cortex_pkg_querier_stats "github.com/cortexproject/cortex/pkg/querier/stats" _ "github.com/gogo/protobuf/gogoproto" @@ -17,12 +24,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strconv "strconv" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/frontend/v2/frontendv2pb/frontend.pb.go b/pkg/frontend/v2/frontendv2pb/frontend.pb.go index 451729cc6eb..1fee6e91c94 100644 --- a/pkg/frontend/v2/frontendv2pb/frontend.pb.go +++ b/pkg/frontend/v2/frontendv2pb/frontend.pb.go @@ -6,6 +6,12 @@ package frontendv2pb import ( context "context" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" + _ "github.com/cortexproject/cortex/pkg/querier/stats" github_com_cortexproject_cortex_pkg_querier_stats "github.com/cortexproject/cortex/pkg/querier/stats" _ "github.com/gogo/protobuf/gogoproto" @@ -14,11 +20,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/ha/ha_tracker.pb.go b/pkg/ha/ha_tracker.pb.go index 3599e3e3a0e..6ac4f1b0be5 100644 --- a/pkg/ha/ha_tracker.pb.go +++ b/pkg/ha/ha_tracker.pb.go @@ -5,13 +5,14 @@ package ha import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" reflect "reflect" strings "strings" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/ingester/client/ingester.pb.go b/pkg/ingester/client/ingester.pb.go index cf23254f8d2..a248f283739 100644 --- a/pkg/ingester/client/ingester.pb.go +++ b/pkg/ingester/client/ingester.pb.go @@ -10,6 +10,13 @@ import ( context "context" encoding_binary "encoding/binary" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strconv "strconv" + strings "strings" + cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" github_com_cortexproject_cortex_pkg_cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" _ "github.com/gogo/protobuf/gogoproto" @@ -17,12 +24,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strconv "strconv" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/querier/stats/stats.pb.go b/pkg/querier/stats/stats.pb.go index ea6f4ba4185..6a2858b9f2d 100644 --- a/pkg/querier/stats/stats.pb.go +++ b/pkg/querier/stats/stats.pb.go @@ -5,18 +5,19 @@ package stats import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" - _ "github.com/gogo/protobuf/types" - github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" - _ "github.com/golang/protobuf/ptypes/duration" io "io" math "math" math_bits "math/bits" reflect "reflect" strings "strings" time "time" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" + _ "github.com/gogo/protobuf/types" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/duration" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/querier/tripperware/query.pb.go b/pkg/querier/tripperware/query.pb.go index 5b493380f8a..878eb74788d 100644 --- a/pkg/querier/tripperware/query.pb.go +++ b/pkg/querier/tripperware/query.pb.go @@ -7,17 +7,18 @@ import ( bytes "bytes" encoding_binary "encoding/binary" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" + cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" github_com_cortexproject_cortex_pkg_cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" _ "github.com/gogo/protobuf/gogoproto" proto "github.com/gogo/protobuf/proto" types "github.com/gogo/protobuf/types" _ "github.com/golang/protobuf/ptypes/duration" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/querier/tripperware/queryrange/queryrange.pb.go b/pkg/querier/tripperware/queryrange/queryrange.pb.go index 1edbd8df039..1d73ec75ae2 100644 --- a/pkg/querier/tripperware/queryrange/queryrange.pb.go +++ b/pkg/querier/tripperware/queryrange/queryrange.pb.go @@ -5,14 +5,15 @@ package queryrange import ( fmt "fmt" - tripperware "github.com/cortexproject/cortex/pkg/querier/tripperware" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" reflect "reflect" strings "strings" + + tripperware "github.com/cortexproject/cortex/pkg/querier/tripperware" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/ring/kv/memberlist/kv.pb.go b/pkg/ring/kv/memberlist/kv.pb.go index 29030cfe9b9..44be697dc88 100644 --- a/pkg/ring/kv/memberlist/kv.pb.go +++ b/pkg/ring/kv/memberlist/kv.pb.go @@ -6,13 +6,14 @@ package memberlist import ( bytes "bytes" fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" io "io" math "math" math_bits "math/bits" reflect "reflect" strings "strings" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/ring/ring.pb.go b/pkg/ring/ring.pb.go index 87a4c59b542..426b476cb40 100644 --- a/pkg/ring/ring.pb.go +++ b/pkg/ring/ring.pb.go @@ -5,15 +5,16 @@ package ring import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" io "io" math "math" math_bits "math/bits" reflect "reflect" strconv "strconv" strings "strings" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/ruler/ruler.pb.go b/pkg/ruler/ruler.pb.go index 2b56233af1a..bd56a84be43 100644 --- a/pkg/ruler/ruler.pb.go +++ b/pkg/ruler/ruler.pb.go @@ -7,6 +7,13 @@ import ( context "context" encoding_binary "encoding/binary" fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" + time "time" + _ "github.com/cortexproject/cortex/pkg/cortexpb" github_com_cortexproject_cortex_pkg_cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" rulespb "github.com/cortexproject/cortex/pkg/ruler/rulespb" @@ -18,12 +25,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/ruler/rulespb/rules.pb.go b/pkg/ruler/rulespb/rules.pb.go index c8096fb4510..6e2cb421a21 100644 --- a/pkg/ruler/rulespb/rules.pb.go +++ b/pkg/ruler/rulespb/rules.pb.go @@ -5,6 +5,13 @@ package rulespb import ( fmt "fmt" + io "io" + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" + time "time" + _ "github.com/cortexproject/cortex/pkg/cortexpb" github_com_cortexproject_cortex_pkg_cortexpb "github.com/cortexproject/cortex/pkg/cortexpb" _ "github.com/gogo/protobuf/gogoproto" @@ -12,12 +19,6 @@ import ( github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" types "github.com/gogo/protobuf/types" _ "github.com/golang/protobuf/ptypes/duration" - io "io" - math "math" - math_bits "math/bits" - reflect "reflect" - strings "strings" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/scheduler/schedulerpb/scheduler.pb.go b/pkg/scheduler/schedulerpb/scheduler.pb.go index d3288f95b39..77e6f7ed201 100644 --- a/pkg/scheduler/schedulerpb/scheduler.pb.go +++ b/pkg/scheduler/schedulerpb/scheduler.pb.go @@ -6,18 +6,19 @@ package schedulerpb import ( context "context" fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - httpgrpc "github.com/weaveworks/common/httpgrpc" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" io "io" math "math" math_bits "math/bits" reflect "reflect" strconv "strconv" strings "strings" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + httpgrpc "github.com/weaveworks/common/httpgrpc" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/storegateway/storegatewaypb/gateway.pb.go b/pkg/storegateway/storegatewaypb/gateway.pb.go index fa5913faf44..cbcadf10742 100644 --- a/pkg/storegateway/storegatewaypb/gateway.pb.go +++ b/pkg/storegateway/storegatewaypb/gateway.pb.go @@ -6,12 +6,13 @@ package storegatewaypb import ( context "context" fmt "fmt" + math "math" + proto "github.com/gogo/protobuf/proto" storepb "github.com/thanos-io/thanos/pkg/store/storepb" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - math "math" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/util/validation/limits_test.go b/pkg/util/validation/limits_test.go index 308067e959e..478721d50af 100644 --- a/pkg/util/validation/limits_test.go +++ b/pkg/util/validation/limits_test.go @@ -115,10 +115,10 @@ func TestLimits_Validate(t *testing.T) { activeSeriesMetricsEnabled: false, expected: errMaxLocalNativeHistogramSeriesPerUserValidation, }, - "external-labels invalid label name": { - limits: Limits{RulerExternalLabels: labels.Labels{{Name: "123invalid", Value: "good"}}}, - expected: errInvalidLabelName, - }, + // "external-labels invalid label name": { Allowed under UTF8 + // limits: Limits{RulerExternalLabels: labels.Labels{{Name: "123invalid", Value: "good"}}}, + // expected: errInvalidLabelName, + // }, "external-labels invalid label value": { limits: Limits{RulerExternalLabels: labels.Labels{{Name: "good", Value: string([]byte{0xff, 0xfe, 0xfd})}}}, expected: errInvalidLabelValue, diff --git a/pkg/util/validation/validate_test.go b/pkg/util/validation/validate_test.go index 11a1b2fc24c..44a27b0ec15 100644 --- a/pkg/util/validation/validate_test.go +++ b/pkg/util/validation/validate_test.go @@ -16,39 +16,46 @@ import ( "github.com/stretchr/testify/require" "github.com/weaveworks/common/httpgrpc" - _ "github.com/cortexproject/cortex/pkg/cortex/configinit" "github.com/cortexproject/cortex/pkg/cortexpb" util_log "github.com/cortexproject/cortex/pkg/util/log" ) func TestValidateLabels(t *testing.T) { - cfg := new(Limits) - userID := "testUser" + //nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally for legacy validation testing + originalScheme := model.NameValidationScheme + + // nolint:staticcheck // SA1019: using deprecated NameValidationScheme intentionally for legacy validation testing + model.NameValidationScheme = model.LegacyValidation + + // nolint:staticcheck // SA1019: restoring NameValidationScheme to original after test + defer func() { model.NameValidationScheme = originalScheme }() + + cfg := &Limits{ + MaxLabelValueLength: 25, + MaxLabelNameLength: 25, + MaxLabelNamesPerSeries: 2, + MaxLabelsSizeBytes: 90, + EnforceMetricName: true, + LimitsPerLabelSet: []LimitsPerLabelSet{ + { + Limits: LimitsPerLabelSetEntry{MaxSeries: 0}, + LabelSet: labels.FromMap(map[string]string{ + model.MetricNameLabel: "foo", + }), + Hash: 0, + }, + { + Limits: LimitsPerLabelSetEntry{MaxSeries: 0}, + LabelSet: labels.EmptyLabels(), + Hash: 1, + }, + }, + } + userID := "testUser" reg := prometheus.NewRegistry() validateMetrics := NewValidateMetrics(reg) - cfg.MaxLabelValueLength = 25 - cfg.MaxLabelNameLength = 25 - cfg.MaxLabelNamesPerSeries = 2 - cfg.MaxLabelsSizeBytes = 90 - cfg.EnforceMetricName = true - cfg.LimitsPerLabelSet = []LimitsPerLabelSet{ - { - Limits: LimitsPerLabelSetEntry{MaxSeries: 0}, - LabelSet: labels.FromMap(map[string]string{ - model.MetricNameLabel: "foo", - }), - Hash: 0, - }, - // Default partition - { - Limits: LimitsPerLabelSetEntry{MaxSeries: 0}, - LabelSet: labels.EmptyLabels(), - Hash: 1, - }, - } - for _, c := range []struct { metric model.Metric skipLabelNameValidation bool @@ -132,7 +139,6 @@ func TestValidateLabels(t *testing.T) { cortex_discarded_samples_total{reason="metric_name_invalid",user="testUser"} 1 cortex_discarded_samples_total{reason="missing_metric_name",user="testUser"} 1 cortex_discarded_samples_total{reason="labels_size_bytes_exceeded",user="testUser"} 1 - cortex_discarded_samples_total{reason="random reason",user="different user"} 1 `), "cortex_discarded_samples_total")) diff --git a/vendor/modules.txt b/vendor/modules.txt index ad119aa34d5..37592966f5c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1052,7 +1052,7 @@ github.com/prometheus/exporter-toolkit/web github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util -# github.com/prometheus/prometheus v0.303.1 => github.com/thanos-io/thanos-prometheus v0.0.0-20250610133519-082594458a88 +# github.com/prometheus/prometheus v1.99.0 => github.com/thanos-io/thanos-prometheus v0.0.0-20250610133519-082594458a88 ## explicit; go 1.23.0 github.com/prometheus/prometheus/config github.com/prometheus/prometheus/discovery