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 started and completed runs in overview sparkline (#91465)

Meikel Ratz0c5f3ef8d552
diff --git a/frontend/src/lib/components/AppMetrics/AppMetricsSparkline.tsx b/frontend/src/lib/components/AppMetrics/AppMetricsSparkline.tsx
index 5f7343a93ade..9954328cdccf 100644
--- a/frontend/src/lib/components/AppMetrics/AppMetricsSparkline.tsx
+++ b/frontend/src/lib/components/AppMetrics/AppMetricsSparkline.tsx
@@ -14,6 +14,10 @@ export interface AppMetricsSparklineProps extends AppMetricsLogicProps {
successMetricNames?: string[]
/** Optional display labels keyed by series name (e.g. `{ rows_synced: 'Rows synced' }`). */
metricLabels?: Record<string, string>
+ /** Optional vars.scss color names keyed by series name; takes precedence over `successMetricNames`. */
+ metricColors?: Record<string, string>
+ /** Bars stack their series. Pass `'line'` when series overlap and a summed height would mislead. @default 'bar' */
+ type?: 'bar' | 'line'
}
const DEFAULT_SUCCESS_METRIC_NAMES = ['success']
@@ -21,6 +25,8 @@ const DEFAULT_SUCCESS_METRIC_NAMES = ['success']
export function AppMetricsSparkline({
successMetricNames,
metricLabels,
+ metricColors,
+ type,
...props
}: AppMetricsSparklineProps): JSX.Element {
const logic = appMetricsLogic(props)
@@ -52,12 +58,12 @@ export function AppMetricsSparkline({
return (
sortedSeries?.map((s) => ({
- color: successNames.includes(s.name) ? 'success' : 'danger',
+ color: metricColors?.[s.name] ?? (successNames.includes(s.name) ? 'success' : 'danger'),
name: metricLabels?.[s.name] ?? s.name,
values: s.values,
})) || []
)
- }, [appMetricsTrends, params, successMetricNames, metricLabels])
+ }, [appMetricsTrends, params, successMetricNames, metricLabels, metricColors])
const labels = appMetricsTrends?.labels || []
@@ -68,7 +74,7 @@ export function AppMetricsSparkline({
) : !appMetricsTrends || appMetricsTrendsLoading ? (
<LemonSkeleton className="h-8 max-w-24" />
) : (
- <Sparkline labels={labels} data={displayData} className="h-8 max-w-24" />
+ <Sparkline labels={labels} data={displayData} type={type} className="h-8 max-w-24" />
)}
</div>
)
diff --git a/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts b/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts
index 3cf040859404..391162ec270e 100644
--- a/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts
+++ b/frontend/src/lib/components/AppMetrics/appMetricsLogic.ts
@@ -30,6 +30,8 @@ const DEFAULT_INTERVAL = 'day'
export type AppMetricsCommonParams = {
appSource?: string
appSourceId?: string
+ /** Match all app_source_ids starting with this prefix (e.g. `<hog flow id>/` for versioned hog flow metrics). */
+ appSourceIdPrefix?: string
instanceId?: string
metricName?: string | string[]
metricKind?: string | string[]
@@ -79,6 +81,11 @@ export type AppMetricsTotalsResponse = Record<
}
>
+const appSourceIdPrefixPattern = (prefix: string): string => {
+ // Escape LIKE wildcards so the prefix matches literally.
+ return prefix.replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_') + '%'
+}
+
export const loadAppMetricsTotals = async (
request: AppMetricsTotalsRequest,
timezone: string
@@ -96,6 +103,10 @@ export const loadAppMetricsTotals = async (
if (request.appSourceId) {
query = (query + hogql`\nAND app_source_id = ${request.appSourceId}`) as HogQLQueryString
}
+ if (request.appSourceIdPrefix) {
+ query = (query +
+ hogql`\nAND app_source_id LIKE ${appSourceIdPrefixPattern(request.appSourceIdPrefix)}`) as HogQLQueryString
+ }
if (typeof request.instanceId === 'string') {
query = (query + hogql`\nAND instance_id = ${request.instanceId}`) as HogQLQueryString
}
@@ -205,6 +216,10 @@ const loadAppMetricsTimeSeries = async (
if (request.appSourceId) {
query = (query + hogql`\nAND app_source_id = ${request.appSourceId}`) as HogQLQueryString
}
+ if (request.appSourceIdPrefix) {
+ query = (query +
+ hogql`\nAND app_source_id LIKE ${appSourceIdPrefixPattern(request.appSourceIdPrefix)}`) as HogQLQueryString
+ }
if (typeof request.instanceId === 'string') {
query = (query + hogql`\nAND instance_id = ${request.instanceId}`) as HogQLQueryString
}
diff --git a/products/workflows/frontend/Workflows/WorkflowsTable.tsx b/products/workflows/frontend/Workflows/WorkflowsTable.tsx
index dc9de3d598d9..8ada3ce7ad6a 100644
--- a/products/workflows/frontend/Workflows/WorkflowsTable.tsx
+++ b/products/workflows/frontend/Workflows/WorkflowsTable.tsx
@@ -229,11 +229,24 @@ export function WorkflowsTable(): JSX.Element {
<Link to={urls.workflow(id, 'metrics')}>
<AppMetricsSparkline
logicKey={id}
+ // Lines, not stacked bars: Started counts a run that also lands in
+ // Completed or Failed the same day, so a stacked total would double-count.
+ type="line"
+ metricLabels={{ triggered: 'Started', succeeded: 'Completed', failed: 'Failed' }}
+ // Same colors as the workflow metrics tab: triggered is blue there too.
+ metricColors={{ triggered: 'blue', succeeded: 'success', failed: 'danger' }}
forceParams={{
- appSource: 'hog_flow',
- appSourceId: id,
- metricKind: ['success', 'failure'],
- breakdownBy: 'metric_kind',
+ // The versioned mirror keys every run's metrics (including batch runs,
+ // which the plain hog_flow source keys under the batch job id) as
+ // `<flow id>/<version>`, so a prefix match covers all activity.
+ appSource: 'hog_flow_version',
+ appSourceIdPrefix: `${id}/`,
+ // Run-level rows carry an empty instance_id; per-action succeeded/failed
+ // rows carry the action id. Filter to run-level so Completed and Failed
+ // count runs, not steps. triggered is run-level too, so Started is unaffected.
+ instanceId: '',
+ metricName: ['triggered', 'succeeded', 'failed'],
+ breakdownBy: 'metric_name',
interval: 'day',
dateFrom: '-7d',
}}