mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
Takes a specific code path for data that identifies itself as dataplane instead of "guessing" what the data is. The data must identify itself by being in the dataplane by having both the following frame metadata properties: - TypeVersion property that is greater than 0.0 - 'Type' property The flag is disableSSEDataplane and disables this functionality and uses the old code for all queries regardless. See https://github.com/grafana/grafana-plugin-sdk-go/blob/main/data/contract_docs/contract.md for dataplane details.
93 lines
3.0 KiB
Go
93 lines
3.0 KiB
Go
package expr
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
// DatasourceType is the string constant used as the datasource when the property is in Datasource.Type.
|
|
// Type in requests is used to identify what type of data source plugin the request belongs to.
|
|
const DatasourceType = "__expr__"
|
|
|
|
// DatasourceUID is the string constant used as the datasource name in requests
|
|
// to identify it as an expression command when use in Datasource.UID.
|
|
const DatasourceUID = DatasourceType
|
|
|
|
// DatasourceID is the fake datasource id used in requests to identify it as an
|
|
// expression command.
|
|
const DatasourceID = -100
|
|
|
|
// OldDatasourceUID is the datasource uid used in requests to identify it as an
|
|
// expression command. It goes with the query root level datasourceUID property. It was accidentally
|
|
// set to the Id and is now kept for backwards compatibility. The newer Datasource.UID property
|
|
// should be used instead and should be set to "__expr__".
|
|
const OldDatasourceUID = "-100"
|
|
|
|
// IsDataSource checks if the uid points to an expression query
|
|
func IsDataSource(uid string) bool {
|
|
return uid == DatasourceUID || uid == OldDatasourceUID
|
|
}
|
|
|
|
// Service is service representation for expression handling.
|
|
type Service struct {
|
|
cfg *setting.Cfg
|
|
dataService backend.QueryDataHandler
|
|
dataSourceService datasources.DataSourceService
|
|
features featuremgmt.FeatureToggles
|
|
}
|
|
|
|
func ProvideService(cfg *setting.Cfg, pluginClient plugins.Client, dataSourceService datasources.DataSourceService, features featuremgmt.FeatureToggles) *Service {
|
|
return &Service{
|
|
cfg: cfg,
|
|
dataService: pluginClient,
|
|
dataSourceService: dataSourceService,
|
|
features: features,
|
|
}
|
|
}
|
|
|
|
func (s *Service) isDisabled() bool {
|
|
if s.cfg == nil {
|
|
return true
|
|
}
|
|
return !s.cfg.ExpressionsEnabled
|
|
}
|
|
|
|
// BuildPipeline builds a pipeline from a request.
|
|
func (s *Service) BuildPipeline(req *Request) (DataPipeline, error) {
|
|
return s.buildPipeline(req)
|
|
}
|
|
|
|
// ExecutePipeline executes an expression pipeline and returns all the results.
|
|
func (s *Service) ExecutePipeline(ctx context.Context, now time.Time, pipeline DataPipeline) (*backend.QueryDataResponse, error) {
|
|
res := backend.NewQueryDataResponse()
|
|
vars, err := pipeline.execute(ctx, now, s)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for refID, val := range vars {
|
|
res.Responses[refID] = backend.DataResponse{
|
|
Frames: val.Values.AsDataFrames(refID),
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
func DataSourceModel() *datasources.DataSource {
|
|
return &datasources.DataSource{
|
|
ID: DatasourceID,
|
|
UID: DatasourceUID,
|
|
Name: DatasourceUID,
|
|
Type: DatasourceType,
|
|
JsonData: simplejson.New(),
|
|
SecureJsonData: make(map[string][]byte),
|
|
}
|
|
}
|