tech(alerting): remove datasource ref from alertjob

This commit is contained in:
bergquist
2016-06-03 07:40:47 +02:00
parent 0bea0cc5b9
commit 910253bc42
5 changed files with 78 additions and 79 deletions
+16 -4
View File
@@ -3,19 +3,31 @@ package graphite
import (
"fmt"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
// AlertDatasource is bacon
type AlertDatasource interface {
GetSeries(job *m.AlertJob) (m.TimeSeriesSlice, error)
GetSeries(job *m.AlertJob, datasource m.DataSource) (m.TimeSeriesSlice, error)
}
// GetSeries returns timeseries data from the datasource
func GetSeries(job *m.AlertJob) (m.TimeSeriesSlice, error) {
if job.Datasource.Type == m.DS_GRAPHITE {
return GraphiteClient{}.GetSeries(job)
query := &m.GetDataSourceByIdQuery{
Id: job.Rule.DatasourceId,
OrgId: job.Rule.OrgId,
}
return nil, fmt.Errorf("Grafana does not support alerts for %s", job.Datasource.Type)
err := bus.Dispatch(query)
if err != nil {
return nil, fmt.Errorf("Could not find datasource for %d", job.Rule.DatasourceId)
}
if query.Result.Type == m.DS_GRAPHITE {
return GraphiteClient{}.GetSeries(job, query.Result)
}
return nil, fmt.Errorf("Grafana does not support alerts for %s", query.Result.Type)
}
@@ -2,14 +2,15 @@ package graphite
import (
"fmt"
"github.com/franela/goreq"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
"github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models"
"net/http"
"net/url"
"strconv"
"time"
"github.com/franela/goreq"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
"github.com/grafana/grafana/pkg/components/simplejson"
m "github.com/grafana/grafana/pkg/models"
)
type GraphiteClient struct{}
@@ -21,7 +22,7 @@ type GraphiteSerie struct {
type GraphiteResponse []GraphiteSerie
func (this GraphiteClient) GetSeries(rule *m.AlertJob) (m.TimeSeriesSlice, error) {
func (this GraphiteClient) GetSeries(rule *m.AlertJob, datasource m.DataSource) (m.TimeSeriesSlice, error) {
v := url.Values{
"format": []string{"json"},
"target": []string{getTargetFromRule(rule.Rule)},
@@ -33,7 +34,7 @@ func (this GraphiteClient) GetSeries(rule *m.AlertJob) (m.TimeSeriesSlice, error
res, err := goreq.Request{
Method: "POST",
Uri: rule.Datasource.Url + "/render",
Uri: datasource.Url + "/render",
Body: v.Encode(),
Timeout: 5 * time.Second,
}.Do()