Validate returns true iff all fields of the matcher have valid values.
()
| 47 | |
| 48 | // Validate returns true iff all fields of the matcher have valid values. |
| 49 | func (m *Matcher) Validate() error { |
| 50 | if !m.Name.IsValid() { |
| 51 | return fmt.Errorf("invalid name %q", m.Name) |
| 52 | } |
| 53 | if m.IsRegex { |
| 54 | if _, err := regexp.Compile(m.Value); err != nil { |
| 55 | return fmt.Errorf("invalid regular expression %q", m.Value) |
| 56 | } |
| 57 | } else if !LabelValue(m.Value).IsValid() || len(m.Value) == 0 { |
| 58 | return fmt.Errorf("invalid value %q", m.Value) |
| 59 | } |
| 60 | return nil |
| 61 | } |
| 62 | |
| 63 | // Silence defines the representation of a silence definition in the Prometheus |
| 64 | // eco-system. |
no test coverage detected