-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat(feature-flags): support quota limiting for feature flags #195
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR adds support for handling quota-limited feature flag responses in the PostHog Python SDK, while also fixing case sensitivity issues in feature flag payload evaluation.
- Added
QuotaLimitError
handling inrequest.py
to properly handle when users exceed their feature flag quota limits - Modified
_process_response
to detect quota-limited responses from/decide
and/local_evaluation
APIs with appropriate error logging - Added test coverage in
test_request.py
for both quota-limited and normal response scenarios - Fixed case sensitivity issues in feature flag payload evaluation (issue Feature flag evaluation is case sensitive, while feature flag payload match evaluation is evaluated as lower() #178)
- Updated version to 3.14.0 to reflect these new features
6 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings | Greptile
posthog/request.py
Outdated
return res.json() if return_json else res | ||
response = res.json() if return_json else res | ||
# Handle quota limited decide responses by raising a specific error | ||
if isinstance(response, dict) and "quotaLimited" in response and "feature_flags" in response["quotaLimited"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider checking for quotaLimited
being a list before checking if feature_flags
is in it to avoid potential type errors
self.feature_flags = [] | ||
self.feature_flags_by_key = {} | ||
self.group_type_mapping = {} | ||
self.cohorts = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we stay consistent with the 401 case above and raise an APIError if debug mode is on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good call
isinstance(response, dict) | ||
and "quotaLimited" in response | ||
and isinstance(response["quotaLimited"], list) | ||
and "feature_flags" in response["quotaLimited"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm assuming this is to cover the /decide
case, correct? Can / should we avoid the special condition for feature_flags
and instead log any quota limited services, maybe raising an error for any of them (or, keep a list of services that should throw an error if quota limited)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah, good call. I think for now I explicitly want to limit feature flag events for now (since I don't know how other services are handling quota limits in the SDK).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a comment to that end though.
with this PR, we now start to respond different with the
/decide
and/local_evaluation
APIs if users have gone over their quota limit. This change is an example for how our SDKs can deal with that. I'll make the same type of changes to all of the SDKs, but wanted to start with this one as an example.