Alerting/Expr: New SSE Request/QueryType, alerting move data source UID (#33282)
This commit is contained in:
@@ -102,13 +102,10 @@ type AlertExecCtx struct {
|
||||
Ctx context.Context
|
||||
}
|
||||
|
||||
// GetQueryDataRequest validates the condition and creates a backend.QueryDataRequest from it.
|
||||
func GetQueryDataRequest(ctx AlertExecCtx, data []models.AlertQuery, now time.Time) (*backend.QueryDataRequest, error) {
|
||||
queryDataReq := &backend.QueryDataRequest{
|
||||
PluginContext: backend.PluginContext{
|
||||
OrgID: ctx.OrgID,
|
||||
},
|
||||
Queries: []backend.DataQuery{},
|
||||
// GetExprRequest validates the condition and creates a expr.Request from it.
|
||||
func GetExprRequest(ctx AlertExecCtx, data []models.AlertQuery, now time.Time) (*expr.Request, error) {
|
||||
req := &expr.Request{
|
||||
OrgId: ctx.OrgID,
|
||||
}
|
||||
|
||||
for i := range data {
|
||||
@@ -127,16 +124,20 @@ func GetQueryDataRequest(ctx AlertExecCtx, data []models.AlertQuery, now time.Ti
|
||||
return nil, fmt.Errorf("failed to retrieve maxDatapoints from the model: %w", err)
|
||||
}
|
||||
|
||||
queryDataReq.Queries = append(queryDataReq.Queries, backend.DataQuery{
|
||||
req.Queries = append(req.Queries, expr.Query{
|
||||
TimeRange: expr.TimeRange{
|
||||
From: q.RelativeTimeRange.ToTimeRange(now).From,
|
||||
To: q.RelativeTimeRange.ToTimeRange(now).To,
|
||||
},
|
||||
DatasourceUID: q.DatasourceUID,
|
||||
JSON: model,
|
||||
Interval: interval,
|
||||
RefID: q.RefID,
|
||||
MaxDataPoints: maxDatapoints,
|
||||
QueryType: q.QueryType,
|
||||
TimeRange: q.RelativeTimeRange.ToTimeRange(now),
|
||||
})
|
||||
}
|
||||
return queryDataReq, nil
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func executeCondition(ctx AlertExecCtx, c *models.Condition, now time.Time, dataService *tsdb.Service) (*ExecutionResults, error) {
|
||||
@@ -165,7 +166,7 @@ func executeCondition(ctx AlertExecCtx, c *models.Condition, now time.Time, data
|
||||
}
|
||||
|
||||
func executeQueriesAndExpressions(ctx AlertExecCtx, data []models.AlertQuery, now time.Time, dataService *tsdb.Service) (*backend.QueryDataResponse, error) {
|
||||
queryDataReq, err := GetQueryDataRequest(ctx, data, now)
|
||||
queryDataReq, err := GetExprRequest(ctx, data, now)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user