Skip to content

Commit

Permalink
🔧(search) add elastic search client custom settings
Browse files Browse the repository at this point in the history
Add settings that permit to configure elastic search client with custom
configuration like custom timeouts. Closes #1613
  • Loading branch information
igobranco committed Jun 28, 2022
1 parent ae01870 commit 318d74f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unrealeased]

## Added

- Add settings that permit to configure elastic search client with custom
configuration like custom timeouts.

## [2.15.0] - 2022-06-22

### Added
Expand Down
4 changes: 4 additions & 0 deletions sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura
default="richie", environ_name="RICHIE_ES_INDICES_PREFIX", environ_prefix=None
)
RICHIE_ES_STATE_WEIGHTS = values.ListValue(None)
# Example to change the timeout: RICHIE_ES_CLIENT_KWARGS={'timeout': 30}
RICHIE_ES_CLIENT_KWARGS = values.DictValue(
{}, environ_name="RICHIE_ES_CLIENT_KWARGS", environ_prefix=None
)

# LTI Content
RICHIE_LTI_PROVIDERS = {
Expand Down
12 changes: 9 additions & 3 deletions src/richie/apps/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
# pylint: disable=invalid-name
default_app_config = "richie.apps.search.apps.SearchConfig"

ES_CLIENT = ElasticsearchClientCompat7to6(
getattr(settings, "RICHIE_ES_HOST", ["elasticsearch"])
)

def new_elasticsearch_client():
return ElasticsearchClientCompat7to6(
getattr(settings, "RICHIE_ES_HOST", ["elasticsearch"]),
**getattr(settings, "RICHIE_ES_CLIENT_KWARGS", {}),
)


ES_CLIENT = new_elasticsearch_client()

ES_INDICES_CLIENT = ElasticsearchIndicesClientCompat7to6(ES_CLIENT)
19 changes: 19 additions & 0 deletions tests/apps/search/test_index_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.test import TestCase
from django.test.utils import override_settings
from django.conf import settings
from richie.apps.search import new_elasticsearch_client


class IndexClientTestCase(TestCase):
"""
Test the index client extra vars
"""

@override_settings(RICHIE_ES_CLIENT_KWARGS={"timeout": 99})
def test_index_client_kwargs(self):
"""
Test `RICHIE_ES_CLIENT_KWARGS` setting, that allows to pass extra configurations to the
elastic search index client.
"""
es_client_to_test = new_elasticsearch_client()
self.assertEqual(es_client_to_test.transport.kwargs, {"timeout": 99})

0 comments on commit 318d74f

Please sign in to comment.