so third parties, Grafana in particular, can over ride the validation. Grafana wants to do this because other data sources will have label keys with things like spaces, periods, or other characters - and looking for a better integration with alert manager. goes with grafana/grafana#38629 replaces https://github.com/prometheus/alertmanager/pull/2694 Signed-off-by: Kyle Brandt <kyle@grafana.com>
This commit is contained in:
parent
186362cef0
commit
1b8afe7cb5
|
@ -438,7 +438,8 @@ func (s *Silences) GC() (int, error) {
|
|||
return n, nil
|
||||
}
|
||||
|
||||
func validateMatcher(m *pb.Matcher) error {
|
||||
// ValidateMatcher runs validation on the matcher name, type, and pattern.
|
||||
var ValidateMatcher = func(m *pb.Matcher) error {
|
||||
if !model.LabelName(m.Name).IsValid() {
|
||||
return fmt.Errorf("invalid label name %q", m.Name)
|
||||
}
|
||||
|
@ -478,7 +479,7 @@ func validateSilence(s *pb.Silence) error {
|
|||
}
|
||||
allMatchEmpty := true
|
||||
for i, m := range s.Matchers {
|
||||
if err := validateMatcher(m); err != nil {
|
||||
if err := ValidateMatcher(m); err != nil {
|
||||
return fmt.Errorf("invalid label matcher %d: %s", i, err)
|
||||
}
|
||||
allMatchEmpty = allMatchEmpty && matchesEmpty(m)
|
||||
|
|
|
@ -1091,7 +1091,7 @@ func TestValidateMatcher(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, c := range cases {
|
||||
checkErr(t, c.err, validateMatcher(c.m))
|
||||
checkErr(t, c.err, ValidateMatcher(c.m))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue