Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase the default throttle rate for enterprise users (POC) #4394

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adamstankiewicz
Copy link
Member

The frontend-app-learner-portal-enterprise MFE makes requests to several API endpoints within course-discovery, e.g. to serve metadata about courses, programs, course recommendations, and course reviews. However, enterprise users are frequently rate limited by the default throttle rate of 100/hour (i.e., N = 2.45k requests rate limited in the past 1 week from this MFE).

This PR proposes a (POC) solution for increasing the default throttle rate if the authenticated user is an enterprise user, as determined by the authenticated user's roles in their decoded JWT cookie.

except UserThrottleRate.DoesNotExist:
# If we don't have a custom user override, skip throttling if they are a privileged user
if user.is_superuser or user.is_staff or is_publisher_user(user):
return True

# If the user is not a privileged user, increase throttling rate if they are an enterprise user
if is_enterprise_user(request):
self.rate = '300/hour'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform/context] This specific rate is still up in the air; it might need to be higher than this (e.g., 600/hour) for enterprise users. This POC PR intends to demonstrate the approach, rather than a specific rate at the moment.

@@ -28,10 +42,15 @@ def allow_request(self, request, view):
# Override this throttle's rate if applicable
user_throttle = UserThrottleRate.objects.get(user=user)
self.rate = user_throttle.rate
self.num_requests, self.duration = self.parse_rate(self.rate)
except UserThrottleRate.DoesNotExist:
# If we don't have a custom user override, skip throttling if they are a privileged user
if user.is_superuser or user.is_staff or is_publisher_user(user):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[inform/context] We already remove the throttling based on whether the authenticated user is a "publisher user" (aka is a member of a Django Group). This POC is largely extending this to account for an is_enterprise_user check as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant