Skip to content

Commit a9e47cd

Browse files
committed
feat(model): remove name validation scheme global
1 parent 48b7fac commit a9e47cd

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

expfmt/decode.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// Decoder types decode an input stream into metric families.
3131
type Decoder interface {
32-
Decode(*dto.MetricFamily, model.NameValidationScheme) error
32+
Decode(*dto.MetricFamily, model.ValidationScheme) error
3333
}
3434

3535
// DecodeOptions contains options used by the Decoder and in sample extraction.
@@ -86,7 +86,7 @@ type protoDecoder struct {
8686
}
8787

8888
// Decode implements the Decoder interface.
89-
func (d *protoDecoder) Decode(v *dto.MetricFamily, nameValidationScheme model.NameValidationScheme) error {
89+
func (d *protoDecoder) Decode(v *dto.MetricFamily, nameValidationScheme model.ValidationScheme) error {
9090
opts := protodelim.UnmarshalOptions{
9191
MaxSize: -1,
9292
}
@@ -123,7 +123,7 @@ type textDecoder struct {
123123
}
124124

125125
// Decode implements the Decoder interface.
126-
func (d *textDecoder) Decode(v *dto.MetricFamily, _ model.NameValidationScheme) error {
126+
func (d *textDecoder) Decode(v *dto.MetricFamily, _ model.ValidationScheme) error {
127127
if d.err == nil {
128128
// Read all metrics in one shot.
129129
var p TextParser
@@ -156,7 +156,7 @@ type SampleDecoder struct {
156156

157157
// Decode calls the Decode method of the wrapped Decoder and then extracts the
158158
// samples from the decoded MetricFamily into the provided model.Vector.
159-
func (sd *SampleDecoder) Decode(s *model.Vector, nameValidationScheme model.NameValidationScheme) error {
159+
func (sd *SampleDecoder) Decode(s *model.Vector, nameValidationScheme model.ValidationScheme) error {
160160
err := sd.Dec.Decode(&sd.f, nameValidationScheme)
161161
if err != nil {
162162
return err

model/alert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (a *Alert) StatusAt(ts time.Time) AlertStatus {
8888
}
8989

9090
// Validate checks whether the alert data is inconsistent.
91-
func (a *Alert) Validate(nameValidationScheme NameValidationScheme) error {
91+
func (a *Alert) Validate(nameValidationScheme ValidationScheme) error {
9292
if a.StartsAt.IsZero() {
9393
return errors.New("start time missing")
9494
}

model/labels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type LabelName string
100100
// IsValid returns true iff the name matches the pattern of LabelNameRE when
101101
// NameValidationScheme is set to LegacyValidation, or valid UTF-8 if
102102
// NameValidationScheme is set to UTF8Validation.
103-
func (ln LabelName) IsValid(scheme NameValidationScheme) bool {
103+
func (ln LabelName) IsValid(scheme ValidationScheme) bool {
104104
if len(ln) == 0 {
105105
return false
106106
}

model/labelset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type LabelSet map[LabelName]LabelValue
2828

2929
// Validate checks whether all names and values in the label set
3030
// are valid.
31-
func (ls LabelSet) Validate(nameValidationScheme NameValidationScheme) error {
31+
func (ls LabelSet) Validate(nameValidationScheme ValidationScheme) error {
3232
for ln, lv := range ls {
3333
if !ln.IsValid(nameValidationScheme) {
3434
return fmt.Errorf("invalid name %q", ln)

model/metric.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ var (
3838

3939
// NameValidationScheme is a Go enum for determining how metric and label names will
4040
// be validated by this library.
41-
type NameValidationScheme int
41+
type ValidationScheme int
4242

4343
const (
4444
// LegacyValidation is a setting that requires that all metric and label names
4545
// conform to the original Prometheus character requirements described by
4646
// MetricNameRE and LabelNameRE.
47-
LegacyValidation NameValidationScheme = iota
47+
LegacyValidation ValidationScheme = iota
4848

4949
// UTF8Validation only requires that metric and label names be valid UTF-8
5050
// strings.
@@ -154,7 +154,7 @@ func (m Metric) FastFingerprint() Fingerprint {
154154
// IsValidMetricName returns true iff name matches the pattern of MetricNameRE
155155
// for legacy names, and iff it's valid UTF-8 if the UTF8Validation scheme is
156156
// selected.
157-
func IsValidMetricName(n LabelValue, scheme NameValidationScheme) bool {
157+
func IsValidMetricName(n LabelValue, scheme ValidationScheme) bool {
158158
switch scheme {
159159
case LegacyValidation:
160160
return IsValidLegacyMetricName(string(n))

model/silence.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (m *Matcher) UnmarshalJSON(b []byte) error {
4646
}
4747

4848
// Validate returns true iff all fields of the matcher have valid values.
49-
func (m *Matcher) Validate(nameValidationScheme NameValidationScheme) error {
49+
func (m *Matcher) Validate(nameValidationScheme ValidationScheme) error {
5050
if !m.Name.IsValid(nameValidationScheme) {
5151
return fmt.Errorf("invalid name %q", m.Name)
5252
}
@@ -76,7 +76,7 @@ type Silence struct {
7676
}
7777

7878
// Validate returns true iff all fields of the silence have valid values.
79-
func (s *Silence) Validate(nameValidationScheme NameValidationScheme) error {
79+
func (s *Silence) Validate(nameValidationScheme ValidationScheme) error {
8080
if len(s.Matchers) == 0 {
8181
return errors.New("at least one matcher required")
8282
}

0 commit comments

Comments
 (0)