Alerting: Update alert rule migration to use expanded queries (#42493)

* move targetData to target

* use constants instead of literals.

* Update comments and add tests

Co-authored-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
Yuriy Tseretyan
2021-12-01 06:45:27 -05:00
committed by GitHub
parent 357e9ed1ea
commit 9139f61105
3 changed files with 102 additions and 5 deletions

View File

@@ -20,6 +20,8 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/opentracing/opentracing-go"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/httpclient"
"github.com/grafana/grafana/pkg/infra/log"
@@ -27,7 +29,6 @@ import (
"github.com/grafana/grafana/pkg/plugins/backendplugin/coreplugin"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb/legacydata"
"github.com/opentracing/opentracing-go"
)
type Service struct {
@@ -35,6 +36,11 @@ type Service struct {
im instancemgmt.InstanceManager
}
const (
TargetFullModelField = "targetFull"
TargetModelField = "target"
)
func ProvideService(httpClientProvider httpclient.Provider, registrar plugins.CoreBackendRegistrar) (*Service, error) {
s := &Service{
logger: log.New("tsdb.graphite"),
@@ -126,10 +132,10 @@ func (s *Service) QueryData(ctx context.Context, req *backend.QueryDataRequest)
}
s.logger.Debug("graphite", "query", model)
currTarget := ""
if fullTarget, err := model.Get("targetFull").String(); err == nil {
if fullTarget, err := model.Get(TargetFullModelField).String(); err == nil {
currTarget = fullTarget
} else {
currTarget = model.Get("target").MustString()
currTarget = model.Get(TargetModelField).MustString()
}
if currTarget == "" {
s.logger.Debug("graphite", "empty query target", model)