Skip to content

Commit 1876be1

Browse files
JoshFergeMichaelSun48
authored andcommitted
feat(feedback): set feedback issue to ignored if spam (#69479)
- If the message is spam, set it to be ignored by producing a status change message to the occurrence consumer. There is not a way currently to set an issues state to ignored upon creation, but this should set it to ignored pretty close to immediate. Note that there is sometimes buggy with issue occurrence messages sometimes processed out of order, but there is some ongoing work with issue platform to fix this soon.
1 parent 133757e commit 1876be1

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/sentry/feedback/usecases/create_feedback.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from sentry.issues.issue_occurrence import IssueEvidence, IssueOccurrence
1717
from sentry.issues.json_schemas import EVENT_PAYLOAD_SCHEMA, LEGACY_EVENT_PAYLOAD_SCHEMA
1818
from sentry.issues.producer import PayloadType, produce_occurrence_to_kafka
19+
from sentry.issues.status_change_message import StatusChangeMessage
20+
from sentry.models.group import GroupStatus
1921
from sentry.models.project import Project
2022
from sentry.signals import first_feedback_received, first_new_feedback_received
2123
from sentry.utils import metrics
@@ -194,13 +196,12 @@ def create_feedback_issue(event, project_id, source: FeedbackCreationSource):
194196
evidence_data, evidence_display = make_evidence(
195197
event["contexts"]["feedback"], source, is_message_spam
196198
)
199+
issue_fingerprint = [uuid4().hex]
197200
occurrence = IssueOccurrence(
198201
id=uuid4().hex,
199202
event_id=event.get("event_id") or uuid4().hex,
200203
project_id=project_id,
201-
fingerprint=[
202-
uuid4().hex
203-
], # random UUID for fingerprint so feedbacks are grouped individually
204+
fingerprint=issue_fingerprint, # random UUID for fingerprint so feedbacks are grouped individually
204205
issue_title="User Feedback",
205206
subtitle=event["contexts"]["feedback"]["message"],
206207
resource_id=None,
@@ -240,6 +241,16 @@ def create_feedback_issue(event, project_id, source: FeedbackCreationSource):
240241
produce_occurrence_to_kafka(
241242
payload_type=PayloadType.OCCURRENCE, occurrence=occurrence, event_data=event_fixed
242243
)
244+
if is_message_spam:
245+
produce_occurrence_to_kafka(
246+
payload_type=PayloadType.STATUS_CHANGE,
247+
status_change=StatusChangeMessage(
248+
fingerprint=issue_fingerprint,
249+
project_id=project_id,
250+
new_status=GroupStatus.RESOLVED,
251+
new_substatus=None,
252+
),
253+
)
243254
metrics.incr(
244255
"feedback.create_feedback_issue.produced_occurrence",
245256
tags={"referrer": source.value},

tests/sentry/feedback/usecases/test_create_feedback.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
fix_for_issue_platform,
1515
validate_issue_platform_event_schema,
1616
)
17+
from sentry.models.group import GroupStatus
1718
from sentry.testutils.helpers import Feature
1819
from sentry.testutils.pytest.fixtures import django_db_all
1920

@@ -528,12 +529,22 @@ def dummy_response(*args, **kwargs):
528529
# Check if the 'is_spam' evidence in the Kafka message matches the expected result
529530
is_spam_evidence = [
530531
evidence.value
531-
for evidence in mock_produce_occurrence_to_kafka.call_args.kwargs[
532-
"occurrence"
533-
].evidence_display
532+
for evidence in mock_produce_occurrence_to_kafka.call_args_list[0]
533+
.kwargs["occurrence"]
534+
.evidence_display
534535
if evidence.name == "is_spam"
535536
]
536537
found_is_spam = is_spam_evidence[0] if is_spam_evidence else None
537538
assert (
538539
found_is_spam == expected_result
539540
), f"Expected {expected_result} but found {found_is_spam} for {input_message} and feature flag {feature_flag}"
541+
542+
if expected_result and feature_flag:
543+
assert (
544+
mock_produce_occurrence_to_kafka.call_args_list[1]
545+
.kwargs["status_change"]
546+
.new_status
547+
== GroupStatus.RESOLVED
548+
)
549+
if not (expected_result and feature_flag):
550+
assert mock_produce_occurrence_to_kafka.call_count == 1

0 commit comments

Comments
 (0)