Removed Elasticsearch and Opensearch channel index schedma check (#30102)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b65771a31
Коммит
35e776d805
@@ -1,153 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
)
|
||||
|
||||
func (a *App) initElasticsearchChannelIndexCheck() {
|
||||
// the logic of when to perform the check has been derived from platform/searchengine.StartSearchEngine()
|
||||
// Wherever we're starting the engine, we're checking the index mapping here.
|
||||
|
||||
a.Log().Debug("initElasticsearchChannelIndexCheck: calling elasticsearchChannelIndexCheckWithRetry before setting up config and license change listeners...")
|
||||
a.elasticsearchChannelIndexCheckWithRetry()
|
||||
|
||||
a.AddConfigListener(func(oldConfig, newConfig *model.Config) {
|
||||
if a.SearchEngine().ElasticsearchEngine == nil {
|
||||
return
|
||||
}
|
||||
|
||||
oldESConfig := oldConfig.ElasticsearchSettings
|
||||
newESConfig := newConfig.ElasticsearchSettings
|
||||
|
||||
// if indexing is turned on, check.
|
||||
if !*oldESConfig.EnableIndexing && *newESConfig.EnableIndexing {
|
||||
a.Log().Debug("initElasticsearchChannelIndexCheck: calling elasticsearchChannelIndexCheckWithRetry from config change listener as ES indexing was turned from 'off' to 'on'")
|
||||
a.elasticsearchChannelIndexCheckWithRetry()
|
||||
} else if *newESConfig.EnableIndexing && (*oldESConfig.Password != *newESConfig.Password || *oldESConfig.Username != *newESConfig.Username || *oldESConfig.ConnectionURL != *newESConfig.ConnectionURL || *oldESConfig.Sniff != *newESConfig.Sniff) {
|
||||
// ES client reconnects if credentials or address changes
|
||||
a.Log().Debug("initElasticsearchChannelIndexCheck: calling elasticsearchChannelIndexCheckWithRetry from config change listener one of the Elasticsearch config param changed")
|
||||
a.elasticsearchChannelIndexCheckWithRetry()
|
||||
}
|
||||
})
|
||||
|
||||
a.AddLicenseListener(func(oldLicense, newLicense *model.License) {
|
||||
if a.SearchEngine() == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// if a license was added, and it has ES enabled-
|
||||
if oldLicense == nil && newLicense != nil {
|
||||
if a.SearchEngine().ElasticsearchEngine != nil {
|
||||
a.Log().Debug("initElasticsearchChannelIndexCheck: calling elasticsearchChannelIndexCheckWithRetry from license change listener")
|
||||
a.elasticsearchChannelIndexCheckWithRetry()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (a *App) elasticsearchChannelIndexCheckWithRetry() {
|
||||
// this is being done async to not block license application and config
|
||||
// processes as the listeners for those are called synchronously.
|
||||
go func() {
|
||||
// using progressive retry because ES client may take some time to connect and be ready.
|
||||
_ = utils.LongProgressiveRetry(func() error {
|
||||
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: attempting to check channel index state...")
|
||||
|
||||
if !*a.Config().ElasticsearchSettings.EnableIndexing {
|
||||
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: skipping because elasticsearch indexing is disabled")
|
||||
return nil
|
||||
}
|
||||
|
||||
elastic := a.SearchEngine().ElasticsearchEngine
|
||||
if elastic == nil {
|
||||
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: skipping because elastic engine is nil")
|
||||
return errors.New("retry")
|
||||
}
|
||||
|
||||
if !elastic.IsActive() {
|
||||
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: skipping because elastic.IsActive is false")
|
||||
return errors.New("retry")
|
||||
}
|
||||
|
||||
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: checking channel index state...")
|
||||
a.elasticsearchChannelIndexCheck()
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
func (a *App) elasticsearchChannelIndexCheck() {
|
||||
a.Log().Debug("elasticsearchChannelIndexCheck: checking if there is a need to notify the admins...")
|
||||
if needNotify := a.elasticChannelsIndexNeedNotifyAdmins(); !needNotify {
|
||||
a.Log().Debug("elasticsearchChannelIndexCheck: index is verified, no need to notify admins.")
|
||||
return
|
||||
}
|
||||
|
||||
a.Log().Debug("elasticsearchChannelIndexCheck: index is not verified, need to notify admins.")
|
||||
|
||||
// notify all system admins
|
||||
systemBot, appErr := a.GetSystemBot(request.EmptyContext(a.Log()))
|
||||
if appErr != nil {
|
||||
a.Log().Error("elasticsearchChannelIndexCheck: couldn't get system bot", mlog.Err(appErr))
|
||||
return
|
||||
}
|
||||
|
||||
sysAdmins, appErr := a.getAllSystemAdmins()
|
||||
if appErr != nil {
|
||||
a.Log().Error("elasticsearchChannelIndexCheck: error occurred fetching all system admins", mlog.Err(appErr))
|
||||
}
|
||||
|
||||
elasticsearchSettingsSectionLink, err := url.JoinPath(*a.Config().ServiceSettings.SiteURL, "admin_console/environment/elasticsearch")
|
||||
if err != nil {
|
||||
a.Log().Error("elasticsearchChannelIndexCheck: error occurred constructing Elasticsearch system console section path")
|
||||
return
|
||||
}
|
||||
|
||||
// TODO include a link to changelog
|
||||
postMessage := i18n.T("app.channel.elasticsearch_channel_index.notify_admin.message", map[string]any{"ElasticsearchSection": elasticsearchSettingsSectionLink})
|
||||
|
||||
for _, sysAdmin := range sysAdmins {
|
||||
var channel *model.Channel
|
||||
channel, appErr = a.GetOrCreateDirectChannel(request.EmptyContext(a.Log()), sysAdmin.Id, systemBot.UserId)
|
||||
if appErr != nil {
|
||||
a.Log().Error("elasticsearchChannelIndexCheck: error occurred ensuring DM channel between system bot and sys admin", mlog.Err(appErr))
|
||||
continue
|
||||
}
|
||||
|
||||
post := &model.Post{
|
||||
Message: postMessage,
|
||||
UserId: systemBot.UserId,
|
||||
ChannelId: channel.Id,
|
||||
}
|
||||
_, appErr = a.CreatePost(request.EmptyContext(a.Log()), post, channel, model.CreatePostFlags{TriggerWebhooks: true})
|
||||
if appErr != nil {
|
||||
a.Log().Error("elasticsearchChannelIndexCheck: error occurred creating post", mlog.Err(appErr))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) elasticChannelsIndexNeedNotifyAdmins() bool {
|
||||
elastic := a.SearchEngine().ElasticsearchEngine
|
||||
if elastic == nil {
|
||||
a.Log().Debug("elasticChannelsIndexNeedNotifyAdmins: skipping because elastic engine is nil")
|
||||
return false
|
||||
}
|
||||
|
||||
if elastic.IsChannelsIndexVerified() {
|
||||
a.Log().Debug("elasticChannelsIndexNeedNotifyAdmins: skipping because channels index is verified")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -502,8 +502,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
}
|
||||
})
|
||||
|
||||
app.initElasticsearchChannelIndexCheck()
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2922,13 +2922,3 @@ func (a *App) UserIsFirstAdmin(rctx request.CTX, user *model.User) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *App) getAllSystemAdmins() ([]*model.User, *model.AppError) {
|
||||
userOptions := &model.UserGetOptions{
|
||||
Page: 0,
|
||||
PerPage: 500,
|
||||
Role: model.SystemAdminRoleId,
|
||||
Inactive: false,
|
||||
}
|
||||
return a.GetUsersFromProfiles(userOptions)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user