Skip to content

Commit

Permalink
feat(suspect-spans): Allow enabling ingestion by percentage (#2181)
Browse files Browse the repository at this point in the history
Previously, suspect span ingestion can only be enabled on a per project basis.
This change allows us to enable it for a percentage of projects at a time. See
getsentry/getsentry#6531 and getsentry/sentry#29692  for the sentry PRs.
  • Loading branch information
Zylphrex authored Nov 3, 2021
1 parent 3a4f453 commit f664b7a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
10 changes: 8 additions & 2 deletions snuba/datasets/transactions_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
_ensure_valid_ip,
_unicodify,
)
from snuba.state import get_config, is_project_in_rollout_group
from snuba.state import (
get_config,
is_project_in_rollout_group,
is_project_in_rollout_list,
)
from snuba.utils.metrics.wrapper import MetricsWrapper

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -299,8 +303,10 @@ def _process_spans(
max_spans_per_transaction = 2000

try:
if not is_project_in_rollout_group(
if not is_project_in_rollout_list(
"write_span_columns_projects", processed["project_id"]
) and not is_project_in_rollout_group(
"write_span_columns_rollout_percentage", processed["project_id"]
):
return

Expand Down
23 changes: 22 additions & 1 deletion snuba/state/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,15 @@ def get_queries() -> Sequence[Mapping[str, Optional[Any]]]:
return queries


def is_project_in_rollout_group(rollout_key: str, project_id: int) -> bool:
def is_project_in_rollout_list(rollout_key: str, project_id: int) -> bool:
"""
Helper function for doing selective rollouts by project ids. The config
value is assumed to be a string of the form `[project,project,...]`.
Returns `True` if `project_id` is present in the config.
"""
project_rollout_setting = get_config(rollout_key, "")
assert isinstance(project_rollout_setting, str)
if project_rollout_setting:
# The expected format is [project,project,...]
project_rollout_setting = project_rollout_setting[1:-1]
Expand All @@ -268,3 +275,17 @@ def is_project_in_rollout_group(rollout_key: str, project_id: int) -> bool:
if int(p.strip()) == project_id:
return True
return False


def is_project_in_rollout_group(rollout_key: str, project_id: int) -> bool:
"""
Helper function for doing consistent incremental rollouts by project ids.
The config value is assumed to be an integer between 0 and 100.
Returns `True` if `project_id` falls within the rollout group.
"""
project_rollout_percentage = get_config(rollout_key, 0)
assert isinstance(project_rollout_percentage, (int, float))
if project_rollout_percentage:
return project_id % 100 < project_rollout_percentage
return False
2 changes: 1 addition & 1 deletion tests/datasets/test_transaction_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def test_missing_trace_context(self) -> None:
def test_base_process(self) -> None:
old_skip_context = settings.TRANSACT_SKIP_CONTEXT_STORE
settings.TRANSACT_SKIP_CONTEXT_STORE = {1: {"experiments"}}
set_config("write_span_columns_projects", "[1]")
set_config("write_span_columns_rollout_percentage", 100)

start, finish = self.__get_timestamps()
message = TransactionEvent(
Expand Down

0 comments on commit f664b7a

Please sign in to comment.