Validate checks whether the alert data is inconsistent.
()
| 89 | |
| 90 | // Validate checks whether the alert data is inconsistent. |
| 91 | func (a *Alert) Validate() error { |
| 92 | if a.StartsAt.IsZero() { |
| 93 | return errors.New("start time missing") |
| 94 | } |
| 95 | if !a.EndsAt.IsZero() && a.EndsAt.Before(a.StartsAt) { |
| 96 | return errors.New("start time must be before end time") |
| 97 | } |
| 98 | if err := a.Labels.Validate(); err != nil { |
| 99 | return fmt.Errorf("invalid label set: %w", err) |
| 100 | } |
| 101 | if len(a.Labels) == 0 { |
| 102 | return errors.New("at least one label pair required") |
| 103 | } |
| 104 | if err := a.Annotations.Validate(); err != nil { |
| 105 | return fmt.Errorf("invalid annotations: %w", err) |
| 106 | } |
| 107 | return nil |
| 108 | } |
| 109 | |
| 110 | // Alert is a list of alerts that can be sorted in chronological order. |
| 111 | type Alerts []*Alert |