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-quality): show freshness staleness as a duration in the runs table (#103972)

Thiago Salvatore1186d1e3ea39
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 10024e9f076c..b51024863327 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -2480,6 +2480,10 @@ snapshots:
hash: v1.k794b7964.3f134e3ce25e5070006cb36e69e4d2fba535b95516be1287f6571275970002fa.XEAgwRGf86ilBY4t6jX0KgGm6b9BHon8bcQwFzMSUBU
data-catalog-metric-tests--unsupported-with-checks--light:
hash: v1.k794b7964.64e9162a5dd7bc47a1667f13d8c77b4d1f00c6e15c70169ab4d4ffc588dd2112.j2HS8sjcKIg0QXaZ9PLel28BVD4vayBEBRzrHVO-dlI
+ data-quality-check-runs-table--every-check-type--dark:
+ hash: v1.k794b7964.adbcb016bd78e4ca2cd9e744794f254c580567d44ec75f2e27cb89d2ae135df0.imF2IHlEi-KBkQ6jP17iC-nrPXQzL2_TWen4HdP8oOI
+ data-quality-check-runs-table--every-check-type--light:
+ hash: v1.k794b7964.e2f7204c2e97806e7325909eb60601d1064614b434ce2309f00e35e13264f438.hZz-kbvnlkChSvEg1xkm0Na0kFBD46FKshLYwcV5vcs
data-warehouse-destinationlist--both-selected--dark:
hash: v1.k794b7964.5da0169833ea8b87e6d903cb4fc0f4d629a1b1db09149c5fb7c450ef312641a0.MH4OyaTjM18a4cpxtpCHPVm1QWWajZL5cz4NlzbJag0
data-warehouse-destinationlist--both-selected--light:
diff --git a/products/data_quality/frontend/CheckRunsTable.stories.tsx b/products/data_quality/frontend/CheckRunsTable.stories.tsx
new file mode 100644
index 000000000000..ebe2714ce5ad
--- /dev/null
+++ b/products/data_quality/frontend/CheckRunsTable.stories.tsx
@@ -0,0 +1,94 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { CheckRunsTable } from './CheckRunsTable'
+import type { DataQualityCheckRunApi } from './generated/api.schemas'
+
+const BASE_RUN: DataQualityCheckRunApi = {
+ id: 'run',
+ quality_check: 'check',
+ check_name: null,
+ suite_run: 'suite-1',
+ subject_type: 'table',
+ subject_uuid: '018f2a1c-0000-7000-8000-000000000001',
+ subject_name: 'orders',
+ check_type: 'not_null',
+ column_name: '',
+ check_config: null,
+ check_severity: 'error',
+ status: 'passed',
+ failed_row_count: 0,
+ observed_value: 0,
+ compiled_query: 'SELECT count() FROM orders',
+ error: '',
+ duration_ms: 1200,
+ started_at: '2026-09-04T09:00:00Z',
+ finished_at: '2026-09-04T09:00:01Z',
+ created_at: '2026-09-04T09:00:01Z',
+}
+
+function run(overrides: Partial<DataQualityCheckRunApi>): DataQualityCheckRunApi {
+ return { ...BASE_RUN, ...overrides, id: `${overrides.check_type}-${overrides.status ?? 'passed'}` }
+}
+
+const RUNS_OF_EVERY_TYPE: DataQualityCheckRunApi[] = [
+ run({
+ check_type: 'freshness',
+ column_name: 'updated_at',
+ check_config: { max_age_minutes: 2160 },
+ status: 'failed',
+ failed_row_count: 1,
+ observed_value: 147117,
+ }),
+ run({
+ check_type: 'row_count',
+ check_config: { min: 1000000, max: 2000000 },
+ status: 'failed',
+ failed_row_count: null,
+ observed_value: 2493355,
+ }),
+ run({ check_type: 'not_null', column_name: 'email', status: 'failed', failed_row_count: 7, observed_value: 7 }),
+ run({ check_type: 'unique', column_name: 'order_id', status: 'failed', failed_row_count: 1, observed_value: 1 }),
+ run({
+ check_type: 'accepted_values',
+ column_name: 'status',
+ check_config: { values: ['paid', 'refunded'] },
+ status: 'failed',
+ failed_row_count: 12,
+ observed_value: 12,
+ }),
+ run({
+ check_type: 'relationships',
+ column_name: 'customer_id',
+ status: 'failed',
+ failed_row_count: 5,
+ observed_value: 5,
+ }),
+ run({
+ check_type: 'custom_sql',
+ check_name: 'orders_have_a_total',
+ check_config: { query: 'SELECT * FROM orders WHERE total IS NULL' },
+ status: 'failed',
+ failed_row_count: 9,
+ observed_value: 9,
+ }),
+ run({ check_type: 'unique', column_name: 'order_id', status: 'passed', failed_row_count: 0, observed_value: 0 }),
+ run({
+ check_type: 'custom_sql',
+ check_name: 'orders_have_a_total',
+ status: 'errored',
+ failed_row_count: null,
+ observed_value: null,
+ error: 'Unknown column total',
+ }),
+]
+
+const meta: Meta<typeof CheckRunsTable> = {
+ title: 'Data quality/Check runs table',
+ component: CheckRunsTable,
+ parameters: { mockDate: '2026-09-04T12:00:00Z', viewMode: 'story' },
+ args: { runs: RUNS_OF_EVERY_TYPE, showCheck: true },
+}
+export default meta
+type Story = StoryObj<typeof CheckRunsTable>
+
+export const EveryCheckType: Story = {}
diff --git a/products/data_quality/frontend/CheckRunsTable.test.tsx b/products/data_quality/frontend/CheckRunsTable.test.tsx
index 8804c0cb08d8..68e81799eb16 100644
--- a/products/data_quality/frontend/CheckRunsTable.test.tsx
+++ b/products/data_quality/frontend/CheckRunsTable.test.tsx
@@ -68,4 +68,25 @@ describe('CheckRunsTable', () => {
expect(screen.getByText('Unknown column signups')).toBeInTheDocument()
expect(screen.queryByText('Observed value')).not.toBeInTheDocument()
})
+
+ it('shows a freshness run as how old its newest row is', () => {
+ initKeaTests()
+ render(
+ <CheckRunsTable
+ subjectType="table"
+ runs={[
+ metricRun({
+ subject_type: 'table',
+ check_type: 'freshness',
+ column_name: 'last_updated_time',
+ check_config: { max_age_minutes: 2160 },
+ status: 'failed',
+ failed_row_count: 1,
+ observed_value: 147117,
+ }),
+ ]}
+ />
+ )
+ expect(screen.getByText('1d 16h old')).toBeInTheDocument()
+ })
})
diff --git a/products/data_quality/frontend/CheckRunsTable.tsx b/products/data_quality/frontend/CheckRunsTable.tsx
index 5efb55127633..800db698c8cc 100644
--- a/products/data_quality/frontend/CheckRunsTable.tsx
+++ b/products/data_quality/frontend/CheckRunsTable.tsx
@@ -6,7 +6,7 @@ import { humanFriendlyDuration } from 'lib/utils/durations'
import { humanFriendlyNumber } from 'lib/utils/numbers'
import type { DataQualitySubjectType } from './checksApi'
-import { CHECK_STATUS_TAG_TYPES, byStatusAttention, checkRunDisplayName } from './checksConstants'
+import { CHECK_STATUS_TAG_TYPES, byStatusAttention, checkRunDisplayName, observedValueCell } from './checksConstants'
import type { DataQualityCheckRunApi } from './generated/api.schemas'
type CheckRunColumn = LemonTableColumn<DataQualityCheckRunApi, keyof DataQualityCheckRunApi | undefined>
@@ -37,7 +37,16 @@ const OUTCOME_COLUMNS: CheckRunColumn[] = [
{
title: 'Observed value',
key: 'observed_value',
- render: (_, run) => (run.observed_value === null ? '-' : humanFriendlyNumber(run.observed_value)),
+ render: (_, run) => {
+ const { label, tooltip } = observedValueCell(run)
+ return tooltip ? (
+ <Tooltip title={tooltip}>
+ <span>{label}</span>
+ </Tooltip>
+ ) : (
+ label
+ )
+ },
},
{
title: 'Failed rows',
diff --git a/products/data_quality/frontend/checksConstants.test.ts b/products/data_quality/frontend/checksConstants.test.ts
index b0f1d2723ccd..ee8f734a3d39 100644
--- a/products/data_quality/frontend/checksConstants.test.ts
+++ b/products/data_quality/frontend/checksConstants.test.ts
@@ -1,6 +1,6 @@
import { dayjs } from 'lib/dayjs'
-import { byStatusAttention, checkRunDisplayName, failingForLabel } from './checksConstants'
+import { byStatusAttention, checkRunDisplayName, failingForLabel, observedValueCell } from './checksConstants'
import { CheckTypeEnumApi } from './generated/api.schemas'
describe('checksConstants', () => {
@@ -62,4 +62,61 @@ describe('checksConstants', () => {
'passed',
])
})
+
+ it.each<[string, CheckTypeEnumApi, number | null, Record<string, unknown> | null, string, string | null]>([
+ [
+ 'a freshness run reads as a duration with its limit',
+ CheckTypeEnumApi.Freshness,
+ 147117,
+ { max_age_minutes: 2160 },
+ '1d\u00a016h old',
+ 'Newest row is 147,117 seconds old. The limit is 1d\u00a012h.',
+ ],
+ [
+ 'a freshness run without a config snapshot omits the limit',
+ CheckTypeEnumApi.Freshness,
+ 147117,
+ null,
+ '1d\u00a016h old',
+ 'Newest row is 147,117 seconds old.',
+ ],
+ [
+ 'a row count run names the bound it is held to',
+ CheckTypeEnumApi.RowCount,
+ 1493355,
+ { min: 1000000, max: 2000000 },
+ '1,493,355 rows',
+ '1,493,355 rows. The limit is between 1,000,000 and 2,000,000\u00a0rows.',
+ ],
+ [
+ 'a row count run with one bound names only that one',
+ CheckTypeEnumApi.RowCount,
+ 12,
+ { max: 10 },
+ '12 rows',
+ '12 rows. The limit is at most 10\u00a0rows.',
+ ],
+ [
+ 'a row count run with a bound of one reads in the singular',
+ CheckTypeEnumApi.RowCount,
+ 0,
+ { min: 1 },
+ '0 rows',
+ '0 rows. The limit is at least 1\u00a0row.',
+ ],
+ [
+ 'a freshness run whose newest row is ahead of the clock says so',
+ CheckTypeEnumApi.Freshness,
+ -3600,
+ { max_age_minutes: 2160 },
+ '1h in the future',
+ 'Newest row is 3,600 seconds in the future. The limit is 1d\u00a012h.',
+ ],
+ ['a not null run stays a plain number', CheckTypeEnumApi.NotNull, 7, null, '7', null],
+ ['a run with nothing observed shows a dash', CheckTypeEnumApi.Freshness, null, null, '-', null],
+ ])('%s', (_case, checkType, observedValue, checkConfig, label, tooltip) => {
+ expect(
+ observedValueCell({ check_type: checkType, observed_value: observedValue, check_config: checkConfig })
+ ).toEqual({ label, tooltip })
+ })
})
diff --git a/products/data_quality/frontend/checksConstants.ts b/products/data_quality/frontend/checksConstants.ts
index f6211be480a7..c71b6474ec18 100644
--- a/products/data_quality/frontend/checksConstants.ts
+++ b/products/data_quality/frontend/checksConstants.ts
@@ -1,5 +1,8 @@
import { Dayjs, dayjs } from 'lib/dayjs'
import { LemonTagType } from 'lib/lemon-ui/LemonTag'
+import { humanFriendlyDuration } from 'lib/utils/durations'
+import { humanFriendlyNumber } from 'lib/utils/numbers'
+import { pluralize } from 'lib/utils/strings'
import { CheckTypeEnumApi } from './generated/api.schemas'
import type { DataQualityCheckApi, DataQualityCheckRunApi } from './generated/api.schemas'
@@ -123,3 +126,61 @@ export function checkRunDisplayName(
): string {
return checkDisplayName({ name: run.check_name, check_type: run.check_type, column_name: run.column_name })
}
+
+const SECONDS_PER_MINUTE = 60
+const DURATION_UNITS = 2
+
+export interface ObservedValueCell {
+ label: string
+ tooltip: string | null
+}
+
+export function observedValueCell(
+ run: Pick<DataQualityCheckRunApi, 'check_type' | 'observed_value' | 'check_config'>
+): ObservedValueCell {
+ if (run.observed_value === null) {
+ return { label: '-', tooltip: null }
+ }
+ if (run.check_type === CheckTypeEnumApi.Freshness) {
+ return freshnessCell(run.observed_value, run.check_config)
+ }
+ if (run.check_type === CheckTypeEnumApi.RowCount) {
+ return rowCountCell(run.observed_value, run.check_config)
+ }
+ return { label: humanFriendlyNumber(run.observed_value), tooltip: null }
+}
+
+function freshnessCell(stalenessSeconds: number, config: DataQualityCheckRunApi['check_config']): ObservedValueCell {
+ const maxAgeMinutes = config?.max_age_minutes
+ const limit =
+ typeof maxAgeMinutes === 'number'
+ ? ` The limit is ${humanFriendlyDuration(maxAgeMinutes * SECONDS_PER_MINUTE, { maxUnits: DURATION_UNITS })}.`
+ : ''
+ const direction = stalenessSeconds < 0 ? 'in the future' : 'old'
+ const magnitude = Math.abs(stalenessSeconds)
+ return {
+ label: `${humanFriendlyDuration(magnitude, { maxUnits: DURATION_UNITS })} ${direction}`,
+ tooltip: `Newest row is ${humanFriendlyNumber(magnitude)} seconds ${direction}.${limit}`,
+ }
+}
+
+function rowCountCell(rowCount: number, config: DataQualityCheckRunApi['check_config']): ObservedValueCell {
+ const label = `${humanFriendlyNumber(rowCount)} rows`
+ const limit = rowCountLimit(config?.min, config?.max)
+ return { label, tooltip: limit ? `${label}. The limit is ${limit}.` : null }
+}
+
+function rowCountLimit(min: unknown, max: unknown): string | null {
+ const hasMin = typeof min === 'number'
+ const hasMax = typeof max === 'number'
+ if (hasMin && hasMax) {
+ return `between ${humanFriendlyNumber(min)} and ${pluralize(max, 'row')}`
+ }
+ if (hasMin) {
+ return `at least ${pluralize(min, 'row')}`
+ }
+ if (hasMax) {
+ return `at most ${pluralize(max, 'row')}`
+ }
+ return null
+}