Merge branch 'add-missing-boto3-healthcheck-app' into 'develop'

Add missing s3 boto healthcheck to installed apps,

See merge request baserow/baserow!1418
This commit is contained in:
Nigel Gott committed 2023-05-16 09:04:39 +00:00
commit e055ee7429
3 files changed
+23 -9

No files matched your search

@@ -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",
+3 -9
View File
@@ -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
@@ -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):
"""