MM-22619: check for nil plugins environment (#13901)

* MM-22619: check for nil plugins environment

Check if plugins were disabled before attempting to collect metrics and emit telemetry for same.

Fixes: https://mattermost.atlassian.net/browse/MM-22619

* Update app/diagnostics_test.go
Этот коммит содержится в:
Jesse Hallam
2020-02-15 18:46:26 -04:00
коммит произвёл GitHub
родитель bd487418f7
Коммит 9a51c73f64
3 изменённых файлов: 82 добавлений и 20 удалений

Просмотреть файл

@@ -636,7 +636,7 @@ func (a *App) trackConfig() {
} }
pluginsEnvironment := a.GetPluginsEnvironment() pluginsEnvironment := a.GetPluginsEnvironment()
if pluginsEnvironment != nil {
if plugins, appErr := pluginsEnvironment.Available(); appErr != nil { if plugins, appErr := pluginsEnvironment.Available(); appErr != nil {
mlog.Error("Unable to add plugin versions to diagnostics", mlog.Err(appErr)) mlog.Error("Unable to add plugin versions to diagnostics", mlog.Err(appErr))
} else { } else {
@@ -653,6 +653,7 @@ func (a *App) trackConfig() {
pluginConfigData["version_welcome_bot"] = pluginVersion(plugins, "com.mattermost.welcomebot") pluginConfigData["version_welcome_bot"] = pluginVersion(plugins, "com.mattermost.welcomebot")
pluginConfigData["version_zoom"] = pluginVersion(plugins, "zoom") pluginConfigData["version_zoom"] = pluginVersion(plugins, "zoom")
} }
}
a.SendDiagnostic(TRACK_CONFIG_PLUGIN, pluginConfigData) a.SendDiagnostic(TRACK_CONFIG_PLUGIN, pluginConfigData)

Просмотреть файл

@@ -68,7 +68,9 @@ func TestDiagnostics(t *testing.T) {
t.SkipNow() t.SkipNow()
} }
th := Setup(t) th := SetupWithCustomConfig(t, func(config *model.Config) {
*config.PluginSettings.Enable = false
})
defer th.TearDown() defer th.TearDown()
type payload struct { type payload struct {
@@ -147,6 +149,58 @@ func TestDiagnostics(t *testing.T) {
} }
}) })
// Plugins remain disabled at this point
t.Run("SendDailyDiagnosticsPluginsDisabled", func(t *testing.T) {
th.App.sendDailyDiagnostics(true)
var info []string
// Collect the info sent.
Loop:
for {
select {
case result := <-data:
assertPayload(t, result, "", nil)
info = append(info, result.Batch[0].Event)
case <-time.After(time.Second * 1):
break Loop
}
}
for _, item := range []string{
TRACK_CONFIG_SERVICE,
TRACK_CONFIG_TEAM,
TRACK_CONFIG_SQL,
TRACK_CONFIG_LOG,
TRACK_CONFIG_NOTIFICATION_LOG,
TRACK_CONFIG_FILE,
TRACK_CONFIG_RATE,
TRACK_CONFIG_EMAIL,
TRACK_CONFIG_PRIVACY,
TRACK_CONFIG_OAUTH,
TRACK_CONFIG_LDAP,
TRACK_CONFIG_COMPLIANCE,
TRACK_CONFIG_LOCALIZATION,
TRACK_CONFIG_SAML,
TRACK_CONFIG_PASSWORD,
TRACK_CONFIG_CLUSTER,
TRACK_CONFIG_METRICS,
TRACK_CONFIG_SUPPORT,
TRACK_CONFIG_NATIVEAPP,
TRACK_CONFIG_EXPERIMENTAL,
TRACK_CONFIG_ANALYTICS,
TRACK_CONFIG_PLUGIN,
TRACK_ACTIVITY,
TRACK_SERVER,
TRACK_CONFIG_MESSAGE_EXPORT,
// TRACK_PLUGINS,
} {
require.Contains(t, info, item)
}
})
// Enable plugins for the remainder of the tests.
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true })
t.Run("SendDailyDiagnostics", func(t *testing.T) { t.Run("SendDailyDiagnostics", func(t *testing.T) {
th.App.sendDailyDiagnostics(true) th.App.sendDailyDiagnostics(true)

Просмотреть файл

@@ -33,7 +33,7 @@ type TestHelper struct {
tempWorkspace string tempWorkspace string
} }
func setupTestHelper(enterprise bool, tb testing.TB) *TestHelper { func setupTestHelper(enterprise bool, tb testing.TB, configSet func(*model.Config)) *TestHelper {
store := mainHelper.GetStore() store := mainHelper.GetStore()
store.DropAllTables() store.DropAllTables()
@@ -48,6 +48,9 @@ func setupTestHelper(enterprise bool, tb testing.TB) *TestHelper {
} }
config := memoryStore.Get() config := memoryStore.Get()
if configSet != nil {
configSet(config)
}
*config.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins") *config.PluginSettings.Directory = filepath.Join(tempWorkspace, "plugins")
*config.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp") *config.PluginSettings.ClientDirectory = filepath.Join(tempWorkspace, "webapp")
memoryStore.Set(config) memoryStore.Set(config)
@@ -105,11 +108,15 @@ func setupTestHelper(enterprise bool, tb testing.TB) *TestHelper {
} }
func SetupEnterprise(tb testing.TB) *TestHelper { func SetupEnterprise(tb testing.TB) *TestHelper {
return setupTestHelper(true, tb) return setupTestHelper(true, tb, nil)
} }
func Setup(tb testing.TB) *TestHelper { func Setup(tb testing.TB) *TestHelper {
return setupTestHelper(false, tb) return setupTestHelper(false, tb, nil)
}
func SetupWithCustomConfig(tb testing.TB, configSet func(*model.Config)) *TestHelper {
return setupTestHelper(false, tb, configSet)
} }
func (me *TestHelper) InitBasic() *TestHelper { func (me *TestHelper) InitBasic() *TestHelper {