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
parent fee0d44e5c
commit 6d64c603c2
8 changed files with 19 additions and 42 deletions

View File

@@ -5,7 +5,7 @@ import "fmt"
// preSave sets datasource and loads the updated model for each alert query.
func (alertDefinition *AlertDefinition) preSave() error {
for i, q := range alertDefinition.Data {
err := q.PreSave(alertDefinition.OrgId)
err := q.PreSave()
if err != nil {
return fmt.Errorf("invalid alert query %s: %w", q.RefID, err)
}

View File

@@ -237,18 +237,6 @@ func (aq *AlertQuery) getModel() ([]byte, error) {
return model, nil
}
func (aq *AlertQuery) setOrgID(orgID int64) error {
if aq.modelProps == nil {
err := aq.setModelProps()
if err != nil {
return err
}
}
aq.modelProps["orgId"] = orgID
return nil
}
func (aq *AlertQuery) setQueryType() error {
if aq.modelProps == nil {
err := aq.setModelProps()
@@ -272,12 +260,7 @@ func (aq *AlertQuery) setQueryType() error {
// PreSave sets query's properties.
// It should be called before being saved.
func (aq *AlertQuery) PreSave(orgID int64) error {
err := aq.setOrgID(orgID)
if err != nil {
return fmt.Errorf("failed to set orgId to query model: %w", err)
}
func (aq *AlertQuery) PreSave() error {
if err := aq.setDatasource(); err != nil {
return fmt.Errorf("failed to set datasource to query model: %w", err)
}

View File

@@ -96,11 +96,12 @@ func (c *Condition) Execute(ctx AlertExecCtx, fromStr, toStr string) (*Execution
result := ExecutionResults{}
if !c.IsValid() {
return nil, fmt.Errorf("invalid conditions")
// TODO: Things probably
}
queryDataReq := &backend.QueryDataRequest{
PluginContext: backend.PluginContext{
// TODO: Things probably
OrgID: ctx.SignedInUser.OrgId,
},
Queries: []backend.DataQuery{},
}