From bf90a9afbb495608c2b870e4f2ed980a4066aef3 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Thu, 21 Nov 2024 20:34:08 -0500 Subject: [PATCH] Use Elasticsearch from new production infrastructure Also rename the setting to be consistent with that of a general external service, as opposed to a piece of application-specific logic. --- .github/workflows/ci.yml | 2 +- dev/.env.docker-compose | 4 ++-- dev/.env.docker-compose-native | 4 ++-- isic/core/migrations/0003_auto_20240701_1459.py | 2 +- isic/core/search.py | 2 +- isic/settings/base.py | 2 +- isic/settings/production.py | 1 - tox.ini | 6 +++--- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8932a827..2dd58938 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -61,7 +61,7 @@ jobs: tox env: DJANGO_DATABASE_URL: postgres://postgres:postgres@localhost:5432/django - DJANGO_ISIC_ELASTICSEARCH_URI: http://elastic:elastic@localhost:9200 + DJANGO_ELASTICSEARCH_URL: http://elastic:elastic@localhost:9200 DJANGO_MINIO_STORAGE_ENDPOINT: localhost:9000 DJANGO_MINIO_STORAGE_ACCESS_KEY: minioAccessKey DJANGO_MINIO_STORAGE_SECRET_KEY: minioSecretKey diff --git a/dev/.env.docker-compose b/dev/.env.docker-compose index 89dd6040..7fa2bbb3 100644 --- a/dev/.env.docker-compose +++ b/dev/.env.docker-compose @@ -1,12 +1,12 @@ DJANGO_SETTINGS_MODULE=isic.settings.development -DJANGO_DATABASE_URL=postgres://postgres:postgres@postgres:5432/django DJANGO_CELERY_BROKER_URL=amqp://rabbitmq:5672/ +DJANGO_DATABASE_URL=postgres://postgres:postgres@postgres:5432/django +DJANGO_ELASTICSEARCH_URL=http://elastic:elastic@elasticsearch:9200 DJANGO_MINIO_STORAGE_ENDPOINT=minio:9000 DJANGO_MINIO_STORAGE_ACCESS_KEY=minioAccessKey DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey DJANGO_STORAGE_BUCKET_NAME=django-storage DJANGO_MINIO_STORAGE_MEDIA_URL=http://localhost:9000/django-storage -DJANGO_ISIC_ELASTICSEARCH_URI=http://elastic:elastic@elasticsearch:9200 DJANGO_REDIS_URL=redis://localhost:6379/0 DJANGO_ISIC_DATACITE_USERNAME="fakeuser" DJANGO_ISIC_DATACITE_PASSWORD="fakepassword" diff --git a/dev/.env.docker-compose-native b/dev/.env.docker-compose-native index 9a5a7ca2..e0dacf8b 100644 --- a/dev/.env.docker-compose-native +++ b/dev/.env.docker-compose-native @@ -1,11 +1,11 @@ DJANGO_SETTINGS_MODULE=isic.settings.development -DJANGO_DATABASE_URL=postgres://postgres:postgres@localhost:5432/django DJANGO_CELERY_BROKER_URL=amqp://localhost:5672/ +DJANGO_DATABASE_URL=postgres://postgres:postgres@localhost:5432/django +DJANGO_ELASTICSEARCH_URL=http://elastic:elastic@elasticsearch:9200 DJANGO_MINIO_STORAGE_ENDPOINT=localhost:9000 DJANGO_MINIO_STORAGE_ACCESS_KEY=minioAccessKey DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey DJANGO_STORAGE_BUCKET_NAME=django-storage -DJANGO_ISIC_ELASTICSEARCH_URI=http://elastic:elastic@localhost:9200 DJANGO_REDIS_URL=redis://localhost:6379/0 DJANGO_ISIC_DATACITE_USERNAME="fakeuser" DJANGO_ISIC_DATACITE_PASSWORD="fakepassword" diff --git a/isic/core/migrations/0003_auto_20240701_1459.py b/isic/core/migrations/0003_auto_20240701_1459.py index 88e15bb3..3bc1d90a 100644 --- a/isic/core/migrations/0003_auto_20240701_1459.py +++ b/isic/core/migrations/0003_auto_20240701_1459.py @@ -16,7 +16,7 @@ def _block_until_elasticsearch_is_available(): while True: try: - requests.get(f"{settings.ISIC_ELASTICSEARCH_URI}/_cluster/health", timeout=1) + requests.get(f"{settings.ELASTICSEARCH_URL}/_cluster/health", timeout=1) except requests.exceptions.ConnectionError: time.sleep(1) time_slept += 1 diff --git a/isic/core/search.py b/isic/core/search.py index 2b22534d..94acd20c 100644 --- a/isic/core/search.py +++ b/isic/core/search.py @@ -95,7 +95,7 @@ def perform_request(self, *args: Any, **kwargs: Any) -> Any: # TODO: investigate using retryable requests with transport_class RetryOnTimeoutTransport = partial(InstrumentedTransport, retry_on_timeout=True) # noqa: N806 - return OpenSearch(settings.ISIC_ELASTICSEARCH_URI, transport_class=RetryOnTimeoutTransport) # type: ignore[arg-type] + return OpenSearch(settings.ELASTICSEARCH_URL, transport_class=RetryOnTimeoutTransport) # type: ignore[arg-type] def maybe_create_index(index: str, mappings: Mapping[str, Any]) -> None: diff --git a/isic/settings/base.py b/isic/settings/base.py index 4603552e..dca7d062 100644 --- a/isic/settings/base.py +++ b/isic/settings/base.py @@ -152,7 +152,7 @@ def _oauth2_pkce_required(client_id): # with both methods. ISIC_USE_ELASTICSEARCH_COUNTS = False -ISIC_ELASTICSEARCH_URI = os.environ.get("DJANGO_ISIC_ELASTICSEARCH_URI") +ELASTICSEARCH_URL = os.environ.get("DJANGO_ELASTICSEARCH_URL") ISIC_ELASTICSEARCH_IMAGES_INDEX = "isic" ISIC_ELASTICSEARCH_LESIONS_INDEX = "isic-lesions" ISIC_GUI_URL = "https://www.isic-archive.com/" diff --git a/isic/settings/production.py b/isic/settings/production.py index ff8cf95a..657c8581 100644 --- a/isic/settings/production.py +++ b/isic/settings/production.py @@ -102,7 +102,6 @@ ISIC_DATACITE_USERNAME = os.environ["DJANGO_ISIC_DATACITE_USERNAME"] ISIC_DATACITE_PASSWORD = os.environ["DJANGO_ISIC_DATACITE_PASSWORD"] -ISIC_ELASTICSEARCH_URI = os.environ["SEARCHBOX_URL"] ISIC_USE_ELASTICSEARCH_COUNTS = True CACHES = { diff --git a/tox.ini b/tox.ini index ec342b20..4246fc49 100644 --- a/tox.ini +++ b/tox.ini @@ -36,10 +36,10 @@ commands = passenv = DJANGO_CELERY_BROKER_URL DJANGO_DATABASE_URL + DJANGO_ELASTICSEARCH_URL DJANGO_MINIO_STORAGE_ACCESS_KEY DJANGO_MINIO_STORAGE_ENDPOINT DJANGO_MINIO_STORAGE_SECRET_KEY - DJANGO_ISIC_ELASTICSEARCH_URI DJANGO_REDIS_URL extras = dev @@ -74,10 +74,10 @@ commands = passenv = DJANGO_CELERY_BROKER_URL DJANGO_DATABASE_URL + DJANGO_ELASTICSEARCH_URL DJANGO_MINIO_STORAGE_ACCESS_KEY DJANGO_MINIO_STORAGE_ENDPOINT DJANGO_MINIO_STORAGE_SECRET_KEY - DJANGO_ISIC_ELASTICSEARCH_URI DJANGO_REDIS_URL extras = dev @@ -93,10 +93,10 @@ setenv = passenv = DJANGO_CELERY_BROKER_URL DJANGO_DATABASE_URL + DJANGO_ELASTICSEARCH_URL DJANGO_MINIO_STORAGE_ACCESS_KEY DJANGO_MINIO_STORAGE_ENDPOINT DJANGO_MINIO_STORAGE_SECRET_KEY - DJANGO_ISIC_ELASTICSEARCH_URI DJANGO_REDIS_URL extras = dev