diff --git a/backend/src/baserow/config/settings/base.py b/backend/src/baserow/config/settings/base.py index 28ffb1af7f..1fa7057572 100644 --- a/backend/src/baserow/config/settings/base.py +++ b/backend/src/baserow/config/settings/base.py @@ -83,6 +83,7 @@ INSTALLED_APPS = [ "health_check.contrib.redis", "health_check.contrib.celery_ping", "health_check.contrib.psutil", + "health_check.contrib.s3boto3_storage", "baserow.core", "baserow.api", "baserow.ws", diff --git a/backend/src/baserow/core/apps.py b/backend/src/baserow/core/apps.py index 4deaa3600a..19870c9f22 100755 --- a/backend/src/baserow/core/apps.py +++ b/backend/src/baserow/core/apps.py @@ -3,6 +3,8 @@ from django.conf import settings from django.db.models import Q from django.db.models.signals import post_migrate +from health_check.storage.backends import DefaultFileStorageHealthCheck + class CoreConfig(AppConfig): name = "baserow.core" @@ -254,11 +256,7 @@ class CoreConfig(AppConfig): post_migrate.connect(sync_operations_after_migrate, sender=self) def _setup_health_checks(self): - from health_check.contrib.s3boto_storage.backends import ( - S3BotoStorageHealthCheck, - ) from health_check.plugins import plugin_dir - from health_check.storage.backends import DefaultFileStorageHealthCheck from .health.custom_health_checks import ( DebugModeHealthCheck, @@ -268,11 +266,7 @@ class CoreConfig(AppConfig): plugin_dir.register(DebugModeHealthCheck) if getattr(settings, "HEROKU_ENABLED", False): plugin_dir.register(HerokuExternalFileStorageConfiguredHealthCheck) - - if settings.DEFAULT_FILE_STORAGE == "storages.backends.s3boto3.S3Boto3Storage": - plugin_dir.register(S3BotoStorageHealthCheck) - else: - plugin_dir.register(DefaultFileStorageHealthCheck) + plugin_dir.register(DefaultFileStorageHealthCheck) # noinspection PyPep8Naming diff --git a/backend/src/baserow/core/health/handler.py b/backend/src/baserow/core/health/handler.py index a7611e96ed..ec831d7a38 100644 --- a/backend/src/baserow/core/health/handler.py +++ b/backend/src/baserow/core/health/handler.py @@ -5,7 +5,9 @@ from django.conf import settings from django.core import mail from django.core.mail import EmailMessage +from health_check.contrib.s3boto3_storage.backends import S3Boto3StorageHealthCheck from health_check.plugins import plugin_dir +from health_check.storage.backends import DefaultFileStorageHealthCheck class HealthCheckResult(NamedTuple): @@ -38,6 +40,8 @@ class HealthCheckHandler: passing = True for plugin in cls.get_plugins(): + if cls._should_skip_check(plugin): + continue # The plugin checks can fail and raise but we always want to catch # to report back that they failed. # noinspection PyBroadException @@ -51,6 +55,21 @@ class HealthCheckHandler: return HealthCheckResult(checks, passing) + @classmethod + def _should_skip_check(cls, plugin): + """ + Make sure we skip the s3 check when s3 is not active and vice versa with + the default storage check. + """ + + s3_enabled = ( + settings.DEFAULT_FILE_STORAGE == "storages.backends.s3boto3.S3Boto3Storage" + ) + if s3_enabled: + return isinstance(plugin, DefaultFileStorageHealthCheck) + else: + return isinstance(plugin, S3Boto3StorageHealthCheck) + @classmethod def send_test_email(cls, target_email: str): """