feat(metrics): render MetricsQuery insights and save from the viewer - #69446
Conversation
🦔 Hogbox preview · ❌ build failedThe preview didn't come up for commit |
|
Reviews (1): Last reviewed commit: "chore(metrics): lock insight persistence..." | Re-trigger Greptile |
|
👋 Visual changes detected for this PR. Review and approve in PostHog Visual Review If these changes are unexpected, they may be caused by a flaky test or a broken snapshot on master. Don't approve — rerun the job or wait for a fix. |
🤖 CI report
|
| File | Size | Δ vs base |
|---|---|---|
render-query/src/render-query/render-query.js |
24.11 MiB | 🔺 +3.0 KiB (+0.0%) |
Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report
✅ Eager graph — within budget
How much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy import() / React.lazy chunks are not counted.
| Root | Eager (shipped) | Δ vs base | Budget |
|---|---|---|---|
entry (logged-out pages, app bootstrap)src/index.tsx |
1.20 MiB · 22 files | no change | ███░░░░░░░ 28.0% of 4.29 MiB |
authenticated shell (every logged-in page)src/scenes/AuthenticatedShell.tsx |
8.07 MiB · 2,956 files | 🔺 +56 B (+0.0%) | █████████░ 87.2% of 9.25 MiB |
🟢 node_modules/monaco-editor/ stays out of src/index.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 node_modules/monaco-editor/ stays out of src/scenes/AuthenticatedShell.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
Largest files eagerly shipped from src/index.tsx
| Size | File |
|---|---|
| 126.8 KiB | ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js |
| 24.6 KiB | ../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js |
| 6.3 KiB | ../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js |
| 4.5 KiB | ../node_modules/.pnpm/@jspm+core@2.1.0/node_modules/@jspm/core/nodelibs/browser/process.js |
| 3.9 KiB | ../node_modules/.pnpm/scheduler@0.23.2/node_modules/scheduler/cjs/scheduler.production.min.js |
| 1.4 KiB | ../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js |
| 1.3 KiB | src/RootErrorBoundary.tsx |
| 912 B | ../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js |
| 789 B | src/scenes/ChunkLoadErrorBoundary.tsx |
| 668 B | src/index.tsx |
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
| Size | File |
|---|---|
| 277.1 KiB | ../node_modules/.pnpm/posthog-js@1.398.2/node_modules/posthog-js/dist/rrweb.js |
| 266.9 KiB | ../node_modules/.pnpm/@posthog+icons@0.37.4_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js |
| 224.6 KiB | src/taxonomy/core-filter-definitions-by-group.json |
| 213.6 KiB | ../node_modules/.pnpm/posthog-js@1.398.2/node_modules/posthog-js/dist/module.js |
| 164.0 KiB | src/queries/validators.js |
| 154.0 KiB | ../node_modules/.pnpm/re2js@0.4.1/node_modules/re2js/build/index.esm.js |
| 126.8 KiB | ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js |
| 105.7 KiB | src/lib/api.ts |
| 93.3 KiB | ../node_modules/.pnpm/prosemirror-view@1.40.1/node_modules/prosemirror-view/dist/index.js |
| 90.5 KiB | ../node_modules/.pnpm/@tiptap+core@3.20.1_@tiptap+pm@3.20.1/node_modules/@tiptap/core/dist/index.js |
Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479
⚠️ Dist folder size — 🔺 +55.6 KiB (+0.0%)
Total size of the built frontend/dist folder (all assets), compared against the base branch.
Total: 1433.84 MiB · 🔺 +55.6 KiB (+0.0%)
|
Note 🤖 stamphog reviewed The diff imports/depends on symbols and files (NodeKind.MetricsQuery, MetricsQuery/MetricsQueryClause/MetricsQueryFilter/MetricsQueryResponse, and products/metrics/backend/tests/test_metrics_query_runner.py with class TestMetricsQueryRunner) that do not exist anywhere in the reviewed checkout — I grepped schema-general.ts, posthog/schema.py, query_runner.py, and the actual metrics backend test files and found only the pre-existing singular MetricQueryRunner/MetricsQueryAPI, never the plural MetricsQuery node kind this PR builds on. The stacked base PR (#69445) this branch is said to sit on is not present in the tree being reviewed.
Gate mechanics and policy version
Updated in place — this replaces 1 earlier stamphog review(s) on this PR. |
|
Re: the refusal reason — this is a stacked PR (base: |
dc8102a to
6b60463
Compare
…rom viewer Adds the frontend half of the MetricsQuery node kind: a Query.tsx dispatch branch rendering the shared MetricsSeriesChart (extracted from the viewer so tiles and the viewer render identically), and a Save as insight action in the metrics viewer that persists the current viewer state as a MetricsQuery insight, addable to any dashboard. The viewer's p95 shorthand maps to the node's quantile aggregation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Guards MetricsQuery's membership in the QuerySchema union: removing it would make every saved metrics insight fail validation silently. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
3eac33f to
44f515c
Compare
|
Review fix pushed (now at 44f515c after restacking on #69445):
|
… into posthog-code/metrics-insights-frontend # Conflicts: # products/metrics/frontend/components/MetricsViewer.tsx # products/metrics/frontend/components/metricsViewerLogic.test.ts # products/metrics/frontend/components/metricsViewerLogic.tsx
f22b0c8
into
posthog-code/metrics-query-node
Problem
Stacked on #69445, which adds the
MetricsQuerynode kind and backend runner. Without aQuery.tsxrenderer the node cannot appear on insights or dashboard tiles, and without a save path nothing producesMetricsQueryinsights in the first place.Changes
MetricsQueryNode(products/metrics/frontend/nodes/) mountsdataNodeLogicand renders the new sharedMetricsSeriesChart, dispatched fromQuery.tsxvia anisMetricsQueryguard, so saved metrics insights render on the insight scene, dashboard tiles, and notebooks.MetricsSeriesChartis extracted from the metrics viewer (Sparkline + legend + the time-axis ladder) and the viewer now uses it too, so tiles and the viewer render identically and cannot drift.MetricsQueryinsight (loader-backed button, disabled without a metric, toast links to the saved insight). The viewer'sp95shorthand maps to the node'squantileaggregation.Screenshots to follow after a local stack run; the viewer chart itself is unchanged visually (same components, extracted).
How did you test this code?
hogli test products/metrics/frontend/components/metricsViewerLogic.test.ts— 7 passed; the 2 new cases lock the viewer-state →MetricsQuerymapping (a wrong mapping silently saves insights that re-run a different query than the viewer showed) and the no-metric null case.hogli test products/metrics/backend/tests/— 159 passed, including the insight-persistence gate added in this branch.Automatic notifications
Docs update
Covered by the metrics doc-sync PRs (#69407, #69409).
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Fable 5) followed the RevenueAnalytics node-component pattern for the
Query.tsxintegration and the SQL editor'sinsightsApi.createpattern for saving. Skills invoked: /writing-tests, /pr-slicing, /get-stamp. Decisions: extract the chart into a shared component rather than duplicate the axis ladder in the tile renderer, and keep the save flow modal-free (default namemetric (aggregation), rename on the insight page) to ship the end-to-end path first.