[v9.3.x] Expressions: Fixes the issue showing expressions editor (#62627)

Expressions: Fixes the issue showing expressions editor (#62510)

* Use suggested value for uid

* update the snapshot

* use __expr__

* replace all -100 with __expr__

* update snapshot

* more changes

* revert redundant change

* Use expr.DatasourceUID where it's possible

* generate files

(cherry picked from commit 91221bc436)
This commit is contained in:
ismail simsek
2023-01-31 14:31:33 -05:00
committed by GitHub
parent 4d450ab910
commit ead3a002df
52 changed files with 235 additions and 224 deletions
@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/expr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -737,7 +738,7 @@ func insertTestRule(t *testing.T, sqlStore sqlstore.Store, foderOrgID int64, fol
Data: []alertQuery{
{
RefID: "A",
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
Model: json.RawMessage(`{
"type": "math",
"expression": "2 + 3 > 1"
@@ -10,6 +10,7 @@ import (
"time"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/expr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -570,7 +571,7 @@ func withClassicConditionSingleQuery() func(r *ngmodels.AlertRule) {
RefID: "B",
QueryType: "",
RelativeTimeRange: ngmodels.RelativeTimeRange{From: ngmodels.Duration(0), To: ngmodels.Duration(0)},
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
Model: json.RawMessage(fmt.Sprintf(classicConditionsModel, "A", "B")),
},
}
@@ -599,21 +600,21 @@ func withExpressionsMultiQuery() func(r *ngmodels.AlertRule) {
RefID: "C",
QueryType: "",
RelativeTimeRange: ngmodels.RelativeTimeRange{From: ngmodels.Duration(0), To: ngmodels.Duration(0)},
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
Model: json.RawMessage(fmt.Sprintf(reduceLastExpressionModel, "A", "C")),
},
{
RefID: "D",
QueryType: "",
RelativeTimeRange: ngmodels.RelativeTimeRange{From: ngmodels.Duration(0), To: ngmodels.Duration(0)},
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
Model: json.RawMessage(fmt.Sprintf(reduceLastExpressionModel, "B", "D")),
},
{
RefID: "E",
QueryType: "",
RelativeTimeRange: ngmodels.RelativeTimeRange{From: ngmodels.Duration(0), To: ngmodels.Duration(0)},
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
Model: json.RawMessage(fmt.Sprintf(mathExpressionModel, "A", "B", "E")),
},
}
@@ -38,7 +38,7 @@ const classicConditionsModel = `
}],
"datasource": {
"type": "__expr__",
"uid": "-100"
"uid": "__expr__"
},
"hide": false,
"intervalMs": 1000,
+3 -1
View File
@@ -227,7 +227,9 @@ func (api *API) authorize(method, path string) web.Handler {
// authorizeDatasourceAccessForRule checks that user has access to all data sources declared by the rule
func authorizeDatasourceAccessForRule(rule *ngmodels.AlertRule, evaluator func(evaluator ac.Evaluator) bool) bool {
for _, query := range rule.Data {
if query.QueryType == expr.DatasourceType || query.DatasourceUID == expr.OldDatasourceUID {
if query.QueryType == expr.DatasourceType || query.DatasourceUID == expr.DatasourceUID || query.
DatasourceUID == expr.
OldDatasourceUID {
continue
}
if !evaluator(ac.EvalPermission(datasources.ActionQuery, datasources.ScopeProvider.GetResourceScopeUID(query.DatasourceUID))) {
@@ -401,7 +401,7 @@ func TestCheckDatasourcePermissionsForRule(t *testing.T) {
expressionByType := models.GenerateAlertQuery()
expressionByType.QueryType = expr.DatasourceType
expressionByUID := models.GenerateAlertQuery()
expressionByUID.DatasourceUID = expr.OldDatasourceUID
expressionByUID.DatasourceUID = expr.DatasourceUID
var data []models.AlertQuery
var scopes []string
@@ -32,7 +32,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
@@ -50,7 +50,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced > 10",
"hide": false,
@@ -95,7 +95,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$A",
"intervalMs": 2000,
@@ -112,4 +112,4 @@
}
}
]
}
}
@@ -39,7 +39,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
@@ -57,7 +57,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced > 10",
"hide": false,
@@ -102,7 +102,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$A",
"intervalMs": 2000,
@@ -119,4 +119,4 @@
}
}
]
}
}
@@ -98,7 +98,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
@@ -116,7 +116,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced > 10",
"hide": false,
@@ -184,7 +184,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
@@ -202,7 +202,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced > 42",
"hide": false,
@@ -283,7 +283,7 @@ Content-Type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "query",
"hide": false,
@@ -301,7 +301,7 @@ Content-Type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$reduced > 42",
"hide": false,
@@ -317,4 +317,4 @@ Content-Type: application/json
}
}
]
}
}
@@ -9,7 +9,7 @@
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"type": "math",
"expression": "2 + 2 > 1"
@@ -18,4 +18,4 @@
],
"now": "2021-03-11T14:50:42.218+02:00"
}
}
}
+5 -5
View File
@@ -15,7 +15,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"type":"math",
"expression":"1 < 2"
@@ -56,7 +56,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"expression": "$A",
"intervalMs": 2000,
@@ -113,7 +113,7 @@ content-type: application/json
"from": 18000,
"to": 10800
},
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"type":"math",
"expression":"1 < 2"
@@ -121,7 +121,7 @@ content-type: application/json
}
]
}
}}
}
### grafana recipient - lotex payload
POST http://admin:admin@localhost:3000/api/v1/rule/test/{{grafanaRecipient}}
@@ -129,4 +129,4 @@ content-type: application/json
{
"expr": "rate({cluster=\"us-central1\", job=\"loki-prod/loki-canary\"}[1m]) > 0"
}
}
+5 -6
View File
@@ -99,7 +99,7 @@
"AlertQuery": {
"properties": {
"datasourceUid": {
"description": "Grafana data source unique identifier; it should be '-100' for a Server Side Expression operation.",
"description": "Grafana data source unique identifier; it should be '__expr__' for a Server Side Expression operation.",
"type": "string"
},
"model": {
@@ -2039,7 +2039,7 @@
"data": {
"example": [
{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"conditions": [
{
@@ -3077,7 +3077,6 @@
"type": "object"
},
"URL": {
"description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.",
"properties": {
"ForceQuery": {
"type": "boolean"
@@ -3110,7 +3109,7 @@
"$ref": "#/definitions/Userinfo"
}
},
"title": "A URL represents a parsed URL (technically, a URI reference).",
"title": "URL is a custom URL type that allows validation at configuration load time.",
"type": "object"
},
"Userinfo": {
@@ -3395,6 +3394,7 @@
"type": "object"
},
"gettableAlert": {
"description": "GettableAlert gettable alert",
"properties": {
"annotations": {
"$ref": "#/definitions/labelSet"
@@ -3457,7 +3457,6 @@
"type": "array"
},
"gettableSilence": {
"description": "GettableSilence gettable silence",
"properties": {
"comment": {
"description": "comment",
@@ -4496,4 +4495,4 @@
}
},
"swagger": "2.0"
}
}
@@ -85,7 +85,7 @@ type ProvisionedAlertRule struct {
// example: A
Condition string `json:"condition"`
// required: true
// example: [{"refId":"A","queryType":"","relativeTimeRange":{"from":0,"to":0},"datasourceUid":"-100","model":{"conditions":[{"evaluator":{"params":[0,0],"type":"gt"},"operator":{"type":"and"},"query":{"params":[]},"reducer":{"params":[],"type":"avg"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"1 == 1","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"A","type":"math"}}]
// example: [{"refId":"A","queryType":"","relativeTimeRange":{"from":0,"to":0},"datasourceUid":"__expr__","model":{"conditions":[{"evaluator":{"params":[0,0],"type":"gt"},"operator":{"type":"and"},"query":{"params":[]},"reducer":{"params":[],"type":"avg"},"type":"query"}],"datasource":{"type":"__expr__","uid":"__expr__"},"expression":"1 == 1","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"A","type":"math"}}]
Data []models.AlertQuery `json:"data"`
// readonly: true
Updated time.Time `json:"updated,omitempty"`
+5 -7
View File
@@ -99,7 +99,7 @@
"AlertQuery": {
"properties": {
"datasourceUid": {
"description": "Grafana data source unique identifier; it should be '-100' for a Server Side Expression operation.",
"description": "Grafana data source unique identifier; it should be '__expr__' for a Server Side Expression operation.",
"type": "string"
},
"model": {
@@ -2039,7 +2039,7 @@
"data": {
"example": [
{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"conditions": [
{
@@ -3077,7 +3077,6 @@
"type": "object"
},
"URL": {
"description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.",
"properties": {
"ForceQuery": {
"type": "boolean"
@@ -3110,7 +3109,7 @@
"$ref": "#/definitions/Userinfo"
}
},
"title": "A URL represents a parsed URL (technically, a URI reference).",
"title": "URL is a custom URL type that allows validation at configuration load time.",
"type": "object"
},
"Userinfo": {
@@ -3266,7 +3265,6 @@
"type": "object"
},
"alertGroup": {
"description": "AlertGroup alert group",
"properties": {
"alerts": {
"description": "alerts",
@@ -3511,6 +3509,7 @@
"type": "array"
},
"integration": {
"description": "Integration integration",
"properties": {
"lastNotifyAttempt": {
"description": "A timestamp indicating the last attempt to deliver a notification regardless of the outcome.\nFormat: date-time",
@@ -3654,7 +3653,6 @@
"type": "array"
},
"postableSilence": {
"description": "PostableSilence postable silence",
"properties": {
"comment": {
"description": "comment",
@@ -6243,4 +6241,4 @@
}
},
"swagger": "2.0"
}
}
+5 -7
View File
@@ -2544,7 +2544,7 @@
"title": "AlertQuery represents a single query associated with an alert definition.",
"properties": {
"datasourceUid": {
"description": "Grafana data source unique identifier; it should be '-100' for a Server Side Expression operation.",
"description": "Grafana data source unique identifier; it should be '__expr__' for a Server Side Expression operation.",
"type": "string"
},
"model": {
@@ -4502,7 +4502,7 @@
},
"example": [
{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"model": {
"conditions": [
{
@@ -5524,9 +5524,8 @@
}
},
"URL": {
"description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.",
"type": "object",
"title": "A URL represents a parsed URL (technically, a URI reference).",
"title": "URL is a custom URL type that allows validation at configuration load time.",
"properties": {
"ForceQuery": {
"type": "boolean"
@@ -5713,7 +5712,6 @@
}
},
"alertGroup": {
"description": "AlertGroup alert group",
"type": "object",
"required": [
"alerts",
@@ -5964,6 +5962,7 @@
"$ref": "#/definitions/gettableSilences"
},
"integration": {
"description": "Integration integration",
"type": "object",
"required": [
"name",
@@ -6108,7 +6107,6 @@
}
},
"postableSilence": {
"description": "PostableSilence postable silence",
"type": "object",
"required": [
"comment",
@@ -6278,4 +6276,4 @@
"type": "basic"
}
}
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ type AlertQuery struct {
// RelativeTimeRange is the relative Start and End of the query as sent by the frontend.
RelativeTimeRange RelativeTimeRange `json:"relativeTimeRange"`
// Grafana data source unique identifier; it should be '-100' for a Server Side Expression operation.
// Grafana data source unique identifier; it should be '__expr__' for a Server Side Expression operation.
DatasourceUID string `json:"datasourceUid"`
// JSON is the raw JSON query and includes the above properties as well as custom properties.
@@ -7,6 +7,7 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/expr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -29,7 +30,7 @@ func TestAlertQuery(t *testing.T) {
"queryType": "metricQuery",
"extraParam": "some text"
}`),
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
},
expectedIsExpression: true,
expectedMaxPoints: int64(defaultMaxDataPoints),
+2 -2
View File
@@ -294,7 +294,7 @@ func CreateClassicConditionExpression(refID string, inputRefID string, reducer s
return AlertQuery{
RefID: refID,
QueryType: expr.DatasourceType,
DatasourceUID: expr.OldDatasourceUID,
DatasourceUID: expr.DatasourceUID,
// the format corresponds to model `ClassicConditionJSON` in /pkg/expr/classic/classic.go
Model: json.RawMessage(fmt.Sprintf(`
{
@@ -328,6 +328,6 @@ func CreateClassicConditionExpression(refID string, inputRefID string, reducer s
}
}
]
}`, refID, inputRefID, operation, threshold, reducer, expr.OldDatasourceUID, expr.DatasourceType)),
}`, refID, inputRefID, operation, threshold, reducer, expr.DatasourceUID, expr.DatasourceType)),
}
}
@@ -7,6 +7,7 @@ import (
"testing"
"time"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/ngalert/models"
@@ -371,7 +372,7 @@ func createTestRule(title string, groupTitle string, orgID int64) models.AlertRu
{
RefID: "A",
Model: json.RawMessage("{}"),
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
RelativeTimeRange: models.RelativeTimeRange{
From: models.Duration(60),
To: models.Duration(0),
@@ -691,13 +691,13 @@ func withQueryForState(t *testing.T, evalResult eval.State) models.AlertRuleMuta
switch evalResult {
case eval.Normal:
expression = `{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"type":"math",
"expression":"2 + 1 < 1"
}`
case eval.Pending, eval.Alerting:
expression = `{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"type":"math",
"expression":"2 + 2 > 1"
}`
@@ -706,7 +706,7 @@ func withQueryForState(t *testing.T, evalResult eval.State) models.AlertRuleMuta
}
case eval.Error:
expression = `{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"type":"math",
"expression":"$A"
}`
@@ -718,7 +718,7 @@ func withQueryForState(t *testing.T, evalResult eval.State) models.AlertRuleMuta
rule.Condition = "A"
rule.Data = []models.AlertQuery{
{
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
Model: json.RawMessage(expression),
RelativeTimeRange: models.RelativeTimeRange{
From: models.Duration(5 * time.Hour),
+1 -1
View File
@@ -147,7 +147,7 @@ func CreateTestAlertRuleWithLabels(t testing.TB, ctx context.Context, dbstore *s
Data: []models.AlertQuery{
{
Model: json.RawMessage(`{
"datasourceUid": "-100",
"datasourceUid": "__expr__",
"type":"math",
"expression":"2 + 2 > 1"
}`),
@@ -31,7 +31,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -49,7 +49,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -30,7 +30,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -30,7 +30,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -30,7 +30,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -30,7 +30,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -84,7 +84,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -102,9 +102,9 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
refId: B
type: classic_conditions
type: classic_conditions
@@ -30,7 +30,7 @@ apiVersion: 1
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ apiVersion: 1
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -41,7 +41,7 @@
"from": 0,
"to": 0
},
"datasourceUID": "-100",
"datasourceUid": "__expr__",
"model": {
"conditions": [
{
@@ -61,7 +61,7 @@
},
"reducer": {
"params": [
],
"type": "last"
},
@@ -70,7 +70,7 @@
],
"datasource": {
"type": "__expr__",
"uid": "-100"
"uid": "__expr__"
},
"hide": false,
"intervalMs": 1000,
@@ -84,4 +84,4 @@
]
}
]
}
}
@@ -30,7 +30,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
@@ -30,7 +30,7 @@ groups:
relativeTimeRange:
from: 0
to: 0
datasourceUID: "-100"
datasourceUid: "__expr__"
model:
conditions:
- evaluator:
@@ -48,7 +48,7 @@ groups:
type: query
datasource:
type: __expr__
uid: "-100"
uid: "__expr__"
hide: false
intervalMs: 1000
maxDataPoints: 43200
+1 -1
View File
@@ -747,7 +747,7 @@ func (c *fakePluginClient) QueryData(ctx context.Context, req *backend.QueryData
c.req = req
// If an expression query ends up getting directly queried, we want it to return an error in our test.
if req.PluginContext.PluginID == "__expr__" {
if req.PluginContext.PluginID == expr.DatasourceUID {
return nil, errors.New("cant query an expression datasource")
}
@@ -171,7 +171,7 @@ func migrateAlertRuleQueries(data []alertQuery) ([]alertQuery, error) {
result := make([]alertQuery, 0, len(data))
for _, d := range data {
// queries that are expression are not relevant, skip them.
if d.DatasourceUID == expr.OldDatasourceUID {
if d.DatasourceUID == expr.DatasourceType {
result = append(result, d)
continue
}
@@ -7,6 +7,7 @@ import (
"strings"
"time"
"github.com/grafana/grafana/pkg/expr"
"github.com/grafana/grafana/pkg/util"
)
@@ -187,7 +188,7 @@ func transConditions(set dashAlertSettings, orgID int64, dsUIDMap dsUIDLookup) (
ccAlertQuery := alertQuery{
RefID: ccRefID,
Model: exprModelJSON,
DatasourceUID: "-100",
DatasourceUID: expr.DatasourceUID,
}
newCond.Data = append(newCond.Data, ccAlertQuery)