Area: Observability Issues
Sub-Area: Assertions and Custom Metrics
Issue
You want to track a custom metric over time for a dataset in DataHub Cloud, such as data freshness (lag in minutes) broken out by segment (for example, a customer program code or shard ID), and view its history as a chart and alert on it. The Stats tab on a dataset only charts built-in fields, so a custom metric cannot be pushed into it, and checking all segments with a single assertion does not retain a raw per-segment value for historical analysis.
You Might Be Asking
- Is there a supported way to chart a custom metric over time (a custom stat or metric on a dataset)?
- Can I push custom values into the Stats tab, as I did with custom stats in open-source DataHub?
- How can I see freshness per segment change over time and alert on it?
Solution
The Stats tab charts only its built-in fields: row count, column count, size, and per-column metrics such as null count and unique count. It cannot hold a custom metric like lag minutes per segment, so pushing these values into Stats will not work. Instead, track one value per segment using Custom SQL Assertions, which give you both the raw history and pass/fail alerting.
Create one Custom SQL Assertion per segment (for example, per program code), with a query that returns that segment's lag in minutes. For example:
SELECT DATEDIFF('minute', MAX(event_ts), CURRENT_TIMESTAMP) FROM my_db.my_schema.my_table WHERE program_code = 'program_a'- Each time the assertion runs, DataHub stores the value the query returns. The assertion's page shows those values as a chart over time alongside pass/fail results. This gives you the raw collection for historical analysis.
- For pass/fail, use either a fixed threshold or "Detect with AI", which learns each segment's normal lag pattern and flags outliers. This covers fine-tuning of thresholds.
- If you want to analyze the history outside DataHub, you can pull the full run history, including values, through the API.
- Because this requires one assertion per segment, create them in bulk with the
upsertDatasetSqlAssertionMonitorGraphQL mutation. Re-run your script when new segments are added.
Additional Notes
- Custom SQL Assertions run directly in your warehouse and are supported on Snowflake, Redshift, BigQuery and Databricks.
- Pushing values from an external job (for example, AWS Glue) into DataHub is not needed for this use case; the assertion queries compute the value in the warehouse.
- The open-source approach of extending the metadata model with a custom timeseries aspect does not apply to DataHub Cloud.
Related Documentation
- None
Tags: custom-sql-assertion, freshness, assertions, stats-tab, custom-metrics, historical-metrics, graphql, bulk-create, datahub-cloud, observability