From 1a4c6240fe381f71126648964e1be843d7998826 Mon Sep 17 00:00:00 2001 From: Daesgar Date: Tue, 31 Dec 2024 16:34:35 +0100 Subject: [PATCH] chore: use setting to fallback to kill query on cluster (#27196) --- posthog/clickhouse/cancel.py | 3 ++- posthog/settings/data_stores.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/posthog/clickhouse/cancel.py b/posthog/clickhouse/cancel.py index 475ae160ccb81..c20c4b2824837 100644 --- a/posthog/clickhouse/cancel.py +++ b/posthog/clickhouse/cancel.py @@ -1,5 +1,6 @@ from statshog.defaults.django import statsd +from posthog import settings from posthog.api.services.query import logger from posthog.clickhouse.client import sync_execute from posthog.clickhouse.client.connection import default_client @@ -32,7 +33,7 @@ def cancel_query_on_cluster(team_id: int, client_query_id: str) -> None: sync_client=client, ) logger.info("Cancelled query %s for team %s, result: %s", client_query_id, team_id, result) - else: + elif settings.CLICKHOUSE_FALLBACK_CANCEL_QUERY_ON_CLUSTER: logger.debug("No initiator host found for query %s, cancelling query on cluster", client_query_id) result = sync_execute( f"KILL QUERY ON CLUSTER '{CLICKHOUSE_CLUSTER}' WHERE query_id LIKE %(client_query_id)s", diff --git a/posthog/settings/data_stores.py b/posthog/settings/data_stores.py index 31eea8e08b768..77bc535da8a08 100644 --- a/posthog/settings/data_stores.py +++ b/posthog/settings/data_stores.py @@ -155,6 +155,9 @@ def postgres_config(host: str) -> dict: CLICKHOUSE_VERIFY: bool = get_from_env("CLICKHOUSE_VERIFY", True, type_cast=str_to_bool) CLICKHOUSE_ENABLE_STORAGE_POLICY: bool = get_from_env("CLICKHOUSE_ENABLE_STORAGE_POLICY", False, type_cast=str_to_bool) CLICKHOUSE_SINGLE_SHARD_CLUSTER: str = os.getenv("CLICKHOUSE_SINGLE_SHARD_CLUSTER", "posthog_single_shard") +CLICKHOUSE_FALLBACK_CANCEL_QUERY_ON_CLUSTER = get_from_env( + "CLICKHOUSE_FALLBACK_CANCEL_QUERY_ON_CLUSTER", default=True, type_cast=str_to_bool +) CLICKHOUSE_CONN_POOL_MIN: int = get_from_env("CLICKHOUSE_CONN_POOL_MIN", 20, type_cast=int) CLICKHOUSE_CONN_POOL_MAX: int = get_from_env("CLICKHOUSE_CONN_POOL_MAX", 1000, type_cast=int)