2021-11-01 09:53:33 +00:00
|
|
|
package loader
|
|
|
|
|
|
|
|
|
|
import (
|
2022-01-14 13:30:39 +01:00
|
|
|
"context"
|
2021-11-01 09:53:33 +00:00
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2023-02-28 15:10:27 +00:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/log"
|
2023-07-27 15:29:13 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/bootstrap"
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/discovery"
|
2023-08-02 18:29:12 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/initialization"
|
2023-08-04 11:57:49 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/termination"
|
2023-08-09 18:25:28 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/pipeline/validation"
|
2021-11-01 09:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Loader struct {
|
2023-08-02 18:29:12 +02:00
|
|
|
discovery discovery.Discoverer
|
|
|
|
|
bootstrap bootstrap.Bootstrapper
|
|
|
|
|
initializer initialization.Initializer
|
2023-08-04 11:57:49 +02:00
|
|
|
termination termination.Terminator
|
2023-08-09 18:25:28 +02:00
|
|
|
validation validation.Validator
|
|
|
|
|
log log.Logger
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-10 10:32:12 +02:00
|
|
|
func New(discovery discovery.Discoverer, bootstrap bootstrap.Bootstrapper, validation validation.Validator,
|
2023-08-09 18:25:28 +02:00
|
|
|
initializer initialization.Initializer, termination termination.Terminator) *Loader {
|
2021-11-01 09:53:33 +00:00
|
|
|
return &Loader{
|
2023-08-09 18:25:28 +02:00
|
|
|
discovery: discovery,
|
|
|
|
|
bootstrap: bootstrap,
|
|
|
|
|
validation: validation,
|
|
|
|
|
initializer: initializer,
|
|
|
|
|
termination: termination,
|
|
|
|
|
log: log.New("plugin.loader"),
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-20 13:35:49 +00:00
|
|
|
func (l *Loader) Load(ctx context.Context, src plugins.PluginSource) ([]*plugins.Plugin, error) {
|
2023-07-27 15:29:13 +02:00
|
|
|
discoveredPlugins, err := l.discovery.Discover(ctx, src)
|
2021-11-01 09:53:33 +00:00
|
|
|
if err != nil {
|
2022-01-31 14:07:10 +01:00
|
|
|
return nil, err
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 15:29:13 +02:00
|
|
|
bootstrappedPlugins, err := l.bootstrap.Bootstrap(ctx, src, discoveredPlugins)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
Plugins: Angular detector: Remote patterns fetching (#69843)
* 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
* Fix merge conflict on updated angular patterns
* 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
* Moved dynamic inspector into pluginsintegration
* Move gcom angulardetectorsprovider into pluginsintegration
* Log errUnknownPatternType at debug level
* re-generate feature flags
* fix error log
2023-06-26 15:33:21 +02:00
|
|
|
|
2023-08-10 14:46:38 +02:00
|
|
|
validatedPlugins, err := l.validation.Validate(ctx, bootstrappedPlugins)
|
2023-08-09 18:25:28 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2023-07-27 15:29:13 +02:00
|
|
|
}
|
2023-06-26 16:38:43 +02:00
|
|
|
|
2023-08-10 14:46:38 +02:00
|
|
|
initializedPlugins, err := l.initializer.Initialize(ctx, validatedPlugins)
|
2023-08-02 18:29:12 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-12 11:34:16 +02:00
|
|
|
return initializedPlugins, nil
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-16 15:44:20 +02:00
|
|
|
func (l *Loader) Unload(ctx context.Context, p *plugins.Plugin) (*plugins.Plugin, error) {
|
|
|
|
|
return l.termination.Terminate(ctx, p)
|
2022-09-23 14:27:01 +02:00
|
|
|
}
|