-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DLQ unprocessable messages on ingest-events (#66236)
This PR depends on getsentry/sentry-kafka-schemas#230 It attempts to be somewhat cautious about DLQing and not DLQ anything that is even potentially retriable. This could be tweaked later. If a non-retriable exception is raised, the consumer tries to further determine whether the message is actually bad (or it's some transient retriable error) by validating the message against the schema. The message will be DLQed only if that also fails.
- Loading branch information
Showing
5 changed files
with
203 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import time | ||
from datetime import datetime | ||
from unittest.mock import Mock | ||
|
||
import msgpack | ||
import pytest | ||
from arroyo.backends.kafka import KafkaPayload | ||
from arroyo.dlq import InvalidMessage | ||
from arroyo.types import BrokerValue, Message, Partition, Topic | ||
|
||
from sentry.ingest.consumer.factory import IngestStrategyFactory | ||
from sentry.testutils.pytest.fixtures import django_db_all | ||
|
||
|
||
def make_message(payload: bytes, partition: Partition, offset: int) -> Message: | ||
return Message( | ||
BrokerValue( | ||
KafkaPayload(None, payload, []), | ||
partition, | ||
offset, | ||
datetime.now(), | ||
) | ||
) | ||
|
||
|
||
@django_db_all | ||
def test_dlq_invalid_messages(factories) -> None: | ||
organization = factories.create_organization() | ||
project = factories.create_project(organization=organization) | ||
|
||
valid_payload = msgpack.packb( | ||
{ | ||
"type": "event", | ||
"project_id": project.id, | ||
"payload": b"{}", | ||
"start_time": int(time.time()), | ||
"event_id": "aaa", | ||
} | ||
) | ||
|
||
bogus_payload = b"bogus message" | ||
|
||
partition = Partition(Topic("ingest-events"), 0) | ||
offset = 5 | ||
|
||
factory = IngestStrategyFactory( | ||
"events", | ||
reprocess_only_stuck_events=False, | ||
num_processes=1, | ||
max_batch_size=1, | ||
max_batch_time=1, | ||
input_block_size=None, | ||
output_block_size=None, | ||
) | ||
strategy = factory.create_with_partitions(Mock(), Mock()) | ||
|
||
# Valid payload raises original error | ||
with pytest.raises(Exception) as exc_info: | ||
message = make_message(valid_payload, partition, offset) | ||
strategy.submit(message) | ||
assert not isinstance(exc_info.value, InvalidMessage) | ||
|
||
# Invalid payload raises InvalidMessage error | ||
|
||
with pytest.raises(InvalidMessage) as exc_info: | ||
message = make_message(bogus_payload, partition, offset) | ||
strategy.submit(message) | ||
|
||
assert exc_info.value.partition == partition | ||
assert exc_info.value.offset == offset |