Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phacops committed Nov 6, 2023
1 parent ccd7aeb commit 7e34c8f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 55 deletions.
10 changes: 6 additions & 4 deletions tests/datasets/test_spans_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@

# some time in way in the future
start_time_ms = 4111111111111
received = 1234567890
duration_ms = 1234560123
project_id = 1234567890123456

required_fields = {
"trace_id": "12345678901234567890123456789012",
"span_id": "1234567890123456",
"project_id": project_id,
"start_timestamp_ms": start_time_ms,
"duration_ms": duration_ms,
"exclusive_time_ms": 1234567890123,
"is_segment": True,
"project_id": project_id,
"received": received,
"retention_days": 90,
"sentry_tags": {},
"span_id": "1234567890123456",
"start_timestamp_ms": start_time_ms,
"trace_id": "12345678901234567890123456789012",
}

expected_for_required_fields = {
Expand Down
106 changes: 55 additions & 51 deletions tests/datasets/test_spans_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,44 @@

@dataclass
class SpanEventExample:
event_id: str
organization_id: int
trace_id: str
span_id: str
parent_span_id: str
segment_id: str
transaction_name: str
op: str
start_timestamp_ms: int
dist: Optional[str]
duration_ms: int
environment: Optional[str]
event_id: str
exclusive_time_ms: int
group: str
group_raw: str
retention_days: int
platform: str
dist: Optional[str]
user_name: Optional[str]
user_id: Optional[str]
environment: Optional[str]
release: str
http_method: Optional[str]
http_referer: Optional[str]
status: str
module: str
op: str
organization_id: int
parent_span_id: str
platform: str
received: float
release: str
retention_days: int
segment_id: str
span_id: str
start_timestamp_ms: int
status: str
trace_id: str
transaction_name: str
user_id: Optional[str]
user_name: Optional[str]

def serialize(self) -> SpanEvent:
return {
"project_id": 1,
"trace_id": self.trace_id,
"span_id": self.span_id,
"parent_span_id": self.parent_span_id,
"segment_id": self.segment_id,
"is_segment": False,
"group_raw": self.group_raw,
"start_timestamp_ms": self.start_timestamp_ms,
"description": "SELECT `sentry_tagkey`.* FROM `sentry_tagkey`",
"duration_ms": self.duration_ms,
"exclusive_time_ms": self.exclusive_time_ms,
"group_raw": self.group_raw,
"is_segment": False,
"parent_span_id": self.parent_span_id,
"project_id": 1,
"received": self.received,
"retention_days": self.retention_days,
"description": "SELECT `sentry_tagkey`.* FROM `sentry_tagkey`",
"tags": {
"tag1": "value1",
"tag2": "123",
"tag3": "True",
"sentry:user": self.user_id or "",
},
"segment_id": self.segment_id,
"sentry_tags": {
"http.method": "GET",
"action": "SELECT",
Expand All @@ -73,6 +66,15 @@ def serialize(self) -> SpanEvent:
"op": "http.client",
"transaction.method": "GET",
},
"span_id": self.span_id,
"start_timestamp_ms": self.start_timestamp_ms,
"tags": {
"tag1": "value1",
"tag2": "123",
"tag3": "True",
"sentry:user": self.user_id or "",
},
"trace_id": self.trace_id,
}

def build_result(self, meta: KafkaMessageMetadata) -> Sequence[Mapping[str, Any]]:
Expand Down Expand Up @@ -191,35 +193,37 @@ class TestSpansProcessor:
def __get_timestamps() -> Tuple[float, float]:
timestamp = datetime.now(tz=timezone.utc) - timedelta(seconds=1000)
start_timestamp = timestamp - timedelta(seconds=10)
return start_timestamp.timestamp(), timestamp.timestamp()
received = timestamp + timedelta(seconds=1)
return received.timestamp(), start_timestamp.timestamp(), timestamp.timestamp()

def __get_span_event(self) -> SpanEventExample:
start, finish = self.__get_timestamps()
received, start, finish = self.__get_timestamps()
return SpanEventExample(
event_id="e5e062bf2e1d4afd96fd2f90b6770431",
organization_id=69,
trace_id="deadbeefdeadbeefdeadbeefdeadbeef",
span_id="deadbeefdeadbeef",
parent_span_id="deadbeefdeadbeef",
segment_id="deadbeefdeadbeef",
transaction_name="/organizations/:orgId/issues/",
status="cancelled",
op="navigation",
start_timestamp_ms=int(start * 1000),
dist="",
duration_ms=int(1000 * (finish - start)),
environment="prod",
event_id="e5e062bf2e1d4afd96fd2f90b6770431",
exclusive_time_ms=int(1000 * (finish - start)),
group="deadbeefdeadbeef",
group_raw="deadbeefdeadbeef",
retention_days=90,
platform="python",
dist="",
user_name="me",
user_id="123",
environment="prod",
release="34a554c14b68285d8a8eb6c5c4c56dfc1db9a83a",
http_method="POST",
http_referer="tagstore.something",
module="http",
op="navigation",
organization_id=69,
parent_span_id="deadbeefdeadbeef",
platform="python",
received=received,
release="34a554c14b68285d8a8eb6c5c4c56dfc1db9a83a",
retention_days=90,
segment_id="deadbeefdeadbeef",
span_id="deadbeefdeadbeef",
start_timestamp_ms=int(start * 1000),
status="cancelled",
trace_id="deadbeefdeadbeefdeadbeefdeadbeef",
transaction_name="/organizations/:orgId/issues/",
user_id="123",
user_name="me",
)

def test_required_clickhouse_columns_are_present(self) -> None:
Expand Down

0 comments on commit 7e34c8f

Please sign in to comment.