diff --git a/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic.go b/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic.go index 5a4d37b97d5..bad2414c9bc 100644 --- a/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic.go +++ b/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic.go @@ -14,6 +14,7 @@ import ( "github.com/grafana/grafana/pkg/plugins/log" "github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector" + "github.com/grafana/grafana/pkg/registry" "github.com/grafana/grafana/pkg/services/pluginsintegration/angularpatternsstore" "github.com/grafana/grafana/pkg/setting" ) @@ -35,6 +36,7 @@ type Dynamic struct { httpClient http.Client baseURL string + disabled bool // store is the underlying angular patterns store used as a cache. store angularpatternsstore.Service @@ -64,6 +66,9 @@ func ProvideDynamic(cfg *setting.Cfg, store angularpatternsstore.Service) (*Dyna httpClient: makeHttpClient(), baseURL: cfg.GrafanaComAPIURL, backgroundJobInterval: backgroundJobInterval, + // Disable the background service if the user has opted out of plugin updates. + // (useful for air-gapped installations) + disabled: !cfg.CheckForPluginUpdates, } d.log.Debug("Providing dynamic angular detection patterns", "baseURL", d.baseURL, "interval", d.backgroundJobInterval) @@ -296,6 +301,11 @@ func (d *Dynamic) Run(ctx context.Context) error { } } +// IsDisabled returns whether the dynamic detectors provider background service is disabled. +func (d *Dynamic) IsDisabled() bool { + return d.disabled +} + // ProvideDetectors returns the cached detectors. It returns an empty slice if there's no value. func (d *Dynamic) ProvideDetectors(_ context.Context) []angulardetector.AngularDetector { d.mux.RLock() @@ -323,3 +333,10 @@ func makeHttpClient() http.Client { Transport: tr, } } + +// static checks + +var ( + _ registry.BackgroundService = (*Dynamic)(nil) + _ registry.CanBeDisabled = (*Dynamic)(nil) +) diff --git a/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic_test.go b/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic_test.go index 0550f9c4a19..b5c01e5ec23 100644 --- a/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic_test.go +++ b/pkg/services/pluginsintegration/angulardetectorsprovider/dynamic_test.go @@ -421,6 +421,24 @@ func TestDynamicAngularDetectorsProviderBackgroundService(t *testing.T) { require.True(t, jobCalls.calledX(tcRuns), "should have the correct number of job calls") require.True(t, gcom.httpCalls.calledX(tcRuns), "should have the correct number of gcom api calls") }) + + t.Run("IsDisabled", func(t *testing.T) { + for _, tc := range []struct { + name string + checkForPluginUpdates bool + expIsDisabled bool + }{ + {name: "true", checkForPluginUpdates: true, expIsDisabled: false}, + {name: "false", checkForPluginUpdates: false, expIsDisabled: true}, + } { + t.Run(tc.name, func(t *testing.T) { + cfg := setting.NewCfg() + cfg.CheckForPluginUpdates = tc.checkForPluginUpdates + svc := provideDynamic(t, srv.URL, provideDynamicOpts{cfg: cfg}) + require.Equal(t, tc.expIsDisabled, svc.IsDisabled(), "IsDisabled should return correct value") + }) + } + }) }) }