: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
feat(batch-exports): filter runs by status in the UI (#89060)
Rossd725627db186
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 9770b04b16ba..8230d8d6de37 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -5052,7 +5052,8 @@ const api = {id: BatchExportConfiguration['id'],params: Record<string, any> = {}): Promise<PaginatedResponse<RawBatchExportRun>> {- return await new ApiRequest().batchExportRuns(id).withQueryString(toParams(params)).get()+ // Explode arrays, as the runs endpoint reads repeated parameters (`?status=Failed&status=Running`).+ return await new ApiRequest().batchExportRuns(id).withQueryString(toParams(params, true)).get()},async createBackfill(id: BatchExportConfiguration['id'],diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRunStatusFilter.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRunStatusFilter.tsxnew file mode 100644index 000000000000..01ed5b8eed1f--- /dev/null+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRunStatusFilter.tsx@@ -0,0 +1,64 @@+import { useActions, useValues } from 'kea'++import { IconChevronDown } from '@posthog/icons'+import { LemonButton, LemonCheckbox, LemonDropdown } from '@posthog/lemon-ui'++import { batchExportRunsLogic } from './batchExportRunsLogic'+import { BATCH_EXPORT_RUN_STATUS_FILTER_OPTIONS, BatchExportRunStatusGroup } from './utils'++function summarize(selected: BatchExportRunStatusGroup[]): string {+ if (selected.length === 0 || selected.length === BATCH_EXPORT_RUN_STATUS_FILTER_OPTIONS.length) {+ return 'All statuses'+ }+ if (selected.length === 1) {+ return BATCH_EXPORT_RUN_STATUS_FILTER_OPTIONS.find((option) => option.value === selected[0])?.label ?? 'Status'+ }+ return `${selected.length} statuses`+}++export function BatchExportRunStatusFilter({ id }: { id: string }): JSX.Element {+ const { statusFilter } = useValues(batchExportRunsLogic({ id }))+ const { setStatusFilter } = useActions(batchExportRunsLogic({ id }))++ return (+ <LemonDropdown+ closeOnClickInside={false}+ overlay={+ <div className="flex flex-col gap-px p-1">+ {BATCH_EXPORT_RUN_STATUS_FILTER_OPTIONS.map((option) => (+ <LemonButton+ key={option.value}+ type="tertiary"+ size="small"+ fullWidth+ icon={+ <LemonCheckbox+ checked={statusFilter.includes(option.value)}+ className="pointer-events-none"+ />+ }+ onClick={() =>+ setStatusFilter(+ statusFilter.includes(option.value)+ ? statusFilter.filter((value) => value !== option.value)+ : [...statusFilter, option.value]+ )+ }+ >+ {option.label}+ </LemonButton>+ ))}+ </div>+ }+ >+ <LemonButton+ type="secondary"+ size="small"+ sideIcon={<IconChevronDown />}+ data-attr="batch-export-runs-status-filter"+ >+ {summarize(statusFilter)}+ </LemonButton>+ </LemonDropdown>+ )+}diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRuns.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRuns.tsxindex 135c40d692ed..20989a4b8125 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRuns.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRuns.tsx@@ -14,7 +14,9 @@ import { BatchExportConfiguration, BatchExportRun, GroupedBatchExportRuns } fromimport { BatchExportBackfillModal } from './BatchExportBackfillModal'import { BatchExportLoadingSkeleton } from './BatchExportLoadingSkeleton'+import { BatchExportRunsEmptyState } from './BatchExportRunsEmptyState'import { BatchExportRunsLogicProps, batchExportRunsLogic } from './batchExportRunsLogic'+import { BatchExportRunStatusFilter } from './BatchExportRunStatusFilter'import { BatchExportContext } from './types'import { statusToLemonTagType } from './utils'@@ -77,6 +79,7 @@ function BatchExportRunsFilters({ id }: { id: string }): JSX.Element {onChange={switchLatestRuns}size="small"/>+ <BatchExportRunStatusFilter id={id} /><DateFilterdateTo={dateRange.to}dateFrom={dateRange.from}@@ -97,7 +100,7 @@ function BatchExportLatestRuns({ id, context }: BatchExportRunsLogicProps): JSX.const logic = batchExportRunsLogic({ id, context })const { batchExportConfig, latestRuns, loading, hasMoreRunsToLoad, recordLabel } = useValues(logic)- const { openBackfillModal, loadOlderRuns, retryRun, cancelRun } = useActions(logic)+ const { loadOlderRuns, retryRun, cancelRun } = useActions(logic)if (!batchExportConfig) {return <NotFound object="batch export" />@@ -204,16 +207,7 @@ function BatchExportLatestRuns({ id, context }: BatchExportRunsLogicProps): JSX.},},]}- emptyState={- <div className="deprecated-space-y-2">- <div>- No runs in this time range. Your exporter runs every <b>{batchExportConfig.interval}</b>.- </div>- <LemonButton type="primary" onClick={() => openBackfillModal()}>- Start backfill- </LemonButton>- </div>- }+ emptyState={<BatchExportRunsEmptyState id={id} interval={batchExportConfig.interval} />}/></>)@@ -240,11 +234,16 @@ export function BatchExportRunsGrouped({}): JSX.Element {const logic = batchExportRunsLogic({ id, context })- const { openBackfillModal } = useActions(logic)- const { recordLabel } = useValues(logic)+ const { recordLabel, statusFilterActive } = useValues(logic)return (<>+ {statusFilterActive && (+ <div className="text-secondary text-xs">+ Only the attempts that match the status filter are shown. An interval can have other attempts that+ are hidden.+ </div>+ )}<LemonTable<GroupedBatchExportRuns>dataSource={groupedRuns}loading={loading}@@ -375,16 +374,7 @@ export function BatchExportRunsGrouped({},},]}- emptyState={- <div className="deprecated-space-y-2">- <div>- No runs in this time range. Your exporter runs every <b>{interval}</b>.- </div>- <LemonButton type="primary" onClick={() => openBackfillModal()}>- Start backfill- </LemonButton>- </div>- }+ emptyState={<BatchExportRunsEmptyState id={id} interval={interval} />}/></>)diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRunsEmptyState.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRunsEmptyState.tsxnew file mode 100644index 000000000000..0499efcf512a--- /dev/null+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportRunsEmptyState.tsx@@ -0,0 +1,40 @@+import { useActions, useValues } from 'kea'++import { LemonButton } from '@posthog/lemon-ui'++import { BatchExportConfiguration } from '~/types'++import { batchExportRunsLogic } from './batchExportRunsLogic'++export function BatchExportRunsEmptyState({+ id,+ interval,+}: {+ id: string+ interval: BatchExportConfiguration['interval']+}): JSX.Element {+ const { statusFilterActive } = useValues(batchExportRunsLogic({ id }))+ const { setStatusFilter, openBackfillModal } = useActions(batchExportRunsLogic({ id }))++ if (statusFilterActive) {+ return (+ <div className="deprecated-space-y-2">+ <div>No runs match this status filter.</div>+ <LemonButton type="secondary" onClick={() => setStatusFilter([])}>+ Clear filter+ </LemonButton>+ </div>+ )+ }++ return (+ <div className="deprecated-space-y-2">+ <div>+ No runs in this time range. Your exporter runs every <b>{interval}</b>.+ </div>+ <LemonButton type="primary" onClick={() => openBackfillModal()}>+ Start backfill+ </LemonButton>+ </div>+ )+}diff --git a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportScene.stories.tsx b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportScene.stories.tsxindex 7730b9920aa0..a890e55a866d 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/BatchExportScene.stories.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/BatchExportScene.stories.tsx@@ -232,9 +232,12 @@ export const RunsWithData: Story = {'/api/environments/:team_id/batch_exports/': batchExports,[`/api/environments/:team_id/batch_exports/${EXISTING_EXPORT.id}/`]: EXISTING_EXPORT,'/api/environments/:team_id/batch_exports/test/': { steps: [] },- [`/api/environments/:team_id/batch_exports/${EXISTING_EXPORT.id}/runs/`]: {- results: MOCK_RUNS,- next: null,+ [`/api/environments/:team_id/batch_exports/${EXISTING_EXPORT.id}/runs/`]: ({ request }) => {+ const statuses = new URL(request.url).searchParams.getAll('status')+ const results = statuses.length+ ? MOCK_RUNS.filter((run) => statuses.includes(run.status))+ : MOCK_RUNS+ return { results, next: null }},[`/api/environments/:team_id/batch_exports/${EXISTING_EXPORT.id}/backfills/`]: { results: [] },},diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.test.ts b/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.test.tsindex 8671188228cc..aaccd51000e7 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.test.ts+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.test.ts@@ -69,17 +69,24 @@ function makeRun(overrides: Partial<RawBatchExportRun> = {}): RawBatchExportRundescribe('batchExportRunsLogic', () => {let logic: ReturnType<typeof batchExportRunsLogic.build>+ let lastRunsRequestUrl: URL | null++ // Spies on the api module survive the test that made them, and would stop later tests reaching the mock server.+ afterEach(() => {+ jest.restoreAllMocks()+ })// oxlint-disable-next-line react-hooks/rules-of-hooks -- useMocks is not a React hookasync function setupLogic(runsResponse?: { results: RawBatchExportRun[]; next: string | null }): Promise<void> {+ lastRunsRequestUrl = null// eslint-disable-next-line react-hooks/rules-of-hooks -- useMocks is an MSW test helper, not a React hookuseMocks({get: {[`/api/environments/:team_id/batch_exports/${MOCK_BATCH_EXPORT_ID}/`]: MOCK_BATCH_EXPORT_CONFIG,'/api/environments/:team_id/batch_exports/test/': { steps: [] },- [`/api/environments/:team_id/batch_exports/${MOCK_BATCH_EXPORT_ID}/runs/`]: runsResponse ?? {- results: [],- next: null,+ [`/api/environments/:team_id/batch_exports/${MOCK_BATCH_EXPORT_ID}/runs/`]: ({ request }) => {+ lastRunsRequestUrl = new URL(request.url)+ return [200, runsResponse ?? { results: [], next: null }]},},})@@ -214,4 +221,26 @@ describe('batchExportRunsLogic', () => {expect(loadSpy).toHaveBeenCalled()})})++ describe('status filter', () => {+ // Asserted through the request URL rather than a listRuns spy, so the group expansion and+ // the repeated-parameter encoding are both covered.+ it.each([+ ['latest runs mode', true],+ ['grouped mode', false],+ ])('sends the expanded statuses as repeated parameters in %s', async (_label, usingLatestRuns) => {+ await setupLogic()++ logic.actions.switchLatestRuns(usingLatestRuns)+ logic.actions.setStatusFilter(['failed'])+ await expectLogic(logic).toFinishAllListeners()++ expect(lastRunsRequestUrl).not.toBeNull()+ expect(lastRunsRequestUrl!.searchParams.getAll('status')).toEqual([+ 'Failed',+ 'FailedRetryable',+ 'FailedBilling',+ ])+ })+ })})diff --git a/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.tsx b/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.tsxindex 0b8c3d7128bb..db6181050eae 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.tsx+++ b/frontend/src/scenes/data-pipelines/batch-exports/batchExportRunsLogic.tsx@@ -14,6 +14,7 @@ import type { BatchExportConfiguration } from '../../../types'import { batchExportBackfillModalLogic } from './batchExportBackfillModalLogic'import { batchExportDataLogic } from './batchExportDataLogic'import { BatchExportContext } from './types'+import { BatchExportRunStatusGroup, BatchExportStatus, batchExportRunStatusesForGroups } from './utils'const DEFAULT_DATE_FROM = '-2d'export interface BatchExportRunsLogicProps {@@ -36,6 +37,9 @@ export interface batchExportRunsLogicValues {recordLabel: stringrunsPaginatedResponse: PaginatedResponse<RawBatchExportRun> | nullrunsPaginatedResponseLoading: boolean+ statusFilter: BatchExportRunStatusGroup[]+ statusFilterActive: boolean+ statusFilterStatuses: BatchExportStatus[]usingLatestRuns: boolean}@@ -104,6 +108,9 @@ export interface batchExportRunsLogicActions {from: string | nullto: string | null}+ setStatusFilter: (statuses: BatchExportRunStatusGroup[]) => {+ statuses: BatchExportRunStatusGroup[]+ }switchLatestRuns: (enabled: boolean) => {enabled: boolean}@@ -121,6 +128,8 @@ export interface batchExportRunsLogicMeta {runsPaginatedResponse: PaginatedResponse<RawBatchExportRun> | null,usingLatestRuns: boolean) => GroupedBatchExportRuns[]+ statusFilterActive: (statusFilter: BatchExportRunStatusGroup[]) => boolean+ statusFilterStatuses: (statusFilter: BatchExportRunStatusGroup[]) => BatchExportStatus[]}}@@ -141,6 +150,7 @@ export const batchExportRunsLogic = kea<batchExportRunsLogicType>([})),actions({setDateRange: (from: string | null, to: string | null) => ({ from, to }),+ setStatusFilter: (statuses: BatchExportRunStatusGroup[]) => ({ statuses }),switchLatestRuns: (enabled: boolean) => ({ enabled }),loadRuns: true,retryRun: (run: BatchExportRun) => ({ run }),@@ -151,15 +161,21 @@ export const batchExportRunsLogic = kea<batchExportRunsLogicType>([null as PaginatedResponse<RawBatchExportRun> | null,{loadRuns: async () => {+ // Leave the key out entirely when nothing is selected, as a blank status is rejected.+ const statusParams = values.statusFilterStatuses.length+ ? { status: values.statusFilterStatuses }+ : {}+// TODO: loading and combining the data could be more efficientif (values.usingLatestRuns) {- return await api.batchExports.listRuns(props.id, {})+ return await api.batchExports.listRuns(props.id, statusParams)}return await api.batchExports.listRuns(props.id, {start: values.dateRange.from,end: values.dateRange.to, // TODO: maybe add 1 dayordering: '-data_interval_start',+ ...statusParams,})},loadOlderRuns: async () => {@@ -183,6 +199,14 @@ export const batchExportRunsLogic = kea<batchExportRunsLogicType>([setDateRange: (_, { from, to }) => ({ from: from ?? DEFAULT_DATE_FROM, to: to }),},],+ // TODO: move this, the date range, and the latest-runs toggle into the URL together, so a+ // filtered view can be shared.+ statusFilter: [+ [] as BatchExportRunStatusGroup[],+ {+ setStatusFilter: (_, { statuses }) => statuses,+ },+ ],usingLatestRuns: [true,{@@ -265,11 +289,23 @@ export const batchExportRunsLogic = kea<batchExportRunsLogicType>([return Object.values(groupedRuns)},],+ statusFilterActive: [+ (s) => [s.statusFilter],+ (statusFilter: BatchExportRunStatusGroup[]): boolean => statusFilter.length > 0,+ ],+ statusFilterStatuses: [+ (s) => [s.statusFilter],+ (statusFilter: BatchExportRunStatusGroup[]): BatchExportStatus[] =>+ batchExportRunStatusesForGroups(statusFilter),+ ],}),listeners(({ actions, props }) => ({setDateRange: () => {actions.loadRuns()},+ setStatusFilter: () => {+ actions.loadRuns()+ },switchLatestRuns: () => {actions.loadRuns()},diff --git a/frontend/src/scenes/data-pipelines/batch-exports/utils.ts b/frontend/src/scenes/data-pipelines/batch-exports/utils.tsindex 5cabbed44302..20f123a31c42 100644--- a/frontend/src/scenes/data-pipelines/batch-exports/utils.ts+++ b/frontend/src/scenes/data-pipelines/batch-exports/utils.ts@@ -60,6 +60,37 @@ export const dayOptions = [/** Run or backfill workflow status (same union on both types). */export type BatchExportStatus = BatchExportRun['status']+/** Statuses a person can filter runs by, collapsing the Temporal states they don't distinguish. */+export type BatchExportRunStatusGroup = 'running' | 'completed' | 'failed' | 'cancelled'++// Typed as a full Record so a new status fails the build until someone puts it in a group.+const STATUS_TO_GROUP: Record<BatchExportStatus, BatchExportRunStatusGroup> = {+ Starting: 'running',+ Running: 'running',+ ContinuedAsNew: 'running',+ Completed: 'completed',+ Failed: 'failed',+ FailedRetryable: 'failed',+ FailedBilling: 'failed',+ Cancelled: 'cancelled',+ Terminated: 'cancelled',+ TimedOut: 'cancelled',+}++export const BATCH_EXPORT_RUN_STATUS_FILTER_OPTIONS: { value: BatchExportRunStatusGroup; label: string }[] = [+ { value: 'running', label: 'Running' },+ { value: 'completed', label: 'Completed' },+ { value: 'failed', label: 'Failed' },+ { value: 'cancelled', label: 'Cancelled' },+]++export function batchExportRunStatusesForGroups(groups: BatchExportRunStatusGroup[]): BatchExportStatus[] {+ const selected = new Set(groups)+ return (Object.keys(STATUS_TO_GROUP) as BatchExportStatus[]).filter((status) =>+ selected.has(STATUS_TO_GROUP[status])+ )+}+export function statusToLemonTagType(status: BatchExportStatus, options?: { recordsFailed?: number }): LemonTagType {if (status === 'Completed' && options?.recordsFailed != null && options.recordsFailed > 0) {return 'warning'@@ -77,6 +108,7 @@ export function statusToLemonTagType(status: BatchExportStatus, options?: { recoreturn 'warning'case 'Failed':case 'FailedRetryable':+ case 'FailedBilling':return 'danger'default:return 'default'@@ -97,6 +129,7 @@ export function statusToProgressStrokeColor(status: BatchExportStatus): string {return 'var(--warning)'case 'Failed':case 'FailedRetryable':+ case 'FailedBilling':return 'var(--danger)'default:return 'var(--color-border-primary)'diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex a1376cb64595..933ff8b4eafd 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -6942,6 +6942,7 @@ export type RawBatchExportRun = {| 'ContinuedAsNew'| 'Failed'| 'FailedRetryable'+ | 'FailedBilling'| 'Terminated'| 'TimedOut'| 'Running'@@ -6964,6 +6965,7 @@ export type BatchExportRun = {| 'ContinuedAsNew'| 'Failed'| 'FailedRetryable'+ | 'FailedBilling'| 'Terminated'| 'TimedOut'| 'Running'