mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: update rule test endpoints to respect data source permissions (#47169)
* make eval.Evaluator an interface * inject Evaluator to TestingApiSrv * move conditionEval to RouteTestGrafanaRuleConfig because it is the only place where it is used * update rule test api to check data source permissions
This commit is contained in:
@@ -22,10 +22,19 @@ import (
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/expr"
|
||||
)
|
||||
|
||||
type Evaluator struct {
|
||||
//go:generate mockery --name Evaluator --structname FakeEvaluator --inpackage --filename evaluator_mock.go --with-expecter
|
||||
type Evaluator interface {
|
||||
// ConditionEval executes conditions and evaluates the result.
|
||||
ConditionEval(condition *models.Condition, now time.Time, expressionService *expr.Service) (Results, error)
|
||||
// QueriesAndExpressionsEval executes queries and expressions and returns the result.
|
||||
QueriesAndExpressionsEval(orgID int64, data []models.AlertQuery, now time.Time, expressionService *expr.Service) (*backend.QueryDataResponse, error)
|
||||
}
|
||||
|
||||
type evaluatorImpl struct {
|
||||
cfg *setting.Cfg
|
||||
log log.Logger
|
||||
dataSourceCache datasources.CacheService
|
||||
@@ -36,8 +45,8 @@ func NewEvaluator(
|
||||
cfg *setting.Cfg,
|
||||
log log.Logger,
|
||||
datasourceCache datasources.CacheService,
|
||||
secretsService secrets.Service) *Evaluator {
|
||||
return &Evaluator{
|
||||
secretsService secrets.Service) Evaluator {
|
||||
return &evaluatorImpl{
|
||||
cfg: cfg,
|
||||
log: log,
|
||||
dataSourceCache: datasourceCache,
|
||||
@@ -576,7 +585,7 @@ func (evalResults Results) AsDataFrame() data.Frame {
|
||||
}
|
||||
|
||||
// ConditionEval executes conditions and evaluates the result.
|
||||
func (e *Evaluator) ConditionEval(condition *models.Condition, now time.Time, expressionService *expr.Service) (Results, error) {
|
||||
func (e *evaluatorImpl) ConditionEval(condition *models.Condition, now time.Time, expressionService *expr.Service) (Results, error) {
|
||||
alertCtx, cancelFn := context.WithTimeout(context.Background(), e.cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
defer cancelFn()
|
||||
|
||||
@@ -589,7 +598,7 @@ func (e *Evaluator) ConditionEval(condition *models.Condition, now time.Time, ex
|
||||
}
|
||||
|
||||
// QueriesAndExpressionsEval executes queries and expressions and returns the result.
|
||||
func (e *Evaluator) QueriesAndExpressionsEval(orgID int64, data []models.AlertQuery, now time.Time, expressionService *expr.Service) (*backend.QueryDataResponse, error) {
|
||||
func (e *evaluatorImpl) QueriesAndExpressionsEval(orgID int64, data []models.AlertQuery, now time.Time, expressionService *expr.Service) (*backend.QueryDataResponse, error) {
|
||||
alertCtx, cancelFn := context.WithTimeout(context.Background(), e.cfg.UnifiedAlerting.EvaluationTimeout)
|
||||
defer cancelFn()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user