MCPcopy Create free account
hub / github.com/prometheus/common / Validate

Method Validate

model/alert.go:91–108  ·  view source on GitHub ↗

Validate checks whether the alert data is inconsistent.

()

Source from the content-addressed store, hash-verified

89
90// Validate checks whether the alert data is inconsistent.
91func (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.
111type Alerts []*Alert

Callers 3

TestMatcherValidateFunction · 0.45
TestSilenceValidateFunction · 0.45
TestAlertValidateFunction · 0.45

Calls 1

BeforeMethod · 0.45

Tested by 3

TestMatcherValidateFunction · 0.36
TestSilenceValidateFunction · 0.36
TestAlertValidateFunction · 0.36