Expr: fix failure to execute due to OrgID (#29653)

* Expr: fix failure to execute due to OrgID
Get orgID from the plugin context, which makes more sense anyways.
makes expressions work again after https://github.com/grafana/grafana/pull/29449 changes.

* Do not save organisation on its alert query model

Co-authored-by: Sofia Papagiannaki <sofia@grafana.com>
This commit is contained in:
Kyle Brandt
2020-12-07 10:30:38 -05:00
committed by GitHub
co-authored by Sofia Papagiannaki
parent fee0d44e5c
commit 6d64c603c2
8 changed files with 19 additions and 42 deletions
+2 -11
View File
@@ -137,7 +137,7 @@ func (dn *DSNode) NodeType() NodeType {
return TypeDatasourceNode
}
func buildDSNode(dp *simple.DirectedGraph, rn *rawNode) (*DSNode, error) {
func buildDSNode(dp *simple.DirectedGraph, rn *rawNode, orgID int64) (*DSNode, error) {
encodedQuery, err := json.Marshal(rn.Query)
if err != nil {
return nil, err
@@ -148,6 +148,7 @@ func buildDSNode(dp *simple.DirectedGraph, rn *rawNode) (*DSNode, error) {
id: dp.NewNode().ID(),
refID: rn.RefID,
},
orgID: orgID,
query: json.RawMessage(encodedQuery),
queryType: rn.QueryType,
intervalMS: defaultIntervalMS,
@@ -165,16 +166,6 @@ func buildDSNode(dp *simple.DirectedGraph, rn *rawNode) (*DSNode, error) {
}
dsNode.datasourceID = int64(floatDsID)
rawOrgID, ok := rn.Query["orgId"]
if !ok {
return nil, fmt.Errorf("no orgId in expression data source request command for refId %v", rn.RefID)
}
floatOrgID, ok := rawOrgID.(float64)
if !ok {
return nil, fmt.Errorf("expected orgId to be a float64, got type %T for refId %v", rawOrgID, rn.RefID)
}
dsNode.orgID = int64(floatOrgID)
var floatIntervalMS float64
if rawIntervalMS := rn.Query["intervalMs"]; ok {
if floatIntervalMS, ok = rawIntervalMS.(float64); !ok {