:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-modeling): link endpoint-backed models to their endpoint (#101239)
Jovan Sakovicc89c1c67b7c1
diff --git a/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx b/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsxindex 89f26dcfd93a..349deb32aa8e 100644--- a/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx+++ b/frontend/src/scenes/data-warehouse/scene/ViewsTab.tsx@@ -22,6 +22,7 @@ import {DataWarehouseSavedQueryRunHistory,} from '~/types'+import { endpointModelUrl, parseEndpointModelName } from 'products/data_modeling/frontend/endpointModelName'import { NodeSuspensionApi } from 'products/data_modeling/frontend/generated/api.schemas'import { statusBackgroundClass } from 'products/data_modeling/frontend/lineage/nodeStyles'import { SEARCH_SYNTAX_HELP } from 'products/data_modeling/frontend/lineage/SearchSyntaxHelp'@@ -160,7 +161,8 @@ export function ViewsTab({ getViewUrl, suspensionByViewId }: ViewsTabProps = {})const viewLink = (view: DataWarehouseSavedQuery): { to: string; description?: string } => {if (view.origin === DataWarehouseSavedQueryOrigin.ENDPOINT) {- return { to: urls.endpoint(view.name), description: `Created by the ${view.name} endpoint` }+ const endpointName = parseEndpointModelName(view.name)?.endpointName ?? view.name+ return { to: endpointModelUrl(view.name), description: `Created by the ${endpointName} endpoint` }}if (view.managed_viewset_kind !== null) {return {@@ -177,12 +179,21 @@ export function ViewsTab({ getViewUrl, suspensionByViewId }: ViewsTabProps = {})key: 'name',render: (_, view) => {const { to, description } = viewLink(view)+ const endpointModel =+ view.origin === DataWarehouseSavedQueryOrigin.ENDPOINT ? parseEndpointModelName(view.name) : nullreturn (<LemonTableLinkto={to}title={<>- {view.name}+ {endpointModel?.endpointName ?? view.name}+ {endpointModel && (+ <Tooltip title={`Version ${endpointModel.version} of this endpoint`}>+ <LemonTag type="muted" size="small">+ v{endpointModel.version}+ </LemonTag>+ </Tooltip>+ )}<Tooltiptitle={view.is_materialized ? VIEW_TYPE_TOOLTIPS.materialized : VIEW_TYPE_TOOLTIPS.viewdiff --git a/frontend/src/scenes/models/tabs/ModelsOverviewTab.tsx b/frontend/src/scenes/models/tabs/ModelsOverviewTab.tsxindex 3dbb6b57a042..7d42c130a288 100644--- a/frontend/src/scenes/models/tabs/ModelsOverviewTab.tsx+++ b/frontend/src/scenes/models/tabs/ModelsOverviewTab.tsx@@ -4,13 +4,13 @@ import { IconCheckCircle } from '@posthog/icons'import { LemonBanner, LemonTableColumns, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'import { TZLabel } from 'lib/components/TZLabel'-import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'import { humanFriendlyDuration } from 'lib/utils/durations'import { pluralize } from 'lib/utils/strings'import { CADENCE_LABELS } from 'scenes/data-warehouse/saved_queries/SyncFrequencySelect'import { urls } from 'scenes/urls'import { BehindScheduleModel } from 'products/data_modeling/frontend/freshness'+import { ModelNameLink } from 'products/data_modeling/frontend/ModelNameLink'import { ModelsOverviewTable } from 'products/data_modeling/frontend/ModelsOverviewTable'import { checkDisplayName } from 'products/data_quality/frontend/checksConstants'import { CheckStatusCell } from 'products/data_quality/frontend/CheckStatusCell'@@ -69,7 +69,7 @@ const ATTENTION_COLUMNS: LemonTableColumns<AttentionModel> = [{title: 'Model',key: 'name',- render: (_, row) => <LemonTableLink to={urls.nodeDetail(row.node.id)} title={row.node.name} />,+ render: (_, row) => <ModelNameLink node={row.node} />,},{title: 'Problem',@@ -105,7 +105,7 @@ const BEHIND_COLUMNS: LemonTableColumns<BehindScheduleModel> = [{title: 'Model',key: 'name',- render: (_, row) => <LemonTableLink to={urls.nodeDetail(row.node.id)} title={row.node.name} />,+ render: (_, row) => <ModelNameLink node={row.node} />,},{title: 'Behind by',diff --git a/products/data_modeling/frontend/ModelNameLink.tsx b/products/data_modeling/frontend/ModelNameLink.tsxnew file mode 100644index 000000000000..f74845fcb26d--- /dev/null+++ b/products/data_modeling/frontend/ModelNameLink.tsx@@ -0,0 +1,30 @@+import { LemonTag, Tooltip } from '@posthog/lemon-ui'++import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'+import { urls } from 'scenes/urls'++import { DataModelingNode } from '~/types'++import { endpointModelUrl, parseEndpointModelName } from './endpointModelName'++export function ModelNameLink({ node }: { node: DataModelingNode }): JSX.Element {+ const endpointModel = node.type === 'endpoint' ? parseEndpointModelName(node.name) : null+ if (!endpointModel) {+ return <LemonTableLink to={urls.nodeDetail(node.id)} title={node.name} />+ }+ return (+ <LemonTableLink+ to={endpointModelUrl(node.name)}+ title={+ <>+ <span className="whitespace-nowrap">{endpointModel.endpointName}</span>+ <Tooltip title={`Version ${endpointModel.version} of this endpoint`}>+ <LemonTag type="muted" size="small">+ v{endpointModel.version}+ </LemonTag>+ </Tooltip>+ </>+ }+ />+ )+}diff --git a/products/data_modeling/frontend/endpointModelName.test.ts b/products/data_modeling/frontend/endpointModelName.test.tsnew file mode 100644index 000000000000..3dc119e1cb90--- /dev/null+++ b/products/data_modeling/frontend/endpointModelName.test.ts@@ -0,0 +1,13 @@+import { parseEndpointModelName } from './endpointModelName'++describe('parseEndpointModelName', () => {+ test.each([+ ['weekly-active-users_v5', { endpointName: 'weekly-active-users', version: 5 }],+ ['usage_v2_daily_v13', { endpointName: 'usage_v2_daily', version: 13 }],+ ['plain_view', null],+ ['trailing_v', null],+ ['_v3', null],+ ])('%s', (name, expected) => {+ expect(parseEndpointModelName(name)).toEqual(expected)+ })+})diff --git a/products/data_modeling/frontend/endpointModelName.ts b/products/data_modeling/frontend/endpointModelName.tsnew file mode 100644index 000000000000..4d9218779294--- /dev/null+++ b/products/data_modeling/frontend/endpointModelName.ts@@ -0,0 +1,20 @@+import { urls } from 'scenes/urls'++export interface EndpointModelName {+ endpointName: string+ version: number+}++// Matches EndpointVersion.saved_query_name. Endpoints depends on data modeling, not the reverse,+// so the name is the only link from a model back to its endpoint that this product can read.+const ENDPOINT_MODEL_NAME = /^(.+)_v(\d+)$/++export function parseEndpointModelName(name: string): EndpointModelName | null {+ const match = name.match(ENDPOINT_MODEL_NAME)+ return match ? { endpointName: match[1], version: parseInt(match[2], 10) } : null+}++export function endpointModelUrl(name: string): string {+ const parsed = parseEndpointModelName(name)+ return parsed ? urls.endpoint(parsed.endpointName, parsed.version) : urls.endpoint(name)+}diff --git a/products/data_modeling/frontend/nodeDetail/NodeDetailActions.tsx b/products/data_modeling/frontend/nodeDetail/NodeDetailActions.tsxindex 1f36e82f0892..dfddaf0deb59 100644--- a/products/data_modeling/frontend/nodeDetail/NodeDetailActions.tsx+++ b/products/data_modeling/frontend/nodeDetail/NodeDetailActions.tsx@@ -8,6 +8,7 @@ import { urls } from 'scenes/urls'import { AccessControlLevel, AccessControlResourceType, DataModelingNode, DataWarehouseSavedQuery } from '~/types'+import { endpointModelUrl } from 'products/data_modeling/frontend/endpointModelName'import { MaterializationRunActions } from 'products/data_warehouse/frontend/shared/components/MaterializationRunActions'export function NodeDetailActions({@@ -20,21 +21,10 @@ export function NodeDetailActions({const { hasMaterializationChanges, savingMaterialization } = useValues(materializationJobsLogic({ viewId: savedQuery.id, kind: node.type === 'endpoint' ? 'endpoint' : 'view' }))- // An endpoint node carries the versioned view name (`my_endpoint_v3`), but the endpoint- // route resolves the plain name and takes the version as a search param.- const versionMatch = node.type === 'endpoint' ? node.name.match(/^(.+)_v(\d+)$/) : nullreturn (<>{node.type === 'endpoint' ? (- <LemonButton- type="secondary"- size="small"- to={- versionMatch- ? urls.endpoint(versionMatch[1], parseInt(versionMatch[2], 10))- : urls.endpoint(node.name)- }- >+ <LemonButton type="secondary" size="small" to={endpointModelUrl(node.name)}>Open endpoint</LemonButton>) : (