From 2c18548e081ba4943de33c1ce2b782347c405f2b Mon Sep 17 00:00:00 2001 From: kreedom <60944649+kreedom@users.noreply.github.com> Date: Sun, 26 Apr 2020 14:15:04 +0300 Subject: [PATCH] alert - rename validate function and flags (#440) * alert - rename validate function and flags --- app/vmalert/README.md | 4 ++-- app/vmalert/config.go | 4 ++-- app/vmalert/main.go | 18 +++++++++--------- app/vmalert/notifier/alert.go | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/vmalert/README.md b/app/vmalert/README.md index 96012529b..b0d21a6d0 100644 --- a/app/vmalert/README.md +++ b/app/vmalert/README.md @@ -77,8 +77,8 @@ Usage of vmalert: -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, absolute path to all .yaml files in root. - -rule.validateAnnotations - Indicates to validate annotation templates (default true) + -rule.validateTemplates + Indicates to validate annotation and label templates (default true) ``` Pass `-help` to `vmalert` in order to see the full list of supported diff --git a/app/vmalert/config.go b/app/vmalert/config.go index aabd6ff2d..ba15956a1 100644 --- a/app/vmalert/config.go +++ b/app/vmalert/config.go @@ -39,10 +39,10 @@ func Parse(pathPatterns []string, validateAnnotations bool) ([]Group, error) { // TODO: this init looks weird here rule.alerts = make(map[uint64]*notifier.Alert) 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) } - 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) } } diff --git a/app/vmalert/main.go b/app/vmalert/main.go index b7371623e..3bd87b5c0 100644 --- a/app/vmalert/main.go +++ b/app/vmalert/main.go @@ -29,14 +29,14 @@ Examples: -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, absolute path to all .yaml files in root.`) - validateAlertAnnotations = flag.Bool("rule.validateAnnotations", true, "Indicates to validate annotation templates") - 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") - basicAuthUsername = flag.String("datasource.basicAuth.username", "", "Optional basic auth username to use for -datasource.url") - basicAuthPassword = flag.String("datasource.basicAuth.password", "", "Optional basic auth password to use for -datasource.url") - evaluationInterval = flag.Duration("evaluationInterval", 1*time.Minute, "How often to evaluate the rules. Default 1m") - notifierURL = flag.String("notifier.url", "", "Prometheus alertmanager URL. Required parameter. e.g. http://127.0.0.1:9093") - externalURL = flag.String("external.url", "", "External URL is used as alert's source for sent alerts to the notifier") + validateTemplates = flag.Bool("rule.validateTemplates", true, "Indicates to validate annotation and label templates") + 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") + basicAuthUsername = flag.String("datasource.basicAuth.username", "", "Optional basic auth username to use for -datasource.url") + basicAuthPassword = flag.String("datasource.basicAuth.password", "", "Optional basic auth password to use for -datasource.url") + evaluationInterval = flag.Duration("evaluationInterval", 1*time.Minute, "How often to evaluate the rules. Default 1m") + notifierURL = flag.String("notifier.url", "", "Prometheus alertmanager URL. Required parameter. e.g. http://127.0.0.1:9093") + externalURL = flag.String("external.url", "", "External URL is used as alert's source for sent alerts to the notifier") ) // TODO: hot configuration reload @@ -54,7 +54,7 @@ func main() { notifier.InitTemplateFunc(eu) 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 { logger.Fatalf("Cannot parse configuration file: %s", err) } diff --git a/app/vmalert/notifier/alert.go b/app/vmalert/notifier/alert.go index 51887532b..766791307 100644 --- a/app/vmalert/notifier/alert.go +++ b/app/vmalert/notifier/alert.go @@ -63,8 +63,8 @@ func (a *Alert) ExecTemplate(annotations map[string]string) (map[string]string, return templateAnnotations(annotations, tplHeader, tplData) } -// ValidateAnnotations validate annotations for possible template error, uses empty data for template population -func ValidateAnnotations(annotations map[string]string) error { +// ValidateTemplates validate annotations for possible template error, uses empty data for template population +func ValidateTemplates(annotations map[string]string) error { _, err := templateAnnotations(annotations, tplHeader, alertTplData{ Labels: map[string]string{}, Value: 0,