Commit cb9da03
fix(eventcounter): deduplicate events by ID in BigQuery count queries
BigQuery has no primary keys, so an at-least-once Pub/Sub redelivery
after a successful append stores the same event twice. The MySQL and
Postgres event tables reject duplicates via PRIMARY KEY (id), but the
BigQuery count queries trusted row uniqueness:
- evaluation_count.sql used COUNT(id) for the event total, so a
duplicated evaluation event inflated evaluationTotal forever.
- goal_count.sql aggregated COUNT(id) and SUM(value) per user directly
over the raw table, so duplicates inflated goalTotal and the per-user
value sums that feed the Bayesian value-metric analysis.
User counts (COUNT(DISTINCT user_id)) and therefore the CVR analysis
were already duplicate-tolerant.
Deduplicate by event ID: COUNT(DISTINCT id) for the evaluation total,
and a DISTINCT-by-ID CTE in the goal query before any aggregation. Each
legitimate event has its own unique ID, so repeat evaluations/goals by
the same user are still counted. This also retroactively corrects
duplicates already stored in the tables.
This is also what made TestGrpcExperimentResult hang in the dev cluster:
the test waits for exact event counts, and a single duplicated event
kept the count above the expected total forever.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 6afb699 commit cb9da03
2 files changed
Lines changed: 26 additions & 8 deletions
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
Lines changed: 21 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
3 | 9 | | |
4 | 10 | | |
5 | | - | |
6 | | - | |
| 11 | + | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
| |||
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
18 | 32 | | |
19 | 33 | | |
20 | 34 | | |
| |||
0 commit comments