-
Notifications
You must be signed in to change notification settings - Fork 31
feat(feature-flags): support quota limiting for feature flags #195
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
Changes from all commits
6910859
6a9bfd5
b37df4f
4f39e18
58494a8
dadb11a
4d2f22e
f7e7b43
03f84f3
f8851e5
a25a4be
1edd48a
dbd0699
6c2cc11
5260c6c
0093fad
cb25435
ffdacbd
8d09e86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,19 @@ def _process_response( | |
log = logging.getLogger("posthog") | ||
if res.status_code == 200: | ||
log.debug(success_message) | ||
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 | ||
# NB: other services also put entries into the quotaLimited key, but right now we only care about feature flags | ||
# since most of the other services handle quota limiting in other places in the application. | ||
if ( | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'm assuming this is to cover the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I'll make a comment to that end though. |
||
): | ||
log.warning("PostHog feature flags quota limited") | ||
raise QuotaLimitError(res.status_code, "Feature flags quota limited") | ||
return response | ||
try: | ||
payload = res.json() | ||
log.debug("received response: %s", payload) | ||
|
@@ -112,6 +124,10 @@ def __str__(self): | |
return msg.format(self.message, self.status) | ||
|
||
|
||
class QuotaLimitError(APIError): | ||
pass | ||
|
||
|
||
class DatetimeSerializer(json.JSONEncoder): | ||
def default(self, obj: Any): | ||
if isinstance(obj, (date, datetime)): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION = "3.14.2" | ||
VERSION = "3.15.0" | ||
|
||
if __name__ == "__main__": | ||
print(VERSION, end="") # noqa: T201 |
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