Plugins: Removed feature toggle pluginsDynamicAngularDetectionPatterns (#85956)

* Plugins: Removed feature toggle pluginsDynamicAngularDetectionPatterns

* re-generate feature toggles
This commit is contained in:
Giuseppe Guerra
2024-04-15 10:37:28 +02:00
committed by GitHub
parent 41e4b95b51
commit eec9d3dbc4
10 changed files with 58 additions and 128 deletions
@@ -14,7 +14,6 @@ import (
"github.com/grafana/grafana/pkg/plugins/log"
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/angularpatternsstore"
"github.com/grafana/grafana/pkg/setting"
)
@@ -31,10 +30,8 @@ var (
// Dynamic is an angulardetector.DetectorsProvider that calls GCOM to get Angular detection patterns,
// converts them to detectors and caches them for all future calls.
// It also provides a background service that will periodically refresh the patterns from GCOM.
// If the feature flag FlagPluginsDynamicAngularDetectionPatterns is disabled, the background service is disabled.
type Dynamic struct {
log log.Logger
features featuremgmt.FeatureToggles
log log.Logger
httpClient http.Client
baseURL string
@@ -53,7 +50,7 @@ type Dynamic struct {
backgroundJobInterval time.Duration
}
func ProvideDynamic(cfg *setting.Cfg, store angularpatternsstore.Service, features featuremgmt.FeatureToggles) (*Dynamic, error) {
func ProvideDynamic(cfg *setting.Cfg, store angularpatternsstore.Service) (*Dynamic, error) {
backgroundJobInterval := backgroundJobIntervalOnPrem
if cfg.StackID != "" {
// Use a shorter interval for cloud.
@@ -63,16 +60,11 @@ func ProvideDynamic(cfg *setting.Cfg, store angularpatternsstore.Service, featur
d := &Dynamic{
log: log.New("plugin.angulardetectorsprovider.dynamic"),
features: features,
store: store,
httpClient: makeHttpClient(),
baseURL: cfg.GrafanaComURL,
backgroundJobInterval: backgroundJobInterval,
}
if d.IsDisabled() {
// Do not attempt to restore if the background service is disabled (no feature flag)
return d, nil
}
d.log.Debug("Providing dynamic angular detection patterns", "baseURL", d.baseURL, "interval", d.backgroundJobInterval)
// Perform the initial restore from db
@@ -233,11 +225,6 @@ func (d *Dynamic) setDetectorsFromCache(ctx context.Context) error {
return nil
}
// IsDisabled returns true if FlagPluginsDynamicAngularDetectionPatterns is not enabled.
func (d *Dynamic) IsDisabled() bool {
return !d.features.IsEnabledGlobally(featuremgmt.FlagPluginsDynamicAngularDetectionPatterns)
}
// randomSkew returns a random time.Duration between 0 and maxSkew.
// This can be added to d.backgroundJobInterval to skew it by a random amount.
func (d *Dynamic) randomSkew(maxSkew time.Duration) time.Duration {
@@ -15,7 +15,6 @@ import (
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/angularpatternsstore"
"github.com/grafana/grafana/pkg/setting"
)
@@ -343,18 +342,6 @@ func TestDynamicAngularDetectorsProviderBackgroundService(t *testing.T) {
backgroundJobIntervalOnPrem = oldBackgroundJobInterval
})
t.Run("is disabled if feature flag is not present", func(t *testing.T) {
svc := provideDynamic(t, srv.URL)
svc.features = featuremgmt.WithFeatures()
require.True(t, svc.IsDisabled(), "background service should be disabled")
})
t.Run("is enabled if feature flag is present", func(t *testing.T) {
svc := provideDynamic(t, srv.URL)
svc.features = featuremgmt.WithFeatures(featuremgmt.FlagPluginsDynamicAngularDetectionPatterns)
require.False(t, svc.IsDisabled(), "background service should be enabled")
})
t.Run("fetches value from gcom on start if too much time has passed", func(t *testing.T) {
gcomCallback := make(chan struct{})
gcom := newDefaultGCOMScenario(func(_ http.ResponseWriter, _ *http.Request) {
@@ -594,11 +581,7 @@ func provideDynamic(t *testing.T, gcomURL string, opts ...provideDynamicOpts) *D
opt.cfg = setting.NewCfg()
}
opt.cfg.GrafanaComURL = gcomURL
d, err := ProvideDynamic(
opt.cfg,
opt.store,
featuremgmt.WithFeatures(featuremgmt.FlagPluginsDynamicAngularDetectionPatterns),
)
d, err := ProvideDynamic(opt.cfg, opt.store)
require.NoError(t, err)
return d
}
@@ -3,7 +3,6 @@ package angularinspector
import (
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector"
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angularinspector"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/angulardetectorsprovider"
)
@@ -11,17 +10,13 @@ type Service struct {
angularinspector.Inspector
}
func ProvideService(features featuremgmt.FeatureToggles, dynamic *angulardetectorsprovider.Dynamic) (*Service, error) {
var detectorsProvider angulardetector.DetectorsProvider
var err error
static := angularinspector.NewDefaultStaticDetectorsProvider()
if features.IsEnabledGlobally(featuremgmt.FlagPluginsDynamicAngularDetectionPatterns) {
detectorsProvider = angulardetector.SequenceDetectorsProvider{dynamic, static}
} else {
detectorsProvider = static
}
if err != nil {
return nil, err
}
return &Service{Inspector: angularinspector.NewPatternListInspector(detectorsProvider)}, nil
func ProvideService(dynamic *angulardetectorsprovider.Dynamic) (*Service, error) {
return &Service{
Inspector: angularinspector.NewPatternListInspector(
angulardetector.SequenceDetectorsProvider{
dynamic,
angularinspector.NewDefaultStaticDetectorsProvider(),
},
),
}, nil
}
@@ -9,40 +9,19 @@ import (
"github.com/grafana/grafana/pkg/infra/kvstore"
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector"
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angularinspector"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/pluginsintegration/angulardetectorsprovider"
"github.com/grafana/grafana/pkg/services/pluginsintegration/angularpatternsstore"
"github.com/grafana/grafana/pkg/setting"
)
func TestProvideService(t *testing.T) {
t.Run("uses hardcoded inspector if feature flag is not present", func(t *testing.T) {
features := featuremgmt.WithFeatures()
t.Run("uses dynamic inspector with hardcoded fallback", func(t *testing.T) {
dynamic, err := angulardetectorsprovider.ProvideDynamic(
setting.NewCfg(),
angularpatternsstore.ProvideService(kvstore.NewFakeKVStore()),
features,
)
require.NoError(t, err)
inspector, err := ProvideService(features, dynamic)
require.NoError(t, err)
require.IsType(t, inspector.Inspector, &angularinspector.PatternsListInspector{})
patternsListInspector := inspector.Inspector.(*angularinspector.PatternsListInspector)
detectors := patternsListInspector.DetectorsProvider.ProvideDetectors(context.Background())
require.NotEmpty(t, detectors, "provided detectors should not be empty")
})
t.Run("uses dynamic inspector with hardcoded fallback if feature flag is present", func(t *testing.T) {
features := featuremgmt.WithFeatures(
featuremgmt.FlagPluginsDynamicAngularDetectionPatterns,
)
dynamic, err := angulardetectorsprovider.ProvideDynamic(
setting.NewCfg(),
angularpatternsstore.ProvideService(kvstore.NewFakeKVStore()),
features,
)
require.NoError(t, err)
inspector, err := ProvideService(features, dynamic)
inspector, err := ProvideService(dynamic)
require.NoError(t, err)
require.IsType(t, inspector.Inspector, &angularinspector.PatternsListInspector{})
require.IsType(t, inspector.Inspector.(*angularinspector.PatternsListInspector).DetectorsProvider, angulardetector.SequenceDetectorsProvider{})