Skip to content

Commit

Permalink
feat: Setting to slowly rollout RemoteConfig (#26978)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Dec 18, 2024
1 parent 6dca54c commit c3552e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
22 changes: 18 additions & 4 deletions posthog/api/decide.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,26 @@
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:
# 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

REMOTE_CONFIG_CACHE_COUNTER.labels(result=use_remote_config).inc()

if use_remote_config:
response = RemoteConfig.get_config_via_token(token, request=request)
Expand Down
8 changes: 6 additions & 2 deletions posthog/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -400,6 +398,12 @@
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)

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", ""))

0 comments on commit c3552e5

Please sign in to comment.