Skip to content

Commit

Permalink
fix: flatten searchable os distribution fields (#81297)
Browse files Browse the repository at this point in the history
<!-- Describe your PR here. -->
update to #69865
To search the distribution fields, we cannot have them in a hierarchy
`os.distribution.name`, we instead need them flattened to
`os.distribution_name`

This is part of reworking the following native-SDK PR:
getsentry/sentry-native#963

The update is also tracked on the docs side:
getsentry/sentry-docs#11936
And on Relay: getsentry/relay#4292
  • Loading branch information
JoshuaMoelans authored and andrewshie-sentry committed Dec 2, 2024
1 parent 0e4cc30 commit 47054f4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 45 deletions.
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

0 comments on commit 47054f4

Please sign in to comment.