Skip to content

Commit

Permalink
add wildcard label name
Browse files Browse the repository at this point in the history
Signed-off-by: Kyryl Sablin <kyryl.sablin@schibsted.com>
  • Loading branch information
Kyryl Sablin committed Nov 1, 2018
1 parent 7e9e6ca commit 4dde940
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion model/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,15 @@ const (
// QuantileLabel is used for the label that defines the quantile in a
// summary.
QuantileLabel = "quantile"

// Used in some configurations to define that all labels should be used.
WildcardLabel = "*"
)

// LabelNameRE is a regular expression matching valid label names. Note that the
// IsValid method of LabelName performs the same check but faster than a match
// with this regular expression.
var LabelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
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
// therewith.
Expand All @@ -96,6 +99,9 @@ func (ln LabelName) IsValid() bool {
if len(ln) == 0 {
return false
}
if len(ln) == 1 && ln[0] == '*' {
return true
}
for i, b := range ln {
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) {
return false
Expand Down
8 changes: 8 additions & 0 deletions model/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ func TestLabelNameIsValid(t *testing.T) {
ln: "colon:in:the:middle",
valid: false,
},
{
ln: "*",
valid: true,
},
{
ln: "a*",
valid: false,
},
}

for _, s := range scenarios {
Expand Down

0 comments on commit 4dde940

Please sign in to comment.