2016-06-06 03:31:21 -05:00
|
|
|
package tsdb
|
|
|
|
|
2016-12-07 04:10:42 -06:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
2016-10-03 02:38:03 -05:00
|
|
|
|
2016-06-06 03:31:21 -05:00
|
|
|
type Executor interface {
|
2016-10-03 07:32:04 -05:00
|
|
|
Execute(ctx context.Context, queries QuerySlice, query *QueryContext) *BatchResult
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var registry map[string]GetExecutorFn
|
|
|
|
|
2016-12-07 04:10:42 -06:00
|
|
|
type GetExecutorFn func(dsInfo *models.DataSource) (Executor, error)
|
2016-06-06 03:31:21 -05:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
registry = make(map[string]GetExecutorFn)
|
|
|
|
}
|
|
|
|
|
2016-12-07 04:10:42 -06:00
|
|
|
func getExecutorFor(dsInfo *models.DataSource) (Executor, error) {
|
|
|
|
if fn, exists := registry[dsInfo.Type]; exists {
|
|
|
|
executor, err := fn(dsInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return executor, nil
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|
2016-12-07 04:10:42 -06:00
|
|
|
return nil, fmt.Errorf("Could not find executor for data source type: %s", dsInfo.Type)
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|
|
|
|
|
2016-06-06 10:11:46 -05:00
|
|
|
func RegisterExecutor(pluginId string, fn GetExecutorFn) {
|
|
|
|
registry[pluginId] = fn
|
2016-06-06 03:31:21 -05:00
|
|
|
}
|