Skip to content

feat(auto_source_config): Add feature flag to control Java's dry-run #88087

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

Merged
merged 2 commits into from
Mar 27, 2025
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
2 changes: 2 additions & 0 deletions src/sentry/features/temporary.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def register_temporary_features(manager: FeatureManager):
manager.add("organizations:issue-search-group-attributes-side-query", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
# Enable custom views features in the issue stream
manager.add("organizations:issue-stream-custom-views", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Control if Java dry run is enabled
manager.add("organizations:auto-source-code-config-java-enabled", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
# Enable left nav issue views
manager.add("organizations:left-nav-issue-views", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=True)
# Enable the updated empty state for issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ def save_in_app_stack_trace_rules(
current_rules = set(current_enhancements.split("\n")) if current_enhancements else set()

united_rules = rules_from_code_mappings.union(current_rules)
if not platform_config.is_dry_run_platform() and united_rules != current_rules:
dry_run = platform_config.is_dry_run_platform(project.organization)
if not dry_run and united_rules != current_rules:
project.update_option(DERIVED_ENHANCEMENTS_OPTION_KEY, "\n".join(sorted(united_rules)))

new_rules_added = united_rules - current_rules
metrics.incr(
key=f"{METRIC_PREFIX}.in_app_stack_trace_rules.created",
amount=len(new_rules_added),
tags={
"platform": platform_config.platform,
"dry_run": platform_config.is_dry_run_platform(),
},
tags={"platform": platform_config.platform, "dry_run": dry_run},
sample_rate=1.0,
)
return list(new_rules_added)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/issues/auto_source_code_config/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def create_configurations(
if not org_integration:
raise InstallationNotFoundError

dry_run = platform_config.is_dry_run_platform()
dry_run = platform_config.is_dry_run_platform(project.organization)
platform = platform_config.platform
tags: Mapping[str, str | bool] = {"platform": platform, "dry_run": dry_run}
with metrics.timer(f"{METRIC_PREFIX}.create_configurations.duration", tags=tags):
Expand Down
11 changes: 9 additions & 2 deletions src/sentry/issues/auto_source_code_config/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Any

from sentry import features
from sentry.models.organization import Organization

from .constants import PLATFORMS_CONFIG


Expand Down Expand Up @@ -35,8 +38,12 @@ def __init__(self, platform: str) -> None:
def is_supported(self) -> bool:
return self.config is not None

def is_dry_run_platform(self) -> bool:
return self.config.get("dry_run", False)
def is_dry_run_platform(self, org: Organization) -> bool:
return (
not features.has("organizations:auto-source-code-config-java-enabled", org, actor=None)
if self.platform == "java"
else self.config.get("dry_run", False)
)

def extracts_filename_from_module(self) -> bool:
return self.config.get("extract_filename_from_module", False)
Expand Down
198 changes: 98 additions & 100 deletions tests/sentry/issues/auto_source_code_config/test_process_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sentry.shared_integrations.exceptions import ApiError
from sentry.testutils.asserts import assert_failure_metric, assert_halt_metric
from sentry.testutils.cases import TestCase
from sentry.testutils.helpers import with_feature
from sentry.testutils.silo import assume_test_silo_mode_of
from sentry.testutils.skips import requires_snuba
from sentry.utils.locking import UnableToAcquireLock
Expand Down Expand Up @@ -89,7 +90,7 @@ def _process_and_assert_configuration_changes(
expected_new_in_app_stack_trace_rules: list[str] | None = None,
) -> GroupEvent:
platform_config = PlatformConfig(platform)
dry_run = platform_config.is_dry_run_platform()
dry_run = platform_config.is_dry_run_platform(self.organization)
tags = {"dry_run": dry_run, "platform": platform}
with (
patch(f"{CLIENT}.get_tree", side_effect=create_mock_get_tree(repo_trees)),
Expand Down Expand Up @@ -663,6 +664,7 @@ def test_multiple_configuration_changes(self) -> None:
],
)

@with_feature({"organizations:auto-source-code-config-java-enabled": True})
def test_multiple_tlds(self) -> None:
# XXX: Multiple TLDs cause over in-app categorization
# Think of uk.co company using packages from another uk.co company
Expand All @@ -672,64 +674,62 @@ def test_multiple_tlds(self) -> None:
self.frame(module="uk.co.not-example.baz.qux", abs_path="qux.kt", in_app=False),
]

# Let's pretend we're not running as dry-run
with patch(f"{CODE_ROOT}.utils.PlatformConfig.is_dry_run_platform", return_value=False):
event = self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/uk/co/example/foo/Bar.kt"]},
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
# XXX: Notice that we loose "example"
self.code_mapping(stack_root="uk/co/", source_root="src/uk/co/"),
],
expected_new_in_app_stack_trace_rules=["stack.module:uk.co.** +app"],
)
assert event.data["metadata"]["in_app_frame_mix"] == "system-only"

event = self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/uk/co/example/foo/Bar.kt"]},
frames=frames,
platform=self.platform,
)
# It's in-app-only because even the not-example package is in-app
assert event.data["metadata"]["in_app_frame_mix"] == "in-app-only"
event = self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/uk/co/example/foo/Bar.kt"]},
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
# XXX: Notice that we loose "example"
self.code_mapping(stack_root="uk/co/", source_root="src/uk/co/"),
],
expected_new_in_app_stack_trace_rules=["stack.module:uk.co.** +app"],
)
assert event.data["metadata"]["in_app_frame_mix"] == "system-only"

# The developer can undo our rule
self.project.update_option(
"sentry:grouping_enhancements",
"stack.module:uk.co.not-example.** -app",
)
event = self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/uk/co/example/foo/Bar.kt"]},
frames=frames,
platform=self.platform,
)
assert event.data["metadata"]["in_app_frame_mix"] == "mixed"
event_frames = event.data["stacktrace"]["frames"]
assert event_frames[0]["module"] == "uk.co.example.foo.Bar"
assert event_frames[0]["in_app"] is True
assert event_frames[1]["module"] == "uk.co.not-example.baz.qux"
assert event_frames[1]["in_app"] is False
event = self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/uk/co/example/foo/Bar.kt"]},
frames=frames,
platform=self.platform,
)
# It's in-app-only because even the not-example package is in-app
assert event.data["metadata"]["in_app_frame_mix"] == "in-app-only"

# The developer can undo our rule
self.project.update_option(
"sentry:grouping_enhancements",
"stack.module:uk.co.not-example.** -app",
)
event = self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/uk/co/example/foo/Bar.kt"]},
frames=frames,
platform=self.platform,
)
assert event.data["metadata"]["in_app_frame_mix"] == "mixed"
event_frames = event.data["stacktrace"]["frames"]
assert event_frames[0]["module"] == "uk.co.example.foo.Bar"
assert event_frames[0]["in_app"] is True
assert event_frames[1]["module"] == "uk.co.not-example.baz.qux"
assert event_frames[1]["in_app"] is False

@with_feature({"organizations:auto-source-code-config-java-enabled": True})
def test_do_not_clobber_rules(self) -> None:
# Let's pretend we're not running as dry-run
with patch(f"{CODE_ROOT}.utils.PlatformConfig.is_dry_run_platform", return_value=False):
self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/a/Bar.java", "src/x/y/Baz.java"]},
frames=[self.frame(module="a.Bar", abs_path="Bar.java", in_app=False)],
platform=self.platform,
expected_new_code_mappings=[self.code_mapping("a/", "src/a/")],
expected_new_in_app_stack_trace_rules=["stack.module:a.** +app"],
)
self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/a/Bar.java", "src/x/y/Baz.java"]},
frames=[self.frame(module="x.y.Baz", abs_path="Baz.java", in_app=False)],
platform=self.platform,
expected_new_code_mappings=[self.code_mapping("x/y/", "src/x/y/")],
# Both rules should exist
expected_new_in_app_stack_trace_rules=["stack.module:x.y.** +app"],
)
self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/a/Bar.java", "src/x/y/Baz.java"]},
frames=[self.frame(module="a.Bar", abs_path="Bar.java", in_app=False)],
platform=self.platform,
expected_new_code_mappings=[self.code_mapping("a/", "src/a/")],
expected_new_in_app_stack_trace_rules=["stack.module:a.** +app"],
)
self._process_and_assert_configuration_changes(
repo_trees={REPO1: ["src/a/Bar.java", "src/x/y/Baz.java"]},
frames=[self.frame(module="x.y.Baz", abs_path="Baz.java", in_app=False)],
platform=self.platform,
expected_new_code_mappings=[self.code_mapping("x/y/", "src/x/y/")],
# Both rules should exist
expected_new_in_app_stack_trace_rules=["stack.module:x.y.** +app"],
)

@with_feature({"organizations:auto-source-code-config-java-enabled": True})
def test_run_without_dry_run(self) -> None:
repo_trees = {REPO1: ["src/com/example/foo/Bar.kt"]}
frames = [
Expand All @@ -739,48 +739,46 @@ def test_run_without_dry_run(self) -> None:
rule = "stack.module:com.example.**"
expected_in_app_rule = f"{rule} +app"

# Let's pretend we're not running as dry-run
with patch(f"{CODE_ROOT}.utils.PlatformConfig.is_dry_run_platform", return_value=False):
event = self._process_and_assert_configuration_changes(
repo_trees=repo_trees,
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
self.code_mapping(stack_root="com/example/", source_root="src/com/example/"),
],
expected_new_in_app_stack_trace_rules=[expected_in_app_rule],
)
# The effects of the configuration changes will be noticed on the second event processing
assert event.data["metadata"]["in_app_frame_mix"] == "system-only"
assert len(event.data["hashes"]) == 1 # Only system hash
system_only_hash = event.data["hashes"][0]
first_enhancements_base64_string = event.data["grouping_config"]["enhancements"]
group_id = event.group_id

# Running a second time will not create any new configurations, however,
# the rules from the previous run will be applied to the event's stack trace
event = self._process_and_assert_configuration_changes(
repo_trees=repo_trees, frames=frames, platform=self.platform
)
assert event.group_id == group_id # The new rules did not cause new groups
assert event.data["metadata"]["in_app_frame_mix"] == "mixed"
second_enhancements_hash = event.data["grouping_config"]["enhancements"]
# The enhancements now contain the automatic rule (+app)
assert second_enhancements_hash != first_enhancements_base64_string
assert len(event.data["hashes"]) == 2
event.data["hashes"].remove(system_only_hash)
in_app_hash = event.data["hashes"][0]
assert in_app_hash != system_only_hash

# The developer will add a rule to invalidate our automatinc rule (-app)
self.project.update_option("sentry:grouping_enhancements", f"{rule} -app")
event = self._process_and_assert_configuration_changes(
repo_trees=repo_trees, frames=frames, platform=self.platform
)
# Back to system-only
assert event.data["metadata"]["in_app_frame_mix"] == "system-only"
assert event.group_id == group_id # It still belongs to the same group
assert event.data["hashes"] == [system_only_hash]
# The enhancements now contain the automatic rule (+app) and the developer's rule (-app)
assert event.data["grouping_config"]["enhancements"] != first_enhancements_base64_string
assert event.data["grouping_config"]["enhancements"] != second_enhancements_hash
event = self._process_and_assert_configuration_changes(
repo_trees=repo_trees,
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
self.code_mapping(stack_root="com/example/", source_root="src/com/example/"),
],
expected_new_in_app_stack_trace_rules=[expected_in_app_rule],
)
# The effects of the configuration changes will be noticed on the second event processing
assert event.data["metadata"]["in_app_frame_mix"] == "system-only"
assert len(event.data["hashes"]) == 1 # Only system hash
system_only_hash = event.data["hashes"][0]
first_enhancements_base64_string = event.data["grouping_config"]["enhancements"]
group_id = event.group_id

# Running a second time will not create any new configurations, however,
# the rules from the previous run will be applied to the event's stack trace
event = self._process_and_assert_configuration_changes(
repo_trees=repo_trees, frames=frames, platform=self.platform
)
assert event.group_id == group_id # The new rules did not cause new groups
assert event.data["metadata"]["in_app_frame_mix"] == "mixed"
second_enhancements_hash = event.data["grouping_config"]["enhancements"]
# The enhancements now contain the automatic rule (+app)
assert second_enhancements_hash != first_enhancements_base64_string
assert len(event.data["hashes"]) == 2
event.data["hashes"].remove(system_only_hash)
in_app_hash = event.data["hashes"][0]
assert in_app_hash != system_only_hash

# The developer will add a rule to invalidate our automatinc rule (-app)
self.project.update_option("sentry:grouping_enhancements", f"{rule} -app")
event = self._process_and_assert_configuration_changes(
repo_trees=repo_trees, frames=frames, platform=self.platform
)
# Back to system-only
assert event.data["metadata"]["in_app_frame_mix"] == "system-only"
assert event.group_id == group_id # It still belongs to the same group
assert event.data["hashes"] == [system_only_hash]
# The enhancements now contain the automatic rule (+app) and the developer's rule (-app)
assert event.data["grouping_config"]["enhancements"] != first_enhancements_base64_string
assert event.data["grouping_config"]["enhancements"] != second_enhancements_hash
Loading