2016-06-06 16:31:21 +08:00
|
|
|
package tsdb
|
|
|
|
|
2017-03-31 17:45:25 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
2016-07-20 20:28:02 +08:00
|
|
|
|
2017-09-21 00:56:33 +08:00
|
|
|
type HandleRequestFunc func(ctx context.Context, req *TsdbQuery) (*Response, error)
|
2016-10-03 15:38:03 +08:00
|
|
|
|
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)
|
2016-06-06 16:31:21 +08:00
|
|
|
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
|
2016-06-06 16:31:21 +08:00
|
|
|
}
|
|
|
|
|
2017-09-21 19:39:25 +08:00
|
|
|
return &Response{
|
|
|
|
Results: res.QueryResults,
|
|
|
|
BatchTimings: []*BatchTiming{res.Timings},
|
|
|
|
}, nil
|
2016-06-06 16:31:21 +08:00
|
|
|
}
|