-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hackweek: Added Makefile entry to fetch schema; eliminate type errors #1198
Changes from 1 commit
ed2bb76
adb9ab7
782d9e3
82699e5
9d9688e
aac41eb
b8f3c93
7a76ce1
e0fddf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,14 +29,17 @@ | |
|
||
from jsonschema_typed import JSONSchema | ||
|
||
EventData = JSONSchema["/Users/untitaker/projects/snuba/event.schema.json"] | ||
EventData = JSONSchema["schema/event.schema.json"] | ||
|
||
|
||
class Event(TypedDict): | ||
data: EventData | ||
search_message: Any | ||
message: Any | ||
event_id: Any | ||
datetime: str | ||
group_id: str | ||
primary_hash: str | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -128,7 +131,7 @@ def extract_sdk( | |
output["sdk_integrations"] = sdk_integrations | ||
|
||
def process_message( | ||
self, message, metadata: Optional[KafkaMessageMetadata] = None | ||
self, message: Event, metadata: Optional[KafkaMessageMetadata] = None | ||
) -> Optional[ProcessedMessage]: | ||
"""\ | ||
Process a raw message into a tuple of (action_type, processed_message): | ||
|
@@ -137,11 +140,13 @@ def process_message( | |
Returns `None` if the event is too old to be written. | ||
""" | ||
action_type = None | ||
processed: Optional[MutableMapping[str, Any]] = None | ||
|
||
if isinstance(message, dict): | ||
# deprecated unwrapped event message == insert | ||
action_type = ProcessorAction.INSERT | ||
try: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intentional ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. |
||
processed = self.process_insert(message, metadata) | ||
except EventTooOld: | ||
return None | ||
|
@@ -206,11 +211,12 @@ def process_message( | |
|
||
def process_insert( | ||
self, event: Event, metadata: Optional[KafkaMessageMetadata] = None | ||
) -> Optional[Mapping[str, Any]]: | ||
) -> Optional[MutableMapping[str, Any]]: | ||
if not self._should_process(event): | ||
return None | ||
|
||
processed = {"deleted": 0} | ||
processed: MutableMapping[str, Any] = {"deleted": 0} | ||
|
||
extract_project_id(processed, event) | ||
self._extract_event_id(processed, event) | ||
processed["retention_days"] = enforce_retention( | ||
|
@@ -228,7 +234,7 @@ def process_insert( | |
self.extract_common(processed, event, metadata) | ||
self.extract_custom(processed, event, metadata) | ||
|
||
sdk = data.get("sdk", None) or {} | ||
sdk = data.get("sdk", None) or {} # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the issue here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "sdk" does not exists on the data object. |
||
self.extract_sdk(processed, sdk) | ||
|
||
tags = _as_dict_safe(data.get("tags", None)) | ||
|
@@ -248,9 +254,13 @@ def process_insert( | |
) | ||
|
||
exception = ( | ||
data.get("exception", data.get("sentry.interfaces.Exception", None)) or {} | ||
data.get( | ||
"exception", | ||
data.get("sentry.interfaces.Exception", None), # type: ignore | ||
) | ||
or {} | ||
) | ||
stacks = exception.get("values", None) or [] | ||
stacks: Sequence[Any] = exception.get("values", None) or [] | ||
self.extract_stacktraces(processed, stacks) | ||
|
||
if metadata is not None: | ||
|
@@ -273,15 +283,15 @@ def extract_common( | |
|
||
# Properties we get from the "data" dict, which is the actual event body. | ||
|
||
received = _collapse_uint32(int(data["received"])) | ||
received = _collapse_uint32(data["received"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The extra |
||
output["received"] = ( | ||
datetime.utcfromtimestamp(received) if received is not None else None | ||
) | ||
output["culprit"] = _unicodify(data.get("culprit", None)) | ||
output["type"] = _unicodify(data.get("type", None)) | ||
output["version"] = _unicodify(data.get("version", None)) | ||
output["title"] = _unicodify(data.get("title", None)) | ||
output["location"] = _unicodify(data.get("location", None)) | ||
output["title"] = _unicodify(data.get("title", None)) # type: ignore | ||
output["location"] = _unicodify(data.get("location", None)) # type: ignore | ||
|
||
module_names = [] | ||
module_versions = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class is duplicate of InsertEvent below. We should have only one.