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
|
|
|
"errors"
|
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
|
|
|
"time"
|
2021-11-01 09:53:33 +00:00
|
|
|
|
2022-01-14 13:30:39 +01:00
|
|
|
"github.com/grafana/grafana/pkg/infra/metrics"
|
2021-11-01 09:53:33 +00:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2022-09-14 14:35:35 +01:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/config"
|
2023-02-28 15:10:27 +00:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/log"
|
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
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angularinspector"
|
2023-01-27 15:08:17 +01:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader/assetpath"
|
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"
|
2022-09-23 14:27:01 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/process"
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/registry"
|
2021-11-01 09:53:33 +00:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/manager/signature"
|
2023-06-26 16:38:43 +02:00
|
|
|
"github.com/grafana/grafana/pkg/plugins/oauth"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2021-11-01 09:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ plugins.ErrorResolver = (*Loader)(nil)
|
|
|
|
|
|
|
|
|
|
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-07-27 15:29:13 +02:00
|
|
|
|
2023-06-26 16:38:43 +02:00
|
|
|
processManager process.Service
|
|
|
|
|
pluginRegistry registry.Service
|
|
|
|
|
roleRegistry plugins.RoleRegistry
|
|
|
|
|
signatureValidator signature.Validator
|
|
|
|
|
externalServiceRegistry oauth.ExternalServiceRegistry
|
|
|
|
|
assetPath *assetpath.Service
|
|
|
|
|
log log.Logger
|
|
|
|
|
cfg *config.Cfg
|
2023-04-20 10:52:59 +01: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
|
|
|
angularInspector angularinspector.Inspector
|
2023-06-07 11:08:01 +02:00
|
|
|
|
2023-04-20 10:52:59 +01:00
|
|
|
errs map[string]*plugins.SignatureError
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 18:29:12 +02:00
|
|
|
func ProvideService(cfg *config.Cfg, authorizer plugins.PluginLoaderAuthorizer,
|
|
|
|
|
pluginRegistry registry.Service, roleRegistry plugins.RoleRegistry, assetPath *assetpath.Service,
|
2023-07-27 15:29:13 +02:00
|
|
|
angularInspector angularinspector.Inspector, externalServiceRegistry oauth.ExternalServiceRegistry,
|
2023-08-04 11:57:49 +02:00
|
|
|
discovery discovery.Discoverer, bootstrap bootstrap.Bootstrapper, initializer initialization.Initializer,
|
|
|
|
|
termination termination.Terminator) *Loader {
|
2023-08-02 18:29:12 +02:00
|
|
|
return New(cfg, authorizer, pluginRegistry, process.NewManager(pluginRegistry), roleRegistry, assetPath,
|
2023-08-04 11:57:49 +02:00
|
|
|
angularInspector, externalServiceRegistry, discovery, bootstrap, initializer, termination)
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-02 18:29:12 +02:00
|
|
|
func New(cfg *config.Cfg, authorizer plugins.PluginLoaderAuthorizer, pluginRegistry registry.Service,
|
2023-07-27 15:29:13 +02:00
|
|
|
processManager process.Service, roleRegistry plugins.RoleRegistry, assetPath *assetpath.Service,
|
|
|
|
|
angularInspector angularinspector.Inspector, externalServiceRegistry oauth.ExternalServiceRegistry,
|
2023-08-04 11:57:49 +02:00
|
|
|
discovery discovery.Discoverer, bootstrap bootstrap.Bootstrapper, initializer initialization.Initializer,
|
|
|
|
|
termination termination.Terminator) *Loader {
|
2021-11-01 09:53:33 +00:00
|
|
|
return &Loader{
|
2023-06-26 16:38:43 +02:00
|
|
|
pluginRegistry: pluginRegistry,
|
|
|
|
|
signatureValidator: signature.NewValidator(authorizer),
|
|
|
|
|
processManager: processManager,
|
|
|
|
|
errs: make(map[string]*plugins.SignatureError),
|
|
|
|
|
log: log.New("plugin.loader"),
|
|
|
|
|
roleRegistry: roleRegistry,
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
assetPath: assetPath,
|
|
|
|
|
angularInspector: angularInspector,
|
|
|
|
|
externalServiceRegistry: externalServiceRegistry,
|
2023-07-27 15:29:13 +02:00
|
|
|
discovery: discovery,
|
|
|
|
|
bootstrap: bootstrap,
|
2023-08-02 18:29:12 +02:00
|
|
|
initializer: initializer,
|
2023-08-04 11:57:49 +02:00
|
|
|
termination: termination,
|
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
|
|
|
// <DISCOVERY STAGE>
|
|
|
|
|
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
|
|
|
// </DISCOVERY STAGE>
|
2021-11-01 09:53:33 +00:00
|
|
|
|
2023-07-27 15:29:13 +02:00
|
|
|
// <BOOTSTRAP STAGE>
|
|
|
|
|
bootstrappedPlugins, err := l.bootstrap.Bootstrap(ctx, src, discoveredPlugins)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
2023-07-27 15:29:13 +02:00
|
|
|
// </BOOTSTRAP STAGE>
|
2021-11-01 09:53:33 +00:00
|
|
|
|
2023-07-27 15:29:13 +02:00
|
|
|
// <VERIFICATION STAGE>
|
|
|
|
|
verifiedPlugins := make([]*plugins.Plugin, 0, len(bootstrappedPlugins))
|
|
|
|
|
for _, plugin := range bootstrappedPlugins {
|
2021-11-01 09:53:33 +00:00
|
|
|
signingError := l.signatureValidator.Validate(plugin)
|
|
|
|
|
if signingError != nil {
|
2021-11-23 16:09:52 +00:00
|
|
|
l.log.Warn("Skipping loading plugin due to problem with signature",
|
2021-11-01 09:53:33 +00:00
|
|
|
"pluginID", plugin.ID, "status", signingError.SignatureStatus)
|
|
|
|
|
plugin.SignatureError = signingError
|
|
|
|
|
l.errs[plugin.ID] = signingError
|
|
|
|
|
// skip plugin so it will not be loaded any further
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clear plugin error if a pre-existing error has since been resolved
|
|
|
|
|
delete(l.errs, plugin.ID)
|
|
|
|
|
|
2023-01-27 15:08:17 +01:00
|
|
|
// verify module.js exists for SystemJS to load.
|
|
|
|
|
// CDN plugins can be loaded with plugin.json only, so do not warn for those.
|
2021-11-01 09:53:33 +00:00
|
|
|
if !plugin.IsRenderer() && !plugin.IsCorePlugin() {
|
2023-04-13 10:48:15 +02:00
|
|
|
f, err := plugin.FS.Open("module.js")
|
2023-03-07 15:47:02 +00:00
|
|
|
if err != nil {
|
2023-04-04 16:01:49 +01:00
|
|
|
if errors.Is(err, plugins.ErrFileNotExist) {
|
2023-03-07 15:47:02 +00:00
|
|
|
l.log.Warn("Plugin missing module.js", "pluginID", plugin.ID,
|
|
|
|
|
"warning", "Missing module.js, If you loaded this plugin from git, make sure to compile it.")
|
|
|
|
|
}
|
2023-04-13 10:48:15 +02:00
|
|
|
} else if f != nil {
|
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
|
l.log.Warn("Could not close module.js", "pluginID", plugin.ID, "err", 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
|
|
|
// detect angular for external plugins
|
2023-07-27 15:29:13 +02:00
|
|
|
if plugin.IsExternalPlugin() {
|
2023-06-07 11:08:01 +02:00
|
|
|
var err error
|
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
|
|
|
|
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
|
|
|
cctx, canc := context.WithTimeout(ctx, time.Second*10)
|
2023-07-27 15:29:13 +02:00
|
|
|
plugin.AngularDetected, err = l.angularInspector.Inspect(cctx, plugin)
|
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
|
|
|
canc()
|
|
|
|
|
|
2023-06-07 11:08:01 +02:00
|
|
|
if err != nil {
|
2023-07-27 15:29:13 +02:00
|
|
|
l.log.Warn("Could not inspect plugin for angular", "pluginID", plugin.ID, "err", err)
|
2023-06-07 11:08:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do not initialize plugins if they're using Angular and Angular support is disabled
|
2023-07-27 15:29:13 +02:00
|
|
|
if plugin.AngularDetected && !l.cfg.AngularSupportEnabled {
|
|
|
|
|
l.log.Error("Refusing to initialize plugin because it's using Angular, which has been disabled", "pluginID", plugin.ID)
|
2023-06-07 11:08:01 +02:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 15:29:13 +02:00
|
|
|
verifiedPlugins = append(verifiedPlugins, plugin)
|
|
|
|
|
}
|
|
|
|
|
// </VERIFICATION STAGE>
|
2023-06-26 16:38:43 +02:00
|
|
|
|
2023-07-27 15:29:13 +02:00
|
|
|
// <INITIALIZATION STAGE>
|
2023-08-02 18:29:12 +02:00
|
|
|
initializedPlugins, err := l.initializer.Initialize(ctx, verifiedPlugins)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
2023-07-27 15:29:13 +02:00
|
|
|
// </INITIALIZATION STAGE>
|
2021-11-01 09:53:33 +00:00
|
|
|
|
2023-07-27 15:29:13 +02:00
|
|
|
// <POST-INITIALIZATION STAGE>
|
2023-04-12 11:34:16 +02:00
|
|
|
for _, p := range initializedPlugins {
|
2023-07-27 15:29:13 +02:00
|
|
|
if err = l.processManager.Start(ctx, p.ID); err != nil {
|
2022-09-23 14:27:01 +02:00
|
|
|
l.log.Error("Could not start plugin", "pluginId", p.ID, "err", err)
|
2023-07-27 15:29:13 +02:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.ExternalServiceRegistration != nil && l.cfg.Features.IsEnabled(featuremgmt.FlagExternalServiceAuth) {
|
|
|
|
|
s, err := l.externalServiceRegistry.RegisterExternalService(ctx, p.ID, p.ExternalServiceRegistration)
|
|
|
|
|
if err != nil {
|
|
|
|
|
l.log.Error("Could not register an external service. Initialization skipped", "pluginID", p.ID, "err", err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
p.ExternalService = s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err = l.roleRegistry.DeclarePluginRoles(ctx, p.ID, p.Name, p.Roles); err != nil {
|
|
|
|
|
l.log.Warn("Declare plugin roles failed.", "pluginID", p.ID, "err", err)
|
2022-09-23 14:27:01 +02:00
|
|
|
}
|
2023-04-06 11:50:50 +01:00
|
|
|
|
|
|
|
|
if !p.IsCorePlugin() && !p.IsBundledPlugin() {
|
|
|
|
|
metrics.SetPluginBuildInformation(p.ID, string(p.Type), p.Info.Version, string(p.Signature))
|
|
|
|
|
}
|
2022-09-23 14:27:01 +02:00
|
|
|
}
|
2023-07-27 15:29:13 +02:00
|
|
|
// </POST-INITIALIZATION STAGE>
|
2022-09-23 14:27:01 +02:00
|
|
|
|
2023-04-12 11:34:16 +02:00
|
|
|
return initializedPlugins, nil
|
2021-11-01 09:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-23 14:27:01 +02:00
|
|
|
func (l *Loader) Unload(ctx context.Context, pluginID string) error {
|
2023-08-04 11:57:49 +02:00
|
|
|
return l.termination.Terminate(ctx, pluginID)
|
2022-09-23 14:27:01 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 09:53:33 +00:00
|
|
|
func (l *Loader) PluginErrors() []*plugins.Error {
|
2023-06-07 17:22:43 +02:00
|
|
|
errs := make([]*plugins.Error, 0, len(l.errs))
|
2021-11-01 09:53:33 +00:00
|
|
|
for _, err := range l.errs {
|
|
|
|
|
errs = append(errs, &plugins.Error{
|
|
|
|
|
PluginID: err.PluginID,
|
|
|
|
|
ErrorCode: err.AsErrorCode(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errs
|
|
|
|
|
}
|