diff --git a/dev/.env.docker-compose b/dev/.env.docker-compose index f9dc8107..60d6736f 100644 --- a/dev/.env.docker-compose +++ b/dev/.env.docker-compose @@ -1,4 +1,4 @@ -DJANGO_CONFIGURATION=DevelopmentConfiguration +DJANGO_SETTINGS_MODULE=isic.settings.development DJANGO_DATABASE_URL=postgres://postgres:postgres@postgres:5432/django DJANGO_CELERY_BROKER_URL=amqp://rabbitmq:5672/ DJANGO_MINIO_STORAGE_ENDPOINT=minio:9000 @@ -7,6 +7,6 @@ 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_ISIC_REDIS_URL=redis://localhost:6379 +DJANGO_ISIC_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 d1546580..5b2bbc49 100644 --- a/dev/.env.docker-compose-native +++ b/dev/.env.docker-compose-native @@ -1,4 +1,4 @@ -DJANGO_CONFIGURATION=DevelopmentConfiguration +DJANGO_SETTINGS_MODULE=isic.settings.development DJANGO_DATABASE_URL=postgres://postgres:postgres@localhost:5432/django DJANGO_CELERY_BROKER_URL=amqp://localhost:5672/ DJANGO_MINIO_STORAGE_ENDPOINT=localhost:9000 @@ -6,6 +6,6 @@ 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_ISIC_REDIS_URL=redis://localhost:6379 +DJANGO_ISIC_REDIS_URL=redis://localhost:6379/0 DJANGO_ISIC_DATACITE_USERNAME="fakeuser" DJANGO_ISIC_DATACITE_PASSWORD="fakepassword" diff --git a/isic/asgi.py b/isic/asgi.py index 3cf45c01..46b77adb 100644 --- a/isic/asgi.py +++ b/isic/asgi.py @@ -1,11 +1,8 @@ import os -import configurations.importer from django.core.asgi import get_asgi_application -os.environ["DJANGO_SETTINGS_MODULE"] = "isic.settings" -if not os.environ.get("DJANGO_CONFIGURATION"): - raise ValueError('The environment variable "DJANGO_CONFIGURATION" must be set.') -configurations.importer.install() +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "isic.settings.production") + application = get_asgi_application() diff --git a/isic/celery.py b/isic/celery.py index 1e26c731..53db625a 100644 --- a/isic/celery.py +++ b/isic/celery.py @@ -3,16 +3,12 @@ from celery import Celery import celery.app.trace from celery.contrib.django.task import DjangoTask -import configurations.importer celery.app.trace.LOG_RECEIVED = """\ Task %(name)s[%(id)s] received: (%(args)s, %(kwargs)s)\ """ -os.environ["DJANGO_SETTINGS_MODULE"] = "isic.settings" -if not os.environ.get("DJANGO_CONFIGURATION"): - raise ValueError('The environment variable "DJANGO_CONFIGURATION" must be set.') -configurations.importer.install() +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "isic.settings.production") # Using a string config_source means the worker doesn't have to serialize diff --git a/isic/conftest.py b/isic/conftest.py index 5b628b17..7d0c1284 100644 --- a/isic/conftest.py +++ b/isic/conftest.py @@ -65,11 +65,6 @@ def staff_client(staff_user): return client -@pytest.fixture() -def _eager_celery(settings): - settings.CELERY_TASK_ALWAYS_EAGER = True - - # To make pytest-factoryboy fixture creation work properly, all factories must be registered at # this top-level conftest, since the factories have inter-app references. diff --git a/isic/core/apps.py b/isic/core/apps.py index 08ec78b4..8ef1b057 100644 --- a/isic/core/apps.py +++ b/isic/core/apps.py @@ -1,12 +1,4 @@ -import logging - from django.apps import AppConfig -from django.conf import settings -import sentry_sdk -from sentry_sdk.integrations.celery import CeleryIntegration -from sentry_sdk.integrations.django import DjangoIntegration -from sentry_sdk.integrations.logging import LoggingIntegration -from sentry_sdk.integrations.pure_eval import PureEvalIntegration from .signals import post_invalidation # noqa: F401 @@ -14,66 +6,3 @@ class CoreConfig(AppConfig): name = "isic.core" verbose_name = "ISIC: Core" - - @staticmethod - def _get_sentry_performance_sample_rate(*args, **kwargs) -> float: # noqa: ARG004 - """ - Determine sample rate of sentry performance. - - Only sample 1% of common requests for performance monitoring, and all staff/admin requests - since they're relatively low volume but high value. Also sample all infrequent tasks. - """ - from isic.core.tasks import populate_collection_from_search_task - from isic.ingest.tasks import ( - extract_zip_task, - publish_cohort_task, - update_metadata_task, - validate_metadata_task, - ) - from isic.studies.tasks import populate_study_tasks_task - - infrequent_tasks: list[str] = [ - task.name - for task in [ - extract_zip_task, - validate_metadata_task, - update_metadata_task, - publish_cohort_task, - populate_collection_from_search_task, - populate_study_tasks_task, - ] - ] - - if args and "wsgi_environ" in args[0]: - path: str = args[0]["wsgi_environ"]["PATH_INFO"] - if path.startswith(("/staff", "/admin")): - return 1.0 - elif args and "celery_job" in args[0]: - if args[0]["celery_job"]["task"] in infrequent_tasks: - return 1.0 - - return 0.05 - - def ready(self): - if hasattr(settings, "SENTRY_DSN"): - sentry_sdk.init( - # If a "dsn" is not explicitly passed, sentry_sdk will attempt to find the DSN in - # the SENTRY_DSN environment variable; however, by pulling it from an explicit - # setting, it can be overridden by downstream project settings. - dsn=settings.SENTRY_DSN, - environment=settings.SENTRY_ENVIRONMENT, - release=settings.SENTRY_RELEASE, - integrations=[ - LoggingIntegration(level=logging.INFO, event_level=logging.WARNING), - DjangoIntegration(), - CeleryIntegration(), - PureEvalIntegration(), - ], - in_app_include=["isic"], - # Send traces for non-exception events too - attach_stacktrace=True, - # Submit request User info from Django - send_default_pii=True, - traces_sampler=self._get_sentry_performance_sample_rate, - profiles_sampler=self._get_sentry_performance_sample_rate, - ) diff --git a/isic/core/signals.py b/isic/core/signals.py index f2b86047..0ef988b9 100644 --- a/isic/core/signals.py +++ b/isic/core/signals.py @@ -1,12 +1,14 @@ import logging from cachalot.signals import post_invalidation +from django.conf import settings logger = logging.getLogger(__name__) def invalidation_debug(sender: str, **kwargs): - logger.info("Invalidated cache for %s:%s", kwargs["db_alias"], sender) + if hasattr(settings, "CACHALOT_ENABLED") and settings.CACHALOT_ENABLED: + logger.info("Invalidated cache for %s:%s", kwargs["db_alias"], sender) post_invalidation.connect(invalidation_debug) diff --git a/isic/core/tests/test_api_collection.py b/isic/core/tests/test_api_collection.py index 0cab6666..2b03cfb2 100644 --- a/isic/core/tests/test_api_collection.py +++ b/isic/core/tests/test_api_collection.py @@ -114,7 +114,6 @@ def test_core_api_collection_detail_permissions(client_, collection, visible): @pytest.mark.django_db() -@pytest.mark.usefixtures("_eager_celery") def test_core_api_collection_populate_from_search( authenticated_client, collection_factory, @@ -234,7 +233,6 @@ def test_core_api_collection_remove_from_list( @pytest.mark.django_db() -@pytest.mark.usefixtures("_eager_celery") def test_core_api_collection_share( staff_client, private_collection, user, django_capture_on_commit_callbacks ): @@ -253,7 +251,6 @@ def test_core_api_collection_share( @pytest.mark.django_db() -@pytest.mark.usefixtures("_eager_celery") def test_core_api_collection_license_breakdown( staff_client, collection_factory, image_factory, user ): diff --git a/isic/core/tests/test_view_image_list.py b/isic/core/tests/test_view_image_list.py index 2a3a7c29..304d1b74 100644 --- a/isic/core/tests/test_view_image_list.py +++ b/isic/core/tests/test_view_image_list.py @@ -9,7 +9,6 @@ # needs a real transaction due to setting the isolation level @pytest.mark.django_db(transaction=True) -@pytest.mark.usefixtures("_eager_celery") def test_image_list_metadata_download_view(staff_client, mailoutbox, user, image: Image): image.accession.update_metadata( user, diff --git a/isic/ingest/templates/ingest/partials/metadata_validation.html b/isic/ingest/templates/ingest/partials/metadata_validation.html index 0bd9bce1..a5d5705e 100644 --- a/isic/ingest/templates/ingest/partials/metadata_validation.html +++ b/isic/ingest/templates/ingest/partials/metadata_validation.html @@ -78,7 +78,7 @@ {% if archive_check is not None %} {% if archive_check.0 or archive_check.1 %}