mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Alerting: Move migration from background service run to ngalert init sqlite database write contention between the migration's single transaction and dashboard provisioning's frequent commits was causing the migration to fail with SQLITE_BUSY/SQLITE_BUSY_SNAPSHOT on all retries. This is not a new issue for sqlite+grafana, but the discrepancy between the length of the transactions was causing it to be very consistent. In addition, since a failed migration has implications on the assumed correctness of the alertmanager and alert rule definition state, we cause a server shutdown on error. This can make e2e tests as well as some high-load provisioned sqlite installations flaky on startup. The correct fix for this is better transaction management across various services and is out of scope for this change as we're primarily interested in mitigating the current bout of server failures in e2e tests when using sqlite.
117 lines
5.3 KiB
Go
117 lines
5.3 KiB
Go
package backgroundsvcs
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/api"
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
|
"github.com/grafana/grafana/pkg/infra/remotecache"
|
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
|
uss "github.com/grafana/grafana/pkg/infra/usagestats/service"
|
|
"github.com/grafana/grafana/pkg/infra/usagestats/statscollector"
|
|
"github.com/grafana/grafana/pkg/registry"
|
|
apiregistry "github.com/grafana/grafana/pkg/registry/apis"
|
|
"github.com/grafana/grafana/pkg/services/alerting"
|
|
"github.com/grafana/grafana/pkg/services/anonymous/anonimpl"
|
|
"github.com/grafana/grafana/pkg/services/auth"
|
|
"github.com/grafana/grafana/pkg/services/cleanup"
|
|
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
|
grafanaapiserver "github.com/grafana/grafana/pkg/services/grafana-apiserver"
|
|
"github.com/grafana/grafana/pkg/services/grpcserver"
|
|
"github.com/grafana/grafana/pkg/services/guardian"
|
|
ldapapi "github.com/grafana/grafana/pkg/services/ldap/api"
|
|
"github.com/grafana/grafana/pkg/services/live"
|
|
"github.com/grafana/grafana/pkg/services/live/pushhttp"
|
|
"github.com/grafana/grafana/pkg/services/login/authinfoservice"
|
|
"github.com/grafana/grafana/pkg/services/loginattempt/loginattemptimpl"
|
|
"github.com/grafana/grafana/pkg/services/ngalert"
|
|
"github.com/grafana/grafana/pkg/services/notifications"
|
|
plugindashboardsservice "github.com/grafana/grafana/pkg/services/plugindashboards/service"
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/angulardetectorsprovider"
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/keyretriever/dynamic"
|
|
pluginStore "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
|
"github.com/grafana/grafana/pkg/services/provisioning"
|
|
publicdashboardsmetric "github.com/grafana/grafana/pkg/services/publicdashboards/metric"
|
|
"github.com/grafana/grafana/pkg/services/rendering"
|
|
"github.com/grafana/grafana/pkg/services/searchV2"
|
|
secretsMigrations "github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations"
|
|
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
|
samanager "github.com/grafana/grafana/pkg/services/serviceaccounts/manager"
|
|
"github.com/grafana/grafana/pkg/services/store"
|
|
"github.com/grafana/grafana/pkg/services/store/entity"
|
|
"github.com/grafana/grafana/pkg/services/store/sanitizer"
|
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlesimpl"
|
|
"github.com/grafana/grafana/pkg/services/team/teamapi"
|
|
"github.com/grafana/grafana/pkg/services/updatechecker"
|
|
)
|
|
|
|
func ProvideBackgroundServiceRegistry(
|
|
httpServer *api.HTTPServer, ng *ngalert.AlertNG, cleanup *cleanup.CleanUpService, live *live.GrafanaLive,
|
|
pushGateway *pushhttp.Gateway, notifications *notifications.NotificationService, pluginStore *pluginStore.Service,
|
|
rendering *rendering.RenderingService, tokenService auth.UserTokenBackgroundService, tracing *tracing.TracingService,
|
|
provisioning *provisioning.ProvisioningServiceImpl, alerting *alerting.AlertEngine, usageStats *uss.UsageStats,
|
|
statsCollector *statscollector.Service, grafanaUpdateChecker *updatechecker.GrafanaService,
|
|
pluginsUpdateChecker *updatechecker.PluginsService, metrics *metrics.InternalMetricsService,
|
|
secretsService *secretsManager.SecretsService, remoteCache *remotecache.RemoteCache, StorageService store.StorageService, searchService searchV2.SearchService, entityEventsService store.EntityEventsService,
|
|
saService *samanager.ServiceAccountsService, authInfoService *authinfoservice.Implementation,
|
|
grpcServerProvider grpcserver.Provider, secretMigrationProvider secretsMigrations.SecretMigrationProvider, loginAttemptService *loginattemptimpl.Service,
|
|
bundleService *supportbundlesimpl.Service, publicDashboardsMetric *publicdashboardsmetric.Service,
|
|
keyRetriever *dynamic.KeyRetriever, dynamicAngularDetectorsProvider *angulardetectorsprovider.Dynamic,
|
|
grafanaAPIServer grafanaapiserver.Service,
|
|
anon *anonimpl.AnonDeviceService,
|
|
// Need to make sure these are initialized, is there a better place to put them?
|
|
_ dashboardsnapshots.Service, _ *alerting.AlertNotificationService,
|
|
_ serviceaccounts.Service, _ *guardian.Provider,
|
|
_ *plugindashboardsservice.DashboardUpdater, _ *sanitizer.Provider,
|
|
_ *grpcserver.HealthService, _ entity.EntityStoreServer, _ *grpcserver.ReflectionService, _ *ldapapi.Service,
|
|
_ *apiregistry.Service, _ auth.IDService, _ *teamapi.TeamAPI,
|
|
) *BackgroundServiceRegistry {
|
|
return NewBackgroundServiceRegistry(
|
|
httpServer,
|
|
ng,
|
|
cleanup,
|
|
live,
|
|
pushGateway,
|
|
notifications,
|
|
rendering,
|
|
tokenService,
|
|
provisioning,
|
|
alerting,
|
|
grafanaUpdateChecker,
|
|
pluginsUpdateChecker,
|
|
metrics,
|
|
usageStats,
|
|
statsCollector,
|
|
tracing,
|
|
remoteCache,
|
|
secretsService,
|
|
StorageService,
|
|
searchService,
|
|
entityEventsService,
|
|
grpcServerProvider,
|
|
saService,
|
|
authInfoService,
|
|
pluginStore,
|
|
secretMigrationProvider,
|
|
loginAttemptService,
|
|
bundleService,
|
|
publicDashboardsMetric,
|
|
keyRetriever,
|
|
dynamicAngularDetectorsProvider,
|
|
grafanaAPIServer,
|
|
anon,
|
|
)
|
|
}
|
|
|
|
// BackgroundServiceRegistry provides background services.
|
|
type BackgroundServiceRegistry struct {
|
|
Services []registry.BackgroundService
|
|
}
|
|
|
|
func NewBackgroundServiceRegistry(services ...registry.BackgroundService) *BackgroundServiceRegistry {
|
|
return &BackgroundServiceRegistry{services}
|
|
}
|
|
|
|
func (r *BackgroundServiceRegistry) GetServices() []registry.BackgroundService {
|
|
return r.Services
|
|
}
|