From f44cb3a4fe817d237aa10bfe20357f7333bbf8f9 Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Thu, 22 Jun 2023 17:39:21 -0400 Subject: [PATCH 1/2] is_enforced --- snuba/query/allocation_policies/__init__.py | 5 ++++- snuba/settings/__init__.py | 5 +++++ snuba/settings/settings_test.py | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/snuba/query/allocation_policies/__init__.py b/snuba/query/allocation_policies/__init__.py index e99ccc6fb5..d01fe16b0b 100644 --- a/snuba/query/allocation_policies/__init__.py +++ b/snuba/query/allocation_policies/__init__.py @@ -395,7 +395,10 @@ def is_active(self) -> bool: @property def is_enforced(self) -> bool: - return bool(self.get_config_value(IS_ENFORCED)) + return ( + bool(self.get_config_value(IS_ENFORCED)) + and settings.ENFORCE_BYTES_SCANNED_WINDOW_POLICY + ) @property def max_threads(self) -> int: diff --git a/snuba/settings/__init__.py b/snuba/settings/__init__.py index 74a02f5f0f..f8bc3ad6a9 100644 --- a/snuba/settings/__init__.py +++ b/snuba/settings/__init__.py @@ -188,6 +188,7 @@ class RedisClusters(TypedDict): BULK_CLICKHOUSE_BUFFER = 10000 BULK_BINARY_LOAD_CHUNK = 2**22 # 4 MB + # Processor/Writer Options @@ -245,6 +246,10 @@ class RedisClusters(TypedDict): PROJECT_STACKTRACE_BLACKLIST: Set[int] = set() PRETTY_FORMAT_EXPRESSIONS = True +# Capacity Management + +ENFORCE_BYTES_SCANNED_WINDOW_POLICY = True + # By default, allocation policies won't block requests from going through in a production # environment to not cause incidents unnecessarily. If something goes wrong with allocation # policy code, the request will still be able to go through (but it will create a dangerous diff --git a/snuba/settings/settings_test.py b/snuba/settings/settings_test.py index d4f0fd5c36..42c7892788 100644 --- a/snuba/settings/settings_test.py +++ b/snuba/settings/settings_test.py @@ -26,6 +26,8 @@ # should fail on bad code RAISE_ON_ALLOCATION_POLICY_FAILURES = True +ENFORCE_BYTES_SCANNED_WINDOW_POLICY = True + # override replacer threshold to write to redis every time a replacement message is consumed REPLACER_PROCESSING_TIMEOUT_THRESHOLD = 0 # ms From d0a952f0c640f8f2d5c6d1600f1e9092637602bf Mon Sep 17 00:00:00 2001 From: Rahul Saini Date: Tue, 27 Jun 2023 13:56:08 -0400 Subject: [PATCH 2/2] description --- snuba/settings/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snuba/settings/__init__.py b/snuba/settings/__init__.py index f8bc3ad6a9..41dd922ddb 100644 --- a/snuba/settings/__init__.py +++ b/snuba/settings/__init__.py @@ -247,7 +247,9 @@ class RedisClusters(TypedDict): PRETTY_FORMAT_EXPRESSIONS = True # Capacity Management - +# HACK: This is necessary because single tenant does not have snuba-admin deployed / accessible +# so we can't change policy configs ourselves. This should be removed once we have snuba-admin +# available for single tenant since we can enable/disable policies at runtime there. ENFORCE_BYTES_SCANNED_WINDOW_POLICY = True # By default, allocation policies won't block requests from going through in a production