mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
78596a6756
Fixes #30144 Co-authored-by: dsotirakis <sotirakis.dim@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: Leon Sorokin <leeoniya@gmail.com> Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com> Co-authored-by: spinillos <selenepinillos@gmail.com> Co-authored-by: Karl Persson <kalle.persson@grafana.com> Co-authored-by: Leonard Gram <leo@xlson.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package expr
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
// DatasourceName is the string constant used as the datasource name in requests
|
|
// to identify it as an expression command.
|
|
const DatasourceName = "__expr__"
|
|
|
|
// DatasourceID is the fake datasource id used in requests to identify it as an
|
|
// expression command.
|
|
const DatasourceID = -100
|
|
|
|
// DatasourceUID is the fake datasource uid used in requests to identify it as an
|
|
// expression command.
|
|
const DatasourceUID = "-100"
|
|
|
|
// Service is service representation for expression handling.
|
|
type Service struct {
|
|
Cfg *setting.Cfg
|
|
DataService plugins.DataRequestHandler
|
|
}
|
|
|
|
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, pipeline DataPipeline) (*backend.QueryDataResponse, error) {
|
|
res := backend.NewQueryDataResponse()
|
|
vars, err := pipeline.execute(ctx, 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
|
|
}
|