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 <carl.bergquist@gmail.com>

* Fix indentation

* Add missing import

Co-authored-by: Carl Bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Sofia Papagiannaki 2020-03-11 10:28:36 +02:00 committed by GitHub
parent cf6adb8b54
commit c6829645c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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}