Added a bunch of debugging logs for Elasticsearch index check (#27678)

* Added a bunch of debugging logs for Elasticsearch index check

* Update server/channels/app/elasticsearch.go

---------

Co-authored-by: Harrison Healey <harrisonmhealey@gmail.com>
Этот коммит содержится в:
Harshil Sharma
2024-07-17 13:37:34 +05:30
коммит произвёл GitHub
родитель d71e5e4f4e
Коммит b25820b5c5

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

@@ -18,6 +18,7 @@ func (a *App) initElasticsearchChannelIndexCheck() {
// the logic of when to perform the check has been derived from platform/searchengine.StartSearchEngine() // 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. // 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.elasticsearchChannelIndexCheckWithRetry()
a.AddConfigListener(func(oldConfig, newConfig *model.Config) { a.AddConfigListener(func(oldConfig, newConfig *model.Config) {
@@ -30,9 +31,11 @@ func (a *App) initElasticsearchChannelIndexCheck() {
// if indexing is turned on, check. // if indexing is turned on, check.
if !*oldESConfig.EnableIndexing && *newESConfig.EnableIndexing { 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() a.elasticsearchChannelIndexCheckWithRetry()
} else if *newESConfig.EnableIndexing && (*oldESConfig.Password != *newESConfig.Password || *oldESConfig.Username != *newESConfig.Username || *oldESConfig.ConnectionURL != *newESConfig.ConnectionURL || *oldESConfig.Sniff != *newESConfig.Sniff) { } 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 // 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.elasticsearchChannelIndexCheckWithRetry()
} }
}) })
@@ -45,6 +48,7 @@ func (a *App) initElasticsearchChannelIndexCheck() {
// if a license was added, and it has ES enabled- // if a license was added, and it has ES enabled-
if oldLicense == nil && newLicense != nil { if oldLicense == nil && newLicense != nil {
if a.SearchEngine().ElasticsearchEngine != nil { if a.SearchEngine().ElasticsearchEngine != nil {
a.Log().Debug("initElasticsearchChannelIndexCheck: calling elasticsearchChannelIndexCheckWithRetry from license change listener")
a.elasticsearchChannelIndexCheckWithRetry() a.elasticsearchChannelIndexCheckWithRetry()
} }
} }
@@ -57,6 +61,8 @@ func (a *App) elasticsearchChannelIndexCheckWithRetry() {
go func() { go func() {
// using progressive retry because ES client may take some time to connect and be ready. // using progressive retry because ES client may take some time to connect and be ready.
_ = utils.LongProgressiveRetry(func() error { _ = utils.LongProgressiveRetry(func() error {
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: attempting to check channel index state...")
if !*a.Config().ElasticsearchSettings.EnableIndexing { if !*a.Config().ElasticsearchSettings.EnableIndexing {
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: skipping because elasticsearch indexing is disabled") a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: skipping because elasticsearch indexing is disabled")
return nil return nil
@@ -73,6 +79,7 @@ func (a *App) elasticsearchChannelIndexCheckWithRetry() {
return errors.New("retry") return errors.New("retry")
} }
a.Log().Debug("elasticsearchChannelIndexCheckWithRetry: checking channel index state...")
a.elasticsearchChannelIndexCheck() a.elasticsearchChannelIndexCheck()
return nil return nil
}) })
@@ -80,10 +87,14 @@ func (a *App) elasticsearchChannelIndexCheckWithRetry() {
} }
func (a *App) elasticsearchChannelIndexCheck() { func (a *App) elasticsearchChannelIndexCheck() {
a.Log().Debug("elasticsearchChannelIndexCheck: checking if there is a need to notify the admins...")
if needNotify := a.elasticChannelsIndexNeedNotifyAdmins(); !needNotify { if needNotify := a.elasticChannelsIndexNeedNotifyAdmins(); !needNotify {
a.Log().Debug("elasticsearchChannelIndexCheck: index is verified, no need to notify admins.")
return return
} }
a.Log().Debug("elasticsearchChannelIndexCheck: index is not verified, need to notify admins.")
// notify all system admins // notify all system admins
systemBot, appErr := a.GetSystemBot(request.EmptyContext(a.Log())) systemBot, appErr := a.GetSystemBot(request.EmptyContext(a.Log()))
if appErr != nil { if appErr != nil {