Skip to content
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

ref(event_manager): Fix typing issues for event_manager #52974

Merged
merged 8 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ module = [
"sentry.discover.endpoints.discover_key_transactions",
"sentry.discover.endpoints.serializers",
"sentry.discover.tasks",
"sentry.event_manager",
"sentry.eventstore.base",
"sentry.eventstore.compressor",
"sentry.eventstore.models",
Expand Down Expand Up @@ -1157,7 +1156,6 @@ module = [
"tests.sentry.eventstore.test_models",
"tests.sentry.eventstream.kafka.test_protocol",
"tests.sentry.eventstream.test_eventstream",
"tests.sentry.eventtypes.test_default",
"tests.sentry.eventtypes.test_error",
"tests.sentry.features.test_manager",
"tests.sentry.grouping.test_enhancer",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/attachments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ["attachment_cache", "CachedAttachment"]
__all__ = ["attachment_cache", "CachedAttachment", "MissingAttachmentChunks"]

from django.conf import settings

Expand Down
39 changes: 11 additions & 28 deletions src/sentry/event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Optional,
Sequence,
Tuple,
Type,
TypedDict,
Union,
cast,
Expand Down Expand Up @@ -55,15 +54,8 @@
from sentry.culprit import generate_culprit
from sentry.dynamic_sampling import LatestReleaseBias, LatestReleaseParams
from sentry.eventstore.processing import event_processing_store
from sentry.eventtypes import (
CspEvent,
DefaultEvent,
ErrorEvent,
ExpectCTEvent,
ExpectStapleEvent,
HpkpEvent,
TransactionEvent,
)
from sentry.eventtypes import EventType
from sentry.eventtypes.transaction import TransactionEvent
from sentry.grouping.api import (
BackgroundGroupingConfigLoader,
GroupingConfig,
Expand Down Expand Up @@ -1249,13 +1241,15 @@ def _tsdb_record_all_metrics(jobs: Sequence[Job]) -> None:
records.append((TSDBModel.users_affected_by_project, project_id, (user.tag_value,)))

if incrs:
tsdb.incr_multi(incrs, timestamp=event.datetime, environment_id=environment.id)
tsdb.backend.incr_multi(incrs, timestamp=event.datetime, environment_id=environment.id)

if records:
tsdb.record_multi(records, timestamp=event.datetime, environment_id=environment.id)
tsdb.backend.record_multi(
records, timestamp=event.datetime, environment_id=environment.id
)

if frequencies:
tsdb.record_frequency_multi(frequencies, timestamp=event.datetime)
tsdb.backend.record_frequency_multi(frequencies, timestamp=event.datetime)


@metrics.wraps("save_event.nodestore_save_many")
Expand Down Expand Up @@ -1427,17 +1421,6 @@ def _get_event_user_impl(
return euser


EventType = Union[
DefaultEvent,
ErrorEvent,
CspEvent,
HpkpEvent,
ExpectCTEvent,
ExpectStapleEvent,
TransactionEvent,
]


def get_event_type(data: Mapping[str, Any]) -> EventType:
return eventtypes.get(data.get("type", "default"))()

Expand Down Expand Up @@ -1911,7 +1894,7 @@ def _process_existing_aggregate(
return bool(is_regression)


Attachment = Type[CachedAttachment]
Attachment = CachedAttachment


def discard_event(job: Job, attachments: Sequence[Attachment]) -> None:
Expand All @@ -1927,7 +1910,7 @@ def discard_event(job: Job, attachments: Sequence[Attachment]) -> None:

project = job["event"].project

quotas.refund(
quotas.backend.refund(
project,
key=job["project_key"],
timestamp=job["start_time"],
Expand Down Expand Up @@ -1964,7 +1947,7 @@ def discard_event(job: Job, attachments: Sequence[Attachment]) -> None:
)

if attachment_quantity:
quotas.refund(
quotas.backend.refund(
project,
key=job["project_key"],
timestamp=job["start_time"],
Expand Down Expand Up @@ -2088,7 +2071,7 @@ def filter_attachments_for_group(attachments: list[Attachment], job: Job) -> lis
cache.set(crashreports_key, max_crashreports, CRASH_REPORT_TIMEOUT)

if refund_quantity:
quotas.refund(
quotas.backend.refund(
project,
key=job["project_key"],
timestamp=job["start_time"],
Expand Down
12 changes: 12 additions & 0 deletions src/sentry/eventtypes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Union

from .base import DefaultEvent
from .error import ErrorEvent
from .generic import GenericEvent
Expand All @@ -17,3 +19,13 @@

get = default_manager.get
register = default_manager.register

EventType = Union[
DefaultEvent,
ErrorEvent,
CspEvent,
HpkpEvent,
ExpectCTEvent,
ExpectStapleEvent,
TransactionEvent,
]
8 changes: 4 additions & 4 deletions src/sentry/grouping/result.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Sequence, TypedDict, Union

from sentry.db.models import NodeData
from sentry.utils.safe import get_path, safe_execute, set_path

EventData = Dict[str, Any]
EventMetadata = Dict[str, Any]


Expand Down Expand Up @@ -63,7 +63,7 @@ def _strip_tree_label(tree_label: TreeLabel, truncate: bool = False) -> Stripped
return rv


def _write_tree_labels(tree_labels: Sequence[Optional[TreeLabel]], event_data: EventData) -> None:
def _write_tree_labels(tree_labels: Sequence[Optional[TreeLabel]], event_data: NodeData) -> None:
event_labels: List[Optional[StrippedTreeLabel]] = []
event_data["hierarchical_tree_labels"] = event_labels

Expand Down Expand Up @@ -97,7 +97,7 @@ class CalculatedHashes:
hierarchical_hashes: Sequence[str]
tree_labels: Sequence[Optional[TreeLabel]]

def write_to_event(self, event_data: EventData) -> None:
def write_to_event(self, event_data: NodeData) -> None:
event_data["hashes"] = self.hashes

if self.hierarchical_hashes:
Expand All @@ -106,7 +106,7 @@ def write_to_event(self, event_data: EventData) -> None:
safe_execute(_write_tree_labels, self.tree_labels, event_data, _with_transaction=False)

@classmethod
def from_event(cls, event_data: EventData) -> Optional["CalculatedHashes"]:
def from_event(cls, event_data: NodeData) -> Optional["CalculatedHashes"]:
hashes = event_data.get("hashes")
hierarchical_hashes = event_data.get("hierarchical_hashes") or []
tree_labels = event_data.get("hierarchical_tree_labels") or []
Expand Down
5 changes: 3 additions & 2 deletions src/sentry/tsdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .base import BaseTSDB
from .dummy import DummyTSDB

LazyServiceWrapper(
backend = LazyServiceWrapper(
BaseTSDB, settings.SENTRY_TSDB, settings.SENTRY_TSDB_OPTIONS, dangerous=[DummyTSDB]
).expose(locals())
)
backend.expose(locals())
2 changes: 1 addition & 1 deletion tests/sentry/eventtypes/test_default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sentry.eventtypes import DefaultEvent
from sentry.eventtypes.base import DefaultEvent
from sentry.testutils import TestCase
from sentry.testutils.silo import region_silo_test

Expand Down