From c6829645c7f1e31590dd561b6f05bff4a679c351 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Wed, 11 Mar 2020 10:28:36 +0200 Subject: [PATCH] Graphite: Don't issue empty "select metric" queries (#22699) * Don't issue empty "select metric" queries * Update pkg/tsdb/graphite/graphite.go Co-Authored-By: Carl Bergquist * Fix indentation * Add missing import Co-authored-by: Carl Bergquist --- pkg/tsdb/graphite/graphite.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/tsdb/graphite/graphite.go b/pkg/tsdb/graphite/graphite.go index 1add49b98b9..82d6d34337a 100644 --- a/pkg/tsdb/graphite/graphite.go +++ b/pkg/tsdb/graphite/graphite.go @@ -3,6 +3,7 @@ package graphite import ( "context" "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -48,13 +49,26 @@ func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource, "maxDataPoints": []string{"500"}, } + emptyQueries := make([]string, 0) for _, query := range tsdbQuery.Queries { glog.Debug("graphite", "query", query.Model) + currTarget := "" if fullTarget, err := query.Model.Get("targetFull").String(); err == nil { - target = fixIntervalFormat(fullTarget) + currTarget = fullTarget } else { - target = fixIntervalFormat(query.Model.Get("target").MustString()) + currTarget = query.Model.Get("target").MustString() } + if currTarget == "" { + glog.Debug("graphite", "empty query target", query.Model) + emptyQueries = append(emptyQueries, fmt.Sprintf("Query: %v has no target", query.Model)) + continue + } + target = fixIntervalFormat(currTarget) + } + + if target == "" { + glog.Error("No targets in query model", "models without targets", strings.Join(emptyQueries, "\n")) + return nil, errors.New("No query target found for the alert rule") } formData["target"] = []string{target}