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.

fix(data-warehouse): show historical rows under the PostHog warehouse (#110695)

Tom Owers5e8be3efa375
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 36a46f890df8..40809615f054 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9815,13 +9815,13 @@ snapshots:
scenes-app-errortracking-linkedreports--several-reports-across-states--light:
hash: v1.k794b7964.fe2161a3bb0e898689ef58a342d071c353ded71ac270a62998ea566055359e7a.AnoCs1sNoTY6J1yl24yuZPh_1Jkjugz-jnYxHgY8ZyU
scenes-app-etl--healthy--dark:
- hash: v1.k794b7964.2db2add131ea077b296ee62e52f0f468917a37a3046d184b0802ea94d0ebd7da.nyXMgbG9Is8OHWPI61v0qLBOb9XNLClA5uwrqSWh2Yg
+ hash: v1.k794b7964.342346c35b32e21a02a09fe488480c9d100dbfda52c5b7c6b8dac3d2f83f3cf2.conExopWBDSppCq6BcJkzZ7MFg2JFCvBC0FF5QDc_xs
scenes-app-etl--healthy--light:
- hash: v1.k794b7964.40a3df65bf4b44f8ee1eaafe56fb8abecb48339f47a39a918c9af4c3dd1d393e.v8nVc5frK8uZ7XEhaAUMx0pTpApv1gJkWfsHPlVN04c
+ hash: v1.k794b7964.88245f9f3d4dbc35485f0f2cad3b516dd603e94441cf19b9e19bda8fd4fe2de6.krGZaFW2zaFivovleByCTzMPyLN3PwIxzf4IuBeUPO0
scenes-app-etl--needs-attention--dark:
- hash: v1.k794b7964.a31167943bf4df4081dda74a532653ab9b72c578cca023907bd9a79c58713473.XwfOOC2wCuW7RemE5vUoD_l1_Yqb4ZA3JZvn5fkO9kM
+ hash: v1.k794b7964.d2e091fbea79cfa1fe3300241367e48b811b2400d49e880a24f4b02785776646.PTrR95S1l8scT-93IqNFp8x7EGVPCC_xlIRPKbLXbCo
scenes-app-etl--needs-attention--light:
- hash: v1.k794b7964.baf6c5d33e97cfba98e911746be731f313be945ecc91d06d3321bcaf7e9c0d78.5c-O2ZGQGWBrcoR-AigyGLsMeVtJLveQh819LyawMw0
+ hash: v1.k794b7964.2191373653f651b1c140b616c7cc6d9d97addf1f79dd3f663e7664f47040c538.yY9v-EpvhW9u0XUs2p7VyYxHmN8dA_QJm6D8zQikTkA
scenes-app-events--event-explorer--dark:
hash: v1.k794b7964.3bf3b01d0972be5ad8fe4a7408d20b10e2431ea8f28874aa0a63f7623c1af97c.ONFJgVNjjG1f32eqlxRZuleSgdLpLGIcFhHN2S4yvhk
scenes-app-events--event-explorer--light:
diff --git a/frontend/src/lib/components/AppMetrics/appMetricsLogic.test.ts b/frontend/src/lib/components/AppMetrics/appMetricsLogic.test.ts
index 4e510e27d836..b2359335b4d0 100644
--- a/frontend/src/lib/components/AppMetrics/appMetricsLogic.test.ts
+++ b/frontend/src/lib/components/AppMetrics/appMetricsLogic.test.ts
@@ -9,6 +9,23 @@ describe('app metrics logic', () => {
jest.restoreAllMocks()
})
+ it('filters a time series to a set of instance ids', async () => {
+ jest.spyOn(api, 'queryHogQL').mockResolvedValue({ results: [] } as HogQLQueryResponse)
+
+ await loadAppMetricsTimeSeries(
+ {
+ appSource: 'warehouse_source_sync',
+ instanceIds: ['schema-1', 'schema-2'],
+ breakdownBy: 'metric_name',
+ dateFrom: '2026-10-01T00:00:00Z',
+ dateTo: '2026-10-02T00:00:00Z',
+ },
+ 'UTC'
+ )
+
+ expect(jest.mocked(api.queryHogQL).mock.calls[0][0]).toContain("instance_id IN ['schema-1', 'schema-2']")
+ })
+
it('keeps ISO offsets that distinguish repeated local hours', async () => {
const labels = ['2026-11-01T01:00:00-07:00', '2026-11-01T01:00:00-08:00']
jest.spyOn(api, 'queryHogQL').mockResolvedValue({
diff --git a/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts b/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts
index 3d60c29838df..48ba72b2e863 100644
--- a/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts
+++ b/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts
@@ -33,6 +33,8 @@ export type AppMetricsCommonParams = {
/** Match all app_source_ids starting with this prefix (e.g. `<hog flow id>/` for versioned hog flow metrics). */
appSourceIdPrefix?: string
instanceId?: string
+ /** Match any of these instance IDs. */
+ instanceIds?: string[]
metricName?: string | string[]
metricKind?: string | string[]
breakdownBy?: 'metric_name' | 'metric_kind' | 'app_source_id' | 'instance_id'
@@ -114,6 +116,9 @@ export const loadAppMetricsTotals = async (
if (typeof request.instanceId === 'string') {
query = (query + hogql`\nAND instance_id = ${request.instanceId}`) as HogQLQueryString
}
+ if (request.instanceIds) {
+ query = (query + hogql`\nAND instance_id IN ${request.instanceIds}`) as HogQLQueryString
+ }
if (request.metricName) {
const metricNames = Array.isArray(request.metricName) ? request.metricName : [request.metricName]
query = (query + hogql`\nAND metric_name IN ${metricNames}`) as HogQLQueryString
@@ -227,6 +232,9 @@ export const loadAppMetricsTimeSeries = async (
if (typeof request.instanceId === 'string') {
query = (query + hogql`\nAND instance_id = ${request.instanceId}`) as HogQLQueryString
}
+ if (request.instanceIds) {
+ query = (query + hogql`\nAND instance_id IN ${request.instanceIds}`) as HogQLQueryString
+ }
if (request.metricName) {
const metricNames = Array.isArray(request.metricName) ? request.metricName : [request.metricName]
query = (query + hogql`\nAND metric_name IN ${metricNames}`) as HogQLQueryString
diff --git a/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.test.ts b/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.test.ts
index b9cbb8d20268..e52a436f8d34 100644
--- a/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.test.ts
+++ b/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.test.ts
@@ -229,6 +229,9 @@ describe('pipelineOverviewSceneLogic', () => {
{ id: 'dest-2', name: 'Analytics Postgres', type: 'Postgres' },
],
})
+ wsApi.externalDataSourcesList.mockResolvedValue({
+ results: [{ id: 'source-1', schemas: [{ id: 'schema-1' }, { id: 'schema-2' }] }],
+ })
metrics.loadAppMetricsTimeSeries.mockResolvedValue({
labels: ['2026-09-27', '2026-09-28'],
interval: 'day',
@@ -240,11 +243,15 @@ describe('pipelineOverviewSceneLogic', () => {
await expectLogic(logic).toFinishAllListeners()
const asked = metrics.loadAppMetricsTimeSeries.mock.calls.map(([request]: any[]) => request)
- expect(asked.map((r: any) => r.instanceId).sort()).toEqual(['dest-1', 'dest-2'])
+ // One request per destination, plus one request restricted to schema attribution keys.
+ expect(asked.map((r: any) => r.instanceId).filter(Boolean)).toEqual(
+ expect.arrayContaining(['dest-1', 'dest-2'])
+ )
+ expect(asked.find((r: any) => r.instanceIds)?.instanceIds).toEqual(['schema-1', 'schema-2'])
// The query interpolates `breakdownBy` with no fallback, so omitting it emits
// `undefined AS breakdown` and the whole chart fails to load. This asserted the
// omission before, which is how that shipped.
- expect(asked.every((r: any) => r.breakdownBy === 'instance_id')).toBe(true)
+ expect(asked.every((r: any) => !!r.breakdownBy)).toBe(true)
// Both bounds go straight into `toDateTime(...)`, so a relative string or a missing
// `dateTo` makes the query throw instead of returning rows.
asked.forEach((r: any) => {
@@ -252,10 +259,6 @@ describe('pipelineOverviewSceneLogic', () => {
expect(Date.parse(r.dateTo)).not.toBeNaN()
expect(Date.parse(r.dateFrom)).toBeLessThan(Date.parse(r.dateTo))
})
- expect(logic.values.rowsByDestination.map((s: any) => s.label)).toEqual([
- 'PostHog warehouse',
- 'Analytics Postgres',
- ])
})
it('leaves webhook tables out of the health list', async () => {
@@ -308,4 +311,39 @@ describe('pipelineOverviewSceneLogic', () => {
expect(wsApi.externalDataSourcesList).toHaveBeenNthCalledWith(1, expect.anything(), { limit: 100, offset: 0 })
expect(wsApi.externalDataSourcesList).toHaveBeenNthCalledWith(2, expect.anything(), { limit: 100, offset: 2 })
})
+
+ it('gives the warehouse whatever the other destinations did not take', async () => {
+ // Runs that resolve to the warehouse alone report no destination, so those rows only
+ // exist in the schema-keyed total. Reading the warehouse series directly showed almost
+ // nothing on a project that had synced billions of rows.
+ logic.unmount()
+ wsApi.externalDataDestinationsList.mockResolvedValue({
+ results: [
+ { id: 'wh', name: 'PostHog warehouse', type: 'PostHogWarehouse' },
+ { id: 'pg', name: 'Analytics Postgres', type: 'Postgres' },
+ ],
+ })
+ wsApi.externalDataSourcesList.mockResolvedValue({
+ results: [{ id: 'source-1', schemas: [{ id: 'schema-1' }] }],
+ })
+ metrics.loadAppMetricsTimeSeries.mockImplementation(async (request: any) => ({
+ labels: ['2026-10-01', '2026-10-02'],
+ interval: 'day',
+ timezone: 'UTC',
+ // The warehouse reports nothing of its own; Postgres took 20 of the 100 total.
+ series:
+ request.instanceId === 'pg'
+ ? [{ name: 'pg', values: [20, 20] }]
+ : request.instanceId === 'wh'
+ ? [{ name: 'wh', values: [0, 0] }]
+ : [{ name: 'rows_synced', values: [100, 100] }],
+ }))
+
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ const byLabel = Object.fromEntries(logic.values.rowsByDestination.map((s: any) => [s.label, s.data]))
+ expect(byLabel['PostHog warehouse']).toEqual([80, 80])
+ expect(byLabel['Analytics Postgres']).toEqual([20, 20])
+ })
})
diff --git a/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.ts b/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.ts
index ae443d2e13d6..040dee17be4d 100644
--- a/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.ts
+++ b/products/warehouse_sources/frontend/scenes/PipelineOverviewScene/pipelineOverviewSceneLogic.ts
@@ -93,7 +93,7 @@ export interface pipelineOverviewSceneLogicValues {
sourcesLoading: boolean
syncingTableCount: number
lastUpdatedAt: string | null
- destinationRowSeries: { labels: string[]; series: { id: string; values: number[] }[] } | null
+ destinationRowSeries: { labels: string[]; series: { id: string; values: number[] }[]; total: number[] } | null
destinationRowSeriesLoading: boolean
rowsByDestination: { key: string; label: string; data: number[]; type: 'area'; fill: { opacity: number } }[]
hasIssues: boolean
@@ -200,12 +200,12 @@ export const pipelineOverviewSceneLogic = kea<pipelineOverviewSceneLogicType>([
},
],
destinationRowSeries: [
- null as { labels: string[]; series: { id: string; values: number[] }[] } | null,
+ null as { labels: string[]; series: { id: string; values: number[] }[]; total: number[] } | null,
{
loadDestinationRowSeries: async () => {
const destinations = values.destinations ?? []
if (destinations.length === 0) {
- return { labels: [], series: [] }
+ return { labels: [], series: [], total: [] }
}
const interval = values.window === 1 ? ('hour' as const) : ('day' as const)
// Both bounds are interpolated into `toDateTime(...)`, so they have to be
@@ -216,34 +216,47 @@ export const pipelineOverviewSceneLogic = kea<pipelineOverviewSceneLogicType>([
// One request per destination, filtered on `instanceId`, rather than one
// breakdown over every instance. The breakdown is capped at 100 rows, and a
// team with thousands of tables pushes every destination out of that cap.
- const answers = await Promise.all(
- destinations.map(async (destination: ExternalDataDestinationApi) => ({
- id: destination.id,
- response: await loadAppMetricsTimeSeries(
- {
- appSource: WAREHOUSE_APP_SOURCE,
- metricName: 'rows_synced',
- instanceId: destination.id,
- // The time-series query interpolates `breakdownBy` with no
- // fallback, so omitting it emits `undefined AS breakdown` and
- // the query fails to resolve. `instance_id` is already pinned
- // to one destination by `instanceId`, so this yields one series.
- breakdownBy: 'instance_id',
- interval,
- dateFrom,
- dateTo,
- },
- values.currentTeam?.timezone ?? 'UTC'
- ),
- }))
+ const common = {
+ appSource: WAREHOUSE_APP_SOURCE,
+ metricName: 'rows_synced',
+ // The time-series query interpolates `breakdownBy` with no fallback, so
+ // omitting it emits `undefined AS breakdown` and the query fails to
+ // resolve. Each request is already pinned to one series by its filter.
+ breakdownBy: 'instance_id' as const,
+ interval,
+ dateFrom,
+ dateTo,
+ }
+ const timezone = values.currentTeam?.timezone ?? 'UTC'
+ const schemaIds = (values.sources ?? []).flatMap((source: ExternalDataSourceSerializersApi) =>
+ (source.schemas ?? []).map((schema) => String(schema.id))
)
+ const [answers, total] = await Promise.all([
+ Promise.all(
+ destinations.map(async (destination: ExternalDataDestinationApi) => ({
+ id: destination.id,
+ response: await loadAppMetricsTimeSeries(
+ { ...common, instanceId: destination.id },
+ timezone
+ ),
+ }))
+ ),
+ schemaIds.length > 0
+ ? loadAppMetricsTimeSeries(
+ { ...common, instanceIds: schemaIds, breakdownBy: 'metric_name' },
+ timezone
+ )
+ : Promise.resolve({ labels: [], interval, timezone, series: [] }),
+ ])
return {
- labels: answers.find((a) => a.response.labels.length > 0)?.response.labels ?? [],
+ labels:
+ answers.find((a) => a.response.labels.length > 0)?.response.labels ?? total.labels ?? [],
series: answers.map((a) => ({
id: a.id,
// Without a breakdown the response carries a single unnamed series.
values: a.response.series[0]?.values ?? [],
})),
+ total: total.series[0]?.values ?? [],
}
},
},
@@ -300,11 +313,18 @@ export const pipelineOverviewSceneLogic = kea<pipelineOverviewSceneLogicType>([
(healthIssues: DataHealthIssuesResponseApi | null): number =>
(healthIssues?.results ?? []).filter((issue) => issue.type === 'external_data_sync').length,
],
- /** One chart series per destination, biggest first so the legend matches the stack. */
+ /**
+ * One chart series per destination, biggest first so the legend matches the stack.
+ *
+ * The PostHog warehouse series is derived rather than read directly. Runs from before
+ * destination attribution landed report no destination at all, and a run that resolves
+ * to the warehouse alone still reports none. Those rows only exist keyed by schema, in
+ * the total, so the warehouse gets whatever the other destinations did not take.
+ */
rowsByDestination: [
(s: any) => [s.destinationRowSeries, s.destinations],
(
- answer: { labels: string[]; series: { id: string; values: number[] }[] } | null,
+ answer: { labels: string[]; series: { id: string; values: number[] }[]; total: number[] } | null,
destinations: ExternalDataDestinationApi[] | null
): {
key: string
@@ -317,15 +337,25 @@ export const pipelineOverviewSceneLogic = kea<pipelineOverviewSceneLogicType>([
return []
}
const byId = new Map(destinations.map((d) => [d.id, d]))
- return answer.series
+ const warehouse = destinations.find((d) => d.type === 'PostHogWarehouse')
+ const elsewhere = answer.series.filter((s) => s.id !== warehouse?.id)
+
+ const derivedWarehouse = answer.total.map((rows, i) =>
+ Math.max(0, rows - elsewhere.reduce((sum, s) => sum + (s.values[i] ?? 0), 0))
+ )
+
+ const series = elsewhere.map((s) => ({ id: s.id, values: s.values }))
+ if (warehouse) {
+ series.push({ id: warehouse.id, values: derivedWarehouse })
+ }
+
+ return series
.map((s) => ({
key: s.id,
label: byId.get(s.id)?.name ?? s.id,
data: s.values,
type: 'area' as const,
// `fill` is what makes an area series fill; `type` alone draws a line.
- // The chart stacks area series and offers no way not to, so the section
- // copy says the total is row-writes rather than rows.
fill: { opacity: 0.25 },
total: s.values.reduce((a, b) => a + b, 0),
}))
@@ -377,7 +407,7 @@ export const pipelineOverviewSceneLogic = kea<pipelineOverviewSceneLogicType>([
): boolean => (jobStatsLoading && jobStats === null) || (healthIssuesLoading && healthIssues === null),
],
}),
- listeners(({ actions }: any) => ({
+ listeners(({ actions, values }: any) => ({
// Health is current state and rows are reported per billing period, so neither is
// windowed. Everything else is.
setWindow: () => {
@@ -386,9 +416,18 @@ export const pipelineOverviewSceneLogic = kea<pipelineOverviewSceneLogicType>([
actions.loadRecentRuns()
},
refresh: () => actions.loadEverything(),
- // The series are fetched one destination at a time, so the destination list has to land
- // first. Chaining on success is what guarantees that on a reload as well as on mount.
- loadDestinationsSuccess: () => actions.loadDestinationRowSeries(),
+ // The destination and schema lists identify the two attribution key types in app_metrics.
+ // Wait for both so the overall request can select schema-keyed rows exactly.
+ loadDestinationsSuccess: () => {
+ if (values.sources !== null) {
+ actions.loadDestinationRowSeries()
+ }
+ },
+ loadSourcesSuccess: () => {
+ if (values.destinations !== null) {
+ actions.loadDestinationRowSeries()
+ }
+ },
loadEverything: () => {
actions.loadJobStats()
actions.loadRowsStats()