grafana/pkg/tsdb/request.go

27 lines
529 B
Go
Raw Normal View History

package tsdb
import (
"context"
)
2017-09-21 00:56:33 +08:00
type HandleRequestFunc func(ctx context.Context, req *TsdbQuery) (*Response, error)
2017-09-21 00:56:33 +08:00
func HandleRequest(ctx context.Context, req *TsdbQuery) (*Response, error) {
2017-09-21 19:39:25 +08:00
//TODO niceify
2017-09-21 21:03:47 +08:00
ds := req.Queries[0].DataSource
endpoint, err := getTsdbQueryEndpointFor(ds)
if err != nil {
return nil, err
}
2017-09-21 21:03:47 +08:00
res := endpoint.Query(ctx, ds, req)
2017-09-21 19:39:25 +08:00
if res.Error != nil {
return nil, res.Error
}
2017-09-21 19:39:25 +08:00
return &Response{
Results: res.QueryResults,
BatchTimings: []*BatchTiming{res.Timings},
}, nil
}