2016-06-06 03:31:21 -05:00
|
|
|
package tsdb
|
|
|
|
|
2017-03-31 04:45:25 -05:00
|
|
|
import (
|
|
|
|
"context"
|
2020-11-05 04:00:00 -06:00
|
|
|
"fmt"
|
2017-09-21 11:04:06 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2017-03-31 04:45:25 -05:00
|
|
|
)
|
2016-07-20 07:28:02 -05:00
|
|
|
|
2017-09-21 11:04:06 -05:00
|
|
|
type HandleRequestFunc func(ctx context.Context, dsInfo *models.DataSource, req *TsdbQuery) (*Response, error)
|
2016-10-03 02:38:03 -05:00
|
|
|
|
2017-09-21 11:04:06 -05:00
|
|
|
func HandleRequest(ctx context.Context, dsInfo *models.DataSource, req *TsdbQuery) (*Response, error) {
|
2020-11-05 04:00:00 -06:00
|
|
|
var endpoint TsdbQueryEndpoint
|
|
|
|
fn, exists := registry[dsInfo.Type]
|
|
|
|
if !exists {
|
2020-11-05 08:37:11 -06:00
|
|
|
return nil, fmt.Errorf("could not find executor for data source type: %s", dsInfo.Type)
|
2020-11-05 04:00:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
endpoint, err = fn(dsInfo)
|
2016-06-06 03:31:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-09-21 11:04:06 -05:00
|
|
|
return endpoint.Query(ctx, dsInfo, req)
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|