mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove Dispatch and AddHandler (#42603)
* Remove Dispatch * Remove context.TODO() * Remove AddHandler and Dispatch
This commit is contained in:
@@ -200,7 +200,7 @@ func (fr *FileReader) handleMissingDashboardFiles(ctx context.Context, provision
|
||||
// so afterwards the dashboard is considered unprovisioned.
|
||||
for _, dashboardID := range dashboardsToDelete {
|
||||
fr.log.Debug("unprovisioning provisioned dashboard. missing on disk", "id", dashboardID)
|
||||
err := fr.dashboardProvisioningService.UnprovisionDashboard(dashboardID)
|
||||
err := fr.dashboardProvisioningService.UnprovisionDashboard(ctx, dashboardID)
|
||||
if err != nil {
|
||||
fr.log.Error("failed to unprovision dashboard", "dashboard_id", dashboardID, "error", err)
|
||||
}
|
||||
|
||||
@@ -608,7 +608,7 @@ func (s *fakeDashboardProvisioningService) SaveFolderForProvisionedDashboards(ct
|
||||
return dto.Dashboard, nil
|
||||
}
|
||||
|
||||
func (s *fakeDashboardProvisioningService) UnprovisionDashboard(dashboardID int64) error {
|
||||
func (s *fakeDashboardProvisioningService) UnprovisionDashboard(ctx context.Context, dashboardID int64) error {
|
||||
for key, val := range s.provisioned {
|
||||
for index, dashboard := range val {
|
||||
if dashboard.DashboardId == dashboardID {
|
||||
@@ -620,7 +620,7 @@ func (s *fakeDashboardProvisioningService) UnprovisionDashboard(dashboardID int6
|
||||
}
|
||||
|
||||
func (s *fakeDashboardProvisioningService) DeleteProvisionedDashboard(ctx context.Context, dashboardID int64, orgID int64) error {
|
||||
err := s.UnprovisionDashboard(dashboardID)
|
||||
err := s.UnprovisionDashboard(ctx, dashboardID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (dc *NotificationProvisioner) apply(ctx context.Context, cfg *notifications
|
||||
return err
|
||||
}
|
||||
|
||||
if err := dc.mergeNotifications(cfg.Notifications); err != nil {
|
||||
if err := dc.mergeNotifications(ctx, cfg.Notifications); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, noti
|
||||
|
||||
if notification.OrgID == 0 && notification.OrgName != "" {
|
||||
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
|
||||
if err := bus.Dispatch(getOrg); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, getOrg); err != nil {
|
||||
return err
|
||||
}
|
||||
notification.OrgID = getOrg.Result.Id
|
||||
@@ -73,11 +73,11 @@ func (dc *NotificationProvisioner) deleteNotifications(ctx context.Context, noti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*notificationFromConfig) error {
|
||||
func (dc *NotificationProvisioner) mergeNotifications(ctx context.Context, notificationToMerge []*notificationFromConfig) error {
|
||||
for _, notification := range notificationToMerge {
|
||||
if notification.OrgID == 0 && notification.OrgName != "" {
|
||||
getOrg := &models.GetOrgByNameQuery{Name: notification.OrgName}
|
||||
if err := bus.Dispatch(getOrg); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, getOrg); err != nil {
|
||||
return err
|
||||
}
|
||||
notification.OrgID = getOrg.Result.Id
|
||||
@@ -86,7 +86,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
|
||||
}
|
||||
|
||||
cmd := &models.GetAlertNotificationsWithUidQuery{OrgId: notification.OrgID, Uid: notification.UID}
|
||||
err := bus.Dispatch(cmd)
|
||||
err := bus.DispatchCtx(ctx, cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
|
||||
SendReminder: notification.SendReminder,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(insertCmd); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, insertCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
@@ -124,7 +124,7 @@ func (dc *NotificationProvisioner) mergeNotifications(notificationToMerge []*not
|
||||
SendReminder: notification.SendReminder,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(updateCmd); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, updateCmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
@@ -11,13 +12,13 @@ import (
|
||||
|
||||
// Provision scans a directory for provisioning config files
|
||||
// and provisions the app in those files.
|
||||
func Provision(configDirectory string, pluginStore plugins.Store) error {
|
||||
func Provision(ctx context.Context, configDirectory string, pluginStore plugins.Store) error {
|
||||
logger := log.New("provisioning.plugins")
|
||||
ap := PluginProvisioner{
|
||||
log: logger,
|
||||
cfgProvider: newConfigReader(logger, pluginStore),
|
||||
}
|
||||
return ap.applyChanges(configDirectory)
|
||||
return ap.applyChanges(ctx, configDirectory)
|
||||
}
|
||||
|
||||
// PluginProvisioner is responsible for provisioning apps based on
|
||||
@@ -27,11 +28,11 @@ type PluginProvisioner struct {
|
||||
cfgProvider configReader
|
||||
}
|
||||
|
||||
func (ap *PluginProvisioner) apply(cfg *pluginsAsConfig) error {
|
||||
func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) error {
|
||||
for _, app := range cfg.Apps {
|
||||
if app.OrgID == 0 && app.OrgName != "" {
|
||||
getOrgQuery := &models.GetOrgByNameQuery{Name: app.OrgName}
|
||||
if err := bus.Dispatch(getOrgQuery); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, getOrgQuery); err != nil {
|
||||
return err
|
||||
}
|
||||
app.OrgID = getOrgQuery.Result.Id
|
||||
@@ -40,7 +41,7 @@ func (ap *PluginProvisioner) apply(cfg *pluginsAsConfig) error {
|
||||
}
|
||||
|
||||
query := &models.GetPluginSettingByIdQuery{OrgId: app.OrgID, PluginId: app.PluginID}
|
||||
err := bus.Dispatch(query)
|
||||
err := bus.DispatchCtx(ctx, query)
|
||||
if err != nil {
|
||||
if !errors.Is(err, models.ErrPluginSettingNotFound) {
|
||||
return err
|
||||
@@ -59,7 +60,7 @@ func (ap *PluginProvisioner) apply(cfg *pluginsAsConfig) error {
|
||||
SecureJsonData: app.SecureJSONData,
|
||||
PluginVersion: app.PluginVersion,
|
||||
}
|
||||
if err := bus.Dispatch(cmd); err != nil {
|
||||
if err := bus.DispatchCtx(ctx, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -67,14 +68,14 @@ func (ap *PluginProvisioner) apply(cfg *pluginsAsConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ap *PluginProvisioner) applyChanges(configPath string) error {
|
||||
func (ap *PluginProvisioner) applyChanges(ctx context.Context, configPath string) error {
|
||||
configs, err := ap.cfgProvider.readConfig(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cfg := range configs {
|
||||
if err := ap.apply(cfg); err != nil {
|
||||
if err := ap.apply(ctx, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
expectedErr := errors.New("test")
|
||||
reader := &testConfigReader{err: expectedErr}
|
||||
ap := PluginProvisioner{log: log.New("test"), cfgProvider: reader}
|
||||
err := ap.applyChanges("")
|
||||
err := ap.applyChanges(context.Background(), "")
|
||||
require.Equal(t, expectedErr, err)
|
||||
})
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestPluginProvisioner(t *testing.T) {
|
||||
}
|
||||
reader := &testConfigReader{result: cfg}
|
||||
ap := PluginProvisioner{log: log.New("test"), cfgProvider: reader}
|
||||
err := ap.applyChanges("")
|
||||
err := ap.applyChanges(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, sentCommands, 4)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ type ProvisioningService interface {
|
||||
registry.BackgroundService
|
||||
RunInitProvisioners(ctx context.Context) error
|
||||
ProvisionDatasources(ctx context.Context) error
|
||||
ProvisionPlugins() error
|
||||
ProvisionPlugins(ctx context.Context) error
|
||||
ProvisionNotifications(ctx context.Context) error
|
||||
ProvisionDashboards(ctx context.Context) error
|
||||
GetDashboardProvisionerResolvedPath(name string) string
|
||||
@@ -61,7 +61,7 @@ func newProvisioningServiceImpl(
|
||||
newDashboardProvisioner dashboards.DashboardProvisionerFactory,
|
||||
provisionNotifiers func(context.Context, string, encryption.Internal) error,
|
||||
provisionDatasources func(context.Context, string) error,
|
||||
provisionPlugins func(string, plugifaces.Store) error,
|
||||
provisionPlugins func(context.Context, string, plugifaces.Store) error,
|
||||
) *ProvisioningServiceImpl {
|
||||
return &ProvisioningServiceImpl{
|
||||
log: log.New("provisioning"),
|
||||
@@ -83,7 +83,7 @@ type ProvisioningServiceImpl struct {
|
||||
dashboardProvisioner dashboards.DashboardProvisioner
|
||||
provisionNotifiers func(context.Context, string, encryption.Internal) error
|
||||
provisionDatasources func(context.Context, string) error
|
||||
provisionPlugins func(string, plugifaces.Store) error
|
||||
provisionPlugins func(context.Context, string, plugifaces.Store) error
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ func (ps *ProvisioningServiceImpl) RunInitProvisioners(ctx context.Context) erro
|
||||
return err
|
||||
}
|
||||
|
||||
err = ps.ProvisionPlugins()
|
||||
err = ps.ProvisionPlugins(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -141,9 +141,9 @@ func (ps *ProvisioningServiceImpl) ProvisionDatasources(ctx context.Context) err
|
||||
return errutil.Wrap("Datasource provisioning error", err)
|
||||
}
|
||||
|
||||
func (ps *ProvisioningServiceImpl) ProvisionPlugins() error {
|
||||
func (ps *ProvisioningServiceImpl) ProvisionPlugins(ctx context.Context) error {
|
||||
appPath := filepath.Join(ps.Cfg.ProvisioningPath, "plugins")
|
||||
err := ps.provisionPlugins(appPath, ps.pluginStore)
|
||||
err := ps.provisionPlugins(ctx, appPath, ps.pluginStore)
|
||||
return errutil.Wrap("app provisioning error", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ func (mock *ProvisioningServiceMock) ProvisionDatasources(ctx context.Context) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mock *ProvisioningServiceMock) ProvisionPlugins() error {
|
||||
func (mock *ProvisioningServiceMock) ProvisionPlugins(ctx context.Context) error {
|
||||
mock.Calls.ProvisionPlugins = append(mock.Calls.ProvisionPlugins, nil)
|
||||
if mock.ProvisionPluginsFunc != nil {
|
||||
return mock.ProvisionPluginsFunc()
|
||||
|
||||
Reference in New Issue
Block a user