Skip to content
Permalink
Browse files
Remove es7/elasticsearch7 references
Replace es7 and ES7 references with es and ES
Make name in docker version agnostic
Replace name in circle
  • Loading branch information
smithellis committed Dec 1, 2022
1 parent b0ae589 commit 8e57e31
Show file tree
Hide file tree
Showing 29 changed files with 89 additions and 89 deletions.
@@ -30,10 +30,10 @@ jobs:
- run:
# copy synonym files to elasticsearch7 container, since circleci doesn't support volume mounts:
# https://circleci.com/docs/2.0/building-docker-images/#mounting-folders
name: Copy synonym files to elasticsearch7
name: Copy synonym files to elasticsearch
command: |
./bin/dc_ci.sh up -d elasticsearch7
docker cp ./kitsune/search/dictionaries/synonyms/. project-elasticsearch7-1:/usr/share/elasticsearch/config/synonyms
./bin/dc_ci.sh up -d elasticsearch
docker cp ./kitsune/search/dictionaries/synonyms/. project-elasticsearch-1:/usr/share/elasticsearch/config/synonyms
- run:
name: Run unit tests
command: ./bin/dc_ci.sh run test ./bin/run-unit-tests.sh
@@ -9,8 +9,8 @@ set -ex
urlwait

# wait for elasticsearch to be ready
urlwait http://elasticsearch7:9200 60
urlwait http://elasticsearch:9200 60

./manage.py es7_init --migrate-writes --migrate-reads
./manage.py es_init --migrate-writes --migrate-reads

./manage.py test --noinput --force-color --timing [email protected]
@@ -13,7 +13,7 @@ services:
tty: true
depends_on:
- mariadb
- elasticsearch7
- elasticsearch
- kibana
- redis
- celery
@@ -36,7 +36,7 @@ services:
volumes:
- mysqlvolume:/var/lib/mysql

elasticsearch7:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2
environment:
- discovery.type=single-node
@@ -52,8 +52,8 @@ services:
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://elasticsearch7:9200
ELASTICSEARCH_HOSTS: http://elasticsearch7:9200
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200

redis:
image: redis:3
@@ -7,7 +7,7 @@ services:
env_file: .env-test
depends_on:
- mariadb
- elasticsearch7
- elasticsearch
- redis

prod:
@@ -165,7 +165,7 @@ or have entered data yourself through the admin interface.
2. Build the indicies

```
$ ./manage.py es7_init && ./manage.py es7_reindex
$ ./manage.py es_init && ./manage.py es_reindex
```

3. Now, exit from web's bash shell
@@ -12,11 +12,11 @@ To know whether a change you make to a Document will work in prod,
try it locally having already set up the mapping:

```
./manage.py es7_init --limit TestDocument
./manage.py es_init --limit TestDocument
... make changes to TestDocument ...
./manage.py es7_init --limit TestDocument
./manage.py es_init --limit TestDocument
```

If that fails with an error,
@@ -26,16 +26,16 @@ and reindex everything into that index.
However if it succeeds then it should also work on prod.

Once the changes are deployed to prod,
and the mapping is updated with `es7_init`,
and the mapping is updated with `es_init`,
some documents may need to be reindexed.
This is because we disable dynamic mapping in `SumoDocument`,
to prevent a dynamic mapping of the wrong type being set up before `es7_init` was able to be run during a deployment.
to prevent a dynamic mapping of the wrong type being set up before `es_init` was able to be run during a deployment.

So to ensure no data is missing from the index,
run something like:

```
./manage.py es7_reindex --limit TestDocument --updated-after <datetime of deploy> --updated-before <datetime of mapping update>
./manage.py es_reindex --limit TestDocument --updated-after <datetime of deploy> --updated-before <datetime of mapping update>
```

### Indexing performance
@@ -45,7 +45,7 @@ you might want to add the `--print-sql-count` argument when testing out your cha
to see how many SQL queries are being executed:

```sh
CELERY_TASK_ALWAYS_EAGER=True ./manage.py es7_reindex --print-sql-count --sql-chunk-size=100 --count=100
CELERY_TASK_ALWAYS_EAGER=True ./manage.py es_reindex --print-sql-count --sql-chunk-size=100 --count=100
```

If the result is much less than 100,
@@ -87,7 +87,7 @@ as that returns a naive or aware datetime depending on the value of `USE_TZ`, wh
You can set the following variable in your .env file to enable the logging of the queries that are sent to your local ElasticSearch instance.

```
ES7_ENABLE_CONSOLE_LOGGING=True
ES_ENABLE_CONSOLE_LOGGING=True
```

### Simulate slow and out of order query responses
@@ -234,7 +234,7 @@ In development synonyms can be updated very easily.
Save your changes in the text file and run:

```
./manage.py es7_init --reload-search-analyzers
./manage.py es_init --reload-search-analyzers
```

If no other changes were made to the index configurations,
@@ -74,7 +74,7 @@ app:
dms_fix_current_revisions: SECRET
dms_generate_missing_share_links: SECRET
dms_rebuild_kb: SECRET
dms_reindex_es7: SECRET
dms_reindex_es: SECRET
dms_reload_question_traffic_stats: SECRET
dms_reload_wiki_traffic_stats: SECRET
dms_report_employee_answers: SECRET
@@ -69,7 +69,7 @@ app:
dms_fix_current_revisions: SECRET
dms_generate_missing_share_links: SECRET
dms_rebuild_kb: SECRET
dms_reindex_es7: SECRET
dms_reindex_es: SECRET
dms_reload_question_traffic_stats: SECRET
dms_reload_wiki_traffic_stats: SECRET
dms_report_employee_answers: SECRET
@@ -93,9 +93,9 @@ app:
engage_robots: True
es_index_prefix: "sumo_prod"
es_live_indexing: True
es7_use_ssl: True
es7_http_auth: SECRET
es7_cloud_id: SECRET
es_use_ssl: True
es_http_auth: SECRET
es_cloud_id: SECRET
ga_account: SECRET
ga_key: SECRET
ga_profile_id: SECRET
@@ -72,7 +72,7 @@ app:
dms_fix_current_revisions: SECRET
dms_generate_missing_share_links: SECRET
dms_rebuild_kb: SECRET
dms_reindex_es7: SECRET
dms_reindex_es: SECRET
dms_reload_question_traffic_stats: SECRET
dms_reload_wiki_traffic_stats: SECRET
dms_report_employee_answers: SECRET
@@ -95,9 +95,9 @@ app:
engage_robots: False
es_index_prefix: "sumo_stage"
es_live_indexing: True
es7_use_ssl: True
es7_http_auth: SECRET
es7_cloud_id: SECRET
es_use_ssl: True
es_http_auth: SECRET
es_cloud_id: SECRET
ga_account: SECRET
ga_key: SECRET
ga_profile_id: SECRET
@@ -69,7 +69,7 @@ app:
dms_fix_current_revisions: SECRET
dms_generate_missing_share_links: SECRET
dms_rebuild_kb: SECRET
dms_reindex_es7: SECRET
dms_reindex_es: SECRET
dms_reload_question_traffic_stats: SECRET
dms_reload_wiki_traffic_stats: SECRET
dms_report_employee_answers: SECRET
@@ -73,7 +73,7 @@ app:
dms_fix_current_revisions: SECRET
dms_generate_missing_share_links: SECRET
dms_rebuild_kb: SECRET
dms_reindex_es7: SECRET
dms_reindex_es: SECRET
dms_reload_question_traffic_stats: SECRET
dms_reload_wiki_traffic_stats: SECRET
dms_report_employee_answers: SECRET
@@ -99,9 +99,9 @@ app:
engage_robots: True
es_index_prefix: "sumo_prod"
es_live_indexing: True
es7_use_ssl: True
es7_http_auth: SECRET
es7_cloud_id: SECRET
es_use_ssl: True
es_http_auth: SECRET
es_cloud_id: SECRET
ga_account: SECRET
ga_key: SECRET
ga_profile_id: SECRET
@@ -72,7 +72,7 @@ app:
dms_fix_current_revisions: SECRET
dms_generate_missing_share_links: SECRET
dms_rebuild_kb: SECRET
dms_reindex_es7: SECRET
dms_reindex_es: SECRET
dms_reload_question_traffic_stats: SECRET
dms_reload_wiki_traffic_stats: SECRET
dms_report_employee_answers: SECRET
@@ -95,9 +95,9 @@ app:
engage_robots: False
es_index_prefix: "sumo_stage"
es_live_indexing: True
es7_use_ssl: True
es7_http_auth: SECRET
es7_cloud_id: SECRET
es_use_ssl: True
es_http_auth: SECRET
es_cloud_id: SECRET
fxa_op_token_endpoint: SECRET
fxa_set_issuer: SECRET
fxa_op_authorization_endpoint: SECRET
@@ -6,7 +6,7 @@
from django.db import connection, transaction

from kitsune.questions.models import Answer, Question
from kitsune.search.es7_utils import index_objects_bulk
from kitsune.search.es_utils import index_objects_bulk

log = logging.getLogger("k.cron")

@@ -18,11 +18,11 @@
from pyparsing import ParseException

from kitsune.search.config import (
DEFAULT_ES7_CONNECTION,
DEFAULT_ES7_REFRESH_INTERVAL,
DEFAULT_ES_CONNECTION,
DEFAULT_ES_REFRESH_INTERVAL,
UPDATE_RETRY_ON_CONFLICT,
)
from kitsune.search.es7_utils import es7_client
from kitsune.search.es_utils import es_client
from kitsune.search.parser import Parser
from kitsune.search.parser.tokens import TermToken

@@ -40,7 +40,7 @@ def __init_subclass__(cls, **kwargs):
"""Automatically set up each subclass' Index attribute."""
super().__init_subclass__(**kwargs)

cls.Index.using = DEFAULT_ES7_CONNECTION
cls.Index.using = DEFAULT_ES_CONNECTION

# this is here to ensure subclasses of subclasses of SumoDocument (e.g. AnswerDocument)
# use the same name in their index as their parent class (e.g. QuestionDocument) since
@@ -55,7 +55,7 @@ def __init_subclass__(cls, **kwargs):
cls.Index.read_alias = f"{cls.Index.base_name}_read"
cls.Index.write_alias = f"{cls.Index.base_name}_write"
# Bump the refresh interval to 1 minute
cls.Index.settings = {"refresh_interval": DEFAULT_ES7_REFRESH_INTERVAL}
cls.Index.settings = {"refresh_interval": DEFAULT_ES_REFRESH_INTERVAL}

# this is the attribute elastic-dsl actually uses to determine which index
# to query. we override the .search() method to get that to use the read
@@ -88,7 +88,7 @@ def migrate_reads(cls):

@classmethod
def _update_alias(cls, alias, new_index):
client = es7_client()
client = es_client()
old_index = cls.alias_points_at(alias)
if not old_index:
client.indices.put_alias(new_index, alias)
@@ -106,7 +106,7 @@ def _update_alias(cls, alias, new_index):
def alias_points_at(cls, alias):
"""Returns the index `alias` points at."""
try:
aliased_indices = list(es7_client().indices.get_alias(name=alias))
aliased_indices = list(es_client().indices.get_alias(name=alias))
except NotFoundError:
aliased_indices = []

@@ -376,8 +376,8 @@ def run(self, key: Union[int, slice] = slice(0, settings.SEARCH_RESULTS_PER_PAGE
"""Perform search, placing the results in `self.results`, and the total
number of results (across all pages) in `self.total`. Chainable."""

search = DSLSearch(using=es7_client(), index=self.get_index()).params(
**settings.ES7_SEARCH_PARAMS
search = DSLSearch(using=es_client(), index=self.get_index()).params(
**settings.ES_SEARCH_PARAMS
)

# add the search class' filter
@@ -371,6 +371,6 @@
},
}

DEFAULT_ES7_CONNECTION = "es7_default"
DEFAULT_ES_CONNECTION = "es_default"
# default refresh_interval for all indices
DEFAULT_ES7_REFRESH_INTERVAL = "60s"
DEFAULT_ES_REFRESH_INTERVAL = "60s"
@@ -5,7 +5,7 @@
from kitsune.questions.models import Answer, Question
from kitsune.search import config
from kitsune.search.base import SumoDocument
from kitsune.search.es7_utils import es7_client
from kitsune.search.es_utils import es_client
from kitsune.search.fields import SumoLocaleAwareKeywordField, SumoLocaleAwareTextField
from kitsune.users.models import Profile
from kitsune.wiki import models as wiki_models
@@ -16,7 +16,7 @@
TEMPLATES_CATEGORY,
)

connections.add_connection(config.DEFAULT_ES7_CONNECTION, es7_client())
connections.add_connection(config.DEFAULT_ES_CONNECTION, es_client())


class WikiDocument(SumoDocument):
@@ -4,7 +4,7 @@
from celery import shared_task
from django.conf import settings
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk as es7_bulk
from elasticsearch.helpers import bulk as es_bulk
from elasticsearch.helpers.errors import BulkIndexError
from elasticsearch_dsl import Document, UpdateByQuery, analyzer, char_filter, token_filter

@@ -90,13 +90,13 @@ def es_analyzer_for_locale(locale, search_analyzer=False):
)


def es7_client(**kwargs):
"""Return an ES7 Elasticsearch client"""
def es_client(**kwargs):
"""Return an ES Elasticsearch client"""
# prefer a cloud_id if available
if es7_cloud_id := settings.ES7_CLOUD_ID:
kwargs.update({"cloud_id": es7_cloud_id, "http_auth": settings.ES7_HTTP_AUTH})
if es_cloud_id := settings.ES_CLOUD_ID:
kwargs.update({"cloud_id": es_cloud_id, "http_auth": settings.ES_HTTP_AUTH})
else:
kwargs.update({"hosts": settings.ES7_URLS})
kwargs.update({"hosts": settings.ES_URLS})
return Elasticsearch(**kwargs)


@@ -166,8 +166,8 @@ def index_objects_bulk(
# if the request doesn't resolve within `timeout`,
# sleep for `timeout` then try again up to `settings.ES_BULK_MAX_RETRIES` times,
# before raising an exception:
success, errors = es7_bulk(
es7_client(
success, errors = es_bulk(
es_client(
timeout=timeout,
retry_on_timeout=True,
initial_backoff=timeout,
@@ -198,7 +198,7 @@ def remove_from_field(doc_type_name, field_name, field_value):
f"}}"
)

update = UpdateByQuery(using=es7_client(), index=doc_type._index._name)
update = UpdateByQuery(using=es_client(), index=doc_type._index._name)
update = update.filter("term", **{field_name: field_value})
update = update.script(source=script, params={"value": field_value}, conflicts="proceed")

@@ -5,7 +5,7 @@
from elasticsearch_dsl.field import Object as DSLObject
from elasticsearch_dsl.field import Text

from kitsune.search.es7_utils import es_analyzer_for_locale
from kitsune.search.es_utils import es_analyzer_for_locale

SUPPORTED_LANGUAGES = list(settings.SUMO_LANGUAGES)
# this is a test locale - no need to add it to ES

0 comments on commit 8e57e31

Please sign in to comment.