simplify metric label key validation

This commit is contained in:
Brian Akins 2017-08-01 07:07:44 -04:00
parent c339cc66ac
commit 9c1cde63be

View file

@ -145,9 +145,8 @@ func (m *metricMapper) initFromYAMLString(fileContents string) error {
// Check that label is correct. // Check that label is correct.
for k, v := range currentMapping.Labels { for k, v := range currentMapping.Labels {
label := fmt.Sprintf("%s=%q", k, v) if !metricNameRE.MatchString(k) {
if len(labelLineRE.FindStringSubmatch(label)) != 3 { return fmt.Errorf("invalid label key: %s", k)
return fmt.Errorf("invalid label: %s: %s", k, v)
} }
if k == "name" && !metricNameRE.MatchString(v) { if k == "name" && !metricNameRE.MatchString(v) {
return fmt.Errorf("metric name '%s' doesn't match regex '%s'", v, metricNameRE) return fmt.Errorf("metric name '%s' doesn't match regex '%s'", v, metricNameRE)