: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(data-warehouse): show non-billable syncs in source sync history (#71545)
Tom Owers30899386fe69
diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex e62e7006031f..0227e1b93556 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -6431,6 +6431,11 @@ export interface ExternalDataJob {* (cdc-only history table). `null` for non-CDC syncs.*/cdc_write_mode?: 'incremental_merge' | 'scd2_append' | null+ /**+ * Whether the rows synced by this job count toward billing. `false` for system-initiated+ * runs the customer isn't charged for. `null` on legacy rows and means billable.+ */+ billable?: boolean | null}export interface SimpleDataWarehouseTable {diff --git a/products/data_warehouse/backend/presentation/views/external_data_source.py b/products/data_warehouse/backend/presentation/views/external_data_source.pyindex 4a69ac0996a5..08241d36c253 100644--- a/products/data_warehouse/backend/presentation/views/external_data_source.py+++ b/products/data_warehouse/backend/presentation/views/external_data_source.py@@ -720,6 +720,15 @@ class ExternalDataJobSerializers(serializers.ModelSerializer):"(cdc-only history table). `null` for non-CDC syncs. Read from `schema_snapshot`."),)+ billable = serializers.BooleanField(+ read_only=True,+ allow_null=True,+ help_text=(+ "Whether the rows synced by this job count toward billing. `false` for system-initiated "+ "runs the customer isn't charged for (e.g. rebuilding a table after an internal issue). "+ "`null` on legacy rows and means billable."+ ),+ )class Meta:model = ExternalDataJob@@ -734,6 +743,7 @@ class ExternalDataJobSerializers(serializers.ModelSerializer):"latest_error","workflow_run_id","cdc_write_mode",+ "billable",]read_only_fields = ["id",@@ -746,6 +756,7 @@ class ExternalDataJobSerializers(serializers.ModelSerializer):"latest_error","workflow_run_id","cdc_write_mode",+ "billable",]def get_cdc_write_mode(self, instance: ExternalDataJob) -> str | None:@@ -4260,9 +4271,10 @@ class ExternalDataSourceViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixi# select_related joins the full ExternalDataSchema row; defer its large JSON/text# columns so the serializer only pulls the fields SimpleExternalDataSchemaSerializer# actually reads (sync_type_config + latest_error can each be sizeable).+ # Non-billable jobs are included on purpose: the UI shows them tagged so a sync the+ # customer wasn't charged for is still visible in the history.jobs = (- instance.jobs.filter(billable=True)- .select_related("schema")+ instance.jobs.select_related("schema").defer("schema__sync_type_config", "schema__latest_error").order_by("-created_at"))diff --git a/products/data_warehouse/backend/tests/api/test_external_data_source.py b/products/data_warehouse/backend/tests/api/test_external_data_source.pyindex f09991c087c9..fe0b757ecf44 100644--- a/products/data_warehouse/backend/tests/api/test_external_data_source.py+++ b/products/data_warehouse/backend/tests/api/test_external_data_source.py@@ -4731,18 +4731,21 @@ class TestExternalDataSource(APIBaseTest):data = response.json()- assert response.status_code, status.HTTP_200_OK+ assert response.status_code == status.HTTP_200_OKassert len(data) == 1assert data[0]["id"] == str(job.pk)assert data[0]["status"] == "Completed"assert data[0]["rows_synced"] == 100assert data[0]["schema"]["id"] == str(schema.pk)assert data[0]["workflow_run_id"] is not None+ assert data[0]["billable"] is True- def test_source_jobs_billable_job(self):+ def test_source_jobs_includes_non_billable(self):+ # Non-billable jobs (system-initiated runs the customer isn't charged for) must show up+ # in the sync history, flagged so the UI can tag them.source = self._create_external_data_source()schema = self._create_external_data_schema(source.pk)- ExternalDataJob.objects.create(+ job = ExternalDataJob.objects.create(team=self.team,pipeline=source,schema=schema,@@ -4759,8 +4762,10 @@ class TestExternalDataSource(APIBaseTest):data = response.json()- assert response.status_code, status.HTTP_200_OK- assert len(data) == 0+ assert response.status_code == status.HTTP_200_OK+ assert len(data) == 1+ assert data[0]["id"] == str(job.pk)+ assert data[0]["billable"] is Falsedef test_source_jobs_pagination(self):source = self._create_external_data_source()diff --git a/products/data_warehouse/frontend/scenes/SourceScene/tabs/SyncsTab.tsx b/products/data_warehouse/frontend/scenes/SourceScene/tabs/SyncsTab.tsxindex db72c23e467f..e327b6dedc31 100644--- a/products/data_warehouse/frontend/scenes/SourceScene/tabs/SyncsTab.tsx+++ b/products/data_warehouse/frontend/scenes/SourceScene/tabs/SyncsTab.tsx@@ -127,12 +127,23 @@ export const SyncsTab = ({ id }: SyncsTabProps): JSX.Element => {const tagContent = (<LemonTag type={StatusTagSetting[job.status] || 'default'}>{job.status}</LemonTag>)- return job.latest_error && job.status === ExternalDataJobStatus.Failed ? (- <Tooltip title={job.latest_error} interactive>- {tagContent}- </Tooltip>- ) : (- tagContent+ return (+ <span className="flex items-center gap-1">+ {job.latest_error && job.status === ExternalDataJobStatus.Failed ? (+ <Tooltip title={job.latest_error} interactive>+ {tagContent}+ </Tooltip>+ ) : (+ tagContent+ )}+ {job.billable === false && (+ <Tooltip title="You're not charged for this sync. These are usually system-initiated runs, like rebuilding a table after an issue on our side.">+ <LemonTag type="muted" size="small">+ Non-billable+ </LemonTag>+ </Tooltip>+ )}+ </span>)},},