77 "time"
88
99 "github.com/grafana/dskit/tenant"
10- prom_validation "github.com/prometheus/prometheus /model/validation "
10+ "github.com/prometheus/common /model"
1111 "github.com/prometheus/prometheus/promql"
1212 "github.com/prometheus/prometheus/storage"
1313
@@ -25,64 +25,64 @@ func NameValidatingEngine(engine promql.QueryEngine, limits *validation.Override
2525 return & nameValidatingEngine {engine : engine , limits : limits }
2626}
2727
28- type optsWithNamingScheme struct {
28+ type optsWithValidationScheme struct {
2929 promql.QueryOpts
30- namingScheme prom_validation. NamingScheme
30+ validationScheme model. ValidationScheme
3131}
3232
33- func (o optsWithNamingScheme ) EnablePerStepStats () bool {
33+ func (o optsWithValidationScheme ) EnablePerStepStats () bool {
3434 return o .QueryOpts .EnablePerStepStats ()
3535}
3636
37- func (o optsWithNamingScheme ) LookbackDelta () time.Duration {
37+ func (o optsWithValidationScheme ) LookbackDelta () time.Duration {
3838 return o .QueryOpts .LookbackDelta ()
3939}
4040
41- func (o optsWithNamingScheme ) NameValidationScheme () prom_validation. NamingScheme {
42- return o .namingScheme
41+ func (o optsWithValidationScheme ) ValidationScheme () model. ValidationScheme {
42+ return o .validationScheme
4343}
4444
4545func (e nameValidatingEngine ) NewInstantQuery (ctx context.Context , q storage.Queryable , opts promql.QueryOpts , qs string , ts time.Time ) (promql.Query , error ) {
46- namingScheme , err := e .getNamingScheme (ctx )
46+ validationScheme , err := e .getValidationScheme (ctx )
4747 if err != nil {
4848 return nil , err
4949 }
5050 if opts == nil {
51- opts = promql .NewPrometheusQueryOpts (false , 0 , prom_validation . UTF8NamingScheme )
51+ opts = promql .NewPrometheusQueryOpts (false , 0 , model . UTF8Validation )
5252 }
53- opts = & optsWithNamingScheme {
54- QueryOpts : opts ,
55- namingScheme : namingScheme ,
53+ opts = & optsWithValidationScheme {
54+ QueryOpts : opts ,
55+ validationScheme : validationScheme ,
5656 }
5757 return e .engine .NewInstantQuery (ctx , q , opts , qs , ts )
5858}
5959
6060func (e nameValidatingEngine ) NewRangeQuery (ctx context.Context , q storage.Queryable , opts promql.QueryOpts , qs string , start , end time.Time , interval time.Duration ) (promql.Query , error ) {
61- namingScheme , err := e .getNamingScheme (ctx )
61+ validationScheme , err := e .getValidationScheme (ctx )
6262 if err != nil {
6363 return nil , err
6464 }
6565 if opts == nil {
66- opts = promql .NewPrometheusQueryOpts (false , 0 , prom_validation . UTF8NamingScheme )
66+ opts = promql .NewPrometheusQueryOpts (false , 0 , model . UTF8Validation )
6767 }
68- opts = & optsWithNamingScheme {
69- QueryOpts : opts ,
70- namingScheme : namingScheme ,
68+ opts = & optsWithValidationScheme {
69+ QueryOpts : opts ,
70+ validationScheme : validationScheme ,
7171 }
7272 return e .engine .NewRangeQuery (ctx , q , opts , qs , start , end , interval )
7373}
7474
75- // getNamingScheme retrieves the name validation scheme to use from a context containing tenant IDs.
75+ // getValidationScheme retrieves the name validation scheme to use from a context containing tenant IDs.
7676// Returns legacy validation scheme if at least one tenant uses legacy validation.
77- func (e nameValidatingEngine ) getNamingScheme (ctx context.Context ) (prom_validation. NamingScheme , error ) {
77+ func (e nameValidatingEngine ) getValidationScheme (ctx context.Context ) (model. ValidationScheme , error ) {
7878 tenantIDs , err := tenant .TenantIDs (ctx )
7979 if err != nil {
80- return "" , err
80+ return model . UnsetValidation , err
8181 }
8282 for _ , tenantID := range tenantIDs {
83- if e .limits .NameValidationScheme (tenantID ) == prom_validation . LegacyNamingScheme {
84- return prom_validation . LegacyNamingScheme , nil
83+ if e .limits .ValidationScheme (tenantID ) == model . LegacyValidation {
84+ return model . LegacyValidation , nil
8585 }
8686 }
87- return prom_validation . UTF8NamingScheme , nil
87+ return model . UTF8Validation , nil
8888}
0 commit comments