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: Setting to slowly rollout RemoteConfig #26978

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
)
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", ""))
Loading