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(workflows): show a per-run overview for batch workflows (#120461)

Daniel Marchuk6ed6d86e8c8e
diff --git a/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx b/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx
index 89d8a85806f5..c71687e95fe0 100644
--- a/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx
+++ b/products/workflows/frontend/Workflows/WorkflowMetricCard.tsx
@@ -66,6 +66,9 @@ export interface WorkflowMetricCardProps {
description?: ReactNode
timeSeries: AppMetricsTimeSeriesResponse | null
previousPeriodTimeSeries?: AppMetricsTimeSeriesResponse | null
+ /** Names the previous value, e.g. "Previous run (Oct 12)". The card then shows that value in words
+ * under its own, instead of a bare change pill. */
+ previousLabel?: string
color?: string
/** Per-series sparkline colors keyed by series name. When the response has more than one series,
* the tile draws one line per series (colored from here) instead of a single summed line. */
@@ -101,6 +104,7 @@ export function WorkflowMetricCard({
description,
timeSeries,
previousPeriodTimeSeries,
+ previousLabel,
color,
seriesColors,
colorIfZero,
@@ -207,7 +211,7 @@ export function WorkflowMetricCard({
labels={timeSeries?.labels}
theme={theme}
color={total === 0 ? colorIfZero : color}
- change={change}
+ change={previousLabel ? null : change}
positiveColor={neutral}
negativeColor={neutral}
formatValue={(v) => humanFriendlyNumber(v)}
@@ -237,6 +241,12 @@ export function WorkflowMetricCard({
<MetricDelta />
</MetricHeader>
<MetricValue className={compact ? 'mt-1' : 'mt-2'} />
+ {previousLabel && previousPeriodTimeSeries && (
+ <div className="text-xs text-muted" data-attr="workflow-metric-card-previous">
+ {`${previousLabel}: ${humanFriendlyNumber(totalPreviousPeriod)}`}
+ {total === totalPreviousPeriod ? ' (no change)' : change ? ` ${change.label}` : ''}
+ </div>
+ )}
<MetricSparkline className={compact ? '-mx-3 mt-2 h-16' : '-mx-3 mt-4'} />
</Metric>
{footer && (
diff --git a/products/workflows/frontend/Workflows/WorkflowMetrics.tsx b/products/workflows/frontend/Workflows/WorkflowMetrics.tsx
index 0f43b8007cb9..fccad3a9011f 100644
--- a/products/workflows/frontend/Workflows/WorkflowMetrics.tsx
+++ b/products/workflows/frontend/Workflows/WorkflowMetrics.tsx
@@ -247,8 +247,11 @@ function BatchJobMetricsHeader({ job }: { job: HogFlowBatchJob }): JSX.Element {
)
}
-function BatchJobMetrics({ job }: { job: HogFlowBatchJob }): JSX.Element {
+function BatchJobMetrics({ job, requestedAction }: { job: HogFlowBatchJob; requestedAction?: string }): JSX.Element {
const logicKey = `hog-flow-metrics-batch-${job.id}`
+ const { workflow, originalWorkflow, hogFunctionTemplatesById } = useValues(workflowLogic)
+ // A step a staged draft removes still has live metrics, and the overview links to it.
+ const knownActions = [...workflow.actions, ...(originalWorkflow?.actions ?? [])]
const jobStart = dayjs(job.created_at).subtract(1, 'hour')
const isFinished = job.status === 'completed' || job.status === 'cancelled' || job.status === 'failed'
@@ -261,6 +264,7 @@ function BatchJobMetrics({ job }: { job: HogFlowBatchJob }): JSX.Element {
defaultParams: {
dateFrom: jobStart.toISOString(),
dateTo: jobEnd.toISOString(),
+ instanceId: knownActions.some((action) => action.id === requestedAction) ? requestedAction : undefined,
},
forceParams: {
appSource: 'hog_flow',
@@ -269,10 +273,6 @@ function BatchJobMetrics({ job }: { job: HogFlowBatchJob }): JSX.Element {
},
})
- const { workflow, originalWorkflow, hogFunctionTemplatesById } = useValues(workflowLogic)
- // A step a staged draft removes still has live metrics, and the overview links to it.
- const knownActions = [...workflow.actions, ...(originalWorkflow?.actions ?? [])]
-
const { appMetricsTrendsLoading, appMetricsTrends, getSingleTrendSeries, params } = useValues(logic)
const { setParams } = useActions(logic)
@@ -387,6 +387,10 @@ function BatchJobMetrics({ job }: { job: HogFlowBatchJob }): JSX.Element {
function WorkflowBatchMetrics(props: WorkflowLogicProps): JSX.Element {
const { jobs, batchWorkflowJobsLoading } = useValues(batchWorkflowJobsLogic(props))
+ const { searchParams } = useValues(router)
+ // The overview links to a step of one run with ?run= and ?action=, so open that run's panel on that step.
+ const requestedRun = jobs.find((job) => job.id === searchParams.run)?.id
+ const requestedAction = typeof searchParams.action === 'string' ? searchParams.action : undefined
if (batchWorkflowJobsLoading) {
return (
@@ -411,10 +415,16 @@ function WorkflowBatchMetrics(props: WorkflowLogicProps): JSX.Element {
return (
<div className="flex flex-col gap-2">
<LemonCollapse
+ defaultActiveKey={requestedRun}
panels={jobs.map((job) => ({
key: job.id,
header: <BatchJobMetricsHeader job={job} />,
- content: <BatchJobMetrics job={job} />,
+ content: (
+ <BatchJobMetrics
+ job={job}
+ requestedAction={job.id === requestedRun ? requestedAction : undefined}
+ />
+ ),
}))}
/>
</div>
diff --git a/products/workflows/frontend/Workflows/WorkflowScene.tsx b/products/workflows/frontend/Workflows/WorkflowScene.tsx
index 870fd8da1729..1bc06a9410ab 100644
--- a/products/workflows/frontend/Workflows/WorkflowScene.tsx
+++ b/products/workflows/frontend/Workflows/WorkflowScene.tsx
@@ -28,6 +28,7 @@ import { EMAIL_PREFILL_PARAM } from '../MessageAudience/messageDrafts'
import { batchWorkflowJobsLogic } from './batchWorkflowJobsLogic'
import { NewWorkflowAgent } from './NewWorkflowAgent'
import { newWorkflowLogic } from './newWorkflowLogic'
+import { WorkflowBatchOverview } from './overview/WorkflowBatchOverview'
import { WorkflowOverview } from './overview/WorkflowOverview'
import { WorkflowSuggestions } from './suggestions/WorkflowSuggestions'
import { workflowSuggestionsAvailabilityLogic } from './suggestions/workflowSuggestionsAvailabilityLogic'
@@ -176,12 +177,16 @@ export function WorkflowScene(props: WorkflowSceneLogicProps): JSX.Element {
}
const tabs: (LemonTab<WorkflowTab> | null)[] = [
- // Batch workflows report per run, so a rolling overview does not fit them.
- overviewTabEnabled && originalWorkflow.trigger?.type !== 'batch' && originalWorkflow.status === 'active'
+ overviewTabEnabled && originalWorkflow.status === 'active'
? {
label: 'Overview',
key: 'overview',
- content: <WorkflowOverview id={workflowSceneProps.id!} />,
+ content:
+ originalWorkflow.trigger?.type === 'batch' ? (
+ <WorkflowBatchOverview id={workflowSceneProps.id!} />
+ ) : (
+ <WorkflowOverview id={workflowSceneProps.id!} />
+ ),
}
: null,
{
diff --git a/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.test.ts b/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.test.ts
index 39c158893640..fed465f97b1f 100644
--- a/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.test.ts
+++ b/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.test.ts
@@ -17,16 +17,18 @@ const WORKFLOW_ID = 'wf-batch-1'
describe('batchWorkflowJobsLogic', () => {
let logic: ReturnType<typeof batchWorkflowJobsLogic.build>
let getCalls: number
+ let getStatus: number
let cancelResponse: HogFlowBatchJobCancelResponseApi
beforeEach(() => {
getCalls = 0
+ getStatus = 200
cancelResponse = { status: 'cancelled', marked: 1, remaining: 0, done: true }
useMocks({
get: {
'/api/environments/:team_id/hog_flows/:id/batch_jobs/': () => {
getCalls += 1
- return [200, []]
+ return getStatus === 200 ? [200, []] : [getStatus, { detail: 'error' }]
},
},
post: {
@@ -84,6 +86,22 @@ describe('batchWorkflowJobsLogic', () => {
expect(getCalls).toBe(2)
})
+ it('flags a failed load until a retry succeeds', async () => {
+ getStatus = 500
+ router.actions.push(urls.workflow(WORKFLOW_ID, 'overview'))
+ await expectLogic(logic).toDispatchActions(['loadBatchWorkflowJobsFailure']).toMatchValues({
+ batchWorkflowJobs: null,
+ batchWorkflowJobsFailed: true,
+ })
+
+ getStatus = 200
+ await expectLogic(logic, () => {
+ logic.actions.loadBatchWorkflowJobs()
+ })
+ .toDispatchActions(['loadBatchWorkflowJobsSuccess'])
+ .toMatchValues({ batchWorkflowJobs: [], batchWorkflowJobsFailed: false })
+ })
+
// The cancel endpoint returns `done: true` with a non-cancelled status when a completion won the
// stop race; the toast must reflect the status, not report a stop that didn't happen.
it.each([
diff --git a/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.ts b/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.ts
index baa7ac87ff7e..5637419d2a6b 100644
--- a/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.ts
+++ b/products/workflows/frontend/Workflows/batchWorkflowJobsLogic.ts
@@ -18,6 +18,7 @@ export interface BatchWorkflowJobsLogicProps {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface batchWorkflowJobsLogicValues {
batchWorkflowJobs: HogFlowBatchJob[] | null
+ batchWorkflowJobsFailed: boolean
batchWorkflowJobsLoading: boolean
cancellingJobIds: string[]
jobs: HogFlowBatchJob[]
@@ -83,6 +84,13 @@ export const batchWorkflowJobsLogic = kea<batchWorkflowJobsLogicType>([
state.filter((id) => id !== jobId),
},
],
+ batchWorkflowJobsFailed: [
+ false,
+ {
+ loadBatchWorkflowJobsFailure: () => true,
+ loadBatchWorkflowJobsSuccess: () => false,
+ },
+ ],
}),
lazyLoaders(({ props }) => ({
batchWorkflowJobs: [
@@ -139,6 +147,12 @@ export const batchWorkflowJobsLogic = kea<batchWorkflowJobsLogicType>([
}
actions.loadBatchWorkflowJobs()
},
+ [urls.workflow(props.id || 'new', 'overview')]: (_, __, ___, currentLocation, previousLocation) => {
+ if (!currentLocation.initial && currentLocation.pathname === previousLocation?.pathname) {
+ return
+ }
+ actions.loadBatchWorkflowJobs()
+ },
[urls.workflow(props.id || 'new', 'metrics')]: (_, __, ___, currentLocation, previousLocation) => {
if (!currentLocation.initial && currentLocation.pathname === previousLocation?.pathname) {
return
diff --git a/products/workflows/frontend/Workflows/metricsDrillParams.ts b/products/workflows/frontend/Workflows/metricsDrillParams.ts
index 91037cead6e1..54d7ac66b947 100644
--- a/products/workflows/frontend/Workflows/metricsDrillParams.ts
+++ b/products/workflows/frontend/Workflows/metricsDrillParams.ts
@@ -19,9 +19,12 @@ export function metricsRangeSearchParams(range: MetricsRange): Record<string, st
return search
}
-/** Links to one step on the Metrics tab, keeping the date range the link was clicked from. */
-export function metricsStepUrl(id: string, actionId: string, range: MetricsRange): string {
+/** Links to one step on the Metrics tab, keeping the date range and the batch run the link was clicked from. */
+export function metricsStepUrl(id: string, actionId: string, range: MetricsRange, runId?: string): string {
const search = new URLSearchParams({ action: actionId, ...metricsRangeSearchParams(range) })
+ if (runId) {
+ search.set('run', runId)
+ }
return `${urls.workflow(id, 'metrics')}?${search.toString()}`
}
diff --git a/products/workflows/frontend/Workflows/overview/WorkflowBatchOverview.tsx b/products/workflows/frontend/Workflows/overview/WorkflowBatchOverview.tsx
new file mode 100644
index 000000000000..50bac783c39f
--- /dev/null
+++ b/products/workflows/frontend/Workflows/overview/WorkflowBatchOverview.tsx
@@ -0,0 +1,102 @@
+import { useActions, useValues } from 'kea'
+import { useMemo, useState } from 'react'
+
+import { LemonBanner, LemonSelect, Spinner } from '@posthog/lemon-ui'
+
+import { dayjs } from 'lib/dayjs'
+
+import { batchWorkflowJobsLogic } from '../batchWorkflowJobsLogic'
+import type { HogFlowBatchJob } from '../hogflows/types'
+import { WorkflowOverview } from './WorkflowOverview'
+
+// A waiting or queued run has not started anyone yet, so it has nothing to show.
+const NOT_STARTED: HogFlowBatchJob['status'][] = ['waiting', 'queued']
+
+function runLabel(run: HogFlowBatchJob): string {
+ // The stored enum value is 'cancelled'; display American spelling.
+ const status = run.status === 'cancelled' ? 'canceled' : run.status
+ return `${dayjs(run.created_at).format('MMM D, YYYY HH:mm')} · ${status}`
+}
+
+export function WorkflowBatchOverview({ id }: { id: string }): JSX.Element {
+ const { batchWorkflowJobs, batchWorkflowJobsLoading, batchWorkflowJobsFailed } = useValues(
+ batchWorkflowJobsLogic({ id })
+ )
+ const { loadBatchWorkflowJobs } = useActions(batchWorkflowJobsLogic({ id }))
+ const runs = useMemo(
+ () =>
+ (batchWorkflowJobs ?? [])
+ .filter((run) => !NOT_STARTED.includes(run.status))
+ .sort((a, b) => dayjs(b.created_at).valueOf() - dayjs(a.created_at).valueOf()),
+ [batchWorkflowJobs]
+ )
+ const [selectedRunId, setSelectedRunId] = useState<string | null>(null)
+
+ if (batchWorkflowJobsFailed && batchWorkflowJobs === null) {
+ return (
+ <LemonBanner
+ type="error"
+ action={{
+ children: 'Try again',
+ onClick: () => loadBatchWorkflowJobs(),
+ loading: batchWorkflowJobsLoading,
+ 'data-attr': 'workflow-batch-overview-retry',
+ }}
+ >
+ Couldn't load this workflow's runs.
+ </LemonBanner>
+ )
+ }
+
+ if (batchWorkflowJobs === null || (batchWorkflowJobsLoading && runs.length === 0)) {
+ return (
+ <div className="flex justify-center">
+ <Spinner size="medium" />
+ </div>
+ )
+ }
+
+ if (runs.length === 0) {
+ return (
+ <div
+ className="flex flex-col items-center rounded bg-surface-primary px-4 py-8 text-center"
+ data-attr="workflow-batch-overview-empty"
+ >
+ <h2 className="text-xl leading-tight">This workflow hasn't run yet</h2>
+ <p className="text-sm text-tertiary">Once a run starts, its results show here.</p>
+ </div>
+ )
+ }
+
+ const runIndex = Math.max(
+ 0,
+ runs.findIndex((run) => run.id === selectedRunId)
+ )
+ const run = runs[runIndex]
+ const previousRun = runs[runIndex + 1] ?? null
+
+ return (
+ <WorkflowOverview
+ key={run.id}
+ id={id}
+ run={run}
+ previousRun={previousRun}
+ controls={
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="text-xs text-muted" data-attr="workflow-batch-overview-comparison">
+ {previousRun
+ ? `Each card shows this run and the previous run, on ${dayjs(previousRun.created_at).format('MMM D, HH:mm')}`
+ : 'This is the first run, so there is no previous run to show'}
+ </span>
+ <LemonSelect
+ size="small"
+ value={run.id}
+ onChange={(value) => setSelectedRunId(value)}
+ options={runs.map((r) => ({ value: r.id, label: runLabel(r) }))}
+ data-attr="workflow-batch-overview-run-picker"
+ />
+ </div>
+ }
+ />
+ )
+}
diff --git a/products/workflows/frontend/Workflows/overview/WorkflowMessageLeaderboard.tsx b/products/workflows/frontend/Workflows/overview/WorkflowMessageLeaderboard.tsx
index 9f7adbe6bc03..18b7ca319534 100644
--- a/products/workflows/frontend/Workflows/overview/WorkflowMessageLeaderboard.tsx
+++ b/products/workflows/frontend/Workflows/overview/WorkflowMessageLeaderboard.tsx
@@ -31,8 +31,16 @@ const METRIC_OPTIONS: { value: LeaderboardMetric; label: string }[] = [
{ value: 'clicked', label: 'Clicked' },
]
-export function WorkflowMessageLeaderboard({ id, logicKey }: { id: string; logicKey: string }): JSX.Element {
- const summaryLogic = workflowMetricsSummaryLogic({ logicKey, id, overview: true })
+export function WorkflowMessageLeaderboard({
+ id,
+ logicKey,
+ appSourceId,
+}: {
+ id: string
+ logicKey: string
+ appSourceId?: string
+}): JSX.Element {
+ const summaryLogic = workflowMetricsSummaryLogic({ logicKey, id, overview: true, appSourceId })
const {
emailMetricsRows,
pushMetricsRows,
@@ -124,7 +132,7 @@ export function WorkflowMessageLeaderboard({ id, logicKey }: { id: string; logic
<span className="inline-flex items-center gap-1.5 font-medium text-muted">{label}</span>
) : (
<Link
- to={metricsStepUrl(id, row.id, params)}
+ to={metricsStepUrl(id, row.id, params, appSourceId)}
className="inline-flex items-center gap-1.5 font-medium"
data-attr="workflow-overview-leaderboard-message"
>
diff --git a/products/workflows/frontend/Workflows/overview/WorkflowOverview.tsx b/products/workflows/frontend/Workflows/overview/WorkflowOverview.tsx
index c41c5750c6c9..93888c4c4e8d 100644
--- a/products/workflows/frontend/Workflows/overview/WorkflowOverview.tsx
+++ b/products/workflows/frontend/Workflows/overview/WorkflowOverview.tsx
@@ -1,12 +1,15 @@
import { useActions, useValues } from 'kea'
+import type { ReactNode } from 'react'
import { LemonBanner, LemonButton, Link } from '@posthog/lemon-ui'
import { getColorVar } from 'lib/colors'
import { AppMetricsFilters } from 'lib/components/AppMetrics/AppMetricsFilters'
import { AppMetricsTimeSeriesResponse, appMetricsLogic } from 'lib/components/AppMetrics/appMetricsLogic'
+import { dayjs } from 'lib/dayjs'
import { percentage } from 'lib/utils/numbers'
+import type { HogFlowBatchJob } from '../hogflows/types'
import { workflowSuggestionsAvailabilityLogic } from '../suggestions/workflowSuggestionsAvailabilityLogic'
import { WorkflowMetricCard } from '../WorkflowMetricCard'
import { METRIC_COLORS, withDisplayName, workflowMetricsSummaryLogic } from '../workflowMetricsSummaryLogic'
@@ -51,15 +54,47 @@ function shareOf(part: number, whole: number, noun: string): JSX.Element | null
return whole > 0 ? <span className="text-muted">{`${percentage(part / whole, 1)} of ${noun}`}</span> : null
}
-export function WorkflowOverview({ id }: { id: string }): JSX.Element {
- const logicKey = `hog-flow-overview-${id}`
+// A run keeps recording for as long as its people wait at delays, so the range stays open to now.
+function runParams(run: HogFlowBatchJob): { dateFrom: string; interval: 'hour' | 'day' } {
+ const start = dayjs(run.created_at)
+ return {
+ dateFrom: start.subtract(1, 'hour').toISOString(),
+ interval: dayjs().diff(start, 'day') < 3 ? 'hour' : 'day',
+ }
+}
+
+export interface WorkflowOverviewProps {
+ id: string
+ run?: HogFlowBatchJob
+ previousRun?: HogFlowBatchJob | null
+ controls?: ReactNode
+}
+
+export function WorkflowOverview({ id, run, previousRun, controls }: WorkflowOverviewProps): JSX.Element {
+ const logicKey = run ? `hog-flow-overview-${id}-run-${run.id}` : `hog-flow-overview-${id}`
+ const appSourceId = run?.id
+ const period = run ? 'in this run' : 'in this date range'
+ const previousLabel = previousRun ? `Previous run (${dayjs(previousRun.created_at).format('MMM D')})` : undefined
const { getSingleTrendSeries: trendSeries, appMetricsTrendsLoading } = useValues(
appMetricsLogic({
logicKey,
loadOnChanges: true,
loadOnMount: true,
- defaultParams: { dateFrom: '-30d', interval: 'day' },
- forceParams: { appSource: 'hog_flow', appSourceId: id, breakdownBy: 'metric_name' },
+ // A date-shifted previous period holds no data for a run, so a run compares with the run before it.
+ loadPreviousPeriod: !run,
+ defaultParams: run ? runParams(run) : { dateFrom: '-30d', interval: 'day' },
+ forceParams: { appSource: 'hog_flow', appSourceId: appSourceId ?? id, breakdownBy: 'metric_name' },
+ })
+ )
+ const previousRunLogicKey = previousRun ? `${logicKey}-previous-${previousRun.id}` : undefined
+ const { getSingleTrendSeries: previousRunSeries } = useValues(
+ appMetricsLogic({
+ logicKey: previousRunLogicKey ?? `${logicKey}-previous-none`,
+ loadOnChanges: !!previousRun,
+ loadOnMount: !!previousRun,
+ loadPreviousPeriod: false,
+ defaultParams: previousRun ? runParams(previousRun) : {},
+ forceParams: { appSource: 'hog_flow', appSourceId: previousRun?.id ?? id, breakdownBy: 'metric_name' },
})
)
const {
@@ -71,14 +106,25 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
conversionRate,
conversionStatsLoading,
conversionStatsFailed,
- } = useValues(workflowMetricsSummaryLogic({ logicKey, id, overview: true }))
- const { loadConversionStats } = useActions(workflowMetricsSummaryLogic({ logicKey, id, overview: true }))
+ } = useValues(workflowMetricsSummaryLogic({ logicKey, id, overview: true, appSourceId }))
+ const { loadConversionStats } = useActions(
+ workflowMetricsSummaryLogic({ logicKey, id, overview: true, appSourceId })
+ )
const { hasEmail, hasPush } = messagingChannels
- const overviewLogic = workflowOverviewLogic({ id, logicKey })
- const { trendsFailed, previousPeriodFailed, retrying } = useValues(overviewLogic)
- // A failed previous-period read leaves the old baseline in place, so the comparison is hidden instead.
+ const overviewLogic = workflowOverviewLogic({ id, logicKey, previousRunLogicKey })
+ const { trendsFailed, previousPeriodFailed, previousRunFailed, retrying } = useValues(overviewLogic)
+ const comparisonFailed = run ? previousRunFailed : previousPeriodFailed
+ // A failed comparison read leaves the old baseline in place, so the comparison is hidden instead.
const getSingleTrendSeries = (name: string, previous?: boolean): AppMetricsTimeSeriesResponse | null =>
- previous && previousPeriodFailed ? null : trendSeries(name, previous)
+ previous && comparisonFailed
+ ? null
+ : run
+ ? previous
+ ? previousRun
+ ? previousRunSeries(name)
+ : null
+ : trendSeries(name)
+ : trendSeries(name, previous)
const { retry } = useActions(overviewLogic)
const retryAll = (): void => {
retry()
@@ -112,9 +158,9 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
<div className="@container flex flex-col gap-4" data-attr="workflow-overview">
<WorkflowOverviewFeedback />
<div className="flex flex-wrap items-center justify-end gap-2">
- <AppMetricsFilters logicKey={logicKey} />
+ {controls ?? <AppMetricsFilters logicKey={logicKey} />}
</div>
- {trendsFailed || previousPeriodFailed ? (
+ {trendsFailed || comparisonFailed ? (
<LemonBanner
type="error"
action={{
@@ -131,9 +177,12 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
<div className="flex flex-wrap gap-2" data-attr="workflow-overview-metric-cards">
<WorkflowMetricCard
name="Started"
- description="Workflow runs that started in this date range."
+ description={
+ run ? 'People this run started the workflow for.' : `Workflow runs that started ${period}.`
+ }
loading={appMetricsTrendsLoading}
timeSeries={started}
+ previousLabel={previousLabel}
previousPeriodTimeSeries={withDisplayName(
getSingleTrendSeries('triggered', true),
'Workflows started'
@@ -145,9 +194,10 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
{hasEmail || hasPush ? (
<WorkflowMetricCard
name="Sent"
- description={`${sentSummaryLabel} by this workflow in this date range.`}
+ description={`${sentSummaryLabel} by this workflow ${period}.`}
loading={appMetricsTrendsLoading}
timeSeries={sent}
+ previousLabel={previousLabel}
previousPeriodTimeSeries={sentFor(true)}
color={METRIC_COLORS[sentSummaryLabel]}
seriesColors={METRIC_COLORS}
@@ -158,9 +208,10 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
{hasEmail || hasPush ? (
<WorkflowMetricCard
name="Opened"
- description="Opens recorded in this date range. Only tracked emails can record opens."
+ description={`Opens recorded ${period}. Only tracked emails can record opens.`}
loading={appMetricsTrendsLoading}
timeSeries={opened}
+ previousLabel={previousLabel}
previousPeriodTimeSeries={openedFor(true)}
color={METRIC_COLORS['Opened']}
seriesColors={OPENED_SERIES_COLORS}
@@ -172,9 +223,10 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
{hasEmail ? (
<WorkflowMetricCard
name="Clicked"
- description="Email link clicks recorded in this date range."
+ description={`Email link clicks recorded ${period}.`}
loading={appMetricsTrendsLoading}
timeSeries={clicked}
+ previousLabel={previousLabel}
previousPeriodTimeSeries={withDisplayName(
getSingleTrendSeries('email_link_clicked', true),
'Link clicked'
@@ -188,9 +240,10 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
{hasConversionGoal ? (
<WorkflowMetricCard
name="Converted"
- description="Conversions recorded in this date range against the workflow's goal."
+ description={`Conversions recorded ${period} against the workflow's goal.`}
loading={appMetricsTrendsLoading}
timeSeries={converted}
+ previousLabel={previousLabel}
previousPeriodTimeSeries={withDisplayName(
getSingleTrendSeries('conversion', true),
'Workflows converted'
@@ -227,17 +280,17 @@ export function WorkflowOverview({ id }: { id: string }): JSX.Element {
) : null}
</div>
- <WorkflowOverviewHealth id={id} logicKey={logicKey} />
+ <WorkflowOverviewHealth id={id} logicKey={logicKey} appSourceId={appSourceId} period={period} />
<div className="grid grid-cols-1 items-start gap-4 @4xl:grid-cols-2">
<div className="flex min-w-0 flex-col gap-4">
- <WorkflowStepReach id={id} logicKey={logicKey} />
+ <WorkflowStepReach id={id} logicKey={logicKey} period={period} runId={appSourceId} />
<WorkflowOverviewDetails id={id} />
</div>
<div className="flex min-w-0 flex-col gap-4">
- <WorkflowOverviewInFlight id={id} logicKey={logicKey} />
+ <WorkflowOverviewInFlight id={id} logicKey={logicKey} allRuns={!!run} />
{suggestionsAvailable ? <WorkflowOverviewSuggestions id={id} /> : null}
- <WorkflowMessageLeaderboard id={id} logicKey={logicKey} />
+ <WorkflowMessageLeaderboard id={id} logicKey={logicKey} appSourceId={appSourceId} />
</div>
</div>
</div>
diff --git a/products/workflows/frontend/Workflows/overview/WorkflowOverviewHealth.tsx b/products/workflows/frontend/Workflows/overview/WorkflowOverviewHealth.tsx
index d964f94d5b88..8999b2a60b14 100644
--- a/products/workflows/frontend/Workflows/overview/WorkflowOverviewHealth.tsx
+++ b/products/workflows/frontend/Workflows/overview/WorkflowOverviewHealth.tsx
@@ -70,7 +70,17 @@ function loggedErrorsUrl(id: string, dateFrom: Dayjs, dateTo: Dayjs): string {
return `${urls.workflow(id, 'invocations')}?${search.toString()}`
}
-export function WorkflowOverviewHealth({ id, logicKey }: { id: string; logicKey: string }): JSX.Element {
+export function WorkflowOverviewHealth({
+ id,
+ logicKey,
+ appSourceId,
+ period = 'in this date range',
+}: {
+ id: string
+ logicKey: string
+ appSourceId?: string
+ period?: string
+}): JSX.Element {
const logic = workflowOverviewLogic({ id, logicKey })
const {
healthTotals,
@@ -84,7 +94,7 @@ export function WorkflowOverviewHealth({ id, logicKey }: { id: string; logicKey:
} = useValues(logic)
const range = getDateRangeAbsolute()
const { retry } = useActions(logic)
- const { messagingChannels } = useValues(workflowMetricsSummaryLogic({ logicKey, id, overview: true }))
+ const { messagingChannels } = useValues(workflowMetricsSummaryLogic({ logicKey, id, overview: true, appSourceId }))
const { emailSendingPaused } = useValues(workflowLogic)
const loading = (healthTotalsLoading && !healthTotals) || (stepTotalsLoading && failedRuns === null)
@@ -143,7 +153,7 @@ export function WorkflowOverviewHealth({ id, logicKey }: { id: string; logicKey:
label="Failed steps"
value={humanFriendlyNumber(failedRuns ?? 0)}
tag={(failedRuns ?? 0) > 0 ? { label: 'Check logs', type: 'warning' } : RATE_LEVEL_TAG.healthy}
- tooltip="Steps that errored in this date range. A failed step either stops the run or continues, depending on the step's error setting."
+ tooltip={`Steps that errored ${period}. A failed step either stops the run or continues, depending on the step's error setting.`}
detail={
(failedRuns ?? 0) > 0 ? (
<Link
diff --git a/products/workflows/frontend/Workflows/overview/WorkflowOverviewInFlight.tsx b/products/workflows/frontend/Workflows/overview/WorkflowOverviewInFlight.tsx
index 13bd11c02b07..ded454b85d7e 100644
--- a/products/workflows/frontend/Workflows/overview/WorkflowOverviewInFlight.tsx
+++ b/products/workflows/frontend/Workflows/overview/WorkflowOverviewInFlight.tsx
@@ -10,7 +10,15 @@ import { workflowOverviewLogic } from './workflowOverviewLogic'
const MAX_STEPS = 5
-export function WorkflowOverviewInFlight({ id, logicKey }: { id: string; logicKey: string }): JSX.Element {
+export function WorkflowOverviewInFlight({
+ id,
+ logicKey,
+ allRuns = false,
+}: {
+ id: string
+ logicKey: string
+ allRuns?: boolean
+}): JSX.Element {
const logic = workflowOverviewLogic({ id, logicKey })
const { inFlight, inFlightLoading, inFlightSteps } = useValues(logic)
const { loadInFlight } = useActions(logic)
@@ -27,7 +35,9 @@ export function WorkflowOverviewInFlight({ id, logicKey }: { id: string; logicKe
<div className="flex flex-col gap-1">
<h3 className="mb-0 text-base font-semibold">In the workflow now</h3>
<span className="text-xs text-muted">
- People partway through, waiting on a step or being processed.
+ {allRuns
+ ? 'People partway through, across all runs of this workflow.'
+ : 'People partway through, waiting on a step or being processed.'}
</span>
</div>
{inFlightLoading && !inFlight ? (
diff --git a/products/workflows/frontend/Workflows/overview/WorkflowStepReach.tsx b/products/workflows/frontend/Workflows/overview/WorkflowStepReach.tsx
index 089f3a1b510d..8c8670d991c9 100644
--- a/products/workflows/frontend/Workflows/overview/WorkflowStepReach.tsx
+++ b/products/workflows/frontend/Workflows/overview/WorkflowStepReach.tsx
@@ -62,7 +62,17 @@ function ReachRow({
)
}
-export function WorkflowStepReach({ id, logicKey }: { id: string; logicKey: string }): JSX.Element {
+export function WorkflowStepReach({
+ id,
+ logicKey,
+ period = 'in this date range',
+ runId,
+}: {
+ id: string
+ logicKey: string
+ period?: string
+ runId?: string
+}): JSX.Element {
const logic = workflowOverviewLogic({ id, logicKey })
const { stepReach, stepTotalsLoading, healthTotals, params, stepTotalsFailed, healthTotalsFailed, retrying } =
useValues(logic)
@@ -82,7 +92,7 @@ export function WorkflowStepReach({ id, logicKey }: { id: string; logicKey: stri
</Tooltip>
</h3>
<span className="text-xs text-muted">
- How many runs got past each step in this date range, as a share of runs started.
+ {`How many runs got past each step ${period}, as a share of runs started.`}
</span>
</div>
{stepTotalsFailed || healthTotalsFailed ? (
@@ -113,7 +123,7 @@ export function WorkflowStepReach({ id, logicKey }: { id: string; logicKey: stri
base={started}
failed={failed}
waiting={waiting}
- to={metricsStepUrl(id, action.id, params)}
+ to={metricsStepUrl(id, action.id, params, runId)}
/>
))}
</div>
diff --git a/products/workflows/frontend/Workflows/overview/workflowOverviewLogic.ts b/products/workflows/frontend/Workflows/overview/workflowOverviewLogic.ts
index b6b20f0b0a92..d0b8c707bce3 100644
--- a/products/workflows/frontend/Workflows/overview/workflowOverviewLogic.ts
+++ b/products/workflows/frontend/Workflows/overview/workflowOverviewLogic.ts
@@ -22,6 +22,8 @@ import { workflowLogic } from '../workflowLogic'
export interface WorkflowOverviewLogicProps {
id: string
logicKey: string
+ // A batch run compares with the run before it, loaded by its own appMetricsLogic under this key.
+ previousRunLogicKey?: string
}
const STEP_METRICS = ['succeeded', 'failed', 'filtered'] as const
@@ -45,7 +47,8 @@ export type StepReach = {
// Runs that finished this step in the selected date range. A step records its metric when it finishes.
reached: number
failed: number
- // Runs at this step now. Counted only when the date range ends now, because the queue has no history.
+ // Runs at this step now. Counted only when the date range ends now, because the queue has no history,
+ // and never for a batch run, because the queue counts every run of the workflow together.
waiting: number
}
@@ -76,6 +79,8 @@ export interface workflowOverviewLogicValues {
inFlightSteps: InFlightStep[]
orderedSteps: HogFlowAction[]
previousPeriodFailed: boolean
+ previousRunFailed: boolean
+ previousRunLoading: boolean
retrying: boolean
stepReach: StepReach[] | null
stepTotals: Record<string, Partial<Record<StepMetric, number>>> | null
@@ -216,11 +221,13 @@ export interface workflowOverviewLogicMeta {
orderedSteps: HogFlowAction[],
stepTotals: Record<string, Partial<Record<'failed' | 'filtered' | 'succeeded', number>>> | null,
inFlight: HogFlowInFlightApi | null,
- params: Partial<AppMetricsCommonParams>
+ params: Partial<AppMetricsCommonParams>,
+ arg: string
) => StepReach[] | null
retrying: (
appMetricsTrendsLoading: boolean,
appMetricsTrendsPreviousPeriodLoading: boolean,
+ previousRunLoading: boolean,
stepTotalsLoading: boolean,
healthTotalsLoading: boolean
) => boolean
@@ -241,7 +248,7 @@ export type workflowOverviewLogicType = MakeLogicType<
export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
path(['products', 'workflows', 'frontend', 'Workflows', 'overview', 'workflowOverviewLogic']),
props({} as WorkflowOverviewLogicProps),
- key(({ id }: WorkflowOverviewLogicProps) => id),
+ key(({ logicKey }: WorkflowOverviewLogicProps) => logicKey),
connect((props: WorkflowOverviewLogicProps) => ({
values: [
workflowLogic,
@@ -272,35 +279,60 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
actions({
retry: true,
}),
- reducers({
- trendsFailed: [
- false,
- {
- loadAppMetricsTrendsFailure: () => true,
- loadAppMetricsTrendsSuccess: () => false,
- },
- ],
- previousPeriodFailed: [
- false,
- {
- loadAppMetricsTrendsPreviousPeriodFailure: () => true,
- loadAppMetricsTrendsPreviousPeriodSuccess: () => false,
- },
- ],
- stepTotalsFailed: [
- false,
- {
- loadStepTotalsFailure: () => true,
- loadStepTotalsSuccess: () => false,
- },
- ],
- healthTotalsFailed: [
- false,
- {
- loadHealthTotalsFailure: () => true,
- loadHealthTotalsSuccess: () => false,
- },
- ],
+ reducers(({ props }) => {
+ // WorkflowOverview builds this appMetricsLogic with its full props before it builds this logic.
+ const previousRun = props.previousRunLogicKey
+ ? appMetricsLogic({ logicKey: props.previousRunLogicKey }).actionTypes
+ : null
+ return {
+ trendsFailed: [
+ false,
+ {
+ loadAppMetricsTrendsFailure: () => true,
+ loadAppMetricsTrendsSuccess: () => false,
+ },
+ ],
+ previousPeriodFailed: [
+ false,
+ {
+ loadAppMetricsTrendsPreviousPeriodFailure: () => true,
+ loadAppMetricsTrendsPreviousPeriodSuccess: () => false,
+ },
+ ],
+ stepTotalsFailed: [
+ false,
+ {
+ loadStepTotalsFailure: () => true,
+ loadStepTotalsSuccess: () => false,
+ },
+ ],
+ healthTotalsFailed: [
+ false,
+ {
+ loadHealthTotalsFailure: () => true,
+ loadHealthTotalsSuccess: () => false,
+ },
+ ],
+ previousRunFailed: [
+ false,
+ previousRun
+ ? {
+ [previousRun.loadAppMetricsTrendsFailure]: () => true,
+ [previousRun.loadAppMetricsTrendsSuccess]: () => false,
+ }
+ : {},
+ ],
+ previousRunLoading: [
+ false,
+ previousRun
+ ? {
+ [previousRun.loadAppMetricsTrends]: () => true,
+ [previousRun.loadAppMetricsTrendsFailure]: () => false,
+ [previousRun.loadAppMetricsTrendsSuccess]: () => false,
+ }
+ : {},
+ ],
+ }
}),
loaders(({ props, values }) => ({
stepTotals: [
@@ -311,7 +343,8 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
const dateRange = values.getDateRangeAbsolute()
const request: AppMetricsTotalsRequest = {
appSource: 'hog_flow',
- appSourceId: props.id,
+ // A batch run records its metrics under the run's id, which the overview passes in as appSourceId.
+ appSourceId: values.params.appSourceId ?? props.id,
breakdownBy: ['instance_id', 'metric_name'],
metricName: [...STEP_METRICS],
limit: STEP_TOTALS_LIMIT,
@@ -343,7 +376,7 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
const dateRange = values.getDateRangeAbsolute()
const request: AppMetricsTotalsRequest = {
appSource: 'hog_flow',
- appSourceId: props.id,
+ appSourceId: values.params.appSourceId ?? props.id,
breakdownBy: ['metric_name'],
metricName: [...HEALTH_METRICS],
dateFrom: dateRange.dateFrom.toISOString(),
@@ -381,18 +414,26 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
: [],
],
stepReach: [
- (s) => [s.orderedSteps, s.stepTotals, s.inFlight, s.params],
+ (s) => [
+ s.orderedSteps,
+ s.stepTotals,
+ s.inFlight,
+ s.params,
+ (_, props: WorkflowOverviewLogicProps): string => props.id,
+ ],
(
steps: HogFlowAction[],
stepTotals: Record<string, Partial<Record<StepMetric, number>>> | null,
inFlight: HogFlowInFlightApi | null,
- params: Partial<AppMetricsCommonParams>
+ params: Partial<AppMetricsCommonParams>,
+ id: string
): StepReach[] | null =>
stepTotals
? steps.map((action) => {
const totals = stepTotals[action.id] ?? {}
const failed = totals.failed ?? 0
- const waiting = params.dateTo ? 0 : (inFlight?.by_action?.[action.id] ?? 0)
+ const isBatchRun = !!params.appSourceId && params.appSourceId !== id
+ const waiting = params.dateTo || isBatchRun ? 0 : (inFlight?.by_action?.[action.id] ?? 0)
// A step that continues on error records `succeeded` as well as `failed`. The current
// on_error setting is applied to the whole range, so a change to it inside the range skews this.
const abortedRuns = action.on_error === 'abort' ? failed : 0
@@ -410,15 +451,22 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
(s) => [
s.appMetricsTrendsLoading,
s.appMetricsTrendsPreviousPeriodLoading,
+ s.previousRunLoading,
s.stepTotalsLoading,
s.healthTotalsLoading,
],
(
trendsLoading: boolean,
previousPeriodLoading: boolean,
+ previousRunLoading: boolean,
stepTotalsLoading: boolean,
healthTotalsLoading: boolean
- ): boolean => trendsLoading || previousPeriodLoading || stepTotalsLoading || healthTotalsLoading,
+ ): boolean =>
+ trendsLoading ||
+ previousPeriodLoading ||
+ previousRunLoading ||
+ stepTotalsLoading ||
+ healthTotalsLoading,
],
failedRuns: [
(s) => [s.stepTotals],
@@ -436,7 +484,7 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
},
],
}),
- listeners(({ actions, values }) => ({
+ listeners(({ actions, values, props }) => ({
setParams: () => {
actions.loadStepTotals({})
actions.loadHealthTotals({})
@@ -452,6 +500,9 @@ export const workflowOverviewLogic = kea<workflowOverviewLogicType>([
actions.loadStepTotals({})
actions.loadHealthTotals({})
actions.loadInFlight()
+ if (props.previousRunLogicKey) {
+ appMetricsLogic.findMounted({ logicKey: props.previousRunLogicKey })?.actions.loadAppMetricsTrends()
+ }
},
})),
afterMount(({ actions }) => {