0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00
posthog/ee
Rick Marron 258cd32f54
chore(api): meter rate limit on team (#12006)
## Problem

Take 2 on [this PR](https://github.com/PostHog/posthog/pull/11993#event-7470261128). The problem is that our rate limits should be based on `team_id` instead of an API key, and the last PR didn't handle views that didn't have a `team_id`.

## Changes

* Moves the rate_limit to be based on the `team_id` when possible
* Handles views that don't have a team_id
* Ensures the enabling/disabling of rate limits applies to all rate_limit classes (it used to only apply to the default classes)

and

* moves enabling the rate limit to an instance setting
* and adds a team id allow list for bypassing the rate limit
* and a simple cache which I think stops us hammering the reading of the infrequently changing settings

👉 *Stay up-to-date with [PostHog coding conventions](https://posthog.com/docs/contribute/coding-conventions) for a smoother review.*

## How did you test this code?

Added tests for the new cases:
* Rate limit works across a team - not just on an individual user.
* Rate limits work on views without a `team_id`
* Disabling the rate limits works


Co-authored-by: Paul D'Ambra <paul@posthog.com>
2022-10-18 09:01:07 +01:00
..
api chore(api): meter rate limit on team (#12006) 2022-10-18 09:01:07 +01:00
benchmarks style(flake8): enable E402 (#11707) 2022-09-07 16:11:55 +02:00
bin
certs
clickhouse fix: correct type hint for plugin activity logs (#12268) 2022-10-14 12:51:07 -07:00
management/commands
migrations
models feat(app-metrics): Set up schema and data gathering of app metrics (#12143) 2022-10-12 11:30:58 +03:00
tasks feat: add text cards to DB (#12110) 2022-10-10 11:49:33 +01:00
test fix(auth): Upgrade personal API keys (#11902) 2022-09-28 12:53:48 +02:00
__init__.py
apps.py
conftest.py
LICENSE
pytest.ini
settings.py
urls.py