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

fix: flatten searchable os distribution fields #81297

Merged
merged 3 commits into from
Nov 28, 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
25 changes: 9 additions & 16 deletions src/sentry/rules/conditions/event_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def _handle(cls, path: list[str], event: GroupEvent) -> list[str]:
"stacktrace.package": Columns.STACK_PACKAGE,
"unreal.crashtype": Columns.UNREAL_CRASH_TYPE,
"app.in_foreground": Columns.APP_IN_FOREGROUND,
"os.distribution.name": Columns.OS_DISTRIBUTION_NAME,
"os.distribution.version": Columns.OS_DISTRIBUTION_VERSION,
"os.distribution_name": Columns.OS_DISTRIBUTION_NAME,
"os.distribution_version": Columns.OS_DISTRIBUTION_VERSION,
}


Expand Down Expand Up @@ -418,21 +418,14 @@ def _handle(cls, path: list[str], event: GroupEvent) -> list[str]:

@attribute_registry.register("os")
class OsAttributeHandler(AttributeHandler):
minimum_path_length = 3
minimum_path_length = 2

@classmethod
def _handle(cls, path: list[str], event: GroupEvent) -> list[str]:
if path[1] in ("distribution"):
if path[2] in ("name", "version"):
contexts = event.data.get("contexts", {})
os_context = contexts.get("os")
if os_context is None:
os_context = {}

distribution = os_context.get(path[1])
if distribution is None:
distribution = {}

return [distribution.get(path[2])]
return []
if path[1] in ("distribution_name", "distribution_version"):
contexts = event.data.get("contexts", {})
os_context = contexts.get("os")
if os_context is None:
os_context = {}
return [os_context.get(path[1])]
return []
24 changes: 12 additions & 12 deletions src/sentry/snuba/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,20 +601,20 @@ class Columns(Enum):
alias="app.in_foreground",
)
OS_DISTRIBUTION_NAME = Column(
group_name="events.contexts[os.distribution.name]",
event_name="contexts[os.distribution.name]",
transaction_name="contexts[os.distribution.name]",
discover_name="contexts[os.distribution.name]",
issue_platform_name="contexts[os.distribution.name]",
alias="os.distribution.name",
group_name="events.contexts[os.distribution_name]",
event_name="contexts[os.distribution_name]",
transaction_name="contexts[os.distribution_name]",
discover_name="contexts[os.distribution_name]",
issue_platform_name="contexts[os.distribution_name]",
alias="os.distribution_name",
)
OS_DISTRIBUTION_VERSION = Column(
group_name="events.contexts[os.distribution.version]",
event_name="contexts[os.distribution.version]",
transaction_name="contexts[os.distribution.version]",
discover_name="contexts[os.distribution.version]",
issue_platform_name="contexts[os.distribution.version]",
alias="os.distribution.version",
group_name="events.contexts[os.distribution_version]",
event_name="contexts[os.distribution_version]",
transaction_name="contexts[os.distribution_version]",
discover_name="contexts[os.distribution_version]",
issue_platform_name="contexts[os.distribution_version]",
alias="os.distribution_version",
)
# Transactions specific columns
TRANSACTION_OP = Column(
Expand Down
26 changes: 9 additions & 17 deletions tests/sentry/rules/conditions/test_event_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ def get_event(self, **kwargs):
"unreal": {
"crash_type": "crash",
},
"os": {
"distribution": {
"name": "ubuntu",
"version": "22.04",
}
},
"os": {"distribution_name": "ubuntu", "distribution_version": "22.04"},
},
"threads": {
"values": [
Expand Down Expand Up @@ -824,24 +819,21 @@ def test_app_in_foreground(self):
)
self.assertDoesNotPass(rule, event)

def test_os_distribution_only(self):
event = self.get_event()
rule = self.get_rule(
data={"match": MatchType.EQUAL, "attribute": "os.distribution", "value": "irrelevant"}
)
self.assertDoesNotPass(rule, event)

def test_os_distribution_name_and_version(self):
event = self.get_event()
rule = self.get_rule(
data={"match": MatchType.EQUAL, "attribute": "os.distribution.name", "value": "ubuntu"}
data={
"match": MatchType.EQUAL,
"attribute": "os.distribution_name",
"value": "ubuntu",
}
)
self.assertPasses(rule, event)

rule = self.get_rule(
data={
"match": MatchType.EQUAL,
"attribute": "os.distribution.version",
"attribute": "os.distribution_version",
"value": "22.04",
}
)
Expand All @@ -850,7 +842,7 @@ def test_os_distribution_name_and_version(self):
rule = self.get_rule(
data={
"match": MatchType.EQUAL,
"attribute": "os.distribution.name",
"attribute": "os.distribution_name",
"value": "slackware",
}
)
Expand All @@ -859,7 +851,7 @@ def test_os_distribution_name_and_version(self):
rule = self.get_rule(
data={
"match": MatchType.EQUAL,
"attribute": "os.distribution.version",
"attribute": "os.distribution_version",
"value": "20.04",
}
)
Expand Down
Loading