summaryrefslogtreecommitdiff
path: root/tools/edit_monitor/utils.py
diff options
context:
space:
mode:
author Zhuoyao Zhang <zhuoyao@google.com> 2024-11-05 19:28:23 +0000
committer Zhuoyao Zhang <zhuoyao@google.com> 2024-11-05 19:37:36 +0000
commita5bec26ceb0211efe701c40efc54340531b5d815 (patch)
tree20d0a92520686731a5aa9b102374c6959dc96263 /tools/edit_monitor/utils.py
parentfe4906450c784d6ab9ee13a048f52f9a0cee4940 (diff)
Rollout edit monitor to 10% users
Simplified the logic in whether to enable edit monitor by passing the rollout percentage directly instead of reading from a env variable as now we do not rely on any env var to control the rollout precentage. Test: atest edit_monitor_utils_test Bug: 365617369 Change-Id: Ia04d5737dafe2c9715a02f84eb5d75ba6119ceb4
Diffstat (limited to 'tools/edit_monitor/utils.py')
-rw-r--r--tools/edit_monitor/utils.py22
1 files changed, 2 insertions, 20 deletions
diff --git a/tools/edit_monitor/utils.py b/tools/edit_monitor/utils.py
index 1a3275c6e2..b88949d300 100644
--- a/tools/edit_monitor/utils.py
+++ b/tools/edit_monitor/utils.py
@@ -21,7 +21,7 @@ def is_feature_enabled(
feature_name: str,
user_name: str,
enable_flag: str = None,
- rollout_flag: str = None,
+ rollout_percent: int = 100,
) -> bool:
"""Determine whether the given feature is enabled.
@@ -46,26 +46,8 @@ def is_feature_enabled(
logging.info("feature: %s is enabled", feature_name)
return True
- if not rollout_flag:
- return True
-
hash_object = hashlib.sha256()
hash_object.update((user_name + feature_name).encode("utf-8"))
hash_number = int(hash_object.hexdigest(), 16) % 100
- roll_out_percentage = os.environ.get(rollout_flag, "0")
- try:
- percentage = int(roll_out_percentage)
- if percentage < 0 or percentage > 100:
- logging.warning(
- "Rollout percentage: %s out of range, disable the feature.",
- roll_out_percentage,
- )
- return False
- return hash_number < percentage
- except ValueError:
- logging.warning(
- "Invalid rollout percentage: %s, disable the feature.",
- roll_out_percentage,
- )
- return False
+ return hash_number < rollout_percent