Skip to content

: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.

feat(data-modeling): add endpoint lineage tab and metric scene polish (#110915)

Jovan Sakoviccca97b50a5ca
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsx
index b4f907fb7aae..6b087e095556 100644
--- a/frontend/src/products.tsx
+++ b/frontend/src/products.tsx
@@ -1375,7 +1375,7 @@ export const productUrls = {
`/dashboard/${id}/subscriptions/${subscriptionId}`,
sharedDashboard: (shareToken: string): string => `/shared_dashboard/${shareToken}`,
dataCatalog: (tab?: string): string => `/data-catalog${tab ? `?tab=${tab}` : ''}`,
- dataCatalogMetric: (name: string, tab?: 'definition' | 'tests' | 'lineage'): string =>
+ dataCatalogMetric: (name: string, tab?: 'definition' | 'data-quality' | 'lineage'): string =>
`/data-catalog/metrics/${name}${tab && tab !== 'definition' ? `?tab=${tab}` : ''}`,
models: (tab?: ModelsSceneTab): string => (tab && tab !== 'overview' ? `/models?tab=${tab}` : '/models'),
nodeDetail: (id: string, tab?: NodeDetailSceneTab): string => `/models/${id}${tab ? `/${tab}` : ''}`,
diff --git a/products/data_catalog/frontend/DataCatalogMetricScene.tsx b/products/data_catalog/frontend/DataCatalogMetricScene.tsx
index 6ee707af6b65..f3a785621bb9 100644
--- a/products/data_catalog/frontend/DataCatalogMetricScene.tsx
+++ b/products/data_catalog/frontend/DataCatalogMetricScene.tsx
@@ -12,7 +12,7 @@ import {
IconSparkles,
IconTrash,
} from '@posthog/icons'
-import { LemonBanner, LemonButton, LemonDialog, LemonDivider, LemonTag } from '@posthog/lemon-ui'
+import { LemonBanner, LemonButton, LemonDialog, LemonDivider, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
import { NotFound } from 'lib/components/NotFound'
import { TZLabel } from 'lib/components/TZLabel'
@@ -21,7 +21,6 @@ import { LemonCollapse } from 'lib/lemon-ui/LemonCollapse'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
import { LemonTabs } from 'lib/lemon-ui/LemonTabs'
-import { Spinner } from 'lib/lemon-ui/Spinner'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'
@@ -137,7 +136,7 @@ export function DataCatalogMetricScene({ name }: DataCatalogMetricSceneLogicProp
}
if (metricLoading && !metric) {
- return <Spinner className="text-2xl" />
+ return <MetricSceneSkeleton />
}
if (!metric) {
return <NotFound object="metric" />
@@ -366,7 +365,7 @@ export function DataCatalogMetricScene({ name }: DataCatalogMetricSceneLogicProp
{ key: 'definition', label: 'Definition' },
{ key: 'lineage', label: 'Lineage' },
metricChecksEnabled && {
- key: 'tests',
+ key: 'data-quality',
label: <MetricTestsTabLabel metricId={metric.id} />,
},
]}
@@ -404,8 +403,8 @@ export function DataCatalogMetricScene({ name }: DataCatalogMetricSceneLogicProp
</div>
)}
- {metricChecksEnabled && mountedTabs.includes('tests') && (
- <div className={tabPanelClassName('tests', activeTab)}>
+ {metricChecksEnabled && mountedTabs.includes('data-quality') && (
+ <div className={tabPanelClassName('data-quality', activeTab)}>
<MetricTestsTab />
</div>
)}
@@ -443,6 +442,20 @@ export function DataCatalogMetricScene({ name }: DataCatalogMetricSceneLogicProp
)
}
+function MetricSceneSkeleton(): JSX.Element {
+ return (
+ <SceneContent>
+ <LemonSkeleton className="h-8 w-80" />
+ <LemonSkeleton className="h-4 w-1/2" />
+ <LemonSkeleton className="h-9 w-72" />
+ <div className="grid grid-cols-2 gap-x-8 gap-y-3 max-w-2xl">
+ <LemonSkeleton className="h-10" repeat={4} />
+ </div>
+ <LemonSkeleton className="h-64 w-full" />
+ </SceneContent>
+ )
+}
+
function StatusRow({ metric }: { metric: DataCatalogMetricApi }): JSX.Element {
return (
<div className="flex items-center gap-1">
diff --git a/products/data_catalog/frontend/dataCatalogMetricSceneLogic.test.ts b/products/data_catalog/frontend/dataCatalogMetricSceneLogic.test.ts
index d17d7888eed2..72c61b5c1e4d 100644
--- a/products/data_catalog/frontend/dataCatalogMetricSceneLogic.test.ts
+++ b/products/data_catalog/frontend/dataCatalogMetricSceneLogic.test.ts
@@ -262,28 +262,29 @@ describe('dataCatalogMetricSceneLogic', () => {
expect(logic.values.lineageRetried).toBe(expected === 'not_ready')
})
- it('synchronizes the Tests tab with navigation and preserves it on rename', async () => {
+ it('redirects the legacy tests key to the data quality tab and preserves it on rename', async () => {
router.actions.push(urls.dataCatalogMetric('weekly_active_users'), { tab: 'tests' })
await expectLogic(logic).toFinishAllListeners()
- expect(logic.values.activeTab).toBe('tests')
- expect(logic.values.mountedTabs).toEqual(['tests'])
+ expect(logic.values.activeTab).toBe('data-quality')
+ expect(router.values.searchParams.tab).toBe('data-quality')
+ expect(logic.values.mountedTabs).toEqual(['data-quality'])
logic.actions.setActiveTab('definition')
expect(router.values.searchParams.tab).toBeUndefined()
- expect(logic.values.mountedTabs).toEqual(['tests', 'definition'])
- logic.actions.setActiveTab('tests')
- expect(router.values.searchParams.tab).toBe('tests')
+ expect(logic.values.mountedTabs).toEqual(['data-quality', 'definition'])
+ logic.actions.setActiveTab('data-quality')
+ expect(router.values.searchParams.tab).toBe('data-quality')
;(dataCatalogMetricsPartialUpdate as jest.Mock).mockResolvedValue(buildMetric({ name: 'wau' }))
logic.actions.renameMetric('wau')
await expectLogic(logic).toFinishAllListeners()
- expect(router.values.searchParams.tab).toBe('tests')
+ expect(router.values.searchParams.tab).toBe('data-quality')
})
// The metric check endpoints are gated on the same flag, so a link to the tab from a project
// outside the rollout has to land on Definition. Otherwise the panel mounts against endpoints
// that reject every request.
- it('refuses the Tests tab while the data quality flag is off', async () => {
+ it('refuses the data quality tab while the data quality flag is off', async () => {
featureFlagLogic.actions.setFeatureFlags([], {})
- router.actions.push(urls.dataCatalogMetric('weekly_active_users'), { tab: 'tests' })
+ router.actions.push(urls.dataCatalogMetric('weekly_active_users'), { tab: 'data-quality' })
await expectLogic(logic).toFinishAllListeners()
expect(logic.values.metricChecksEnabled).toBe(false)
expect(logic.values.activeTab).toBe('definition')
diff --git a/products/data_catalog/frontend/dataCatalogMetricSceneLogic.tsx b/products/data_catalog/frontend/dataCatalogMetricSceneLogic.tsx
index 4c32f61e84b2..ec7e21504fe4 100644
--- a/products/data_catalog/frontend/dataCatalogMetricSceneLogic.tsx
+++ b/products/data_catalog/frontend/dataCatalogMetricSceneLogic.tsx
@@ -43,7 +43,7 @@ export interface DataCatalogMetricSceneLogicProps {
name: string
}
-export type MetricSceneTab = 'definition' | 'tests' | 'lineage'
+export type MetricSceneTab = 'definition' | 'data-quality' | 'lineage'
/** What stopped the lineage load, in the terms the tab has a screen for. */
export type LineageLoadProblem = 'not_ready' | 'no_warehouse_access' | 'failed'
@@ -453,7 +453,7 @@ export const dataCatalogMetricSceneLogic = kea<dataCatalogMetricSceneLogicType>(
visitedTabs.includes(activeTab) ? visitedTabs : [...visitedTabs, activeTab],
],
// The metric check endpoints are gated on the same flag, so a project outside the rollout
- // must not reach the Tests tab: every request it makes is rejected.
+ // must not reach the data quality tab: every request it makes is rejected.
metricChecksEnabled: [
(s) => [s.featureFlags],
(featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.DATA_QUALITY_CHECKS],
@@ -677,10 +677,13 @@ export const dataCatalogMetricSceneLogic = kea<dataCatalogMetricSceneLogicType>(
if (name !== props.name) {
return
}
+ // `tests` is the old key for the data quality tab; links in sent notifications still use it.
+ const tabParam = searchParams.tab === 'tests' ? 'data-quality' : searchParams.tab
const requestedTab: MetricSceneTab =
- searchParams.tab === 'tests' || searchParams.tab === 'lineage' ? searchParams.tab : 'definition'
- const activeTab = requestedTab === 'tests' && !values.metricChecksEnabled ? 'definition' : requestedTab
- if (activeTab !== requestedTab) {
+ tabParam === 'data-quality' || tabParam === 'lineage' ? tabParam : 'definition'
+ const activeTab =
+ requestedTab === 'data-quality' && !values.metricChecksEnabled ? 'definition' : requestedTab
+ if (activeTab !== searchParams.tab && searchParams.tab !== undefined) {
// Drop the param so a refresh or a back navigation does not ask for the tab again.
router.actions.replace(urls.dataCatalogMetric(props.name, activeTab))
}
diff --git a/products/data_catalog/frontend/tabs/MetricTestsTabLabel.tsx b/products/data_catalog/frontend/tabs/MetricTestsTabLabel.tsx
index 1f5ab7d94b9f..e7e42a832629 100644
--- a/products/data_catalog/frontend/tabs/MetricTestsTabLabel.tsx
+++ b/products/data_catalog/frontend/tabs/MetricTestsTabLabel.tsx
@@ -10,7 +10,7 @@ export function MetricTestsTabLabel({ metricId }: { metricId: string }): JSX.Ele
return (
<span className="flex items-center gap-1">
- Tests{failing > 0 && <LemonTag type="danger">{failing} failing</LemonTag>}
+ Data quality{failing > 0 && <LemonTag type="danger">{failing} failing</LemonTag>}
</span>
)
}
diff --git a/products/data_catalog/manifest.tsx b/products/data_catalog/manifest.tsx
index 58ebd9bd0162..4407f697df79 100644
--- a/products/data_catalog/manifest.tsx
+++ b/products/data_catalog/manifest.tsx
@@ -28,7 +28,7 @@ export const manifest: ProductManifest = {
redirects: {},
urls: {
dataCatalog: (tab?: string): string => `/data-catalog${tab ? `?tab=${tab}` : ''}`,
- dataCatalogMetric: (name: string, tab?: 'definition' | 'tests' | 'lineage'): string =>
+ dataCatalogMetric: (name: string, tab?: 'definition' | 'data-quality' | 'lineage'): string =>
`/data-catalog/metrics/${name}${tab && tab !== 'definition' ? `?tab=${tab}` : ''}`,
},
fileSystemTypes: {},
diff --git a/products/data_modeling/frontend/ModelsOverviewTab.tsx b/products/data_modeling/frontend/ModelsOverviewTab.tsx
index 6030d7167286..64aa32021c66 100644
--- a/products/data_modeling/frontend/ModelsOverviewTab.tsx
+++ b/products/data_modeling/frontend/ModelsOverviewTab.tsx
@@ -153,7 +153,7 @@ const CHECK_COLUMNS: LemonTableColumns<DataQualityOverviewCheckApi> = [
key: 'subject',
render: (_, check) =>
check.subject_node_id ? (
- <Link to={urls.nodeDetail(check.subject_node_id, 'tests')}>{check.subject_name}</Link>
+ <Link to={urls.nodeDetail(check.subject_node_id, 'data-quality')}>{check.subject_name}</Link>
) : (
check.subject_name
),
diff --git a/products/data_modeling/frontend/nodeDetail/NodeDetailScene.tsx b/products/data_modeling/frontend/nodeDetail/NodeDetailScene.tsx
index 89b8a303c65b..07db30ffad74 100644
--- a/products/data_modeling/frontend/nodeDetail/NodeDetailScene.tsx
+++ b/products/data_modeling/frontend/nodeDetail/NodeDetailScene.tsx
@@ -40,7 +40,7 @@ const TAB_LABELS: Record<NodeDetailSceneTab, string> = {
query: 'Query',
lineage: 'Lineage',
materialization: 'Materialization',
- tests: 'Data quality',
+ 'data-quality': 'Data quality',
history: 'History',
}
@@ -48,7 +48,7 @@ function tabLabel(
tab: NodeDetailSceneTab,
dataQualitySubject: NodeDetailDataQualitySubject | null
): JSX.Element | string {
- if (tab === 'tests' && dataQualitySubject) {
+ if (tab === 'data-quality' && dataQualitySubject) {
return <NodeDetailTestsTabLabel {...dataQualitySubject} />
}
return TAB_LABELS[tab]
@@ -104,7 +104,7 @@ export function NodeDetailScene({ id }: NodeDetailSceneLogicProps): JSX.Element
id={savedQueryId ?? ''}
/>
)
- case 'tests':
+ case 'data-quality':
return <NodeDetailTests id={id} />
}
}
diff --git a/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.test.ts b/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.test.ts
index 2b9b5051b537..727d2657eefa 100644
--- a/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.test.ts
+++ b/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.test.ts
@@ -148,7 +148,7 @@ describe('nodeDetailSceneLogic', () => {
await mountScene(urls.nodeDetail(NODE_ID))
- expect(logic.values.availableTabs).toEqual(['lineage', 'tests'])
+ expect(logic.values.availableTabs).toEqual(['lineage', 'data-quality'])
expect(logic.values.dataQualitySubject).toEqual({ subjectType: 'table', subjectId: 'table-1' })
expect(logic.values.tableDetails).toMatchObject({
table: { id: 'table-1' },
@@ -184,7 +184,7 @@ describe('nodeDetailSceneLogic', () => {
await mountScene(urls.nodeDetail(NODE_ID))
- expect(logic.values.availableTabs).toEqual(['lineage', 'tests'])
+ expect(logic.values.availableTabs).toEqual(['lineage', 'data-quality'])
expect(logic.values.dataQualitySubject).toEqual({
subjectType: 'posthog_table',
subjectId: `${tableName}-subject`,
@@ -232,7 +232,7 @@ describe('nodeDetailSceneLogic', () => {
})
}).toFinishAllListeners()
- expect(logic.values.availableTabs).toEqual(['lineage', 'tests'])
+ expect(logic.values.availableTabs).toEqual(['lineage', 'data-quality'])
expect(logic.values.dataQualitySubject).toMatchObject({
subjectType: 'posthog_table',
subjectId: 'events-subject',
@@ -249,9 +249,10 @@ describe('nodeDetailSceneLogic', () => {
},
})
- await mountScene(urls.nodeDetail(NODE_ID, 'tests'))
+ await mountScene(`/models/${NODE_ID}/tests`)
- expect(logic.values.effectiveTab).toEqual('tests')
+ expect(logic.values.effectiveTab).toEqual('data-quality')
+ expect(router.values.location.pathname).toEqual(`/project/997${urls.nodeDetail(NODE_ID, 'data-quality')}`)
expect(logic.values.dataQualitySubject).toBeNull()
render(createElement(NodeDetailTests, { id: NODE_ID }))
@@ -271,7 +272,7 @@ describe('nodeDetailSceneLogic', () => {
await mountScene(urls.nodeDetail(NODE_ID))
- expect(logic.values.availableTabs).toEqual(['lineage', 'tests'])
+ expect(logic.values.availableTabs).toEqual(['lineage', 'data-quality'])
expect(logic.values.lineageGraph).toEqual({ currentNodeId: NODE_ID, nodes: [], edges: [] })
expect(logic.values.postHogSubjectError).toBe(true)
@@ -346,7 +347,7 @@ describe('nodeDetailSceneLogic', () => {
it('lists every tab a saved query supports when data quality checks are on', async () => {
await mountScene(urls.nodeDetail(NODE_ID))
- expect(logic.values.availableTabs).toEqual(['query', 'lineage', 'materialization', 'tests', 'history'])
+ expect(logic.values.availableTabs).toEqual(['query', 'lineage', 'materialization', 'data-quality', 'history'])
})
// The tab is gated on the node's saved_query_id, not the loaded saved query, so a load failure
@@ -391,7 +392,7 @@ describe('nodeDetailSceneLogic', () => {
it('falls back to the default tab when the URL names a tab this model does not have', async () => {
flagsLogic.actions.setFeatureFlags([], {})
- await mountScene(urls.nodeDetail(NODE_ID, 'tests'))
+ await mountScene(urls.nodeDetail(NODE_ID, 'data-quality'))
expect(logic.values.effectiveTab).toEqual('query')
expect(logic.values.currentTab).toEqual('query')
diff --git a/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.ts b/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.ts
index 42d74f559017..b5c243362ffe 100644
--- a/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.ts
+++ b/products/data_modeling/frontend/nodeDetail/nodeDetailSceneLogic.ts
@@ -26,7 +26,7 @@ import type { DataQualitySubjectApi } from 'products/data_quality/frontend/gener
import { MATERIALIZING_TYPES } from '../freshness'
import type { NodeTypeEnumApi } from '../generated/api.schemas'
-export const NODE_DETAIL_SCENE_TABS = ['query', 'lineage', 'materialization', 'tests', 'history'] as const
+export const NODE_DETAIL_SCENE_TABS = ['query', 'lineage', 'materialization', 'data-quality', 'history'] as const
export type NodeDetailSceneTab = (typeof NODE_DETAIL_SCENE_TABS)[number]
export interface NodeDetailSceneLogicProps {
@@ -220,7 +220,7 @@ export interface nodeDetailSceneLogicActions {
value: true
}
setCurrentTab: (tab: NodeDetailSceneTab | null) => {
- tab: 'history' | 'lineage' | 'materialization' | 'query' | 'tests' | null
+ tab: 'data-quality' | 'history' | 'lineage' | 'materialization' | 'query' | null
}
updateNodeDescription: (description: string) => {
description: string
@@ -264,9 +264,9 @@ export interface nodeDetailSceneLogicMeta {
isMaterialized: (node: DataModelingNode | null, savedQuery: DataWarehouseSavedQuery | null) => boolean
defaultTab: (node: DataModelingNode | null, isMaterialized: boolean) => NodeDetailSceneTab
effectiveTab: (
- currentTab: 'history' | 'lineage' | 'materialization' | 'query' | 'tests' | null,
- availableTabs: ('history' | 'lineage' | 'materialization' | 'query' | 'tests')[],
- defaultTab: 'history' | 'lineage' | 'materialization' | 'query' | 'tests'
+ currentTab: 'data-quality' | 'history' | 'lineage' | 'materialization' | 'query' | null,
+ availableTabs: ('data-quality' | 'history' | 'lineage' | 'materialization' | 'query')[],
+ defaultTab: 'data-quality' | 'history' | 'lineage' | 'materialization' | 'query'
) => NodeDetailSceneTab | null
effectiveLastRunAt: (node: DataModelingNode | null, savedQuery: DataWarehouseSavedQuery | null) => string | null
effectiveLastRunStatus: (
@@ -489,7 +489,7 @@ export const nodeDetailSceneLogic = kea<nodeDetailSceneLogicType>([
'lineage',
...(featureFlags[FEATURE_FLAGS.DATA_QUALITY_CHECKS] &&
(node.warehouse_table_id || node.origin === 'posthog')
- ? ['tests' as const]
+ ? ['data-quality' as const]
: []),
]
}
@@ -506,7 +506,7 @@ export const nodeDetailSceneLogic = kea<nodeDetailSceneLogicType>([
tabs.push('materialization')
}
if (featureFlags[FEATURE_FLAGS.DATA_QUALITY_CHECKS] && node.saved_query_id) {
- tabs.push('tests')
+ tabs.push('data-quality')
}
if (node.saved_query_id) {
tabs.push('history')
@@ -662,6 +662,11 @@ export const nodeDetailSceneLogic = kea<nodeDetailSceneLogicType>([
if (id !== props.id) {
return
}
+ // `tests` is the tab's old URL segment; keep links built before the rename working.
+ if (tab === 'tests') {
+ router.actions.replace(urls.nodeDetail(id, 'data-quality'))
+ return
+ }
actions.setCurrentTab(isNodeDetailSceneTab(tab) ? tab : null)
actions.canonicalizeTab()
}
diff --git a/products/data_quality/backend/logic/notifications.py b/products/data_quality/backend/logic/notifications.py
index 03eb6a7ee888..e8434aad7941 100644
--- a/products/data_quality/backend/logic/notifications.py
+++ b/products/data_quality/backend/logic/notifications.py
@@ -170,7 +170,7 @@ class _WarehouseSubjectResolver(RecipientsResolver):
def _source_url(team_id: int, subject_type: str, subject_name: str) -> str:
if subject_type == SubjectType.METRIC:
- return f"/project/{team_id}/data-catalog/metrics/{quote(subject_name, safe='')}?tab=tests"
+ return f"/project/{team_id}/data-catalog/metrics/{quote(subject_name, safe='')}?tab=data-quality"
if subject_type == SubjectType.POSTHOG_TABLE:
return f"/project/{team_id}/models?tab=data-quality"
return ""
diff --git a/products/data_quality/backend/tests/test_notifications.py b/products/data_quality/backend/tests/test_notifications.py
index 733909ab19f7..f044b638d407 100644
--- a/products/data_quality/backend/tests/test_notifications.py
+++ b/products/data_quality/backend/tests/test_notifications.py
@@ -180,7 +180,7 @@ class TestDataQualityNotifications(BaseTest):
notification = notifications.call_args.args[0]
assert notification.resource_type == "data_catalog"
assert notification.resource_id == str(metric.id)
- assert notification.source_url == f"/project/{self.team.id}/data-catalog/metrics/signups?tab=tests"
+ assert notification.source_url == f"/project/{self.team.id}/data-catalog/metrics/signups?tab=data-quality"
assert notification.title == "Data quality check failed on signups"
with CaptureQueriesContext(connection) as queries:
recipients = notification.resolver.resolve(TargetType.TEAM, str(self.team.id), self.team.id)
diff --git a/products/data_quality/frontend/overview/DataQualityOverview.test.tsx b/products/data_quality/frontend/overview/DataQualityOverview.test.tsx
index 2cc0296398fb..1a80849f1f90 100644
--- a/products/data_quality/frontend/overview/DataQualityOverview.test.tsx
+++ b/products/data_quality/frontend/overview/DataQualityOverview.test.tsx
@@ -183,7 +183,7 @@ describe('DataQualityOverview', () => {
expect(within(disclosure.parentElement!).getByText('Failing')).toBeTruthy()
// Suffix match: the rendered href carries the /project/:id prefix, so an exact match on the
// path would find nothing and the assertion below would pass on a null link.
- const link = document.querySelector('a[href$="/models/node-1/tests"]')
+ const link = document.querySelector('a[href$="/models/node-1/data-quality"]')
expect(link).not.toBeNull()
expect(disclosure.contains(link)).toBe(false)
expect(disclosure.contains(runSubjectButtons()[0])).toBe(false)
diff --git a/products/data_quality/frontend/overview/dataQualityOverviewLogic.test.ts b/products/data_quality/frontend/overview/dataQualityOverviewLogic.test.ts
index 00eac78705bf..09ab3a5359ad 100644
--- a/products/data_quality/frontend/overview/dataQualityOverviewLogic.test.ts
+++ b/products/data_quality/frontend/overview/dataQualityOverviewLogic.test.ts
@@ -550,7 +550,7 @@ describe('dataQualityOverviewLogic', () => {
})
it.each<[string, Partial<DataQualityOverviewCheckApi>, string | null]>([
- ['a view on a DAG node', { subject_type: 'view', subject_node_id: 'node-1' }, '/models/node-1/tests'],
+ ['a view on a DAG node', { subject_type: 'view', subject_node_id: 'node-1' }, '/models/node-1/data-quality'],
['a view on no DAG', { subject_type: 'view', subject_node_id: null }, null],
[
'a PostHog table on a DAG node',
@@ -561,7 +561,7 @@ describe('dataQualityOverviewLogic', () => {
[
'a metric',
{ subject_type: 'metric', subject_metric_name: 'weekly_signups' },
- '/data-catalog/metrics/weekly_signups?tab=tests',
+ '/data-catalog/metrics/weekly_signups?tab=data-quality',
],
['a deleted metric', { subject_type: 'metric', subject_metric_name: null }, null],
[
@@ -577,7 +577,7 @@ describe('dataQualityOverviewLogic', () => {
[
'a metric on its catalog page',
{ subject_type: 'metric', subject_uuid: 'uuid-metric', subject_metric_name: 'signups' },
- '/data-catalog/metrics/signups?tab=tests',
+ '/data-catalog/metrics/signups?tab=data-quality',
],
[
'a metric whose name did not come through',
diff --git a/products/data_quality/frontend/overview/dataQualityOverviewLogic.ts b/products/data_quality/frontend/overview/dataQualityOverviewLogic.ts
index 958aefb534dc..3fb18c4c1c36 100644
--- a/products/data_quality/frontend/overview/dataQualityOverviewLogic.ts
+++ b/products/data_quality/frontend/overview/dataQualityOverviewLogic.ts
@@ -82,10 +82,10 @@ export function subjectDetailUrl(check: DataQualityOverviewCheckApi): string | n
}
if (check.subject_type === 'metric') {
// The catalog addresses a metric by name, so a row that came without one has no route.
- return check.subject_metric_name ? urls.dataCatalogMetric(check.subject_metric_name, 'tests') : null
+ return check.subject_metric_name ? urls.dataCatalogMetric(check.subject_metric_name, 'data-quality') : null
}
if (check.subject_type === 'view') {
- return check.subject_node_id ? urls.nodeDetail(check.subject_node_id, 'tests') : null
+ return check.subject_node_id ? urls.nodeDetail(check.subject_node_id, 'data-quality') : null
}
if (check.subject_source_id && check.subject_schema_id) {
return urls.dataWarehouseSourceSchema(check.subject_source_id, check.subject_schema_id)
diff --git a/products/endpoints/frontend/EndpointScene.tsx b/products/endpoints/frontend/EndpointScene.tsx
index a6c0ad96f8d4..0010c043feb1 100644
--- a/products/endpoints/frontend/EndpointScene.tsx
+++ b/products/endpoints/frontend/EndpointScene.tsx
@@ -6,6 +6,7 @@ import {
IconClock,
IconCode2,
IconDatabase,
+ IconDecisionTree,
IconEndpoints,
IconGraph,
IconLive,
@@ -47,6 +48,7 @@ import { ProductKey } from '~/queries/schema/schema-general'
import { ActivityScope, EndpointVersionType } from '~/types'
import { EndpointConfiguration } from './endpoint-tabs/EndpointConfiguration'
+import { EndpointLineage } from './endpoint-tabs/EndpointLineage'
import { EndpointLogs } from './endpoint-tabs/EndpointLogs'
import { EndpointOverview } from './endpoint-tabs/EndpointOverview'
import { EndpointPlayground } from './endpoint-tabs/EndpointPlayground'
@@ -75,6 +77,9 @@ export function EndpointScene(): JSX.Element {
const { tags: tagsAvailable } = useValues(tagsModel)
const { searchParams } = useValues(router)
const { featureFlags } = useValues(featureFlagLogic)
+ const lineageSavedQueryId = (viewingVersion ?? endpoint)?.materialization?.saved_query_id ?? null
+ const visibleTab =
+ activeTab === EndpointTab.LINEAGE && endpoint && !lineageSavedQueryId ? EndpointTab.QUERY : activeTab
const sceneMenuBarEnabled = !!featureFlags[FEATURE_FLAGS.SCENE_MENU_BAR]
const tabs: LemonTab<EndpointTab>[] = [
@@ -122,6 +127,19 @@ export function EndpointScene(): JSX.Element {
? combineUrl(urls.endpoint(endpoint.name), { ...searchParams, tab: EndpointTab.LOGS }).url
: undefined,
},
+ ...(lineageSavedQueryId
+ ? [
+ {
+ key: EndpointTab.LINEAGE,
+ label: 'Lineage',
+ 'data-attr': 'endpoint-lineage-tab',
+ content: <EndpointLineage savedQueryId={lineageSavedQueryId} />,
+ link: endpoint
+ ? combineUrl(urls.endpoint(endpoint.name), { ...searchParams, tab: EndpointTab.LINEAGE }).url
+ : undefined,
+ },
+ ]
+ : []),
{
key: EndpointTab.HISTORY,
label: 'History',
@@ -178,7 +196,7 @@ export function EndpointScene(): JSX.Element {
if (!endpoint) {
return <></>
}
- switch (activeTab) {
+ switch (visibleTab) {
case EndpointTab.CONFIGURATION:
return <EndpointConfiguration />
case EndpointTab.VERSIONS:
@@ -187,6 +205,8 @@ export function EndpointScene(): JSX.Element {
return <EndpointPlayground />
case EndpointTab.LOGS:
return <EndpointLogs />
+ case EndpointTab.LINEAGE:
+ return lineageSavedQueryId ? <EndpointLineage savedQueryId={lineageSavedQueryId} /> : <></>
case EndpointTab.HISTORY:
return <ActivityLog scope={[ActivityScope.ENDPOINT, ActivityScope.ENDPOINT_VERSION]} id={endpoint.id} />
case EndpointTab.QUERY:
@@ -249,6 +269,19 @@ export function EndpointScene(): JSX.Element {
<IconLive />
View logs
</SceneMenuBarItem>
+ {lineageSavedQueryId && (
+ <SceneMenuBarItem
+ onClick={() =>
+ router.actions.push(
+ combineUrl(urls.endpoint(endpoint.name), { tab: EndpointTab.LINEAGE }).url
+ )
+ }
+ data-attr="endpoint-menubar-view-lineage"
+ >
+ <IconDecisionTree />
+ View lineage
+ </SceneMenuBarItem>
+ )}
<SceneMenuBarItem
onClick={() =>
router.actions.push(
@@ -330,7 +363,7 @@ export function EndpointScene(): JSX.Element {
/>
)}
{!endpointLoading && <EndpointOverview />}
- {sceneMenuBarEnabled ? renderTabContent() : <LemonTabs activeKey={activeTab} tabs={tabs} />}
+ {sceneMenuBarEnabled ? renderTabContent() : <LemonTabs activeKey={visibleTab} tabs={tabs} />}
</SceneContent>
{endpoint && (
<ScenePanel>
diff --git a/products/endpoints/frontend/endpoint-tabs/EndpointLineage.tsx b/products/endpoints/frontend/endpoint-tabs/EndpointLineage.tsx
new file mode 100644
index 000000000000..1c1dab257cf2
--- /dev/null
+++ b/products/endpoints/frontend/endpoint-tabs/EndpointLineage.tsx
@@ -0,0 +1,62 @@
+import { useActions, useValues } from 'kea'
+import { router } from 'kea-router'
+
+import { IconExternal } from '@posthog/icons'
+import { LemonBanner, LemonButton } from '@posthog/lemon-ui'
+
+import { urls } from 'scenes/urls'
+
+import { LineageGraph } from 'products/data_modeling/frontend/lineage/LineageGraph'
+import { lineageNodeUrl } from 'products/data_modeling/frontend/lineage/lineageNodeUrl'
+
+import { endpointLineageLogic } from './endpointLineageLogic'
+
+export function EndpointLineage({ savedQueryId }: { savedQueryId: string }): JSX.Element {
+ const logic = endpointLineageLogic({ savedQueryId })
+ const { lineage, lineageLoading, lineageMissing, lineageFailed, currentNodeId } = useValues(logic)
+ const { loadLineage } = useActions(logic)
+
+ if (lineageFailed) {
+ return (
+ <LemonBanner type="error" action={{ children: 'Retry', onClick: loadLineage }}>
+ Couldn't load lineage.
+ </LemonBanner>
+ )
+ }
+
+ if (lineageMissing) {
+ return (
+ <div className="flex min-h-64 flex-col items-center justify-center rounded border bg-bg-light p-6 text-center">
+ <h3 className="mb-2">No lineage yet</h3>
+ <p className="mb-0 max-w-120 text-secondary">
+ This endpoint's model isn't in the lineage graph yet. Check back after its next run.
+ </p>
+ </div>
+ )
+ }
+
+ return (
+ <div className="h-[70vh] min-h-[400px] w-full border rounded bg-bg-light overflow-hidden">
+ <LineageGraph
+ nodes={lineage?.nodes ?? []}
+ edges={lineage?.edges ?? []}
+ currentNodeId={currentNodeId}
+ loading={lineageLoading}
+ variant="full"
+ interactive
+ showControls
+ showMinimap
+ onNodeClick={(node) => router.actions.push(lineageNodeUrl(node, 'lineage'))}
+ panels={
+ <LemonButton
+ type="secondary"
+ size="small"
+ to={urls.models('lineage')}
+ tooltip="Open the full graph"
+ icon={<IconExternal />}
+ />
+ }
+ />
+ </div>
+ )
+}
diff --git a/products/endpoints/frontend/endpoint-tabs/endpointLineageLogic.test.ts b/products/endpoints/frontend/endpoint-tabs/endpointLineageLogic.test.ts
new file mode 100644
index 000000000000..7c611a480cc5
--- /dev/null
+++ b/products/endpoints/frontend/endpoint-tabs/endpointLineageLogic.test.ts
@@ -0,0 +1,89 @@
+import api, { ApiError } from 'lib/api'
+
+import { initKeaTests } from '~/test/init'
+import { expectLogic } from '~/test/keaTestUtils'
+
+import { endpointLineageLogic } from './endpointLineageLogic'
+
+jest.mock('lib/api', () => {
+ class ApiError extends Error {
+ status?: number
+ constructor(message?: string, status?: number) {
+ super(message)
+ this.status = status
+ }
+ }
+ return {
+ __esModule: true,
+ default: { dataModelingNodes: { lineage: jest.fn() } },
+ ApiConfig: { getCurrentTeamId: jest.fn(() => 1) },
+ ApiError,
+ }
+})
+
+describe('endpointLineageLogic', () => {
+ let logic: ReturnType<typeof endpointLineageLogic.build>
+
+ const lineageRequest = (): jest.Mock => api.dataModelingNodes.lineage as unknown as jest.Mock
+
+ const mountLogic = async (): Promise<void> => {
+ logic = endpointLineageLogic({ savedQueryId: 'saved-query-1' })
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ }
+
+ beforeEach(() => {
+ lineageRequest().mockReset()
+ initKeaTests()
+ })
+
+ it('asks for the lineage of the endpoint it was given and marks that endpoint node', async () => {
+ lineageRequest().mockResolvedValue({
+ nodes: [
+ { id: 'node-upstream', saved_query_id: 'saved-query-0' },
+ { id: 'node-self', saved_query_id: 'saved-query-1' },
+ ],
+ edges: [],
+ })
+
+ await mountLogic()
+
+ expect(lineageRequest()).toHaveBeenCalledWith({ savedQueryId: 'saved-query-1' })
+ expect(logic.values.currentNodeId).toBe('node-self')
+ expect(logic.values.lineageMissing).toBe(false)
+ expect(logic.values.lineageFailed).toBe(false)
+ })
+
+ const failures: [string, number | undefined, boolean, boolean][] = [
+ ['a model that has no lineage node yet', 404, true, false],
+ ['a request that broke', 500, false, true],
+ ['a request that broke without a status', undefined, false, true],
+ ]
+
+ it.each(failures)('tells %s apart from the other outcome', async (_, status, missing, failed) => {
+ lineageRequest().mockRejectedValue(new ApiError('nope', status))
+
+ await mountLogic()
+
+ expect(logic.values.lineage).toBeNull()
+ expect(logic.values.lineageMissing).toBe(missing)
+ expect(logic.values.lineageFailed).toBe(failed)
+ })
+
+ it('clears the error and asks again when the retry runs', async () => {
+ lineageRequest().mockRejectedValueOnce(new ApiError('nope', 500))
+ await mountLogic()
+ expect(logic.values.lineageFailed).toBe(true)
+
+ lineageRequest().mockResolvedValue({
+ nodes: [{ id: 'node-self', saved_query_id: 'saved-query-1' }],
+ edges: [],
+ })
+ logic.actions.loadLineage()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(lineageRequest()).toHaveBeenCalledTimes(2)
+ expect(logic.values.lineageFailed).toBe(false)
+ expect(logic.values.currentNodeId).toBe('node-self')
+ })
+})
diff --git a/products/endpoints/frontend/endpoint-tabs/endpointLineageLogic.ts b/products/endpoints/frontend/endpoint-tabs/endpointLineageLogic.ts
new file mode 100644
index 000000000000..d34c07403ede
--- /dev/null
+++ b/products/endpoints/frontend/endpoint-tabs/endpointLineageLogic.ts
@@ -0,0 +1,105 @@
+import { MakeLogicType, afterMount, kea, key, path, props, reducers, selectors } from 'kea'
+import { loaders } from 'kea-loaders'
+
+import api from 'lib/api'
+
+import { DataModelingEdge, DataModelingNode } from '~/types'
+
+export interface EndpointLineageLogicProps {
+ savedQueryId: string
+}
+
+export interface EndpointLineageGraph {
+ nodes: DataModelingNode[]
+ edges: DataModelingEdge[]
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface endpointLineageLogicValues {
+ currentNodeId: string | undefined
+ lineage: EndpointLineageGraph | null
+ lineageFailed: boolean
+ lineageLoading: boolean
+ lineageMissing: boolean
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface endpointLineageLogicActions {
+ loadLineage: () => any
+ loadLineageFailure: (
+ error: string,
+ errorObject?: any
+ ) => {
+ error: string
+ errorObject?: any
+ }
+ loadLineageSuccess: (
+ lineage: {
+ edges: DataModelingEdge[]
+ nodes: DataModelingNode[]
+ },
+ payload?: any
+ ) => {
+ lineage: {
+ edges: DataModelingEdge[]
+ nodes: DataModelingNode[]
+ }
+ payload?: any
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface endpointLineageLogicMeta {
+ key: string
+ __keaTypeGenInternalSelectorTypes: {
+ currentNodeId: (lineage: EndpointLineageGraph | null, savedQueryId: string) => string | undefined
+ }
+}
+
+export type endpointLineageLogicType = MakeLogicType<
+ endpointLineageLogicValues,
+ endpointLineageLogicActions,
+ EndpointLineageLogicProps,
+ endpointLineageLogicMeta
+>
+
+export const endpointLineageLogic = kea<endpointLineageLogicType>([
+ path((savedQueryId) => ['products', 'endpoints', 'frontend', 'endpointLineageLogic', savedQueryId]),
+ props({} as EndpointLineageLogicProps),
+ key((props) => props.savedQueryId),
+ loaders(({ props }) => ({
+ lineage: {
+ __default: null as EndpointLineageGraph | null,
+ loadLineage: async () => await api.dataModelingNodes.lineage({ savedQueryId: props.savedQueryId }),
+ },
+ })),
+ reducers({
+ lineageMissing: [
+ false,
+ {
+ loadLineage: () => false,
+ loadLineageSuccess: () => false,
+ // The backing model has no lineage node yet, which is not a failure the user can retry away.
+ loadLineageFailure: (_, { errorObject }) => errorObject?.status === 404,
+ },
+ ],
+ lineageFailed: [
+ false,
+ {
+ loadLineage: () => false,
+ loadLineageSuccess: () => false,
+ loadLineageFailure: (_, { errorObject }) => errorObject?.status !== 404,
+ },
+ ],
+ }),
+ selectors({
+ currentNodeId: [
+ (s, p) => [s.lineage, p.savedQueryId],
+ (lineage: EndpointLineageGraph | null, savedQueryId: string): string | undefined =>
+ lineage?.nodes.find((node) => node.saved_query_id === savedQueryId)?.id,
+ ],
+ }),
+ afterMount(({ actions }) => {
+ actions.loadLineage()
+ }),
+])
diff --git a/products/endpoints/frontend/endpointSceneLogic.tsx b/products/endpoints/frontend/endpointSceneLogic.tsx
index b12d66d3bc5e..18b9b8bedb0c 100644
--- a/products/endpoints/frontend/endpointSceneLogic.tsx
+++ b/products/endpoints/frontend/endpointSceneLogic.tsx
@@ -120,6 +120,7 @@ export enum EndpointTab {
VERSIONS = 'versions',
PLAYGROUND = 'playground',
LOGS = 'logs',
+ LINEAGE = 'lineage',
HISTORY = 'history',
}