backend/datasources: move datasources models into the datasources service package (#51267)
* backend/datasources: move datasources models into the datasources service pkg
This commit is contained in:
@@ -4,8 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
)
|
||||
|
||||
func TestServicebuildPipeLine(t *testing.T) {
|
||||
@@ -30,7 +31,7 @@ func TestServicebuildPipeLine(t *testing.T) {
|
||||
},
|
||||
{
|
||||
RefID: "B",
|
||||
DataSource: &models.DataSource{
|
||||
DataSource: &datasources.DataSource{
|
||||
Uid: "Fake",
|
||||
},
|
||||
},
|
||||
@@ -140,7 +141,7 @@ func TestServicebuildPipeLine(t *testing.T) {
|
||||
},
|
||||
{
|
||||
RefID: "C",
|
||||
DataSource: &models.DataSource{
|
||||
DataSource: &datasources.DataSource{
|
||||
Uid: "Fake",
|
||||
},
|
||||
},
|
||||
@@ -194,7 +195,7 @@ func TestServicebuildPipeLine(t *testing.T) {
|
||||
},
|
||||
{
|
||||
RefID: "C",
|
||||
DataSource: &models.DataSource{
|
||||
DataSource: &datasources.DataSource{
|
||||
Uid: "Fake",
|
||||
},
|
||||
},
|
||||
@@ -217,7 +218,7 @@ func TestServicebuildPipeLine(t *testing.T) {
|
||||
},
|
||||
{
|
||||
RefID: "B",
|
||||
DataSource: &models.DataSource{
|
||||
DataSource: &datasources.DataSource{
|
||||
Uid: "Fake",
|
||||
},
|
||||
},
|
||||
|
||||
+4
-4
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/grafana/grafana/pkg/expr/classic"
|
||||
"github.com/grafana/grafana/pkg/expr/mathexp"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins/adapters"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
|
||||
"gonum.org/v1/gonum/graph/simple"
|
||||
)
|
||||
@@ -46,7 +46,7 @@ type rawNode struct {
|
||||
Query map[string]interface{}
|
||||
QueryType string
|
||||
TimeRange TimeRange
|
||||
DataSource *models.DataSource
|
||||
DataSource *datasources.DataSource
|
||||
}
|
||||
|
||||
func (rn *rawNode) GetCommandType() (c CommandType, err error) {
|
||||
@@ -138,7 +138,7 @@ const (
|
||||
type DSNode struct {
|
||||
baseNode
|
||||
query json.RawMessage
|
||||
datasource *models.DataSource
|
||||
datasource *datasources.DataSource
|
||||
|
||||
orgID int64
|
||||
queryType string
|
||||
@@ -268,7 +268,7 @@ func (dn *DSNode) Execute(ctx context.Context, vars mathexp.Vars, s *Service) (m
|
||||
// Check for TimeSeriesTypeNot in InfluxDB queries. A data frame of this type will cause
|
||||
// the WideToMany() function to error out, which results in unhealthy alerts.
|
||||
// This check should be removed once inconsistencies in data source responses are solved.
|
||||
if frame.TimeSeriesSchema().Type == data.TimeSeriesTypeNot && dataSource == models.DS_INFLUXDB {
|
||||
if frame.TimeSeriesSchema().Type == data.TimeSeriesTypeNot && dataSource == datasources.DS_INFLUXDB {
|
||||
logger.Warn("ignoring InfluxDB data frame due to missing numeric fields", "frame", frame)
|
||||
continue
|
||||
}
|
||||
|
||||
+3
-3
@@ -4,8 +4,8 @@ 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/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -76,8 +76,8 @@ func (s *Service) ExecutePipeline(ctx context.Context, pipeline DataPipeline) (*
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func DataSourceModel() *models.DataSource {
|
||||
return &models.DataSource{
|
||||
func DataSourceModel() *datasources.DataSource {
|
||||
return &datasources.DataSource{
|
||||
Id: DatasourceID,
|
||||
Uid: DatasourceUID,
|
||||
Name: DatasourceUID,
|
||||
|
||||
@@ -10,10 +10,11 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
datasources "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
datafakes "github.com/grafana/grafana/pkg/services/datasources/fakes"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
func TestService(t *testing.T) {
|
||||
@@ -30,13 +31,13 @@ func TestService(t *testing.T) {
|
||||
s := Service{
|
||||
cfg: cfg,
|
||||
dataService: me,
|
||||
dataSourceService: &datasources.FakeDataSourceService{},
|
||||
dataSourceService: &datafakes.FakeDataSourceService{},
|
||||
}
|
||||
|
||||
queries := []Query{
|
||||
{
|
||||
RefID: "A",
|
||||
DataSource: &models.DataSource{
|
||||
DataSource: &datasources.DataSource{
|
||||
OrgId: 1,
|
||||
Uid: "test",
|
||||
Type: "test",
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -41,7 +42,7 @@ type Request struct {
|
||||
type Query struct {
|
||||
RefID string
|
||||
TimeRange TimeRange
|
||||
DataSource *models.DataSource `json:"datasource"`
|
||||
DataSource *datasources.DataSource `json:"datasource"`
|
||||
JSON json.RawMessage
|
||||
Interval time.Duration
|
||||
QueryType string
|
||||
@@ -126,8 +127,8 @@ func hiddenRefIDs(queries []Query) (map[string]struct{}, error) {
|
||||
return hidden, nil
|
||||
}
|
||||
|
||||
func (s *Service) decryptSecureJsonDataFn(ctx context.Context) func(ds *models.DataSource) map[string]string {
|
||||
return func(ds *models.DataSource) map[string]string {
|
||||
func (s *Service) decryptSecureJsonDataFn(ctx context.Context) func(ds *datasources.DataSource) map[string]string {
|
||||
return func(ds *datasources.DataSource) map[string]string {
|
||||
decryptedJsonData, err := s.dataSourceService.DecryptedValues(ctx, ds)
|
||||
if err != nil {
|
||||
logger.Error("Failed to decrypt secure json data", "error", err)
|
||||
|
||||
Reference in New Issue
Block a user