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

feat(feature-flags): support quota limiting for feature flags #195

Merged
merged 19 commits into from
Feb 21, 2025

Conversation

dmarticus
Copy link
Contributor

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.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 in request.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

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"]:
Copy link
Contributor

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

@dmarticus dmarticus changed the title feat(feature-flags): support quota limiting in the server-side SDK feat(feature-flags): support quota limiting for feature flags Feb 20, 2025
self.feature_flags = []
self.feature_flags_by_key = {}
self.group_type_mapping = {}
self.cohorts = {}
Copy link
Contributor

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?

Copy link
Contributor Author

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"]
Copy link
Contributor

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)

Copy link
Contributor Author

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).

Copy link
Contributor Author

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.

@dmarticus dmarticus merged commit 5e0f9e3 into master Feb 21, 2025
6 checks passed
@dmarticus dmarticus deleted the feat/quota-limited-flags branch February 21, 2025 20:45
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.

None yet

2 participants