Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add throttle classess for health check endpoint (#2061)
Krystle Salazar249e1856e209
diff --git a/api/api/utils/throttle.py b/api/api/utils/throttle.pyindex 4e21b2f34..7fb19f7c3 100644--- a/api/api/utils/throttle.py+++ b/api/api/utils/throttle.py@@ -82,6 +82,10 @@ class SustainedRateThrottle(AbstractAnonRateThrottle):scope = "anon_sustained"+class HealthcheckAnonRateThrottle(AbstractAnonRateThrottle):+ scope = "anon_healthcheck"++class AnonThumbnailRateThrottle(AbstractAnonRateThrottle):scope = "anon_thumbnail"diff --git a/api/api/views/health_views.py b/api/api/views/health_views.pyindex 8c2c2f8d5..fb7e1da15 100644--- a/api/api/views/health_views.py+++ b/api/api/views/health_views.py@@ -6,6 +6,8 @@ from rest_framework.request import Requestfrom rest_framework.response import Responsefrom rest_framework.views import APIView+from api.utils.throttle import ExemptOAuth2IdRateThrottle, HealthcheckAnonRateThrottle+class ElasticsearchHealthcheckException(APIException):status_code = status.HTTP_503_SERVICE_UNAVAILABLE@@ -20,6 +22,7 @@ class HealthCheck(APIView):load balancer and destroyed."""+ throttle_classes = [HealthcheckAnonRateThrottle, ExemptOAuth2IdRateThrottle]schema = None # Hide this view from the OpenAPI schema.@staticmethoddiff --git a/api/conf/settings/rest_framework.py b/api/conf/settings/rest_framework.pyindex fd4b7ec97..1ced0971b 100644--- a/api/conf/settings/rest_framework.py+++ b/api/conf/settings/rest_framework.py@@ -12,6 +12,7 @@ THROTTLE_ANON_BURST = config("THROTTLE_ANON_BURST", default="5/hour")THROTTLE_ANON_SUSTAINED = config("THROTTLE_ANON_SUSTAINED", default="100/day")THROTTLE_ANON_THUMBS = config("THROTTLE_ANON_THUMBS", default="150/minute")THROTTLE_OAUTH2_THUMBS = config("THROTTLE_OAUTH2_THUMBS", default="500/minute")+THROTTLE_ANON_HEALTHCHECK = config("THROTTLE_ANON_HEALTHCHECK", default="3/minute")REST_FRAMEWORK = {"DEFAULT_AUTHENTICATION_CLASSES": (@@ -36,6 +37,7 @@ REST_FRAMEWORK = {"DEFAULT_THROTTLE_RATES": {"anon_burst": THROTTLE_ANON_BURST,"anon_sustained": THROTTLE_ANON_SUSTAINED,+ "anon_healthcheck": THROTTLE_ANON_HEALTHCHECK,"anon_thumbnail": THROTTLE_ANON_THUMBS,"oauth2_client_credentials_thumbnail": THROTTLE_OAUTH2_THUMBS,"oauth2_client_credentials_sustained": "10000/day",