Source File
silence.go
Belonging Package
github.com/prometheus/common/model
package model
import (
)
type Matcher struct {
Name LabelName `json:"name"`
Value string `json:"value"`
IsRegex bool `json:"isRegex"`
}
func ( *Matcher) ( []byte) error {
type Matcher
if := json.Unmarshal(, (*)()); != nil {
return
}
if len(.Name) == 0 {
return fmt.Errorf("label name in matcher must not be empty")
}
if .IsRegex {
if , := regexp.Compile(.Value); != nil {
return
}
}
return nil
}
func ( *Matcher) () error {
if !.Name.IsValid() {
return fmt.Errorf("invalid name %q", .Name)
}
if .IsRegex {
if , := regexp.Compile(.Value); != nil {
return fmt.Errorf("invalid regular expression %q", .Value)
}
} else if !LabelValue(.Value).IsValid() || len(.Value) == 0 {
return fmt.Errorf("invalid value %q", .Value)
}
return nil
}
func ( *Silence) () error {
if len(.Matchers) == 0 {
return fmt.Errorf("at least one matcher required")
}
for , := range .Matchers {
if := .Validate(); != nil {
return fmt.Errorf("invalid matcher: %s", )
}
}
if .StartsAt.IsZero() {
return fmt.Errorf("start time missing")
}
if .EndsAt.IsZero() {
return fmt.Errorf("end time missing")
}
if .EndsAt.Before(.StartsAt) {
return fmt.Errorf("start time must be before end time")
}
if .CreatedBy == "" {
return fmt.Errorf("creator information missing")
}
if .Comment == "" {
return fmt.Errorf("comment missing")
}
if .CreatedAt.IsZero() {
return fmt.Errorf("creation timestamp missing")
}
return nil
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |