mirror of https://github.com/grafana/grafana
Alerting: Condition evaluator with cached pipeline (#57479)
* create rule evaluator * load header from the context * init one factory * update schedulerpull/58069/head
parent
d9c40ca41e
commit
e3a4bde622
@ -0,0 +1,137 @@ |
||||
// Code generated by mockery v2.14.0. DO NOT EDIT.
|
||||
|
||||
package eval_mocks |
||||
|
||||
import ( |
||||
context "context" |
||||
|
||||
backend "github.com/grafana/grafana-plugin-sdk-go/backend" |
||||
|
||||
eval "github.com/grafana/grafana/pkg/services/ngalert/eval" |
||||
|
||||
mock "github.com/stretchr/testify/mock" |
||||
|
||||
time "time" |
||||
) |
||||
|
||||
// ConditionEvaluatorMock is an autogenerated mock type for the ConditionEvaluator type
|
||||
type ConditionEvaluatorMock struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
type ConditionEvaluatorMock_Expecter struct { |
||||
mock *mock.Mock |
||||
} |
||||
|
||||
func (_m *ConditionEvaluatorMock) EXPECT() *ConditionEvaluatorMock_Expecter { |
||||
return &ConditionEvaluatorMock_Expecter{mock: &_m.Mock} |
||||
} |
||||
|
||||
// Evaluate provides a mock function with given fields: ctx, now
|
||||
func (_m *ConditionEvaluatorMock) Evaluate(ctx context.Context, now time.Time) (eval.Results, error) { |
||||
ret := _m.Called(ctx, now) |
||||
|
||||
var r0 eval.Results |
||||
if rf, ok := ret.Get(0).(func(context.Context, time.Time) eval.Results); ok { |
||||
r0 = rf(ctx, now) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(eval.Results) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { |
||||
r1 = rf(ctx, now) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// ConditionEvaluatorMock_Evaluate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Evaluate'
|
||||
type ConditionEvaluatorMock_Evaluate_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Evaluate is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - now time.Time
|
||||
func (_e *ConditionEvaluatorMock_Expecter) Evaluate(ctx interface{}, now interface{}) *ConditionEvaluatorMock_Evaluate_Call { |
||||
return &ConditionEvaluatorMock_Evaluate_Call{Call: _e.mock.On("Evaluate", ctx, now)} |
||||
} |
||||
|
||||
func (_c *ConditionEvaluatorMock_Evaluate_Call) Run(run func(ctx context.Context, now time.Time)) *ConditionEvaluatorMock_Evaluate_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run(args[0].(context.Context), args[1].(time.Time)) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *ConditionEvaluatorMock_Evaluate_Call) Return(_a0 eval.Results, _a1 error) *ConditionEvaluatorMock_Evaluate_Call { |
||||
_c.Call.Return(_a0, _a1) |
||||
return _c |
||||
} |
||||
|
||||
// EvaluateRaw provides a mock function with given fields: ctx, now
|
||||
func (_m *ConditionEvaluatorMock) EvaluateRaw(ctx context.Context, now time.Time) (*backend.QueryDataResponse, error) { |
||||
ret := _m.Called(ctx, now) |
||||
|
||||
var r0 *backend.QueryDataResponse |
||||
if rf, ok := ret.Get(0).(func(context.Context, time.Time) *backend.QueryDataResponse); ok { |
||||
r0 = rf(ctx, now) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*backend.QueryDataResponse) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(context.Context, time.Time) error); ok { |
||||
r1 = rf(ctx, now) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// ConditionEvaluatorMock_EvaluateRaw_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EvaluateRaw'
|
||||
type ConditionEvaluatorMock_EvaluateRaw_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// EvaluateRaw is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - now time.Time
|
||||
func (_e *ConditionEvaluatorMock_Expecter) EvaluateRaw(ctx interface{}, now interface{}) *ConditionEvaluatorMock_EvaluateRaw_Call { |
||||
return &ConditionEvaluatorMock_EvaluateRaw_Call{Call: _e.mock.On("EvaluateRaw", ctx, now)} |
||||
} |
||||
|
||||
func (_c *ConditionEvaluatorMock_EvaluateRaw_Call) Run(run func(ctx context.Context, now time.Time)) *ConditionEvaluatorMock_EvaluateRaw_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run(args[0].(context.Context), args[1].(time.Time)) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *ConditionEvaluatorMock_EvaluateRaw_Call) Return(resp *backend.QueryDataResponse, err error) *ConditionEvaluatorMock_EvaluateRaw_Call { |
||||
_c.Call.Return(resp, err) |
||||
return _c |
||||
} |
||||
|
||||
type mockConstructorTestingTNewConditionEvaluatorMock interface { |
||||
mock.TestingT |
||||
Cleanup(func()) |
||||
} |
||||
|
||||
// NewConditionEvaluatorMock creates a new instance of ConditionEvaluatorMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewConditionEvaluatorMock(t mockConstructorTestingTNewConditionEvaluatorMock) *ConditionEvaluatorMock { |
||||
mock := &ConditionEvaluatorMock{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
@ -0,0 +1,32 @@ |
||||
package eval_mocks |
||||
|
||||
import ( |
||||
"errors" |
||||
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/eval" |
||||
"github.com/grafana/grafana/pkg/services/ngalert/models" |
||||
) |
||||
|
||||
type fakeEvaluatorFactory struct { |
||||
err error |
||||
evaluator eval.ConditionEvaluator |
||||
} |
||||
|
||||
func NewEvaluatorFactory(evaluator eval.ConditionEvaluator) eval.EvaluatorFactory { |
||||
return &fakeEvaluatorFactory{evaluator: evaluator} |
||||
} |
||||
|
||||
func NewFailingEvaluatorFactory(err error) eval.EvaluatorFactory { |
||||
if err == nil { |
||||
err = errors.New("test") |
||||
} |
||||
return &fakeEvaluatorFactory{err: err} |
||||
} |
||||
|
||||
func (f fakeEvaluatorFactory) Validate(ctx eval.EvaluationContext, condition models.Condition) error { |
||||
return f.err |
||||
} |
||||
|
||||
func (f fakeEvaluatorFactory) Create(ctx eval.EvaluationContext, condition models.Condition) (eval.ConditionEvaluator, error) { |
||||
return f.evaluator, f.err |
||||
} |
||||
@ -1,160 +0,0 @@ |
||||
// Code generated by mockery v2.12.0. DO NOT EDIT.
|
||||
|
||||
package eval |
||||
|
||||
import ( |
||||
backend "github.com/grafana/grafana-plugin-sdk-go/backend" |
||||
mock "github.com/stretchr/testify/mock" |
||||
|
||||
models "github.com/grafana/grafana/pkg/services/ngalert/models" |
||||
|
||||
testing "testing" |
||||
) |
||||
|
||||
// FakeEvaluator is an autogenerated mock type for the Evaluator type
|
||||
type FakeEvaluator struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
type FakeEvaluator_Expecter struct { |
||||
mock *mock.Mock |
||||
} |
||||
|
||||
func (_m *FakeEvaluator) EXPECT() *FakeEvaluator_Expecter { |
||||
return &FakeEvaluator_Expecter{mock: &_m.Mock} |
||||
} |
||||
|
||||
// ConditionEval provides a mock function with given fields: ctx, condition
|
||||
func (_m *FakeEvaluator) ConditionEval(ctx EvaluationContext, condition models.Condition) Results { |
||||
ret := _m.Called(ctx, condition) |
||||
|
||||
var r0 Results |
||||
if rf, ok := ret.Get(0).(func(EvaluationContext, models.Condition) Results); ok { |
||||
r0 = rf(ctx, condition) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(Results) |
||||
} |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// FakeEvaluator_ConditionEval_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ConditionEval'
|
||||
type FakeEvaluator_ConditionEval_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// ConditionEval is a helper method to define mock.On call
|
||||
// - ctx EvaluationContext
|
||||
// - condition models.Condition
|
||||
func (_e *FakeEvaluator_Expecter) ConditionEval(ctx interface{}, condition interface{}) *FakeEvaluator_ConditionEval_Call { |
||||
return &FakeEvaluator_ConditionEval_Call{Call: _e.mock.On("ConditionEval", ctx, condition)} |
||||
} |
||||
|
||||
func (_c *FakeEvaluator_ConditionEval_Call) Run(run func(ctx EvaluationContext, condition models.Condition)) *FakeEvaluator_ConditionEval_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run(args[0].(EvaluationContext), args[1].(models.Condition)) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *FakeEvaluator_ConditionEval_Call) Return(_a0 Results) *FakeEvaluator_ConditionEval_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
// QueriesAndExpressionsEval provides a mock function with given fields: ctx, data
|
||||
func (_m *FakeEvaluator) QueriesAndExpressionsEval(ctx EvaluationContext, data []models.AlertQuery) (*backend.QueryDataResponse, error) { |
||||
ret := _m.Called(ctx, data) |
||||
|
||||
var r0 *backend.QueryDataResponse |
||||
if rf, ok := ret.Get(0).(func(EvaluationContext, []models.AlertQuery) *backend.QueryDataResponse); ok { |
||||
r0 = rf(ctx, data) |
||||
} else { |
||||
if ret.Get(0) != nil { |
||||
r0 = ret.Get(0).(*backend.QueryDataResponse) |
||||
} |
||||
} |
||||
|
||||
var r1 error |
||||
if rf, ok := ret.Get(1).(func(EvaluationContext, []models.AlertQuery) error); ok { |
||||
r1 = rf(ctx, data) |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// FakeEvaluator_QueriesAndExpressionsEval_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueriesAndExpressionsEval'
|
||||
type FakeEvaluator_QueriesAndExpressionsEval_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// QueriesAndExpressionsEval is a helper method to define mock.On call
|
||||
// - ctx EvaluationContext
|
||||
// - data []models.AlertQuery
|
||||
func (_e *FakeEvaluator_Expecter) QueriesAndExpressionsEval(ctx interface{}, data interface{}) *FakeEvaluator_QueriesAndExpressionsEval_Call { |
||||
return &FakeEvaluator_QueriesAndExpressionsEval_Call{Call: _e.mock.On("QueriesAndExpressionsEval", ctx, data)} |
||||
} |
||||
|
||||
func (_c *FakeEvaluator_QueriesAndExpressionsEval_Call) Run(run func(ctx EvaluationContext, data []models.AlertQuery)) *FakeEvaluator_QueriesAndExpressionsEval_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run(args[0].(EvaluationContext), args[1].([]models.AlertQuery)) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *FakeEvaluator_QueriesAndExpressionsEval_Call) Return(_a0 *backend.QueryDataResponse, _a1 error) *FakeEvaluator_QueriesAndExpressionsEval_Call { |
||||
_c.Call.Return(_a0, _a1) |
||||
return _c |
||||
} |
||||
|
||||
// Validate provides a mock function with given fields: ctx, condition
|
||||
func (_m *FakeEvaluator) Validate(ctx EvaluationContext, condition models.Condition) error { |
||||
ret := _m.Called(ctx, condition) |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func(EvaluationContext, models.Condition) error); ok { |
||||
r0 = rf(ctx, condition) |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// FakeEvaluator_Validate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Validate'
|
||||
type FakeEvaluator_Validate_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Validate is a helper method to define mock.On call
|
||||
// - ctx EvaluationContext
|
||||
// - condition models.Condition
|
||||
func (_e *FakeEvaluator_Expecter) Validate(ctx interface{}, condition interface{}) *FakeEvaluator_Validate_Call { |
||||
return &FakeEvaluator_Validate_Call{Call: _e.mock.On("Validate", ctx, condition)} |
||||
} |
||||
|
||||
func (_c *FakeEvaluator_Validate_Call) Run(run func(ctx EvaluationContext, condition models.Condition)) *FakeEvaluator_Validate_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run(args[0].(EvaluationContext), args[1].(models.Condition)) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *FakeEvaluator_Validate_Call) Return(_a0 error) *FakeEvaluator_Validate_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
// NewFakeEvaluator creates a new instance of FakeEvaluator. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewFakeEvaluator(t testing.TB) *FakeEvaluator { |
||||
mock := &FakeEvaluator{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
Loading…
Reference in new issue