2021-08-25 15:11:22 +02:00
|
|
|
package backgroundsvcs
|
|
|
|
|
|
|
|
|
|
import (
|
2023-08-03 09:19:01 -04:00
|
|
|
"github.com/grafana/grafana/pkg/api"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
|
|
|
|
"github.com/grafana/grafana/pkg/infra/remotecache"
|
|
|
|
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
2021-09-21 20:50:37 +02:00
|
|
|
uss "github.com/grafana/grafana/pkg/infra/usagestats/service"
|
2022-04-08 12:41:26 +01:00
|
|
|
"github.com/grafana/grafana/pkg/infra/usagestats/statscollector"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/registry"
|
2023-09-25 18:31:58 -04:00
|
|
|
apiregistry "github.com/grafana/grafana/pkg/registry/apis"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/alerting"
|
2023-09-25 16:25:29 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/anonymous/anonimpl"
|
2024-02-01 17:27:30 -05:00
|
|
|
grafanaapiserver "github.com/grafana/grafana/pkg/services/apiserver"
|
2022-11-18 09:56:06 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/auth"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/cleanup"
|
2021-09-01 13:05:15 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/dashboardsnapshots"
|
2022-09-27 00:25:34 +04:00
|
|
|
"github.com/grafana/grafana/pkg/services/grpcserver"
|
2022-03-03 15:05:47 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/guardian"
|
2023-02-08 09:32:59 +01:00
|
|
|
ldapapi "github.com/grafana/grafana/pkg/services/ldap/api"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/live"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/live/pushhttp"
|
2022-11-22 11:37:18 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/loginattempt/loginattemptimpl"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/notifications"
|
2022-03-10 18:38:04 +01:00
|
|
|
plugindashboardsservice "github.com/grafana/grafana/pkg/services/plugindashboards/service"
|
Plugins: Angular detector: Add database cache store for remote patterns (#70693)
* Plugins: Angular detector: Remote patterns fetching
* Renamed PatternType to GCOMPatternType
* Renamed files
* Renamed more files
* Moved files again
* Add type checks, unexport GCOM structs
* Cache failures, update log messages, fix GCOM URL
* Fail silently for unknown pattern types, update docstrings
* Fix tests
* Rename gcomPattern.Value to gcomPattern.Pattern
* Refactoring
* Add FlagPluginsRemoteAngularDetectionPatterns feature flag
* Fix tests
* Re-generate feature flags
* Add TestProvideInspector, renamed TestDefaultStaticDetectorsInspector
* Add TestProvideInspector
* Add TestContainsBytesDetector and TestRegexDetector
* Renamed getter to provider
* More tests
* TestStaticDetectorsProvider, TestSequenceDetectorsProvider
* GCOM tests
* Lint
* Made detector.detect unexported, updated docstrings
* Allow changing grafana.com URL
* Fix API path, add more logs
* Update tryUpdateRemoteDetectors docstring
* Use angulardetector http client
* Return false, nil if module.js does not exist
* Chore: Split angualrdetector into angularinspector and angulardetector packages
Moved files around, changed references and fixed tests:
- Split the old angulardetector package into angular/angulardetector and angular/angularinspector
- angulardetector provides the detection structs/interfaces (Detector, DetectorsProvider...)
- angularinspector provides the actual angular detection service used directly in pluginsintegration
- Exported most of the stuff that was private and now put into angulardetector, as it is not required by angularinspector
* Renamed detector.go -> angulardetector.go and inspector.go -> angularinspector.go
Forgot to rename those two files to match the package's names
* Renamed angularinspector.ProvideInspector to angularinspector.ProvideService
* Renamed "harcoded" to "static" and "remote" to "dynamic"
from PR review, matches the same naming schema used for signing keys fetching
* WIP: Angular: cache patterns in db, moved gcom into pluginsintegration
More similar to signing keys fetching
* Rename package, refactoring
* try to solve circular import
* Fix merge conflict on updated angular patterns
* Fix circular imports
* Fix wire gen
* Add docstrings, refactoring
* Removed angualrdetectorsprovider dependency into angularpatternsstore
* Moved GCOM test files
* Removed GCOM cache
* Renamed Detect to DetectAngular and Detector to AngularDetector
* Fix call to NewGCOMDetectorsProvider in newDynamicInspector
* Removed unused test function newError500GCOMScenario
* Added angularinspector service definition in pluginsintegration
* refactoring
* lint
* Fix angularinspector TestProvideService
* cleanup
* Await initial restore
* Register dynamicAngularDetector background service
* Removed static detectors provider from pluginsintegration
* Add tests for kvstore
* Add more tests
* order imports in dynamic_test.go
* Fix potential panic in dynamic_test
* Add "runs the job periodically" test
* lint
* add timeout to test
* refactoring
* Removed context.Context from DetectorsProvider
* Refactoring, ensure angular dynamic background service is not started if feature flag is off
* Fix deadlock on startup
* Fix angulardetectorsprovider tests
* Revert "Removed context.Context from DetectorsProvider"
This reverts commit 4e8c6dded70844709400fa0ce4ce45e66c8458ca.
* Fix wrong argument number in dynamic_teset
* Standardize gcom http client
* Reduce context timeout for angular inspector in plugins loader
* Simplify initial restore logic
* Fix dynamic detectors provider tests
* Chore: removed angulardetector/provider.go
* Add more tests
* Removed backgroundJob interface, PR review feedback
* Update tests
* PR review feedback: remove ErrNoCachedValue from kv store Get
* Update tests
* PR review feedback: add IsDisabled and remove nop background srevice
* Update tests
* Remove initialRestore channel, use mux instead
* Removed backgroundJobInterval, use package-level variable instead
* Add TestDynamicAngularDetectorsProviderBackgroundService
* Removed timeouts
* pr review feedback: restore from store before returning the service
* Update tests
* Log duration on startup restore and cron run
* Switch cron job start log to debug level
* Do not attempt to restore if disabled
2023-07-06 16:34:27 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/angulardetectorsprovider"
|
2023-04-27 17:54:28 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/keyretriever/dynamic"
|
2024-02-07 15:17:13 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/pluginexternal"
|
2023-09-11 13:59:24 +02:00
|
|
|
pluginStore "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning"
|
2023-04-11 14:36:50 -03:00
|
|
|
publicdashboardsmetric "github.com/grafana/grafana/pkg/services/publicdashboards/metric"
|
2021-08-25 15:11:22 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/rendering"
|
2022-04-27 12:29:39 +04:00
|
|
|
"github.com/grafana/grafana/pkg/services/searchV2"
|
2023-08-03 09:19:01 -04:00
|
|
|
secretsMigrations "github.com/grafana/grafana/pkg/services/secrets/kvstore/migrations"
|
2021-12-27 18:04:47 +01:00
|
|
|
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
2021-11-11 15:10:24 +00:00
|
|
|
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
2022-07-07 14:03:16 +00:00
|
|
|
samanager "github.com/grafana/grafana/pkg/services/serviceaccounts/manager"
|
2023-11-08 10:50:01 +01:00
|
|
|
"github.com/grafana/grafana/pkg/services/ssosettings"
|
2024-01-10 16:01:37 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/ssosettings/ssosettingsimpl"
|
2022-03-17 10:19:23 -07:00
|
|
|
"github.com/grafana/grafana/pkg/services/store"
|
2022-11-30 13:42:42 -08:00
|
|
|
"github.com/grafana/grafana/pkg/services/store/entity"
|
2022-07-07 15:32:18 +04:00
|
|
|
"github.com/grafana/grafana/pkg/services/store/sanitizer"
|
2023-01-04 16:33:18 +00:00
|
|
|
"github.com/grafana/grafana/pkg/services/supportbundles/supportbundlesimpl"
|
2023-10-12 10:10:54 +02:00
|
|
|
"github.com/grafana/grafana/pkg/services/team/teamapi"
|
2021-11-01 09:53:33 +00:00
|
|
|
"github.com/grafana/grafana/pkg/services/updatechecker"
|
2021-08-25 15:11:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func ProvideBackgroundServiceRegistry(
|
2023-10-19 12:03:00 -02:00
|
|
|
httpServer *api.HTTPServer, ng *ngalert.AlertNG, cleanup *cleanup.CleanUpService, live *live.GrafanaLive,
|
2023-08-16 10:46:00 +02:00
|
|
|
pushGateway *pushhttp.Gateway, notifications *notifications.NotificationService, pluginStore *pluginStore.Service,
|
2023-10-03 14:54:20 +02:00
|
|
|
rendering *rendering.RenderingService, tokenService auth.UserTokenBackgroundService, tracing *tracing.TracingService,
|
2022-01-31 16:06:16 +01:00
|
|
|
provisioning *provisioning.ProvisioningServiceImpl, alerting *alerting.AlertEngine, usageStats *uss.UsageStats,
|
2022-04-08 12:41:26 +01:00
|
|
|
statsCollector *statscollector.Service, grafanaUpdateChecker *updatechecker.GrafanaService,
|
|
|
|
|
pluginsUpdateChecker *updatechecker.PluginsService, metrics *metrics.InternalMetricsService,
|
2023-04-13 21:42:24 +04:00
|
|
|
secretsService *secretsManager.SecretsService, remoteCache *remotecache.RemoteCache, StorageService store.StorageService, searchService searchV2.SearchService, entityEventsService store.EntityEventsService,
|
2023-11-21 14:47:23 +01:00
|
|
|
saService *samanager.ServiceAccountsService, grpcServerProvider grpcserver.Provider,
|
|
|
|
|
secretMigrationProvider secretsMigrations.SecretMigrationProvider, loginAttemptService *loginattemptimpl.Service,
|
2023-09-25 18:31:58 -04:00
|
|
|
bundleService *supportbundlesimpl.Service, publicDashboardsMetric *publicdashboardsmetric.Service,
|
|
|
|
|
keyRetriever *dynamic.KeyRetriever, dynamicAngularDetectorsProvider *angulardetectorsprovider.Dynamic,
|
|
|
|
|
grafanaAPIServer grafanaapiserver.Service,
|
2023-12-04 22:26:55 +01:00
|
|
|
anon *anonimpl.AnonDeviceService,
|
2024-01-24 15:39:50 +01:00
|
|
|
ssoSettings *ssosettingsimpl.Service,
|
2024-02-07 15:17:13 +01:00
|
|
|
pluginExternal *pluginexternal.Service,
|
2021-08-25 15:11:22 +02:00
|
|
|
// Need to make sure these are initialized, is there a better place to put them?
|
2022-06-14 13:41:29 -04:00
|
|
|
_ dashboardsnapshots.Service, _ *alerting.AlertNotificationService,
|
2022-03-10 18:38:04 +01:00
|
|
|
_ serviceaccounts.Service, _ *guardian.Provider,
|
2022-07-07 15:32:18 +04:00
|
|
|
_ *plugindashboardsservice.DashboardUpdater, _ *sanitizer.Provider,
|
2023-02-08 09:32:59 +01:00
|
|
|
_ *grpcserver.HealthService, _ entity.EntityStoreServer, _ *grpcserver.ReflectionService, _ *ldapapi.Service,
|
2023-11-08 10:50:01 +01:00
|
|
|
_ *apiregistry.Service, _ auth.IDService, _ *teamapi.TeamAPI, _ ssosettings.Service,
|
2021-08-25 15:11:22 +02:00
|
|
|
) *BackgroundServiceRegistry {
|
|
|
|
|
return NewBackgroundServiceRegistry(
|
2023-08-03 09:19:01 -04:00
|
|
|
httpServer,
|
2021-08-25 15:11:22 +02:00
|
|
|
ng,
|
|
|
|
|
cleanup,
|
|
|
|
|
live,
|
|
|
|
|
pushGateway,
|
|
|
|
|
notifications,
|
|
|
|
|
rendering,
|
|
|
|
|
tokenService,
|
|
|
|
|
provisioning,
|
|
|
|
|
alerting,
|
2022-01-31 16:06:16 +01:00
|
|
|
grafanaUpdateChecker,
|
|
|
|
|
pluginsUpdateChecker,
|
2021-08-25 15:11:22 +02:00
|
|
|
metrics,
|
|
|
|
|
usageStats,
|
2022-04-08 12:41:26 +01:00
|
|
|
statsCollector,
|
2021-08-25 15:11:22 +02:00
|
|
|
tracing,
|
2021-12-27 18:04:47 +01:00
|
|
|
remoteCache,
|
2022-02-10 22:45:00 +04:00
|
|
|
secretsService,
|
2022-03-17 10:19:23 -07:00
|
|
|
StorageService,
|
2022-04-27 12:29:39 +04:00
|
|
|
searchService,
|
|
|
|
|
entityEventsService,
|
2022-09-27 00:25:34 +04:00
|
|
|
grpcServerProvider,
|
2022-07-07 14:03:16 +00:00
|
|
|
saService,
|
2023-08-16 10:46:00 +02:00
|
|
|
pluginStore,
|
2023-08-03 09:19:01 -04:00
|
|
|
secretMigrationProvider,
|
2022-11-22 11:37:18 +01:00
|
|
|
loginAttemptService,
|
2022-12-20 10:13:37 +00:00
|
|
|
bundleService,
|
2023-04-11 14:36:50 -03:00
|
|
|
publicDashboardsMetric,
|
2023-04-27 17:54:28 +02:00
|
|
|
keyRetriever,
|
Plugins: Angular detector: Add database cache store for remote patterns (#70693)
* Plugins: Angular detector: Remote patterns fetching
* Renamed PatternType to GCOMPatternType
* Renamed files
* Renamed more files
* Moved files again
* Add type checks, unexport GCOM structs
* Cache failures, update log messages, fix GCOM URL
* Fail silently for unknown pattern types, update docstrings
* Fix tests
* Rename gcomPattern.Value to gcomPattern.Pattern
* Refactoring
* Add FlagPluginsRemoteAngularDetectionPatterns feature flag
* Fix tests
* Re-generate feature flags
* Add TestProvideInspector, renamed TestDefaultStaticDetectorsInspector
* Add TestProvideInspector
* Add TestContainsBytesDetector and TestRegexDetector
* Renamed getter to provider
* More tests
* TestStaticDetectorsProvider, TestSequenceDetectorsProvider
* GCOM tests
* Lint
* Made detector.detect unexported, updated docstrings
* Allow changing grafana.com URL
* Fix API path, add more logs
* Update tryUpdateRemoteDetectors docstring
* Use angulardetector http client
* Return false, nil if module.js does not exist
* Chore: Split angualrdetector into angularinspector and angulardetector packages
Moved files around, changed references and fixed tests:
- Split the old angulardetector package into angular/angulardetector and angular/angularinspector
- angulardetector provides the detection structs/interfaces (Detector, DetectorsProvider...)
- angularinspector provides the actual angular detection service used directly in pluginsintegration
- Exported most of the stuff that was private and now put into angulardetector, as it is not required by angularinspector
* Renamed detector.go -> angulardetector.go and inspector.go -> angularinspector.go
Forgot to rename those two files to match the package's names
* Renamed angularinspector.ProvideInspector to angularinspector.ProvideService
* Renamed "harcoded" to "static" and "remote" to "dynamic"
from PR review, matches the same naming schema used for signing keys fetching
* WIP: Angular: cache patterns in db, moved gcom into pluginsintegration
More similar to signing keys fetching
* Rename package, refactoring
* try to solve circular import
* Fix merge conflict on updated angular patterns
* Fix circular imports
* Fix wire gen
* Add docstrings, refactoring
* Removed angualrdetectorsprovider dependency into angularpatternsstore
* Moved GCOM test files
* Removed GCOM cache
* Renamed Detect to DetectAngular and Detector to AngularDetector
* Fix call to NewGCOMDetectorsProvider in newDynamicInspector
* Removed unused test function newError500GCOMScenario
* Added angularinspector service definition in pluginsintegration
* refactoring
* lint
* Fix angularinspector TestProvideService
* cleanup
* Await initial restore
* Register dynamicAngularDetector background service
* Removed static detectors provider from pluginsintegration
* Add tests for kvstore
* Add more tests
* order imports in dynamic_test.go
* Fix potential panic in dynamic_test
* Add "runs the job periodically" test
* lint
* add timeout to test
* refactoring
* Removed context.Context from DetectorsProvider
* Refactoring, ensure angular dynamic background service is not started if feature flag is off
* Fix deadlock on startup
* Fix angulardetectorsprovider tests
* Revert "Removed context.Context from DetectorsProvider"
This reverts commit 4e8c6dded70844709400fa0ce4ce45e66c8458ca.
* Fix wrong argument number in dynamic_teset
* Standardize gcom http client
* Reduce context timeout for angular inspector in plugins loader
* Simplify initial restore logic
* Fix dynamic detectors provider tests
* Chore: removed angulardetector/provider.go
* Add more tests
* Removed backgroundJob interface, PR review feedback
* Update tests
* PR review feedback: remove ErrNoCachedValue from kv store Get
* Update tests
* PR review feedback: add IsDisabled and remove nop background srevice
* Update tests
* Remove initialRestore channel, use mux instead
* Removed backgroundJobInterval, use package-level variable instead
* Add TestDynamicAngularDetectorsProviderBackgroundService
* Removed timeouts
* pr review feedback: restore from store before returning the service
* Update tests
* Log duration on startup restore and cron run
* Switch cron job start log to debug level
* Do not attempt to restore if disabled
2023-07-06 16:34:27 +02:00
|
|
|
dynamicAngularDetectorsProvider,
|
2023-09-25 18:31:58 -04:00
|
|
|
grafanaAPIServer,
|
2023-09-25 16:25:29 +02:00
|
|
|
anon,
|
2024-01-10 16:01:37 +02:00
|
|
|
ssoSettings,
|
2024-02-07 15:17:13 +01:00
|
|
|
pluginExternal,
|
2022-04-08 12:41:26 +01:00
|
|
|
)
|
2021-08-25 15:11:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BackgroundServiceRegistry provides background services.
|
|
|
|
|
type BackgroundServiceRegistry struct {
|
2023-08-03 09:19:01 -04:00
|
|
|
Services []registry.BackgroundService
|
2021-08-25 15:11:22 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-03 09:19:01 -04:00
|
|
|
func NewBackgroundServiceRegistry(services ...registry.BackgroundService) *BackgroundServiceRegistry {
|
|
|
|
|
return &BackgroundServiceRegistry{services}
|
2021-08-25 15:11:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *BackgroundServiceRegistry) GetServices() []registry.BackgroundService {
|
2023-08-03 09:19:01 -04:00
|
|
|
return r.Services
|
2021-08-25 15:11:22 +02:00
|
|
|
}
|