#45498: add IsDisabled to entityEventsService
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/registry"
|
"github.com/grafana/grafana/pkg/registry"
|
||||||
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
)
|
)
|
||||||
@@ -55,6 +56,7 @@ type SaveEventCmd struct {
|
|||||||
//go:generate mockery --name EntityEventsService --structname MockEntityEventsService --inpackage --filename entity_events_mock.go
|
//go:generate mockery --name EntityEventsService --structname MockEntityEventsService --inpackage --filename entity_events_mock.go
|
||||||
type EntityEventsService interface {
|
type EntityEventsService interface {
|
||||||
registry.BackgroundService
|
registry.BackgroundService
|
||||||
|
registry.CanBeDisabled
|
||||||
SaveEvent(ctx context.Context, cmd SaveEventCmd) error
|
SaveEvent(ctx context.Context, cmd SaveEventCmd) error
|
||||||
GetLastEvent(ctx context.Context) (*EntityEvent, error)
|
GetLastEvent(ctx context.Context) (*EntityEvent, error)
|
||||||
GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
|
GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error)
|
||||||
@@ -62,16 +64,22 @@ type EntityEventsService interface {
|
|||||||
deleteEventsOlderThan(ctx context.Context, duration time.Duration) error
|
deleteEventsOlderThan(ctx context.Context, duration time.Duration) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideEntityEventsService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore) EntityEventsService {
|
func ProvideEntityEventsService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore, features featuremgmt.FeatureToggles) EntityEventsService {
|
||||||
|
if !features.IsEnabled(featuremgmt.FlagPanelTitleSearch) {
|
||||||
|
return &dummyEntityEventsService{}
|
||||||
|
}
|
||||||
|
|
||||||
return &entityEventService{
|
return &entityEventService{
|
||||||
sql: sqlStore,
|
sql: sqlStore,
|
||||||
log: log.New("entity-events"),
|
features: features,
|
||||||
|
log: log.New("entity-events"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type entityEventService struct {
|
type entityEventService struct {
|
||||||
sql *sqlstore.SQLStore
|
sql *sqlstore.SQLStore
|
||||||
log log.Logger
|
log log.Logger
|
||||||
|
features featuremgmt.FeatureToggles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *entityEventService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error {
|
func (e *entityEventService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error {
|
||||||
@@ -117,6 +125,10 @@ func (e *entityEventService) deleteEventsOlderThan(ctx context.Context, duration
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *entityEventService) IsDisabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (e *entityEventService) Run(ctx context.Context) error {
|
func (e *entityEventService) Run(ctx context.Context) error {
|
||||||
clean := time.NewTicker(1 * time.Hour)
|
clean := time.NewTicker(1 * time.Hour)
|
||||||
|
|
||||||
@@ -136,3 +148,32 @@ func (e *entityEventService) Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type dummyEntityEventsService struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dummyEntityEventsService) Run(ctx context.Context) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dummyEntityEventsService) IsDisabled() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dummyEntityEventsService) SaveEvent(ctx context.Context, cmd SaveEventCmd) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dummyEntityEventsService) GetLastEvent(ctx context.Context) (*EntityEvent, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dummyEntityEventsService) GetAllEventsAfter(ctx context.Context, id int64) ([]*EntityEvent, error) {
|
||||||
|
return make([]*EntityEvent, 0), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d dummyEntityEventsService) deleteEventsOlderThan(ctx context.Context, duration time.Duration) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ EntityEventsService = &dummyEntityEventsService{}
|
||||||
|
|||||||
@@ -60,6 +60,20 @@ func (_m *MockEntityEventsService) GetLastEvent(ctx context.Context) (*EntityEve
|
|||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDisabled provides a mock function with given fields:
|
||||||
|
func (_m *MockEntityEventsService) IsDisabled() bool {
|
||||||
|
ret := _m.Called()
|
||||||
|
|
||||||
|
var r0 bool
|
||||||
|
if rf, ok := ret.Get(0).(func() bool); ok {
|
||||||
|
r0 = rf()
|
||||||
|
} else {
|
||||||
|
r0 = ret.Get(0).(bool)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0
|
||||||
|
}
|
||||||
|
|
||||||
// Run provides a mock function with given fields: ctx
|
// Run provides a mock function with given fields: ctx
|
||||||
func (_m *MockEntityEventsService) Run(ctx context.Context) error {
|
func (_m *MockEntityEventsService) Run(ctx context.Context) error {
|
||||||
ret := _m.Called(ctx)
|
ret := _m.Called(ctx)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestEntityEventsService(t *testing.T) {
|
func TestEntityEventsService(t *testing.T) {
|
||||||
|
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
var service EntityEventsService
|
var service EntityEventsService
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user