From 3a15df4e77dd569e9d01659c26bf483741eb6190 Mon Sep 17 00:00:00 2001 From: christopher lee Date: Thu, 10 May 2018 12:01:04 -0400 Subject: [PATCH] Revert "Clean up enrollment rate limit waffles" This reverts commit 813d59d0919da500c9be9d8e4661606da2e98342. --- common/djangoapps/enrollment/__init__.py | 9 +++++++++ common/djangoapps/enrollment/views.py | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/common/djangoapps/enrollment/__init__.py b/common/djangoapps/enrollment/__init__.py index e69de29bb2..c3623e65c5 100644 --- a/common/djangoapps/enrollment/__init__.py +++ b/common/djangoapps/enrollment/__init__.py @@ -0,0 +1,9 @@ +""" +Enrollment API helpers and settings +""" +from openedx.core.djangoapps.waffle_utils import (WaffleFlag, WaffleFlagNamespace) + +WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace(name='enrollment_api_rate_limit') + +REDUCE_RATE_LIMIT_FOR_STAFF_FOR_ENROLLMENT_API = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'reduce_staff_rate_limit') +USE_UNIVERSAL_RATE_LIMIT_FOR_ENROLLMENT_API = WaffleFlag(WAFFLE_FLAG_NAMESPACE, 'use_universal_rate_limit') diff --git a/common/djangoapps/enrollment/views.py b/common/djangoapps/enrollment/views.py index 33aff74ec0..cb5e7577e9 100644 --- a/common/djangoapps/enrollment/views.py +++ b/common/djangoapps/enrollment/views.py @@ -12,6 +12,8 @@ from django.utils.decorators import method_decorator from edx_rest_framework_extensions.authentication import JwtAuthentication from enrollment import api from enrollment.errors import CourseEnrollmentError, CourseEnrollmentExistsError, CourseModeNotFoundError +from enrollment import REDUCE_RATE_LIMIT_FOR_STAFF_FOR_ENROLLMENT_API, \ + USE_UNIVERSAL_RATE_LIMIT_FOR_ENROLLMENT_API from opaque_keys import InvalidKeyError from opaque_keys.edx.keys import CourseKey @@ -76,10 +78,31 @@ class ApiKeyPermissionMixIn(object): class EnrollmentUserThrottle(UserRateThrottle, ApiKeyPermissionMixIn): """Limit the number of requests users can make to the enrollment API.""" + # TODO: After confirming that reducing the throttle is successful, remove + # and clean up waffles. The rate limit has been increased over the course + # of a few months to account for unnecessary calls from the ecommerce + # service. These calls are no longer made and the plan is to set the + # rate limit back to its original state. LEARNER-5148 + + # Current rate limit THROTTLE_RATES = { 'user': '40/minute', + 'staff': '2000/minute', } + # Less aggressive reduction in throttle limit. This should not be necessary + if REDUCE_RATE_LIMIT_FOR_STAFF_FOR_ENROLLMENT_API.is_enabled(): + THROTTLE_RATES = { + 'user': '40/minute', + 'staff': '400/minute', + } + + # Original rate Limit before rate limit increases. + if USE_UNIVERSAL_RATE_LIMIT_FOR_ENROLLMENT_API.is_enabled(): + THROTTLE_RATES = { + 'user': '40/minute', + } + def allow_request(self, request, view): # Use a special scope for staff to allow for a separate throttle rate user = request.user