Expressions: use datasource model from the query (#41376)

* refactor datasource loading

* refactor datasource loading

* pass uid

* use dscache in alerting to get DS

* remove expr/translate pacakge

* remove dup injection entry

* fix DS type on metrics endpoint, remove SQL DS lookup inside SSE

* update test and adapter

* comment fix

* Make eval run as admin when getting datasource info

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>

* fmt and comment

* remove unncessary/redundant code

Co-authored-by: Kyle Brandt <kyle@grafana.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: Santiago <santiagohernandez.1997@gmail.com>
This commit is contained in:
Ryan McKinley
2021-12-16 13:51:46 -03:00
committed by GitHub
co-authored by Marcus Efraimsson Kyle Brandt Santiago
parent 1745cd8186
commit 2754e4fdf0
15 changed files with 119 additions and 1088 deletions
+35 -30
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"testing"
"github.com/grafana/grafana/pkg/models"
"github.com/stretchr/testify/require"
)
@@ -19,8 +20,8 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
DatasourceUID: OldDatasourceUID,
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "B",
"reducer": "mean",
@@ -28,8 +29,10 @@ func TestServicebuildPipeLine(t *testing.T) {
}`),
},
{
RefID: "B",
DatasourceUID: "Fake",
RefID: "B",
DataSource: &models.DataSource{
Uid: "Fake",
},
},
},
},
@@ -40,16 +43,16 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
DatasourceUID: OldDatasourceUID,
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "$B",
"type": "math"
}`),
},
{
RefID: "B",
DatasourceUID: OldDatasourceUID,
RefID: "B",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "$A",
"type": "math"
@@ -64,8 +67,8 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
DatasourceUID: OldDatasourceUID,
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "$A",
"type": "math"
@@ -80,8 +83,8 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
DatasourceUID: OldDatasourceUID,
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "$B",
"type": "math"
@@ -96,8 +99,8 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
DatasourceUID: OldDatasourceUID,
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"type": "classic_conditions",
"conditions": [
@@ -127,8 +130,8 @@ func TestServicebuildPipeLine(t *testing.T) {
}`),
},
{
RefID: "B",
DatasourceUID: OldDatasourceUID,
RefID: "B",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "C",
"reducer": "mean",
@@ -136,8 +139,10 @@ func TestServicebuildPipeLine(t *testing.T) {
}`),
},
{
RefID: "C",
DatasourceUID: "Fake",
RefID: "C",
DataSource: &models.DataSource{
Uid: "Fake",
},
},
},
},
@@ -148,8 +153,8 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
DatasourceUID: OldDatasourceUID,
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"type": "classic_conditions",
"conditions": [
@@ -179,8 +184,8 @@ func TestServicebuildPipeLine(t *testing.T) {
}`),
},
{
RefID: "B",
DatasourceUID: OldDatasourceUID,
RefID: "B",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "A",
"reducer": "mean",
@@ -188,8 +193,10 @@ func TestServicebuildPipeLine(t *testing.T) {
}`),
},
{
RefID: "C",
DatasourceUID: "Fake",
RefID: "C",
DataSource: &models.DataSource{
Uid: "Fake",
},
},
},
},
@@ -200,10 +207,8 @@ func TestServicebuildPipeLine(t *testing.T) {
req: &Request{
Queries: []Query{
{
RefID: "A",
Datasource: DataSourceRef{
UID: DatasourceUID,
},
RefID: "A",
DataSource: DataSourceModel(),
JSON: json.RawMessage(`{
"expression": "B",
"reducer": "mean",
@@ -212,8 +217,8 @@ func TestServicebuildPipeLine(t *testing.T) {
},
{
RefID: "B",
Datasource: DataSourceRef{
UID: "Fake",
DataSource: &models.DataSource{
Uid: "Fake",
},
},
},