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

Method Validate

model/alert.go:85–102  ·  view source on GitHub ↗

Validate checks whether the alert data is inconsistent.

()

Source from the content-addressed store, hash-verified

83
84// Validate checks whether the alert data is inconsistent.
85func (a *Alert) Validate() error {
86 if a.StartsAt.IsZero() {
87 return fmt.Errorf("start time missing")
88 }
89 if !a.EndsAt.IsZero() && a.EndsAt.Before(a.StartsAt) {
90 return fmt.Errorf("start time must be before end time")
91 }
92 if err := a.Labels.Validate(); err != nil {
93 return fmt.Errorf("invalid label set: %w", err)
94 }
95 if len(a.Labels) == 0 {
96 return fmt.Errorf("at least one label pair required")
97 }
98 if err := a.Annotations.Validate(); err != nil {
99 return fmt.Errorf("invalid annotations: %w", err)
100 }
101 return nil
102}
103
104// Alert is a list of alerts that can be sorted in chronological order.
105type 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