mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
api/ds/query: simplify data sources lookup for queries and expressions (#41172)
This commit is contained in:
+30
-6
@@ -4,21 +4,34 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"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__"
|
||||
// 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
|
||||
|
||||
// DatasourceUID is the fake datasource uid used in requests to identify it as an
|
||||
// expression command.
|
||||
const DatasourceUID = "-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 {
|
||||
@@ -52,3 +65,14 @@ func (s *Service) ExecutePipeline(ctx context.Context, pipeline DataPipeline) (*
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func DataSourceModel() *models.DataSource {
|
||||
return &models.DataSource{
|
||||
Id: DatasourceID,
|
||||
Uid: DatasourceUID,
|
||||
Name: DatasourceUID,
|
||||
Type: DatasourceType,
|
||||
JsonData: simplejson.New(),
|
||||
SecureJsonData: make(map[string][]byte),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user