From 1c0874372169d75c6765c89097863750ff490f21 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Wed, 14 Jun 2017 13:32:26 +0530 Subject: [PATCH] Update check-rules to new format. Signed-off-by: Goutham Veeramachaneni --- cmd/promtool/main.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/promtool/main.go b/cmd/promtool/main.go index cf2debf8f..75f6061e9 100644 --- a/cmd/promtool/main.go +++ b/cmd/promtool/main.go @@ -29,6 +29,7 @@ import ( "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/util/cli" "github.com/prometheus/prometheus/util/promlint" + "github.com/prometheus/tsdb" ) // CheckConfigCmd validates configuration files. @@ -175,16 +176,17 @@ func checkRules(t cli.Term, filename string) (int, error) { return 0, fmt.Errorf("is a directory") } - content, err := ioutil.ReadFile(filename) - if err != nil { - return 0, err + rgs, errs := rulefmt.ParseFile(filename) + if errs != nil { + return 0, tsdb.MultiError(errs) } - rules, err := promql.ParseStmts(string(content)) - if err != nil { - return 0, err + numRules := 0 + for _, rg := range rgs.Groups { + numRules += len(rg.Rules) } - return len(rules), nil + + return numRules, nil } // UpdateRulesCmd updates the rule files.