-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crons): Add empty incident_occurrences_consumer (#80527)
Part of GH-79328
- Loading branch information
1 parent
49ce622
commit 5fc9f67
Showing
10 changed files
with
107 additions
and
3 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
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
43 changes: 43 additions & 0 deletions
43
src/sentry/monitors/consumers/incident_occurrences_consumer.py
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,43 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from collections.abc import Mapping | ||
|
||
from arroyo.backends.kafka.consumer import KafkaPayload | ||
from arroyo.processing.strategies.abstract import ProcessingStrategy, ProcessingStrategyFactory | ||
from arroyo.processing.strategies.commit import CommitOffsets | ||
from arroyo.processing.strategies.run_task import RunTask | ||
from arroyo.types import BrokerValue, Commit, FilteredPayload, Message, Partition | ||
from sentry_kafka_schemas.codecs import Codec | ||
from sentry_kafka_schemas.schema_types.monitors_incident_occurrences_v1 import IncidentOccurrence | ||
|
||
from sentry.conf.types.kafka_definition import Topic, get_topic_codec | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
MONITORS_INCIDENT_OCCURRENCES: Codec[IncidentOccurrence] = get_topic_codec( | ||
Topic.MONITORS_INCIDENT_OCCURRENCES | ||
) | ||
|
||
|
||
def process_incident_occurrence(message: Message[KafkaPayload | FilteredPayload]): | ||
assert not isinstance(message.payload, FilteredPayload) | ||
assert isinstance(message.value, BrokerValue) | ||
|
||
# wrapper: IncidentOccurrence = MONITORS_INCIDENT_OCCURRENCES.decode(message.payload.value) | ||
# TODO(epurkhiser): Do something with issue occurrence | ||
|
||
|
||
class MonitorIncidentOccurenceStrategyFactory(ProcessingStrategyFactory[KafkaPayload]): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def create_with_partitions( | ||
self, | ||
commit: Commit, | ||
partitions: Mapping[Partition, int], | ||
) -> ProcessingStrategy[KafkaPayload]: | ||
return RunTask( | ||
function=process_incident_occurrence, | ||
next_step=CommitOffsets(commit), | ||
) |
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
53 changes: 53 additions & 0 deletions
53
tests/sentry/monitors/consumers/test_incident_occurrence_consumer.py
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,53 @@ | ||
from datetime import datetime | ||
from unittest import mock | ||
|
||
from arroyo.backends.kafka import KafkaPayload | ||
from arroyo.processing.strategies import ProcessingStrategy | ||
from arroyo.types import BrokerValue, Message, Partition, Topic | ||
from django.utils import timezone | ||
from sentry_kafka_schemas.schema_types.monitors_incident_occurrences_v1 import IncidentOccurrence | ||
|
||
from sentry.monitors.consumers.incident_occurrences_consumer import ( | ||
MONITORS_INCIDENT_OCCURRENCES, | ||
MonitorIncidentOccurenceStrategyFactory, | ||
) | ||
|
||
partition = Partition(Topic("test"), 0) | ||
|
||
|
||
def create_consumer() -> ProcessingStrategy[KafkaPayload]: | ||
factory = MonitorIncidentOccurenceStrategyFactory() | ||
commit = mock.Mock() | ||
return factory.create_with_partitions(commit, {partition: 0}) | ||
|
||
|
||
def sned_incident_occurrence( | ||
consumer: ProcessingStrategy[KafkaPayload], | ||
ts: datetime, | ||
incident_occurrence: IncidentOccurrence, | ||
): | ||
value = BrokerValue( | ||
KafkaPayload(b"fake-key", MONITORS_INCIDENT_OCCURRENCES.encode(incident_occurrence), []), | ||
partition, | ||
1, | ||
ts, | ||
) | ||
consumer.submit(Message(value)) | ||
|
||
|
||
def test_simple(): | ||
# XXX(epurkhiser): Doesn't really test anything yet | ||
ts = timezone.now().replace(second=0, microsecond=0) | ||
|
||
consumer = create_consumer() | ||
sned_incident_occurrence( | ||
consumer, | ||
ts, | ||
{ | ||
"clock_tick_ts": 1617895645, | ||
"received_ts": 1617895650, | ||
"failed_checkin_id": 123456, | ||
"incident_id": 987654, | ||
"previous_checkin_ids": [111222, 333444, 55666], | ||
}, | ||
) |