alert - rename validate function and flags (#440)

* alert - rename validate function and flags
This commit is contained in:
kreedom 2020-04-26 14:15:04 +03:00 committed by GitHub
parent 5f61d43db9
commit 2c18548e08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 15 deletions

View file

@ -77,8 +77,8 @@ Usage of vmalert:
-rule /path/to/file. Path to a single file with alerting rules -rule /path/to/file. Path to a single file with alerting rules
-rule dir/*.yaml -rule /*.yaml. Relative path to all .yaml files in "dir" folder, -rule dir/*.yaml -rule /*.yaml. Relative path to all .yaml files in "dir" folder,
absolute path to all .yaml files in root. absolute path to all .yaml files in root.
-rule.validateAnnotations -rule.validateTemplates
Indicates to validate annotation templates (default true) Indicates to validate annotation and label templates (default true)
``` ```
Pass `-help` to `vmalert` in order to see the full list of supported Pass `-help` to `vmalert` in order to see the full list of supported

View file

@ -39,10 +39,10 @@ func Parse(pathPatterns []string, validateAnnotations bool) ([]Group, error) {
// TODO: this init looks weird here // TODO: this init looks weird here
rule.alerts = make(map[uint64]*notifier.Alert) rule.alerts = make(map[uint64]*notifier.Alert)
if validateAnnotations { if validateAnnotations {
if err = notifier.ValidateAnnotations(rule.Annotations); err != nil { if err = notifier.ValidateTemplates(rule.Annotations); err != nil {
return nil, fmt.Errorf("invalid annotations filepath:%s, group %s:%w", file, group.Name, err) return nil, fmt.Errorf("invalid annotations filepath:%s, group %s:%w", file, group.Name, err)
} }
if err = notifier.ValidateAnnotations(rule.Labels); err != nil { if err = notifier.ValidateTemplates(rule.Labels); err != nil {
return nil, fmt.Errorf("invalid labels filepath:%s, group %s:%w", file, group.Name, err) return nil, fmt.Errorf("invalid labels filepath:%s, group %s:%w", file, group.Name, err)
} }
} }

View file

@ -29,7 +29,7 @@ Examples:
-rule /path/to/file. Path to a single file with alerting rules -rule /path/to/file. Path to a single file with alerting rules
-rule dir/*.yaml -rule /*.yaml. Relative path to all .yaml files in "dir" folder, -rule dir/*.yaml -rule /*.yaml. Relative path to all .yaml files in "dir" folder,
absolute path to all .yaml files in root.`) absolute path to all .yaml files in root.`)
validateAlertAnnotations = flag.Bool("rule.validateAnnotations", true, "Indicates to validate annotation templates") validateTemplates = flag.Bool("rule.validateTemplates", true, "Indicates to validate annotation and label templates")
httpListenAddr = flag.String("httpListenAddr", ":8880", "Address to listen for http connections") httpListenAddr = flag.String("httpListenAddr", ":8880", "Address to listen for http connections")
datasourceURL = flag.String("datasource.url", "", "Victoria Metrics or VMSelect url. Required parameter. e.g. http://127.0.0.1:8428") datasourceURL = flag.String("datasource.url", "", "Victoria Metrics or VMSelect url. Required parameter. e.g. http://127.0.0.1:8428")
basicAuthUsername = flag.String("datasource.basicAuth.username", "", "Optional basic auth username to use for -datasource.url") basicAuthUsername = flag.String("datasource.basicAuth.username", "", "Optional basic auth username to use for -datasource.url")
@ -54,7 +54,7 @@ func main() {
notifier.InitTemplateFunc(eu) notifier.InitTemplateFunc(eu)
logger.Infof("reading alert rules configuration file from %s", strings.Join(*rulePath, ";")) logger.Infof("reading alert rules configuration file from %s", strings.Join(*rulePath, ";"))
groups, err := Parse(*rulePath, *validateAlertAnnotations) groups, err := Parse(*rulePath, *validateTemplates)
if err != nil { if err != nil {
logger.Fatalf("Cannot parse configuration file: %s", err) logger.Fatalf("Cannot parse configuration file: %s", err)
} }

View file

@ -63,8 +63,8 @@ func (a *Alert) ExecTemplate(annotations map[string]string) (map[string]string,
return templateAnnotations(annotations, tplHeader, tplData) return templateAnnotations(annotations, tplHeader, tplData)
} }
// ValidateAnnotations validate annotations for possible template error, uses empty data for template population // ValidateTemplates validate annotations for possible template error, uses empty data for template population
func ValidateAnnotations(annotations map[string]string) error { func ValidateTemplates(annotations map[string]string) error {
_, err := templateAnnotations(annotations, tplHeader, alertTplData{ _, err := templateAnnotations(annotations, tplHeader, alertTplData{
Labels: map[string]string{}, Labels: map[string]string{},
Value: 0, Value: 0,