Make LabelNameRE public.

This commit is contained in:
beorn7 2015-06-01 15:41:09 +02:00
parent a842dc11e0
commit 10eab41b48
2 changed files with 6 additions and 6 deletions

View File

@ -61,7 +61,8 @@ const (
QuantileLabel = "quantile" QuantileLabel = "quantile"
) )
var labelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$") // LabelNameRE is a regular expression matching valid label names.
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
// A LabelName is a key for a LabelSet or Metric. It has a value associated // A LabelName is a key for a LabelSet or Metric. It has a value associated
// therewith. // therewith.
@ -73,7 +74,7 @@ func (ln *LabelName) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&s); err != nil { if err := unmarshal(&s); err != nil {
return err return err
} }
if !labelNameRE.MatchString(s) { if !LabelNameRE.MatchString(s) {
return fmt.Errorf("%q is not a valid label name", s) return fmt.Errorf("%q is not a valid label name", s)
} }
*ln = LabelName(s) *ln = LabelName(s)

View File

@ -9,16 +9,15 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/prometheus/client_golang/model" "github.com/golang/protobuf/proto"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/golang/protobuf/proto" "github.com/prometheus/client_golang/model"
) )
var ( var (
metricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`) metricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`)
labelNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
) )
// Labels represents a collection of label name -> value mappings. This type is // Labels represents a collection of label name -> value mappings. This type is
@ -194,6 +193,6 @@ func (d *Desc) String() string {
} }
func checkLabelName(l string) bool { func checkLabelName(l string) bool {
return labelNameRE.MatchString(l) && return model.LabelNameRE.MatchString(l) &&
!strings.HasPrefix(l, model.ReservedLabelPrefix) !strings.HasPrefix(l, model.ReservedLabelPrefix)
} }