@@ -21,6 +21,7 @@ import (
2121 "math"
2222 "net/http"
2323 "net/url"
24+ "regexp"
2425 "strconv"
2526 "strings"
2627 "text/template"
@@ -74,7 +75,7 @@ func SanitizeIntValue(s string) (int64, error) {
7475 return value , fmt .Errorf (resultErr )
7576}
7677
77- func CreateMetricsList (c config.Module ) ([]JSONMetric , error ) {
78+ func CreateMetricsList (c config.Module , logger log. Logger ) ([]JSONMetric , error ) {
7879 var (
7980 metrics []JSONMetric
8081 valueType prometheus.ValueType
@@ -91,10 +92,18 @@ func CreateMetricsList(c config.Module) ([]JSONMetric, error) {
9192 switch metric .Type {
9293 case config .ValueScrape :
9394 var variableLabels , variableLabelsValues []string
95+ var err error
96+ var re * regexp.Regexp
9497 for k , v := range metric .Labels {
9598 variableLabels = append (variableLabels , k )
9699 variableLabelsValues = append (variableLabelsValues , v )
97100 }
101+ if metric .Regex != "" {
102+ if re , err = regexp .Compile (metric .Regex ); err != nil {
103+ level .Error (logger ).Log ("msg" , "invalid regex expression" , "err" , err )
104+ continue
105+ }
106+ }
98107 jsonMetric := JSONMetric {
99108 Type : config .ValueScrape ,
100109 Desc : prometheus .NewDesc (
@@ -107,6 +116,7 @@ func CreateMetricsList(c config.Module) ([]JSONMetric, error) {
107116 LabelsJSONPaths : variableLabelsValues ,
108117 ValueType : valueType ,
109118 EpochTimestampJSONPath : metric .EpochTimestamp ,
119+ Regex : re ,
110120 }
111121 metrics = append (metrics , jsonMetric )
112122 case config .ObjectScrape :
0 commit comments