Skip to content

Commit

Permalink
fix: Actually use include and exclude events
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasfarias committed Jun 12, 2024
1 parent caab583 commit 1bfe5b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion posthog/api/app_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def get_batch_export_runs_app_metrics_queryset(self, batch_export_id: str):
)
date_range = (after_datetime, before_datetime)
runs = (
BatchExportRun.objects.filter(
BatchExportRun.objects.select_related("batch_export__destination")
.filter(
batch_export_id=batch_export_uuid,
last_updated_at__range=date_range,
status__in=(
Expand Down Expand Up @@ -128,6 +129,8 @@ def get_batch_export_runs_app_metrics_queryset(self, batch_export_id: str):

count = fetch_batch_export_run_count(
team_id=run.batch_export.team_id,
include_events=run.batch_export.destination.config.get("include_events", None),
exclude_events=run.batch_export.destination.config.get("exclude_events", None),
data_interval_start=run.data_interval_start,
data_interval_end=run.data_interval_end,
)
Expand Down
16 changes: 11 additions & 5 deletions posthog/api/test/test_app_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@
SAMPLE_PAYLOAD = {"dateRange": ["2021-06-10", "2022-06-12"], "parallelism": 1}


def insert_event(
team_id: int,
timestamp: dt.datetime,
):
def insert_event(team_id: int, timestamp: dt.datetime, event: str = "test-event"):
sync_execute(
"INSERT INTO `sharded_events` (uuid, team_id, event, timestamp) VALUES",
[
{
"uuid": uuid.uuid4(),
"team_id": team_id,
"event": "test_event",
"event": event,
"timestamp": timestamp,
}
],
Expand Down Expand Up @@ -107,6 +104,7 @@ def test_retrieve_batch_export_runs_app_metrics(self):
"prefix": "posthog-events/",
"aws_access_key_id": "abc123",
"aws_secret_access_key": "secret",
"include_events": ["test-event"],
},
}

Expand Down Expand Up @@ -142,6 +140,10 @@ def test_retrieve_batch_export_runs_app_metrics(self):
for _ in range(3):
insert_event(team_id=self.team.pk, timestamp=last_updated_at - dt.timedelta(minutes=1))

insert_event(
team_id=self.team.pk, timestamp=last_updated_at - dt.timedelta(minutes=1), event="not-included"
)

BatchExportRun.objects.create(
batch_export_id=batch_export_id,
data_interval_end=last_updated_at - dt.timedelta(hours=2),
Expand Down Expand Up @@ -186,6 +188,7 @@ def test_retrieve_batch_export_runs_app_metrics_defaults_to_zero(self):
"prefix": "posthog-events/",
"aws_access_key_id": "abc123",
"aws_secret_access_key": "secret",
"exclude_events": ["exclude-me"],
},
}

Expand Down Expand Up @@ -219,6 +222,9 @@ def test_retrieve_batch_export_runs_app_metrics_defaults_to_zero(self):
status=BatchExportRun.Status.COMPLETED,
)
insert_event(team_id=self.team.pk, timestamp=last_updated_at - dt.timedelta(minutes=1))
insert_event(
team_id=self.team.pk, timestamp=last_updated_at - dt.timedelta(minutes=1), event="exclude-me"
)

response = self.client.get(f"/api/projects/@current/app_metrics/{batch_export_id}?date_from=-7d")
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand Down

0 comments on commit 1bfe5b4

Please sign in to comment.