From e8a3667e445280fa09eb4396d4378254eea1c721 Mon Sep 17 00:00:00 2001 From: Ben White Date: Tue, 17 Dec 2024 17:25:07 +0100 Subject: [PATCH 1/3] Added settings --- posthog/api/decide.py | 14 ++++++++++---- posthog/settings/web.py | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/posthog/api/decide.py b/posthog/api/decide.py index 98b331de0472d..9e5db3c9404ff 100644 --- a/posthog/api/decide.py +++ b/posthog/api/decide.py @@ -47,10 +47,16 @@ def get_base_config(token: str, team: Team, request: HttpRequest, skip_db: bool = False) -> dict: - # Check for query param "use_remote_config" - use_remote_config = request.GET.get("use_remote_config") == "true" or token in ( - settings.DECIDE_TOKENS_FOR_REMOTE_CONFIG or [] - ) + use_remote_config = False + + # Explicitly set via query param for testing otherwise rollout percentage + if request.GET.get("use_remote_config") == "true": + use_remote_config = True + elif request.GET.get("use_remote_config") == "false": + use_remote_config = False + elif settings.REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE > 0: + if random() < settings.REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE: + use_remote_config = True if use_remote_config: response = RemoteConfig.get_config_via_token(token, request=request) diff --git a/posthog/settings/web.py b/posthog/settings/web.py index 49c68b0adb978..23329f9701262 100644 --- a/posthog/settings/web.py +++ b/posthog/settings/web.py @@ -36,8 +36,6 @@ DECIDE_SKIP_POSTGRES_FLAGS = get_from_env("DECIDE_SKIP_POSTGRES_FLAGS", False, type_cast=str_to_bool) -DECIDE_TOKENS_FOR_REMOTE_CONFIG = get_list(os.getenv("DECIDE_TOKENS_FOR_REMOTE_CONFIG", "")) - # Decide billing analytics DECIDE_BILLING_SAMPLING_RATE = get_from_env("DECIDE_BILLING_SAMPLING_RATE", 0.1, type_cast=float) @@ -400,6 +398,7 @@ DEV_DISABLE_NAVIGATION_HOOKS = get_from_env("DEV_DISABLE_NAVIGATION_HOOKS", False, type_cast=bool) +REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE = get_from_env("REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE", 0.0, type_cast=float) REMOTE_CONFIG_CDN_PURGE_ENDPOINT = get_from_env("REMOTE_CONFIG_CDN_PURGE_ENDPOINT", "") REMOTE_CONFIG_CDN_PURGE_TOKEN = get_from_env("REMOTE_CONFIG_CDN_PURGE_TOKEN", "") REMOTE_CONFIG_CDN_PURGE_DOMAINS = get_list(os.getenv("REMOTE_CONFIG_CDN_PURGE_DOMAINS", "")) From 8eb13c8a6b74def300c719fb343b298955e19b67 Mon Sep 17 00:00:00 2001 From: Ben White Date: Tue, 17 Dec 2024 17:26:22 +0100 Subject: [PATCH 2/3] Fixes --- posthog/settings/web.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/posthog/settings/web.py b/posthog/settings/web.py index 23329f9701262..05dd38af055a9 100644 --- a/posthog/settings/web.py +++ b/posthog/settings/web.py @@ -399,6 +399,11 @@ REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE = get_from_env("REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE", 0.0, type_cast=float) + +if REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE > 1: + raise ValueError( + f"REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE must be between 0 and 1 but got {REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE}" + ) REMOTE_CONFIG_CDN_PURGE_ENDPOINT = get_from_env("REMOTE_CONFIG_CDN_PURGE_ENDPOINT", "") REMOTE_CONFIG_CDN_PURGE_TOKEN = get_from_env("REMOTE_CONFIG_CDN_PURGE_TOKEN", "") REMOTE_CONFIG_CDN_PURGE_DOMAINS = get_list(os.getenv("REMOTE_CONFIG_CDN_PURGE_DOMAINS", "")) From da8c194cd3f9edd2481cc17e1ec9eeecbbc38951 Mon Sep 17 00:00:00 2001 From: Ben White Date: Tue, 17 Dec 2024 17:27:27 +0100 Subject: [PATCH 3/3] Fixes --- posthog/api/decide.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/posthog/api/decide.py b/posthog/api/decide.py index 9e5db3c9404ff..b3b9cbf0dde0c 100644 --- a/posthog/api/decide.py +++ b/posthog/api/decide.py @@ -45,6 +45,12 @@ labelnames=[LABEL_TEAM_ID, "errors_computing", "has_hash_key_override"], ) +REMOTE_CONFIG_CACHE_COUNTER = Counter( + "posthog_remote_config_for_decide", + "Metric tracking whether Remote Config was used for decide", + labelnames=["result"], +) + def get_base_config(token: str, team: Team, request: HttpRequest, skip_db: bool = False) -> dict: use_remote_config = False @@ -58,6 +64,8 @@ def get_base_config(token: str, team: Team, request: HttpRequest, skip_db: bool if random() < settings.REMOTE_CONFIG_DECIDE_ROLLOUT_PERCENTAGE: use_remote_config = True + REMOTE_CONFIG_CACHE_COUNTER.labels(result=use_remote_config).inc() + if use_remote_config: response = RemoteConfig.get_config_via_token(token, request=request)