2017-08-19 23:12:52 +03:00
|
|
|
package prometheus
|
2017-08-19 23:56:18 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"unicode/utf8"
|
|
|
|
)
|
|
|
|
|
|
|
|
func validateLabelValues(vals []string, expectedNumberOfValues int) error {
|
|
|
|
if len(vals) != expectedNumberOfValues {
|
|
|
|
return errInconsistentCardinality
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, val := range vals {
|
|
|
|
if !utf8.ValidString(val) {
|
|
|
|
return errors.New(fmt.Sprintf("label %q is not valid utf8", val))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateLabels(labels Labels, expectedNumberOfValues int) error {
|
|
|
|
if len(labels) != expectedNumberOfValues {
|
|
|
|
return errInconsistentCardinality
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, val := range labels {
|
|
|
|
if !utf8.ValidString(val) {
|
|
|
|
return errors.New(fmt.Sprintf("label %s: %q is not valid utf8", name, val))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|