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: create a limit of queries made by a personal token #29376

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion ee/api/test/test_instance_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework import status

from ee.api.test.base import APILicensedTest
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.instance_setting import get_instance_setting
from posthog.models.performance.sql import PERFORMANCE_EVENT_DATA_TABLE
from posthog.settings.data_stores import CLICKHOUSE_DATABASE
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/materialized_columns/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
MATERIALIZE_COLUMNS_MINIMUM_QUERY_TIME,
)
from posthog.cache_utils import instance_memoize
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.filters.mixins.utils import cached_property
from posthog.models.person.sql import (
GET_EVENT_PROPERTIES_COUNT,
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/materialized_columns/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from posthog.clickhouse.cluster import ClickhouseCluster, FuturesMap, HostInfo, get_cluster
from posthog.clickhouse.kafka_engine import trim_quotes_expr
from posthog.clickhouse.materialized_columns import ColumnName, TablesWithMaterializedColumns
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.event.sql import EVENTS_DATA_TABLE
from posthog.models.person.sql import PERSONS_TABLE
from posthog.models.property import PropertyName, TableColumn, TableWithProperties
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/materialized_columns/test/test_analyze.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from posthog.test.base import BaseTest, ClickhouseTestMixin
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from ee.clickhouse.materialized_columns.analyze import materialize_properties_task

from unittest.mock import patch, call
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/materialized_columns/test/test_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from ee.tasks.materialized_columns import mark_all_materialized
from posthog.clickhouse.materialized_columns import TablesWithMaterializedColumns
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.conftest import create_clickhouse_tables
from posthog.constants import GROUP_TYPES_LIMIT
from posthog.models.event.sql import EVENTS_DATA_TABLE
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/models/test/test_action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dataclasses

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.hogql.compiler.bytecode import create_bytecode
from posthog.hogql.hogql import HogQLContext
from posthog.hogql.property import action_to_expr
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/models/test/test_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils import timezone
from freezegun import freeze_time

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.hogql.constants import MAX_SELECT_COHORT_CALCULATION_LIMIT
from posthog.hogql.hogql import HogQLContext
from posthog.models.action import Action
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/models/test/test_dead_letter_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
INSERT_DEAD_LETTER_QUEUE_EVENT_SQL,
KAFKA_DEAD_LETTER_QUEUE_TABLE_SQL,
)
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.kafka_client.topics import KAFKA_DEAD_LETTER_QUEUE
from posthog.settings import KAFKA_HOSTS
from posthog.test.base import BaseTest, ClickhouseTestMixin
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/models/test/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from typing import Optional

from posthog.client import query_with_columns, sync_execute
from posthog.clickhouse.client import query_with_columns, sync_execute
from posthog.constants import FILTER_TEST_ACCOUNTS
from posthog.models import Element, Organization, Person, Team
from posthog.models.cohort import Cohort
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/models/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.exceptions import ValidationError

from ee.clickhouse.materialized_columns.columns import materialize
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import PropertyOperatorType
from posthog.models.cohort import Cohort
from posthog.models.element import Element
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/models/test/utils/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from time import sleep, time

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute


# this normally is unnecessary as CH is fast to consume from Kafka when testing
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/queries/experiments/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import TREND_FILTER_TYPE_ACTIONS
from posthog.models.filters.filter import Filter
from posthog.models.team.team import Team
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/queries/related_actors_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.utils.timezone import now

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models import Team
from posthog.models.filters.utils import validate_group_type_index
from posthog.models.group_type_mapping import GroupTypeMapping
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/queries/test/test_cohort_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


from ee.clickhouse.queries.enterprise_cohort_query import check_negation_clause
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import PropertyOperatorType
from posthog.hogql_queries.hogql_cohort_query import TestWrapperCohortQuery as CohortQuery
from posthog.models import Team
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/queries/test/test_event_query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from freezegun import freeze_time

from ee.clickhouse.materialized_columns.columns import materialize
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models import Action
from posthog.models.cohort import Cohort
from posthog.models.element import Element
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/queries/test/test_person_query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from ee.clickhouse.materialized_columns.columns import materialize
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.filters import Filter
from posthog.models.team import Team
from posthog.queries.person_query import PersonQuery
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/queries/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from zoneinfo import ZoneInfo
from freezegun.api import freeze_time

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.hogql.hogql import HogQLContext
from posthog.models.action import Action
from posthog.models.cohort import Cohort
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/views/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from posthog.api.documentation import extend_schema
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.clickhouse.kafka_engine import trim_quotes_expr
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.group import Group
from posthog.models.group_type_mapping import GroupTypeMapping

Expand Down
2 changes: 1 addition & 1 deletion ee/tasks/materialized_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from clickhouse_driver import Client

from ee.clickhouse.materialized_columns.columns import MaterializedColumn, tables as table_infos
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.settings import CLICKHOUSE_DATABASE
from posthog.clickhouse.cluster import get_cluster
from posthog.clickhouse.materialized_columns import ColumnName, TablesWithMaterializedColumns
Expand Down
2 changes: 1 addition & 1 deletion ee/tasks/send_license_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.timezone import now

from ee.models.license import License
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models import User
from posthog.settings import SITE_URL

Expand Down
2 changes: 1 addition & 1 deletion ee/tasks/test/test_calculate_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from freezegun import freeze_time

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.cohort import Cohort
from posthog.models.person import Person
from posthog.tasks.calculate_cohort import insert_cohort_from_insight_filter
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
from posthog.api.utils import get_target_entity
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import (
INSIGHT_FUNNELS,
INSIGHT_LIFECYCLE,
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/dead_letter_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from rest_framework import mixins, permissions, serializers, viewsets

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.permissions import IsStaffUser

# keep in sync with posthog/frontend/src/scenes/instance/DeadLetterQueue/MetricsTab.tsx
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/debug_ch_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from rest_framework.response import Response
from rest_framework.request import Request

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.cloud_utils import is_cloud
from posthog.settings.base_variables import DEBUG
from posthog.settings.data_stores import CLICKHOUSE_CLUSTER
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.auth import TemporaryTokenAuthentication
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models import Element, Filter
from posthog.models.element.element import chain_to_elements
from posthog.models.element.sql import GET_ELEMENTS, GET_VALUES
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from posthog.api.documentation import PropertiesSerializer, extend_schema
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.client import query_with_columns
from posthog.clickhouse.client import query_with_columns
from posthog.hogql.constants import DEFAULT_RETURNED_ROWS, MAX_SELECT_RETURNED_ROWS
from posthog.models import Element, Filter, Person
from posthog.models.event.query_event_list import query_events_list
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/ingestion_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.response import Response

from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute


class IngestionWarningsViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/instance_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def update(self, instance: InstanceSettingHelper, validated_data: dict[str, Any]
raise serializers.ValidationError("This setting cannot be updated on cloud.")

# TODO: Move to top-level imports once CH is moved out of `ee`
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.session_recordings.sql.session_recording_event_sql import (
UPDATE_RECORDINGS_TABLE_TTL_SQL,
)
Expand All @@ -107,7 +107,7 @@ def update(self, instance: InstanceSettingHelper, validated_data: dict[str, Any]
raise serializers.ValidationError("This setting cannot be updated on cloud.")

# TODO: Move to top-level imports once CH is moved out of `ee`
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.performance.sql import (
UPDATE_PERFORMANCE_EVENTS_TABLE_TTL_SQL,
)
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.shared import UserBasicSerializer
from posthog.api.utils import action, get_token
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.cloud_utils import is_cloud
from posthog.constants import AvailableFeature
from posthog.event_usage import report_user_action
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/test/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def test_pagination(self):

page2 = self.client.get(response["next"]).json()

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute

self.assertEqual(
sync_execute(
Expand Down Expand Up @@ -594,7 +594,7 @@ def test_pagination_bounded_date_range(self):

page2 = self.client.get(response["next"]).json()

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute

self.assertEqual(
sync_execute(
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/test_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from freezegun.api import freeze_time
from rest_framework import status

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models import Cohort, Organization, Person, Team
from posthog.models.async_deletion import AsyncDeletion, DeletionType
from posthog.models.person import PersonDistinctId
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/test/test_stickiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils import timezone
from freezegun import freeze_time

from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import ENTITY_ID, ENTITY_TYPE
from posthog.models.team import Team
from posthog.test.base import (
Expand Down
2 changes: 1 addition & 1 deletion posthog/async_migrations/disk_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.settings import CLICKHOUSE_DATABASE


Expand Down
2 changes: 1 addition & 1 deletion posthog/async_migrations/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AsyncMigrationOperation,
AsyncMigrationOperationSQL,
)
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import AnalyticsDBMS
from posthog.models.person.sql import (
KAFKA_PERSONS_DISTINCT_ID_TABLE_SQL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)
from posthog.async_migrations.disk_util import analyze_enough_disk_space_free_for_table
from posthog.async_migrations.utils import run_optimize_table
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.cloud_utils import is_cloud
from posthog.constants import AnalyticsDBMS
from posthog.models.instance_setting import set_instance_setting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
AsyncMigrationDefinition,
AsyncMigrationOperationSQL,
)
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import AnalyticsDBMS
from posthog.settings import CLICKHOUSE_DATABASE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.conf import settings

from posthog.async_migrations.definition import AsyncMigrationDefinition
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute

logger = structlog.get_logger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from posthog.async_migrations.utils import execute_op_clickhouse, run_optimize_table
from posthog.clickhouse.kafka_engine import STORAGE_POLICY
from posthog.clickhouse.table_engines import ReplacingMergeTree
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import AnalyticsDBMS
from posthog.models.async_migration import AsyncMigration
from posthog.models.person.person import Person
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
run_optimize_table,
sleep_until_finished,
)
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.event.sql import EVENTS_DATA_TABLE
from posthog.utils import str_to_bool

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AsyncMigrationDefinition,
AsyncMigrationOperationSQL,
)
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import AnalyticsDBMS
from posthog.version_requirement import ServiceVersionRequirement

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
AsyncMigrationDefinition,
AsyncMigrationOperationSQL,
)
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.constants import AnalyticsDBMS
from posthog.version_requirement import ServiceVersionRequirement
from datetime import datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup_async_migrations,
)
from posthog.async_migrations.test.util import AsyncMigrationBaseTest
from posthog.client import query_with_columns, sync_execute
from posthog.clickhouse.client import query_with_columns, sync_execute
from posthog.models import Person
from posthog.models.async_migration import (
AsyncMigration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from posthog.async_migrations.setup import ALL_ASYNC_MIGRATIONS
from posthog.async_migrations.test.util import AsyncMigrationBaseTest
from posthog.client import sync_execute
from posthog.clickhouse.client import sync_execute
from posthog.models.person.sql import COMMENT_DISTINCT_ID_COLUMN_SQL

pytestmark = pytest.mark.async_migrations
Expand Down
Loading
Loading