From 4dde940244c1d5108ddacd7a67c6a4ec4b186f68 Mon Sep 17 00:00:00 2001 From: Kyryl Sablin Date: Thu, 1 Nov 2018 15:22:02 +0100 Subject: [PATCH] add wildcard label name Signed-off-by: Kyryl Sablin --- model/labels.go | 8 +++++++- model/labels_test.go | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/model/labels.go b/model/labels.go index 41051a01..3394283b 100644 --- a/model/labels.go +++ b/model/labels.go @@ -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. @@ -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 diff --git a/model/labels_test.go b/model/labels_test.go index e8df28ff..a9354035 100644 --- a/model/labels_test.go +++ b/model/labels_test.go @@ -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 {