mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
context is reserved for go's context
This commit is contained in:
@@ -37,11 +37,11 @@ func init() {
|
|||||||
tsdb.RegisterTsdbQueryEndpoint("graphite", NewGraphiteExecutor)
|
tsdb.RegisterTsdbQueryEndpoint("graphite", NewGraphiteExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource, context *tsdb.TsdbQuery) *tsdb.BatchResult {
|
func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) *tsdb.BatchResult {
|
||||||
result := &tsdb.BatchResult{}
|
result := &tsdb.BatchResult{}
|
||||||
|
|
||||||
from := "-" + formatTimeRange(context.TimeRange.From)
|
from := "-" + formatTimeRange(tsdbQuery.TimeRange.From)
|
||||||
until := formatTimeRange(context.TimeRange.To)
|
until := formatTimeRange(tsdbQuery.TimeRange.To)
|
||||||
var target string
|
var target string
|
||||||
|
|
||||||
formData := url.Values{
|
formData := url.Values{
|
||||||
@@ -51,7 +51,7 @@ func (e *GraphiteExecutor) Query(ctx context.Context, dsInfo *models.DataSource,
|
|||||||
"maxDataPoints": []string{"500"},
|
"maxDataPoints": []string{"500"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, query := range context.Queries {
|
for _, query := range tsdbQuery.Queries {
|
||||||
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
|
if fullTarget, err := query.Model.Get("targetFull").String(); err == nil {
|
||||||
target = fixIntervalFormat(fullTarget)
|
target = fixIntervalFormat(fullTarget)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,15 +39,15 @@ func init() {
|
|||||||
tsdb.RegisterTsdbQueryEndpoint("influxdb", NewInfluxDBExecutor)
|
tsdb.RegisterTsdbQueryEndpoint("influxdb", NewInfluxDBExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource, context *tsdb.TsdbQuery) *tsdb.BatchResult {
|
func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) *tsdb.BatchResult {
|
||||||
result := &tsdb.BatchResult{}
|
result := &tsdb.BatchResult{}
|
||||||
|
|
||||||
query, err := e.getQuery(dsInfo, context.Queries, context)
|
query, err := e.getQuery(dsInfo, tsdbQuery.Queries, tsdbQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rawQuery, err := query.Build(context)
|
rawQuery, err := query.Build(tsdbQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,17 +85,17 @@ func (e *MysqlExecutor) initEngine(dsInfo *models.DataSource) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *MysqlExecutor) Query(ctx context.Context, dsInfo *models.DataSource, context *tsdb.TsdbQuery) *tsdb.BatchResult {
|
func (e *MysqlExecutor) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) *tsdb.BatchResult {
|
||||||
result := &tsdb.BatchResult{
|
result := &tsdb.BatchResult{
|
||||||
QueryResults: make(map[string]*tsdb.QueryResult),
|
QueryResults: make(map[string]*tsdb.QueryResult),
|
||||||
}
|
}
|
||||||
|
|
||||||
macroEngine := NewMysqlMacroEngine(context.TimeRange)
|
macroEngine := NewMysqlMacroEngine(tsdbQuery.TimeRange)
|
||||||
session := e.engine.NewSession()
|
session := e.engine.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB()
|
db := session.DB()
|
||||||
|
|
||||||
for _, query := range context.Queries {
|
for _, query := range tsdbQuery.Queries {
|
||||||
rawSql := query.Model.Get("rawSql").MustString()
|
rawSql := query.Model.Get("rawSql").MustString()
|
||||||
if rawSql == "" {
|
if rawSql == "" {
|
||||||
continue
|
continue
|
||||||
@@ -276,8 +276,6 @@ func (e MysqlExecutor) TransformToTimeSeries(query *tsdb.Query, rows *core.Rows,
|
|||||||
rowData.metric = "Unknown"
|
rowData.metric = "Unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
//e.log.Debug("Rows", "metric", rowData.metric, "time", rowData.time, "value", rowData.value)
|
|
||||||
|
|
||||||
if !rowData.time.Valid {
|
if !rowData.time.Valid {
|
||||||
return fmt.Errorf("Found row with no time value")
|
return fmt.Errorf("Found row with no time value")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func (e *PrometheusExecutor) getClient(dsInfo *models.DataSource) (apiv1.API, er
|
|||||||
return apiv1.NewAPI(client), nil
|
return apiv1.NewAPI(client), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *PrometheusExecutor) Query(ctx context.Context, dsInfo *models.DataSource, queryContext *tsdb.TsdbQuery) *tsdb.BatchResult {
|
func (e *PrometheusExecutor) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) *tsdb.BatchResult {
|
||||||
result := &tsdb.BatchResult{}
|
result := &tsdb.BatchResult{}
|
||||||
|
|
||||||
client, err := e.getClient(dsInfo)
|
client, err := e.getClient(dsInfo)
|
||||||
@@ -88,7 +88,7 @@ func (e *PrometheusExecutor) Query(ctx context.Context, dsInfo *models.DataSourc
|
|||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
query, err := parseQuery(queryContext.Queries, queryContext)
|
query, err := parseQuery(tsdbQuery.Queries, tsdbQuery)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result.WithError(err)
|
return result.WithError(err)
|
||||||
}
|
}
|
||||||
|
|||||||
6
pkg/tsdb/testdata/scenarios.go
vendored
6
pkg/tsdb/testdata/scenarios.go
vendored
@@ -33,9 +33,9 @@ func init() {
|
|||||||
Id: "random_walk",
|
Id: "random_walk",
|
||||||
Name: "Random Walk",
|
Name: "Random Walk",
|
||||||
|
|
||||||
Handler: func(query *tsdb.Query, context *tsdb.TsdbQuery) *tsdb.QueryResult {
|
Handler: func(query *tsdb.Query, tsdbQuery *tsdb.TsdbQuery) *tsdb.QueryResult {
|
||||||
timeWalkerMs := context.TimeRange.GetFromAsMsEpoch()
|
timeWalkerMs := tsdbQuery.TimeRange.GetFromAsMsEpoch()
|
||||||
to := context.TimeRange.GetToAsMsEpoch()
|
to := tsdbQuery.TimeRange.GetToAsMsEpoch()
|
||||||
|
|
||||||
series := newSeriesForQuery(query)
|
series := newSeriesForQuery(query)
|
||||||
|
|
||||||
|
|||||||
6
pkg/tsdb/testdata/testdata.go
vendored
6
pkg/tsdb/testdata/testdata.go
vendored
@@ -24,14 +24,14 @@ func init() {
|
|||||||
tsdb.RegisterTsdbQueryEndpoint("grafana-testdata-datasource", NewTestDataExecutor)
|
tsdb.RegisterTsdbQueryEndpoint("grafana-testdata-datasource", NewTestDataExecutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *TestDataExecutor) Query(ctx context.Context, dsInfo *models.DataSource, context *tsdb.TsdbQuery) *tsdb.BatchResult {
|
func (e *TestDataExecutor) Query(ctx context.Context, dsInfo *models.DataSource, tsdbQuery *tsdb.TsdbQuery) *tsdb.BatchResult {
|
||||||
result := &tsdb.BatchResult{}
|
result := &tsdb.BatchResult{}
|
||||||
result.QueryResults = make(map[string]*tsdb.QueryResult)
|
result.QueryResults = make(map[string]*tsdb.QueryResult)
|
||||||
|
|
||||||
for _, query := range context.Queries {
|
for _, query := range tsdbQuery.Queries {
|
||||||
scenarioId := query.Model.Get("scenarioId").MustString("random_walk")
|
scenarioId := query.Model.Get("scenarioId").MustString("random_walk")
|
||||||
if scenario, exist := ScenarioRegistry[scenarioId]; exist {
|
if scenario, exist := ScenarioRegistry[scenarioId]; exist {
|
||||||
result.QueryResults[query.RefId] = scenario.Handler(query, context)
|
result.QueryResults[query.RefId] = scenario.Handler(query, tsdbQuery)
|
||||||
result.QueryResults[query.RefId].RefId = query.RefId
|
result.QueryResults[query.RefId].RefId = query.RefId
|
||||||
} else {
|
} else {
|
||||||
e.log.Error("Scenario not found", "scenarioId", scenarioId)
|
e.log.Error("Scenario not found", "scenarioId", scenarioId)
|
||||||
|
|||||||
Reference in New Issue
Block a user