Skip to content

Commit ce17387

Browse files
authored
feat(ingest): DLQ all non-retriable messages even if schema is valid (#67200)
Since ingest messages contain json bytes inside a msgpack payload the schema cannot be relied on to determine whether to DLQ, as the inner message can be invalid even if schema checking still passes. This now DLQs any exception that is not marked Retriable.
1 parent 871522d commit ce17387

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

src/sentry/ingest/consumer/processors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ def process_event(
8787
# keeping it around because it does provide some protection against
8888
# reprocessing good events if a single consumer is in a restart loop.
8989
deduplication_key = f"ev:{project_id}:{event_id}"
90-
if cache.get(deduplication_key) is not None:
90+
91+
try:
92+
cached_value = cache.get(deduplication_key)
93+
except Exception as exc:
94+
raise Retriable(exc)
95+
96+
if cached_value is not None:
9197
logger.warning(
9298
"pre-process-forwarder detected a duplicated event" " with id:%s for project:%s.",
9399
event_id,

src/sentry/ingest/consumer/simple_event.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
import msgpack
4-
import sentry_kafka_schemas
54
from arroyo.backends.kafka.consumer import KafkaPayload
65
from arroyo.dlq import InvalidMessage
76
from arroyo.types import BrokerValue, Message
@@ -71,23 +70,12 @@ def process_simple_event_message(
7170
if isinstance(exc, Retriable):
7271
raise
7372

74-
# If no retriable exception was raised, check the schema to decide whether to DLQ
73+
# TODO: Remove this line once all topics (transactions, attachments,
74+
# user feedback) also have DLQs
7575
default_topic = consumer_type_to_default_topic[consumer_type].value
76-
77-
# TODO: Currently, there is only a schema for ingest-events, so just continue to re-raise
78-
# the exception if it's a different topic. This can be removed once attachments and transactions
79-
# have schemas too.
8076
if default_topic != "ingest-events":
8177
raise
8278

83-
codec = sentry_kafka_schemas.get_codec(default_topic)
84-
85-
try:
86-
codec.decode(raw_payload, validate=True)
87-
except Exception:
88-
raw_value = raw_message.value
89-
assert isinstance(raw_value, BrokerValue)
90-
91-
raise InvalidMessage(raw_value.partition, raw_value.offset)
92-
93-
raise
79+
raw_value = raw_message.value
80+
assert isinstance(raw_value, BrokerValue)
81+
raise InvalidMessage(raw_value.partition, raw_value.offset) from exc

0 commit comments

Comments
 (0)