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