PLT-6976: Elasticsearch capitalisation and tests. (#6839)
* Fixes Elasticsearch to have consistent capitalisation everywhere across the code and UI (except the config file unfortunately). * Adds basic unit tests for Elastichsearch. * Adds a Elasticsearch docker image to the Makefile to enable testing the Elasticsearch feature.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0495a51949
Коммит
db2f6cf076
19
Makefile
19
Makefile
@@ -123,6 +123,14 @@ ifeq ($(BUILD_ENTERPRISE_READY),true)
|
|||||||
docker start mattermost-openldap > /dev/null; \
|
docker start mattermost-openldap > /dev/null; \
|
||||||
sleep 10; \
|
sleep 10; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
|
||||||
|
echo starting mattermost-elasticsearch; \
|
||||||
|
docker run --name mattermost-elasticsearch -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "ES_JAVA_OPTS=-Xms250m -Xmx250m" -d grundleborg/elasticsearch:latest > /dev/null; \
|
||||||
|
elif [ $(shell docker ps | grep -ci mattermost-elasticsearch) -eq 0 ]; then \
|
||||||
|
echo restarting mattermost-elasticsearch; \
|
||||||
|
docker start mattermost-elasticsearch> /dev/null; \
|
||||||
|
fi
|
||||||
endif
|
endif
|
||||||
|
|
||||||
stop-docker:
|
stop-docker:
|
||||||
@@ -148,6 +156,11 @@ stop-docker:
|
|||||||
docker stop mattermost-inbucket > /dev/null; \
|
docker stop mattermost-inbucket > /dev/null; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
||||||
|
echo stopping mattermost-elasticsearch; \
|
||||||
|
docker stop mattermost-elasticsearch > /dev/null; \
|
||||||
|
fi
|
||||||
|
|
||||||
clean-docker:
|
clean-docker:
|
||||||
@echo Removing docker containers
|
@echo Removing docker containers
|
||||||
|
|
||||||
@@ -175,6 +188,12 @@ clean-docker:
|
|||||||
docker rm -v mattermost-inbucket > /dev/null; \
|
docker rm -v mattermost-inbucket > /dev/null; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@if [ $(shell docker ps -a | grep -ci mattermost-elasticsearch) -eq 1 ]; then \
|
||||||
|
echo removing mattermost-elasticsearch; \
|
||||||
|
docker stop mattermost-elasticsearch > /dev/null; \
|
||||||
|
docker rm -v mattermost-elasticsearch > /dev/null; \
|
||||||
|
fi
|
||||||
|
|
||||||
check-client-style:
|
check-client-style:
|
||||||
@echo Checking client style
|
@echo Checking client style
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestElasticsearch() *model.AppError {
|
func TestElasticsearch() *model.AppError {
|
||||||
if esI := einterfaces.GetElasticSearchInterface(); esI != nil {
|
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
|
||||||
if err := esI.TestConfig(); err != nil {
|
if err := esI.TestConfig(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
12
app/post.go
12
app/post.go
@@ -99,7 +99,7 @@ func CreatePost(post *model.Post, teamId string, triggerWebhooks bool) (*model.P
|
|||||||
rpost = result.Data.(*model.Post)
|
rpost = result.Data.(*model.Post)
|
||||||
}
|
}
|
||||||
|
|
||||||
esInterface := einterfaces.GetElasticSearchInterface()
|
esInterface := einterfaces.GetElasticsearchInterface()
|
||||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
||||||
go esInterface.IndexPost(rpost, teamId)
|
go esInterface.IndexPost(rpost, teamId)
|
||||||
}
|
}
|
||||||
@@ -284,7 +284,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
|
|||||||
} else {
|
} else {
|
||||||
rpost := result.Data.(*model.Post)
|
rpost := result.Data.(*model.Post)
|
||||||
|
|
||||||
esInterface := einterfaces.GetElasticSearchInterface()
|
esInterface := einterfaces.GetElasticsearchInterface()
|
||||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
||||||
go func() {
|
go func() {
|
||||||
if rchannel := <-Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil {
|
if rchannel := <-Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil {
|
||||||
@@ -471,7 +471,7 @@ func DeletePost(postId string) (*model.Post, *model.AppError) {
|
|||||||
go DeletePostFiles(post)
|
go DeletePostFiles(post)
|
||||||
go DeleteFlaggedPosts(post.Id)
|
go DeleteFlaggedPosts(post.Id)
|
||||||
|
|
||||||
esInterface := einterfaces.GetElasticSearchInterface()
|
esInterface := einterfaces.GetElasticsearchInterface()
|
||||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
|
||||||
go esInterface.DeletePost(post.Id)
|
go esInterface.DeletePost(post.Id)
|
||||||
}
|
}
|
||||||
@@ -502,8 +502,8 @@ func DeletePostFiles(post *model.Post) {
|
|||||||
func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostList, *model.AppError) {
|
func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostList, *model.AppError) {
|
||||||
paramsList := model.ParseSearchParams(terms)
|
paramsList := model.ParseSearchParams(terms)
|
||||||
|
|
||||||
esInterface := einterfaces.GetElasticSearchInterface()
|
esInterface := einterfaces.GetElasticsearchInterface()
|
||||||
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.ElasticSearch {
|
if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.Elasticsearch {
|
||||||
finalParamsList := []*model.SearchParams{}
|
finalParamsList := []*model.SearchParams{}
|
||||||
|
|
||||||
for _, params := range paramsList {
|
for _, params := range paramsList {
|
||||||
@@ -539,7 +539,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
postIds, err := einterfaces.GetElasticSearchInterface().SearchPosts(userChannels, finalParamsList)
|
postIds, err := einterfaces.GetElasticsearchInterface().SearchPosts(userChannels, finalParamsList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,8 +120,8 @@ func runServer(configFileLocation string) {
|
|||||||
einterfaces.GetMetricsInterface().StartServer()
|
einterfaces.GetMetricsInterface().StartServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
if einterfaces.GetElasticSearchInterface() != nil {
|
if einterfaces.GetElasticsearchInterface() != nil {
|
||||||
if err := einterfaces.GetElasticSearchInterface().Start(); err != nil {
|
if err := einterfaces.GetElasticsearchInterface().Start(); err != nil {
|
||||||
l4g.Error(err.Error())
|
l4g.Error(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,20 +5,20 @@ package einterfaces
|
|||||||
|
|
||||||
import "github.com/mattermost/platform/model"
|
import "github.com/mattermost/platform/model"
|
||||||
|
|
||||||
type ElasticSearchInterface interface {
|
type ElasticsearchInterface interface {
|
||||||
Start() *model.AppError
|
Start() *model.AppError
|
||||||
IndexPost(post *model.Post, teamId string)
|
IndexPost(post *model.Post, teamId string) *model.AppError
|
||||||
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
|
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
|
||||||
DeletePost(postId string)
|
DeletePost(postId string) *model.AppError
|
||||||
TestConfig() *model.AppError
|
TestConfig() *model.AppError
|
||||||
}
|
}
|
||||||
|
|
||||||
var theElasticSearchInterface ElasticSearchInterface
|
var theElasticsearchInterface ElasticsearchInterface
|
||||||
|
|
||||||
func RegisterElasticSearchInterface(newInterface ElasticSearchInterface) {
|
func RegisterElasticsearchInterface(newInterface ElasticsearchInterface) {
|
||||||
theElasticSearchInterface = newInterface
|
theElasticsearchInterface = newInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetElasticSearchInterface() ElasticSearchInterface {
|
func GetElasticsearchInterface() ElasticsearchInterface {
|
||||||
return theElasticSearchInterface
|
return theElasticsearchInterface
|
||||||
}
|
}
|
||||||
|
|||||||
16
i18n/en.json
16
i18n/en.json
@@ -3491,6 +3491,18 @@
|
|||||||
"id": "ent.compliance.run_started.info",
|
"id": "ent.compliance.run_started.info",
|
||||||
"translation": "Compliance export started for job '{{.JobName}}' at '{{.FilePath}}'"
|
"translation": "Compliance export started for job '{{.JobName}}' at '{{.FilePath}}'"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "ent.elasticsearch.delete_post.error",
|
||||||
|
"translation": "Failed to delete the post"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ent.elasticsearch.index_post.error",
|
||||||
|
"translation": "Failed to index the post"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "ent.elasticsearch.not_started.error",
|
||||||
|
"translation": "Elasticsearch is not started"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "ent.elasticsearch.search_posts.disabled",
|
"id": "ent.elasticsearch.search_posts.disabled",
|
||||||
"translation": "ElasticSearch searching is disabled on this server"
|
"translation": "ElasticSearch searching is disabled on this server"
|
||||||
@@ -3523,6 +3535,10 @@
|
|||||||
"id": "ent.elasticsearch.start.index_settings_failed",
|
"id": "ent.elasticsearch.start.index_settings_failed",
|
||||||
"translation": "Failed to set ElasticSearch index settings"
|
"translation": "Failed to set ElasticSearch index settings"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "ent.elasticsearch.test_config.connect_failed",
|
||||||
|
"translation": "Connecting to Elasticsearch server failed."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "ent.elasticsearch.test_config.indexing_disabled.error",
|
"id": "ent.elasticsearch.test_config.indexing_disabled.error",
|
||||||
"translation": "Elasticsearch is disabled."
|
"translation": "Elasticsearch is disabled."
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ type Features struct {
|
|||||||
MHPNS *bool `json:"mhpns"`
|
MHPNS *bool `json:"mhpns"`
|
||||||
SAML *bool `json:"saml"`
|
SAML *bool `json:"saml"`
|
||||||
PasswordRequirements *bool `json:"password_requirements"`
|
PasswordRequirements *bool `json:"password_requirements"`
|
||||||
ElasticSearch *bool `json:"elastic_search"`
|
Elasticsearch *bool `json:"elastic_search"`
|
||||||
Announcement *bool `json:"announcement"`
|
Announcement *bool `json:"announcement"`
|
||||||
// after we enabled more features for webrtc we'll need to control them with this
|
// after we enabled more features for webrtc we'll need to control them with this
|
||||||
FutureFeatures *bool `json:"future_features"`
|
FutureFeatures *bool `json:"future_features"`
|
||||||
@@ -68,7 +68,7 @@ func (f *Features) ToMap() map[string]interface{} {
|
|||||||
"mhpns": *f.MHPNS,
|
"mhpns": *f.MHPNS,
|
||||||
"saml": *f.SAML,
|
"saml": *f.SAML,
|
||||||
"password": *f.PasswordRequirements,
|
"password": *f.PasswordRequirements,
|
||||||
"elastic_search": *f.ElasticSearch,
|
"elastic_search": *f.Elasticsearch,
|
||||||
"future": *f.FutureFeatures,
|
"future": *f.FutureFeatures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,9 +139,9 @@ func (f *Features) SetDefaults() {
|
|||||||
*f.PasswordRequirements = *f.FutureFeatures
|
*f.PasswordRequirements = *f.FutureFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.ElasticSearch == nil {
|
if f.Elasticsearch == nil {
|
||||||
f.ElasticSearch = new(bool)
|
f.Elasticsearch = new(bool)
|
||||||
*f.ElasticSearch = *f.FutureFeatures
|
*f.Elasticsearch = *f.FutureFeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Announcement == nil {
|
if f.Announcement == nil {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
|||||||
CheckTrue(t, *f.MHPNS)
|
CheckTrue(t, *f.MHPNS)
|
||||||
CheckTrue(t, *f.SAML)
|
CheckTrue(t, *f.SAML)
|
||||||
CheckTrue(t, *f.PasswordRequirements)
|
CheckTrue(t, *f.PasswordRequirements)
|
||||||
CheckTrue(t, *f.ElasticSearch)
|
CheckTrue(t, *f.Elasticsearch)
|
||||||
CheckTrue(t, *f.FutureFeatures)
|
CheckTrue(t, *f.FutureFeatures)
|
||||||
|
|
||||||
f = Features{}
|
f = Features{}
|
||||||
@@ -64,7 +64,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
|||||||
*f.MHPNS = true
|
*f.MHPNS = true
|
||||||
*f.SAML = true
|
*f.SAML = true
|
||||||
*f.PasswordRequirements = true
|
*f.PasswordRequirements = true
|
||||||
*f.ElasticSearch = true
|
*f.Elasticsearch = true
|
||||||
|
|
||||||
f.SetDefaults()
|
f.SetDefaults()
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ func TestLicenseFeaturesSetDefaults(t *testing.T) {
|
|||||||
CheckTrue(t, *f.MHPNS)
|
CheckTrue(t, *f.MHPNS)
|
||||||
CheckTrue(t, *f.SAML)
|
CheckTrue(t, *f.SAML)
|
||||||
CheckTrue(t, *f.PasswordRequirements)
|
CheckTrue(t, *f.PasswordRequirements)
|
||||||
CheckTrue(t, *f.ElasticSearch)
|
CheckTrue(t, *f.Elasticsearch)
|
||||||
CheckFalse(t, *f.FutureFeatures)
|
CheckFalse(t, *f.FutureFeatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ func TestLicenseToFromJson(t *testing.T) {
|
|||||||
CheckBool(t, *f1.MHPNS, *f.MHPNS)
|
CheckBool(t, *f1.MHPNS, *f.MHPNS)
|
||||||
CheckBool(t, *f1.SAML, *f.SAML)
|
CheckBool(t, *f1.SAML, *f.SAML)
|
||||||
CheckBool(t, *f1.PasswordRequirements, *f.PasswordRequirements)
|
CheckBool(t, *f1.PasswordRequirements, *f.PasswordRequirements)
|
||||||
CheckBool(t, *f1.ElasticSearch, *f.ElasticSearch)
|
CheckBool(t, *f1.Elasticsearch, *f.Elasticsearch)
|
||||||
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
|
CheckBool(t, *f1.FutureFeatures, *f.FutureFeatures)
|
||||||
|
|
||||||
invalid := `{"asdf`
|
invalid := `{"asdf`
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ func getClientConfig(c *model.Config) map[string]string {
|
|||||||
props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol)
|
props["PasswordRequireSymbol"] = strconv.FormatBool(*c.PasswordSettings.Symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *License.Features.ElasticSearch {
|
if *License.Features.Elasticsearch {
|
||||||
props["ElasticSearchEnableIndexing"] = strconv.FormatBool(*c.ElasticSearchSettings.EnableIndexing)
|
props["ElasticSearchEnableIndexing"] = strconv.FormatBool(*c.ElasticSearchSettings.EnableIndexing)
|
||||||
props["ElasticSearchEnableSearching"] = strconv.FormatBool(*c.ElasticSearchSettings.EnableSearching)
|
props["ElasticSearchEnableSearching"] = strconv.FormatBool(*c.ElasticSearchSettings.EnableSearching)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user