Skip to content

perf(error-tracking): cut weekly digest clickhouse query load - #70471

Merged
ablaszkiewicz merged 8 commits into
masterfrom
perf/et-weekly-digest-query-reduction
Jul 14, 2026
Merged

perf(error-tracking): cut weekly digest clickhouse query load#70471
ablaszkiewicz merged 8 commits into
masterfrom
perf/et-weekly-digest-query-reduction

Conversation

@ablaszkiewicz

@ablaszkiewicz ablaszkiewicz commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Build weekly ET digest data only for teams a recipient is subscribed to, instead of every team in the org that has exceptions.
  • Fuse the 5 per-team ClickHouse queries into 2 (one (issue_id, day) breakdown feeds summary/top/new/daily; crash-free stays separate).
  • Query failures now propagate instead of being swallowed as "no activity" — a failed scan fails the per-org task and retries (max_retries 3 → 5) rather than silently dropping the team's section.

Digest stays on the default ClickHouse user. The emitted payload is unchanged.

How did you test this code?

hogli test products/error_tracking/backend/test/test_weekly_digest.py — 55 passing. The existing suite covers the payload, which is unchanged, so no test edits were needed. No manual or prod run.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

🤖 Generated with Claude Code

Build digest data only for teams a recipient is subscribed to (was every
team with exceptions), fuse the 5 per-team ClickHouse queries into 2, and
stop swallowing query failures so a failed scan fails the task and retries
(max_retries 3->5) instead of silently dropping the team.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ablaszkiewicz ablaszkiewicz self-assigned this Jul 13, 2026
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 13, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review July 13, 2026 14:48
Copilot AI review requested due to automatic review settings July 13, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team, cat-ph and hpouillot July 13, 2026 14:48
Comment thread products/error_tracking/backend/weekly_digest.py Outdated
@veria-ai

veria-ai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 3 · PR risk: 0/10

@ablaszkiewicz
ablaszkiewicz removed the request for review from a team July 13, 2026 15:03
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

Playwright — all passed

All tests passed.

View test results →

⚠️ Backend coverage — 77.0% of changed backend lines covered — 52 uncovered

🧪 Backend test coverage

Patch coverage — changed backend lines (products + core): ███████████████░░░░░ 77.0% (182 / 234)

File Patch Uncovered changed lines
posthog/tasks/email.py 3.7% 1966, 1976–1977, 1989–1992, 2008, 2011, 2013–2014, 2024, 2026–2028, 2030, 2032–2034, 2039–2049, 2054, 2063–2064, 2066–2069, 2071–2072, 2076, 2080–2082, 2108, 2115–2117, 2120–2121, 2132, 2146, 2149

🤖 Agents: add a test covering the lines above, or note why under "How did you test this code?". Machine-readable gap list: the patch-coverage artifact on this run (gh run download 29322577600 -n patch-coverage), or the coverage-data block at the end of this comment.

Per-product line coverage (touched products)
Product Coverage Lines
platform_features ██░░░░░░░░░░░░░░░░░░ 12.1% 7 / 58
batch_exports ████████░░░░░░░░░░░░ 39.6% 8,411 / 21,215
demo ███████████░░░░░░░░░ 55.2% 1,436 / 2,601
warehouse_sources_queue ████████████░░░░░░░░ 59.2% 148 / 250
tasks █████████████░░░░░░░ 66.8% 24,736 / 37,026
data_tools ██████████████░░░░░░ 70.0% 63 / 90
ai_gateway ███████████████░░░░░ 75.0% 9 / 12
data_modeling ████████████████░░░░ 78.4% 4,696 / 5,987
signals ████████████████░░░░ 78.5% 18,101 / 23,059
cdp ████████████████░░░░ 80.6% 3,105 / 3,851
wizard ████████████████░░░░ 82.5% 772 / 936
cohorts █████████████████░░░ 82.9% 3,048 / 3,675
notebooks █████████████████░░░ 83.8% 6,086 / 7,259
agent_platform █████████████████░░░ 84.1% 3,095 / 3,678
actions █████████████████░░░ 86.6% 717 / 828
product_tours █████████████████░░░ 87.5% 1,266 / 1,447
engineering_analytics ██████████████████░░ 87.6% 4,417 / 5,040
exports ██████████████████░░ 88.3% 6,857 / 7,763
visual_review ██████████████████░░ 88.5% 5,565 / 6,287
business_knowledge ██████████████████░░ 88.5% 4,400 / 4,969
conversations ██████████████████░░ 88.9% 15,924 / 17,921
mcp_analytics ██████████████████░░ 89.1% 2,485 / 2,790
dashboards ██████████████████░░ 89.1% 5,650 / 6,342
error_tracking ██████████████████░░ 89.5% 9,611 / 10,734
streamlit_apps ██████████████████░░ 90.4% 2,499 / 2,764
slack_app ██████████████████░░ 90.6% 9,460 / 10,444
links ██████████████████░░ 90.6% 183 / 202
marketing_analytics ██████████████████░░ 90.7% 11,476 / 12,646
product_analytics ██████████████████░░ 91.2% 5,652 / 6,195
managed_migrations ██████████████████░░ 91.9% 908 / 988
workflows ██████████████████░░ 92.0% 4,795 / 5,210
mcp_store ██████████████████░░ 92.1% 3,665 / 3,981
data_warehouse ██████████████████░░ 92.1% 17,281 / 18,764
alerts ██████████████████░░ 92.1% 3,389 / 3,678
web_analytics ███████████████████░ 92.7% 13,702 / 14,787
notifications ███████████████████░ 92.7% 1,026 / 1,107
ai_observability ███████████████████░ 92.7% 14,670 / 15,822
surveys ███████████████████░ 92.9% 5,660 / 6,094
posthog_ai ███████████████████░ 93.2% 1,311 / 1,407
tracing ███████████████████░ 93.2% 2,423 / 2,599
approvals ███████████████████░ 93.3% 3,395 / 3,640
reminders ███████████████████░ 93.4% 468 / 501
early_access_features ███████████████████░ 93.8% 848 / 904
legal_documents ███████████████████░ 94.1% 1,568 / 1,667
endpoints ███████████████████░ 94.1% 8,606 / 9,143
messaging ███████████████████░ 94.3% 2,366 / 2,508
skills ███████████████████░ 94.4% 2,827 / 2,995
revenue_analytics ███████████████████░ 94.4% 3,586 / 3,797
review_hog ███████████████████░ 94.5% 6,429 / 6,802
growth ███████████████████░ 94.9% 2,393 / 2,522
logs ███████████████████░ 95.3% 9,429 / 9,895
experiments ███████████████████░ 95.6% 24,017 / 25,124
replay_vision ███████████████████░ 95.6% 12,690 / 13,272
feature_flags ███████████████████░ 96.0% 14,600 / 15,203
warehouse_sources ███████████████████░ 96.1% 213,037 / 221,723
annotations ███████████████████░ 96.2% 732 / 761
user_interviews ███████████████████░ 96.4% 2,242 / 2,325
access_control ███████████████████░ 96.8% 849 / 877
customer_analytics ███████████████████░ 97.3% 7,277 / 7,481
data_catalog ███████████████████░ 97.3% 1,288 / 1,324
analytics_platform ████████████████████ 98.2% 2,098 / 2,137
metrics ████████████████████ 98.3% 2,363 / 2,403
live_debugger ████████████████████ 99.2% 613 / 618
field_notes ████████████████████ 99.4% 158 / 159

Report-only. Patch coverage = changed backend lines covered vs origin/master. Sorted lowest first.
Known gaps: lines covered only by Temporal tests show as uncovered; core line numbers may drift if master changed the same file.

ablaszkiewicz and others added 2 commits July 13, 2026 17:43
…via issue_id_v2

The per-(issue, day) breakdown query had no LIMIT, so HogQL silently
appended LIMIT 100. With ORDER BY day ASC, prior-week rows filled the
result set first on high-cardinality projects, truncating the current
week and suppressing the digest entirely.

Replace it with two bounded queries per team:
- daily aggregates (max 14 rows) for the summary and sparkline
- ranked per-issue rows (LIMIT 5 BY is_new, max 10 rows) feeding both
  the top-issues and new-issues sections

Issue attribution now uses issue_id_v2 (the fingerprint issue state
table), matching the error tracking UI after merges. Ingestion failures
keep the old semantics via isNull(properties.$exception_issue_id).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread products/error_tracking/backend/weekly_digest.py Outdated
ablaszkiewicz and others added 2 commits July 13, 2026 18:22
- bucket day counts against team-local today, not UTC (a full day was
  misbucketed for teams west of UTC-8:30 at the Monday 08:30 UTC run,
  which could suppress a team's digest entirely)
- rank first-time-user auto-select by test-account-filtered counts so
  a user can't be permanently enrolled onto a project whose digest
  builds empty
- skip a team whose digest build fails instead of aborting the whole
  org, re-raising at the end so autoretry still covers it
- stop counting recipient-disabled teams in excluded_project_count
  (they are already named in the disabled list)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…st typing

Embedding every new-issue UUID as an IN-list constant made the rendered
SQL grow with weekly issue cardinality toward ClickHouse's 1 MiB
max_query_size. Newness now derives from issue_first_seen (fingerprint
issue state) inside the query, which also matches the UI's merge-aware
first-seen. Adds explicit LIMIT 14 to the daily query and fixes the
mypy arg-type error in the cardinality test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ablaszkiewicz
ablaszkiewicz marked this pull request as draft July 13, 2026 17:40
@ablaszkiewicz
ablaszkiewicz removed request for a team, cat-ph and hpouillot July 13, 2026 17:40
@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review July 13, 2026 18:45
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team, cat-ph and hpouillot July 13, 2026 18:45
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(error-tracking): compute digest issu..." | Re-trigger Greptile

Comment thread products/error_tracking/backend/weekly_digest.py
Comment thread products/error_tracking/backend/weekly_digest.py
Comment thread products/error_tracking/backend/weekly_digest.py

@cat-ph cat-ph left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Comment thread posthog/tasks/email.py
Comment thread products/error_tracking/backend/weekly_digest.py
@ablaszkiewicz
ablaszkiewicz merged commit 35a43af into master Jul 14, 2026
244 checks passed
@ablaszkiewicz
ablaszkiewicz deleted the perf/et-weekly-digest-query-reduction branch July 14, 2026 10:11
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-14 10:44 UTC Run
prod-us ✅ Deployed 2026-07-14 10:59 UTC Run
prod-eu ✅ Deployed 2026-07-14 11:02 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants