diff --git a/api/app/settings/common.py b/api/app/settings/common.py index c5ff83281bdc..5adde3332224 100644 --- a/api/app/settings/common.py +++ b/api/app/settings/common.py @@ -806,9 +806,6 @@ # Redis Cluster URL used to communicate with the event ingestion server. INGESTION_REDIS_URL = env.str("INGESTION_REDIS_URL", default="") -# DSN for the ClickHouse instance holding ingested experimentation events. -EXPERIMENTATION_CLICKHOUSE_URL = env.str("EXPERIMENTATION_CLICKHOUSE_URL", default=None) - CACHES = { "default": { "BACKEND": "django.core.cache.backends.locmem.LocMemCache", @@ -1501,6 +1498,13 @@ CLICKHOUSE_ENABLED = bool(CLICKHOUSE_URL or CLICKHOUSE_HOST) +CLICKHOUSE_CONNECTION_CLIENT_NAME = "flagsmith-core-api" + +# DSN for the ClickHouse instance holding ingested experimentation events. +# TODO: consolidate connection management across the two CH use cases +# https://github.com/Flagsmith/flagsmith/issues/8033 +EXPERIMENTATION_CLICKHOUSE_URL = env.str("EXPERIMENTATION_CLICKHOUSE_URL", default=None) + SEGMENT_MEMBERSHIP_REFRESH_INTERVAL_HOURS = env.int( "SEGMENT_MEMBERSHIP_REFRESH_INTERVAL_HOURS", default=6 ) @@ -1543,7 +1547,7 @@ # from breaking migrations with Error 517. "alter_sync": 2, }, - "client_name": "flagsmith-core-api", + "client_name": CLICKHOUSE_CONNECTION_CLIENT_NAME, }, } DATABASES["clickhouse"] = _clickhouse_db # type: ignore[assignment] diff --git a/api/experimentation/services.py b/api/experimentation/services.py index d1cd4935c44c..c304f2878b1a 100644 --- a/api/experimentation/services.py +++ b/api/experimentation/services.py @@ -117,6 +117,7 @@ def _get_clickhouse_client() -> Client: host, kwargs = parse_url(settings.EXPERIMENTATION_CLICKHOUSE_URL) kwargs.setdefault("connect_timeout", CLICKHOUSE_CONNECT_TIMEOUT_SECONDS) kwargs.setdefault("send_receive_timeout", CLICKHOUSE_QUERY_TIMEOUT_SECONDS) + kwargs.setdefault("client_name", settings.CLICKHOUSE_CONNECTION_CLIENT_NAME) return Client(host, **kwargs) diff --git a/api/tests/unit/experimentation/test_services.py b/api/tests/unit/experimentation/test_services.py index 804de33159d3..81f5561291d5 100644 --- a/api/tests/unit/experimentation/test_services.py +++ b/api/tests/unit/experimentation/test_services.py @@ -71,6 +71,7 @@ def test_get_clickhouse_client__configured_url__builds_client_with_timeouts( secure=True, connect_timeout=services.CLICKHOUSE_CONNECT_TIMEOUT_SECONDS, send_receive_timeout=services.CLICKHOUSE_QUERY_TIMEOUT_SECONDS, + client_name=settings.CLICKHOUSE_CONNECTION_CLIENT_NAME, ) assert client is mock_client_cls.return_value services._get_clickhouse_client.cache_clear() @@ -97,6 +98,7 @@ def test_get_clickhouse_client__dsn_timeouts__are_preserved( database="db", connect_timeout=1, send_receive_timeout=2, + client_name=settings.CLICKHOUSE_CONNECTION_CLIENT_NAME, ) services._get_clickhouse_client.cache_clear() diff --git a/docs/docs/deployment-self-hosting/observability/_events-catalogue.md b/docs/docs/deployment-self-hosting/observability/_events-catalogue.md index 7458c075e032..5cf57971d597 100644 --- a/docs/docs/deployment-self-hosting/observability/_events-catalogue.md +++ b/docs/docs/deployment-self-hosting/observability/_events-catalogue.md @@ -532,7 +532,7 @@ Attributes: ### `warehouse.connection.connected` Logged at `info` from: - - `api/experimentation/services.py:802` + - `api/experimentation/services.py:803` Attributes: - `environment.id` @@ -541,7 +541,7 @@ Attributes: ### `warehouse.connection.test_event_sent` Logged at `info` from: - - `api/experimentation/services.py:782` + - `api/experimentation/services.py:783` Attributes: - `environment.id` @@ -550,7 +550,7 @@ Attributes: ### `warehouse.srm.overallocated` Logged at `error` from: - - `api/experimentation/services.py:404` + - `api/experimentation/services.py:405` Attributes: - `environment.id` @@ -560,7 +560,7 @@ Attributes: ### `warehouse.srm.unkeyed_variant` Logged at `error` from: - - `api/experimentation/services.py:390` + - `api/experimentation/services.py:391` Attributes: - `environment.id`