Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Jul 26, 2024
1 parent b91cb09 commit 708a58e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
max(toTimeZone(events.timestamp, 'UTC')) AS last_seen,
min(toTimeZone(events.timestamp, 'UTC')) AS first_seen,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')) AS exception_type,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '') AS fingerprint
FROM events
INNER JOIN
Expand Down Expand Up @@ -47,7 +48,8 @@
count(DISTINCT events.distinct_id) AS users,
max(toTimeZone(events.timestamp, 'UTC')) AS last_seen,
min(toTimeZone(events.timestamp, 'UTC')) AS first_seen,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')) AS exception_type
FROM events
INNER JOIN
(SELECT argMax(person_distinct_id2.person_id, person_distinct_id2.version) AS events__pdi___person_id,
Expand Down Expand Up @@ -87,6 +89,7 @@
max(toTimeZone(events.timestamp, 'UTC')) AS last_seen,
min(toTimeZone(events.timestamp, 'UTC')) AS first_seen,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')) AS exception_type,
groupArray(tuple(events.uuid, events.distinct_id, events.distinct_id)) AS events
FROM events
INNER JOIN
Expand Down Expand Up @@ -126,7 +129,8 @@
count(DISTINCT events.distinct_id) AS users,
max(toTimeZone(events.timestamp, 'UTC')) AS last_seen,
min(toTimeZone(events.timestamp, 'UTC')) AS first_seen,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')) AS exception_type
FROM events
WHERE and(equals(events.team_id, 2), equals(events.event, '$exception'), 1, ifNull(in(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', ''), ['SyntaxError']), 0))
LIMIT 101
Expand All @@ -148,6 +152,7 @@
max(toTimeZone(events.timestamp, 'UTC')) AS last_seen,
min(toTimeZone(events.timestamp, 'UTC')) AS first_seen,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')) AS exception_type,
replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '') AS fingerprint
FROM events
INNER JOIN
Expand Down Expand Up @@ -189,6 +194,7 @@
max(toTimeZone(events.timestamp, 'UTC')) AS last_seen,
min(toTimeZone(events.timestamp, 'UTC')) AS first_seen,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_message'), ''), 'null'), '^"|"$', '')) AS description,
any(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, '$exception_type'), ''), 'null'), '^"|"$', '')) AS exception_type,
groupArray(tuple(events.uuid, events.distinct_id, events.distinct_id)) AS events
FROM events
INNER JOIN
Expand Down
22 changes: 20 additions & 2 deletions posthog/hogql_queries/test/test_error_tracking_query_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def setUp(self):
team=self.team,
properties={
"$exception_fingerprint": "SyntaxError",
"$exception_type": "SyntaxError",
"$exception_message": "this is the same error message",
},
)
Expand All @@ -62,6 +63,7 @@ def setUp(self):
team=self.team,
properties={
"$exception_fingerprint": "TypeError",
"$exception_type": "TypeError",
},
)
_create_event(
Expand All @@ -70,6 +72,7 @@ def setUp(self):
team=self.team,
properties={
"$exception_fingerprint": "SyntaxError",
"$exception_type": "SyntaxError",
"$exception_message": "this is the same error message",
},
)
Expand All @@ -79,6 +82,7 @@ def setUp(self):
team=self.team,
properties={
"$exception_fingerprint": "custom_fingerprint",
"$exception_type": "SyntaxError",
"$exception_message": "this is the same error message",
},
)
Expand All @@ -102,7 +106,17 @@ def test_column_names(self):

columns = self._calculate(runner)["columns"]
self.assertEqual(
columns, ["occurrences", "sessions", "users", "last_seen", "first_seen", "description", "fingerprint"]
columns,
[
"occurrences",
"sessions",
"users",
"last_seen",
"first_seen",
"description",
"exception_type",
"fingerprint",
],
)

runner = ErrorTrackingQueryRunner(
Expand All @@ -125,6 +139,7 @@ def test_column_names(self):
"last_seen",
"first_seen",
"description",
"exception_type",
],
)

Expand All @@ -143,7 +158,8 @@ def test_column_names(self):
columns = result["columns"]
# only adds the events column when fields are specificed in `eventColumns`
self.assertEqual(
columns, ["occurrences", "sessions", "users", "last_seen", "first_seen", "description", "events"]
columns,
["occurrences", "sessions", "users", "last_seen", "first_seen", "description", "exception_type", "events"],
)

@snapshot_clickhouse_queries
Expand Down Expand Up @@ -279,6 +295,7 @@ def test_merges_and_defaults_groups(self):
{
"assignee": self.user.id,
"description": "this is the same error message",
"exception_type": "SyntaxError",
"events": None,
"fingerprint": "SyntaxError",
"first_seen": datetime(2020, 1, 10, 12, 11, tzinfo=ZoneInfo("UTC")),
Expand All @@ -294,6 +311,7 @@ def test_merges_and_defaults_groups(self):
{
"assignee": None,
"description": None,
"exception_type": "TypeError",
"events": None,
"fingerprint": "TypeError",
"first_seen": datetime(2020, 1, 10, 12, 11, tzinfo=ZoneInfo("UTC")),
Expand Down

0 comments on commit 708a58e

Please sign in to comment.