Repository navigation
[Data Observability] Add guide for creating monitors with the API or Terraform - #41959
kevinzenghu wants to merge 8 commits into
Conversation
…rraform Covers data quality, source to target, schema change, and job monitors, with validated API and Terraform examples. Also adds sidebar entries for the Quality Monitoring guides. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preview links (active after the
|
The left nav hides children of any entry named exactly "Guides", so rename the Quality Monitoring entry to "How-To Guides" to list each guide like Data Warehouses does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
traegerdog
left a comment
There was a problem hiding this comment.
Thanks for writing this. It's the page people managing Data Observability monitors as code have been missing, and most of it holds up. I tested it three ways:
- I sent the examples, plus variants of the edge cases the guide describes, to
POST /api/v1/monitor/validate. - I ran
terraform validateon the HCL with provider 4.20.0, 4.21.0 and 4.30.0. - I compared the definitions with existing UI-created Data Observability monitors.
Many readers will be new to Datadog and will copy the examples as written, so I've put my suggestions in a patch you can apply instead of listing them. Below are the patch, what it changes, and a few questions that need an answer from the Data Observability team.
Apply the patch
The patch was built against 7dd73cdd76 and applies cleanly. Save the diff at the end of this comment as suggested.patch, then run:
git checkout kevinzenghu/do-monitors-as-code-guide
git apply suggested.patchIt changes monitors_as_code.md and main.en.yaml. Each change is backed by /validate, terraform validate, the public API spec, or existing monitors.
What the patch changes
Fixes
- dbt snapshots removed from the job table. The API rejects
dbt.snapshot:job_type must be one of ['adf.pipeline', 'airflow.dag', 'airflow.job', 'databricks.job', 'dbt.job', 'dbt.model', 'dbt.test', 'glue.job', 'iwa.job', 'iwa.job_stream', 'spark.application'] or prefixed with 'custom.ol.'. - Databricks
.by()keys. They're nowname, platform, workspace_id, workspace_name, entity_id, in both examples and in the table. That's what currentaastraDatabricks monitors use. Both updated examples validate. - Run on demand. Per the API spec, only monitors whose
crontab_overrideisnot_scheduledcan be triggered. The run ID is indata.id, notrun_id. The section now shows how to poll the status and readerror_message. - Troubleshooting uses the exact error strings the API returns. For example, the nullness error names
database_table, nottable, and the custom SQL error starts withgroup_by_columns is required when custom_sql returns group columns.
Gaps for readers new to Datadog
-
New "Find an entity ID" section. Source to target and schema change monitors require entity IDs, but no page explains what they are or where to find them. The section lists four places: the Catalog URL, an exported monitor's filter, the
entity_idtag on alerts, and the MCP Server'ssearch_data_entities/get_data_entity_detailstools. -
New "Configure the Terraform provider" section. It shows
api_url, because without it, organizations outside US1 fail on their firstterraform apply. -
Key permissions. API keys don't carry permissions. The section now says the application key acts as its creator's role, and that scoped application keys need
monitors_write, plusdata_observability_monitors_writeto run monitors on demand. -
What validation doesn't catch.
/validateaccepted all of these:sensitivityof7and of0.05model_instructionswith 600 characters- a
*/5cron - custom SQL without
dd_value - a
job_typethat doesn't matchjobs_query
The patch says so under "Validate before you create" and adds a "monitor is created but never evaluates" Troubleshooting entry.
-
Smaller notes:
search for tableandsearch for columnare aliases of thedatabase_*forms, and both appear in exports.@slack-…handles need the Slack integration; the patch links it and the notifications docs.- Some SDKs reject
schema-change alertbefore sending the request, because the type isn't in the API spec'sMonitorTypeenum.
Accuracy and consistency
- Schema change queries. They now use space-separated terms, the format UI-created monitors use, and the filter keys include
@entity_id. - Model configuration. Adds
auto_resolve_days,enable_flatline_detectionandfunction, which are in the API and in Terraform. Adds a warning: in amodel_configurationblock, the provider always sendsenable_flatline_detection(defaulttrue), so an apply can turn flatline detection back on after someone switched it off in the UI. - Source to target.
- The JSON example was right to leave out the config-level
entity_type; UI-created monitors don't set it. - The patch adds a note that the Terraform resource requires that field anyway.
- The examples use
<SOURCE_ENTITY_ID>/<TARGET_ENTITY_ID>placeholders.
- The JSON example was right to leave out the config-level
group_bywording. "Always include…" becomes "To get a separate status, alert, and chart for each asset, include…", which matches the Multi Alert guidance on the monitor page.- Menu label. Reverted from
How-To GuidestoGuides, the label every other section uses.
Checked and unchanged. These match what I found:
- The 4.21.0 provider minimum. 4.20.0 fails on
sensitivity,source_to_target_configandmodel_configuration. - A
criticalthreshold that doesn't match the query is rejected. variablesmust contain exactly one query.custom_wherecan't be combined with custom SQL.- Lowercase
model_bounds_overrideis rejected. - The lineage and exclusion filters validate.
- The unquoted
.last(1d)form and the 10-day maximum for job monitors. - The query variable must be named
run_query. - The duration
group_byand.detection()matching rules. - All internal links and anchors.
Questions for the Data Observability team (not covered by the patch)
- Freshness or row count with
not_scheduled. The validator accepts it, but the monitor page's Monitor schedule section says Manual mode doesn't apply to default row count and freshness metrics. Can these monitors be triggered on demand? Either this guide or that page needs to change. model_instructions. It isn't in the public API spec, and the validator accepts unknown keys, so passing validation proves nothing here. Does the field come back fromGET? If not, it should be marked UI-only rather than pointing readers todatadog_monitor_json.- Job
.by()keys for the other platforms. The validator doesn't check group keys: a query withoutentity_idin.by()passed. Existing Airflow DAG and dbt model monitors use a mix of keys, so please confirm each row against what the UI generates today. - The
@change_type:(a OR b)form for schema change monitors. I couldn't validate schema change queries through the SDK, and the existing monitors I saw only use single values. - Billing wording. The guide says "Each table a filter matches counts as a monitored table". Please confirm it, and say explicitly how source to target, schema change and custom SQL monitors are billed.
- The 15-minute minimum schedule. The validator accepted
*/5 * * * *. Is the minimum enforced? - The
Unknown validation errorentry in the patch (anORDER BY, or several rows withoutgroup_by_columns). This comes from earlier team guidance, not a test, so please confirm it. - What
function(DIFF/DIFF_PERCENT) does. The patch uses the spec's description. A plainer explanation, such as "change since the previous run" if that's what it means, would help new users. - Migration guide link. If there's a migration guide for teams moving from other tools, link to it from the Overview.
suggested.patch (click to expand)
diff --git a/hugo/content/en/data_observability/quality_monitoring/guides/monitors_as_code.md b/hugo/content/en/data_observability/quality_monitoring/guides/monitors_as_code.md
index 876a440..bd28036 100644
--- a/hugo/content/en/data_observability/quality_monitoring/guides/monitors_as_code.md
+++ b/hugo/content/en/data_observability/quality_monitoring/guides/monitors_as_code.md
@@ -34,14 +34,47 @@ The [`datadog_monitor_json`][4] resource sends a monitor definition to the API a
## Before you start
-- Create an [API key and an application key][5] with the `monitors_write` permission.
+- Create an [API key and an application key][5]. The application key acts as the user who created it, so that user needs a role with the Monitors Write permission. If you restrict the application key with scopes, include `monitors_write`, and add `data_observability_monitors_write` to [run monitors on demand](#run-a-monitor-on-demand).
- Connect the warehouse or job platform you want to monitor. Monitors only find assets that Data Observability has already collected.
- For Terraform, use version 4.21.0 or later of the [Datadog provider][6]. Sensitivity, model configuration, and source to target settings require 4.21.0.
+### Configure the Terraform provider
+
+Set `api_url` to the API endpoint for your [Datadog site][8]. Without it, the provider sends requests to US1 (`https://api.datadoghq.com/`), and requests for an organization on another site fail with an authentication error.
+
+```hcl
+terraform {
+ required_providers {
+ datadog = {
+ source = "DataDog/datadog"
+ version = ">= 4.21.0"
+ }
+ }
+}
+
+provider "datadog" {
+ # When api_key and app_key are omitted, the provider reads DD_API_KEY and DD_APP_KEY from the environment.
+ api_url = "https://api.datadoghq.eu/"
+}
+```
+
### Start from a monitor created in the UI
The fastest way to get a correct definition is to build the monitor in the UI, then export it. Open the monitor, click the settings menu, and select **Export** to copy its JSON or Terraform. Exported definitions reference assets by `entity_id`, which avoids matching two tables that share a name.
+### Find an entity ID
+
+Data Observability gives every asset it collects, such as a table, column, job, or warehouse account, an `entity_id`, a hexadecimal ID such as `9f8e7d6c5b4a3921`. [Source to target monitors](#source-to-target-monitors) and [schema change monitors](#schema-change-monitors) require entity IDs, and filtering by `entity_id` is the most precise way to select an asset in any monitor.
+
+To find an entity ID:
+
+- **In the Catalog**: Open the asset in the [Catalog][9]. The entity ID is the last segment of the page URL, for example `/data-obs/catalog/9f8e7d6c5b4a3921`.
+- **From an existing monitor**: Export a monitor that covers the asset. The ID appears in the `filter`, for example ``search for database_table where `entity_id:9f8e7d6c5b4a3921` ``.
+- **From an alert**: Data Observability alerts include an `entity_id:<ID>` tag for each asset.
+- **Programmatically**: Use the `search_data_entities` and `get_data_entity_details` tools of the [MCP Server][10]. To look up many assets, such as when you migrate a large set of monitors, this is the fastest option.
+
+To find the account entity ID for a schema change monitor, export a schema change monitor created in the UI.
+
### Validate before you create
Send a definition to the [validate endpoint][7] to check it without creating anything:
@@ -56,6 +89,8 @@ curl -X POST "https://api.datadoghq.com/api/v1/monitor/validate" \
Replace `datadoghq.com` with your [Datadog site][8]. A valid definition returns `{}`. Validation checks syntax only: a filter that matches no assets passes validation and creates a monitor that never reports data. Confirm that your filter returns the assets you expect in the [Catalog][9] or with the [MCP Server][10] `search_data_entities` tool before you deploy.
+Validation also doesn't check every value against its limits. For example, it accepts a `sensitivity` outside 0.1 to 6, `model_instructions` longer than 500 characters, a schedule more frequent than every 15 minutes, custom SQL that doesn't return a `dd_value` column, and a `job_type` that doesn't match the jobs in `jobs_query`. Check these settings against this guide before you deploy.
+
## Data quality monitors
A data quality monitor has a `query` and exactly one query variable, named `query1`, that selects the assets and the metric.
@@ -119,6 +154,8 @@ resource "datadog_monitor" "orders_freshness" {
{{% /tab %}}
{{< /tabs >}}
+The `@slack-data-alerts` handle in `message` sends notifications to a Slack channel and requires the [Slack integration][17]. For other notification channels and template variables, see [Notifications][18].
+
### Query
The `query` sets the detection method:
@@ -160,7 +197,7 @@ search for database_table where `database:ANALYTICS_DB AND schema:PROD AND name:
search for database_column where `database:ANALYTICS_DB AND schema:PROD AND table:USERS AND name:EMAIL`
```
-For both tables and columns, `name:` is the asset's own name. A column filter uses `table:` for the parent table. Filters support the same syntax as [asset selection in the UI][11]:
+For both tables and columns, `name:` is the asset's own name. A column filter uses `table:` for the parent table. `search for table` and `search for column` are equivalent to `search for database_table` and `search for database_column`, and exported monitors can use either form. Filters support the same syntax as [asset selection in the UI][11]:
- Attributes: `name:`, `schema:`, `database:`, `account:`, `entity_id:`, and any tag key, such as `owner:data-platform`.
- Lineage score: `lineage_score:(0.90 OR 1.00)`.
@@ -183,7 +220,7 @@ A monitor covers up to 5,000 assets. Each table a filter matches counts as a mon
### Group by
-Always include the asset keys in `group_by` so each asset reports its own status and chart:
+To get a separate status, alert, and chart for each asset, include the asset keys in `group_by`. The UI uses these keys by default:
- Tables: `["entity_id", "table", "schema", "database"]`
- Columns: `["entity_id", "column", "table", "schema", "database"]`
@@ -289,8 +326,13 @@ Anomaly monitors accept these settings in `monitor_options`. For what each one d
| `min_lower_bound_size`, `min_upper_bound_size` | The smallest distance between the prediction and each bound, in the metric's unit. |
| `model_bounds_override` | Alert direction: `UPPER_ONLY` alerts above the range, `LOWER_ONLY` below it. Omit to alert in both directions. Values are case sensitive. |
| `model_instructions` | Up to 500 characters of plain-language context about behavior you expect. |
+| `auto_resolve_days` | Resolves an open alert automatically after this many days, from 1 to 365. When unset, an alert stays open until the metric returns within the bounds. |
+| `enable_flatline_detection` | Whether to alert when the metric stops changing. Default `true`. |
+| `function` | `DIFF` or `DIFF_PERCENT`. Applies a difference function to the metric before the model compares it with the bounds. |
+
+The Terraform `datadog_monitor` resource supports every setting in this table except `model_instructions`, so use `datadog_monitor_json` if you set instructions. If you apply a `datadog_monitor` resource to a monitor whose instructions were set in the UI, Terraform removes them.
-The Terraform `datadog_monitor` resource supports `sensitivity`, `min_lower_bound_size`, `min_upper_bound_size`, and `model_bounds_override`. It doesn't support `model_instructions`, so use `datadog_monitor_json` if you set instructions. If you apply a `datadog_monitor` resource to a monitor whose instructions were set in the UI, Terraform removes them.
+When a `model_configuration` block is present, the provider always sends `enable_flatline_detection`, which defaults to `true`. If you turned off flatline detection in the UI, set `enable_flatline_detection = false` in Terraform, or the next apply turns it back on.
To alert only after several anomalies in a row, widen the window and add a trigger window. For three consecutive anomalies on an hourly monitor:
@@ -314,7 +356,7 @@ Set `on_missing_data` to `default`, `show_no_data`, `show_and_notify_no_data`, o
Source to target monitors are in Preview. Contact your Datadog representative or <a href="/help/">support</a> to request access.
{{< /callout >}}
-A source to target monitor is a `data-quality alert` with a `source_to_target_config` in `monitor_options`. The `filter` selects the target asset. Source to target monitors reference both assets by `entity_id`, so export a monitor from the UI or look up the IDs in the Catalog. A table that Data Observability hasn't crawled yet has no `entity_id`.
+A source to target monitor is a `data-quality alert` with a `source_to_target_config` in `monitor_options`. The `filter` selects the target asset. Source to target monitors reference both assets by `entity_id`. See [Find an entity ID](#find-an-entity-id). A table that Data Observability hasn't collected yet has no `entity_id`.
{{< tabs >}}
{{% tab "API" %}}
@@ -332,13 +374,13 @@ A source to target monitor is a `data-quality alert` with a `source_to_target_co
"data_source": "data_quality_metrics",
"schema_version": "0.0.1",
"measure": "row_count",
- "filter": "search for database_table where `entity_id:9f8e7d6c5b4a3921`",
+ "filter": "search for database_table where `entity_id:<TARGET_ENTITY_ID>`",
"group_by": ["entity_id", "table", "schema", "database"],
"monitor_options": {
"crontab_override": "0 * * * *",
"source_to_target_config": {
- "source": { "entity_id": "1a2b3c4d5e6f7081", "entity_type": "database_table" },
- "target": { "entity_id": "9f8e7d6c5b4a3921", "entity_type": "database_table" },
+ "source": { "entity_id": "<SOURCE_ENTITY_ID>", "entity_type": "database_table" },
+ "target": { "entity_id": "<TARGET_ENTITY_ID>", "entity_type": "database_table" },
"diff_type": "absolute"
}
}
@@ -368,7 +410,7 @@ resource "datadog_monitor" "orders_replication" {
data_source = "data_quality_metrics"
schema_version = "0.0.1"
measure = "row_count"
- filter = "search for database_table where `entity_id:9f8e7d6c5b4a3921`"
+ filter = "search for database_table where `entity_id:<TARGET_ENTITY_ID>`"
group_by = ["entity_id", "table", "schema", "database"]
monitor_options {
crontab_override = "0 * * * *"
@@ -376,11 +418,11 @@ resource "datadog_monitor" "orders_replication" {
diff_type = "absolute"
entity_type = "database_table"
source {
- entity_id = "1a2b3c4d5e6f7081"
+ entity_id = "<SOURCE_ENTITY_ID>"
entity_type = "database_table"
}
target {
- entity_id = "9f8e7d6c5b4a3921"
+ entity_id = "<TARGET_ENTITY_ID>"
entity_type = "database_table"
}
}
@@ -394,7 +436,7 @@ resource "datadog_monitor" "orders_replication" {
{{< /tabs >}}
- `diff_type` is `absolute` (target minus source) or `diff_percent` (the difference as a percent of the source).
-- `entity_type` is `database_table` or `database_column`, and must be the same for the source and the target.
+- `entity_type` is `database_table` or `database_column`. Use the same type for the source and the target. The Terraform resource also requires `entity_type` directly under `source_to_target_config`. The API doesn't.
- To compare custom metrics, set `measure` to `custom` and add `custom_sql` to both `source` and `target`.
- An anomaly monitor learns the current difference as normal, so it doesn't alert on a mismatch that already exists when you create it. To alert on any difference, use a threshold, such as `formula("query1").last("2h") != 0` with `critical` set to `0`.
@@ -404,7 +446,7 @@ resource "datadog_monitor" "orders_replication" {
Schema change monitors are in Preview.
{{< /callout >}}
-Schema change monitors use the `schema-change alert` type. The Terraform `datadog_monitor` resource doesn't accept this type, so use `datadog_monitor_json`. Build the JSON with `jsonencode()` rather than a heredoc, because heredocs change the escaped quotes inside the query.
+Schema change monitors use the `schema-change alert` type. The Terraform `datadog_monitor` resource doesn't accept this type, so use `datadog_monitor_json`. Some Datadog API client libraries also reject this type before they send the request, so call the HTTP API directly. Build the JSON with `jsonencode()` rather than a heredoc, because heredocs change the escaped quotes inside the query.
{{< tabs >}}
{{% tab "API" %}}
@@ -413,7 +455,7 @@ Schema change monitors use the `schema-change alert` type. The Terraform `datado
{
"name": "Columns removed, renamed, or retyped in ANALYTICS_DB.PROD",
"type": "schema-change alert",
- "query": "schema-changes(\"@account_entity_id:1a2b3c4d5e6f7081 AND @database:ANALYTICS_DB AND @schema:PROD AND @change_type:(removed OR renamed OR type_changed)\").rollup(\"count\").last(\"10m\") > 0",
+ "query": "schema-changes(\"@account_entity_id:<ACCOUNT_ENTITY_ID> @database:ANALYTICS_DB @schema:PROD @change_type:(removed OR renamed OR type_changed)\").rollup(\"count\").last(\"10m\") > 0",
"message": "Schema change detected in ANALYTICS_DB.PROD. @slack-data-alerts",
"options": {
"thresholds": { "critical": 0 }
@@ -429,7 +471,7 @@ resource "datadog_monitor_json" "prod_schema_changes" {
monitor = jsonencode({
name = "Columns removed, renamed, or retyped in ANALYTICS_DB.PROD"
type = "schema-change alert"
- query = "schema-changes(\"@account_entity_id:1a2b3c4d5e6f7081 AND @database:ANALYTICS_DB AND @schema:PROD AND @change_type:(removed OR renamed OR type_changed)\").rollup(\"count\").last(\"10m\") > 0"
+ query = "schema-changes(\"@account_entity_id:<ACCOUNT_ENTITY_ID> @database:ANALYTICS_DB @schema:PROD @change_type:(removed OR renamed OR type_changed)\").rollup(\"count\").last(\"10m\") > 0"
message = "Schema change detected in ANALYTICS_DB.PROD. @slack-data-alerts"
options = {
thresholds = { critical = 0 }
@@ -441,10 +483,11 @@ resource "datadog_monitor_json" "prod_schema_changes" {
{{% /tab %}}
{{< /tabs >}}
-The query filter accepts:
+The query filter accepts the following attributes. Separate them with spaces, as the UI does:
- `@account_entity_id`: the warehouse account. Export a schema change monitor created in the UI to find this ID.
- `@database`, `@schema`, `@table`, `@column`: the assets to watch.
+- `@entity_id`: specific assets, such as `@entity_id:(<ENTITY_ID_1> OR <ENTITY_ID_2>)`.
- `@change_type`: `added`, `removed`, `renamed`, or `type_changed`. Omit it to alert on every change.
## Job monitors
@@ -460,7 +503,7 @@ Job monitors use the `data-jobs alert` type. The query variable must be named `r
{
"name": "Databricks nightly job failed",
"type": "data-jobs alert",
- "query": "formula(\"failed_runs(run_query)\").by(job_name,workspace_name,entity_id).last(1d) > 0",
+ "query": "formula(\"failed_runs(run_query)\").by(name,platform,workspace_id,workspace_name,entity_id).last(1d) > 0",
"message": "A Databricks nightly job failed. @slack-data-alerts",
"options": {
"thresholds": { "critical": 0 },
@@ -485,7 +528,7 @@ resource "datadog_monitor" "databricks_nightly_failed" {
name = "Databricks nightly job failed"
type = "data-jobs alert"
message = "A Databricks nightly job failed. @slack-data-alerts"
- query = "formula(\"failed_runs(run_query)\").by(job_name,workspace_name,entity_id).last(1d) > 0"
+ query = "formula(\"failed_runs(run_query)\").by(name,platform,workspace_id,workspace_name,entity_id).last(1d) > 0"
monitor_thresholds {
critical = 0
@@ -509,15 +552,17 @@ The threshold counts consecutive failed runs: `> 0` alerts on the first failure,
`run_filter` filters individual runs by tag, such as `env:prod`. The Terraform `data_jobs_query` block doesn't support `run_filter`, so use `datadog_monitor_json` if you need it.
+To alert on each failed run instead of on the count of consecutive failures, add `"monitor_options": { "alert_on_every_failure": true }` to the `run_query` variable. This setting requires the `aastra` query dialect, a `> 0` threshold with no warning threshold, a window of `2d` or less, and renotification turned off. The Terraform `data_jobs_query` block doesn't support it, so use `datadog_monitor_json`.
+
Use the `job_type` and group-by keys that match the jobs you select. These are the keys the UI uses, and `entity_id` always comes last in `.by()`:
| Jobs | `jobs_query` asset type | `job_type` | `.by()` keys |
|---|---|---|---|
-| Databricks jobs | `databricks_job` | `databricks.job` | `job_name`, `workspace_name` |
+| Databricks jobs | `databricks_job` | `databricks.job` | `name`, `platform`, `workspace_id`, `workspace_name` |
| Spark applications | `spark_application` | `spark.application` | `job_name`, `env` |
| Airflow DAGs | `airflow_dag` | `airflow.dag` | `name`, `env` |
| Airflow tasks | `airflow_job` | `airflow.job` | `name`, `dag_name`, `env` |
-| dbt jobs, models, snapshots, tests | `dbt_job`, `dbt_model`, `dbt_snapshot`, `dbt_test` | `dbt.job`, `dbt.model`, `dbt.snapshot`, `dbt.test` | `name`, `project`, `env` |
+| dbt jobs, models, tests | `dbt_job`, `dbt_model`, `dbt_test` | `dbt.job`, `dbt.model`, `dbt.test` | `name`, `project`, `env` |
| AWS Glue jobs | `glue_job` | `glue.job` | `name`, `env`, `account`, `region` |
| Azure Data Factory pipelines | `azure_data_factory_pipeline` | `adf.pipeline` | `name`, `tenant`, `subscription`, `factory` |
| Custom jobs from OpenLineage | `data_job` with `platform:custom AND integration:<NAME>` | `custom.ol.<NAME>` | `integration`, `name`, `env` |
@@ -535,7 +580,7 @@ Duration monitors alert when a run takes longer than a threshold, or longer than
{
"name": "Databricks nightly job ran longer than 2 hours",
"type": "data-jobs alert",
- "query": "formula(\"job_duration(run_query)\").detection(static).by(job_name,workspace_name,entity_id) > 7200",
+ "query": "formula(\"job_duration(run_query)\").detection(static).by(name,platform,workspace_id,workspace_name,entity_id) > 7200",
"message": "A Databricks nightly job ran longer than 2 hours. @slack-data-alerts",
"options": {
"thresholds": { "critical": 7200, "warning": 5400 },
@@ -546,7 +591,7 @@ Duration monitors alert when a run takes longer than a threshold, or longer than
"schema_version": "0.0.1",
"measure": "duration",
"filter": "search for databricks_job where `name:nightly_* AND workspace_name:prod`",
- "group_by": ["job_name", "workspace_name", "entity_id"],
+ "group_by": ["name", "platform", "workspace_id", "workspace_name", "entity_id"],
"run_filter": "",
"job_duration": {},
"monitor_options": { "detection_type": "static", "consecutive_runs": 1 }
@@ -564,7 +609,7 @@ resource "datadog_monitor_json" "databricks_nightly_duration" {
monitor = jsonencode({
name = "Databricks nightly job ran longer than 2 hours"
type = "data-jobs alert"
- query = "formula(\"job_duration(run_query)\").detection(static).by(job_name,workspace_name,entity_id) > 7200"
+ query = "formula(\"job_duration(run_query)\").detection(static).by(name,platform,workspace_id,workspace_name,entity_id) > 7200"
message = "A Databricks nightly job ran longer than 2 hours. @slack-data-alerts"
options = {
thresholds = { critical = 7200, warning = 5400 }
@@ -574,7 +619,7 @@ resource "datadog_monitor_json" "databricks_nightly_duration" {
schema_version = "0.0.1"
measure = "duration"
filter = "search for databricks_job where `name:nightly_* AND workspace_name:prod`"
- group_by = ["job_name", "workspace_name", "entity_id"]
+ group_by = ["name", "platform", "workspace_id", "workspace_name", "entity_id"]
run_filter = ""
job_duration = {}
monitor_options = { detection_type = "static", consecutive_runs = 1 }
@@ -597,7 +642,7 @@ resource "datadog_monitor_json" "databricks_nightly_duration" {
Running monitors on demand is in Preview.
{{< /callout >}}
-Trigger a run with the [Data Observability API][15], for example after a pipeline finishes:
+Trigger a run with the [Data Observability API][15], for example after a pipeline finishes. You can only trigger monitors whose `crontab_override` is `not_scheduled`.
```shell
curl -X POST "https://api.datadoghq.com/api/v2/data-observability/monitors/<MONITOR_ID>/run" \
@@ -605,7 +650,13 @@ curl -X POST "https://api.datadoghq.com/api/v2/data-observability/monitors/<MONI
-H "DD-APPLICATION-KEY: ${DD_APP_KEY}"
```
-The response includes a `run_id`. Check the result with `GET /api/v2/data-observability/monitors/runs/<RUN_ID>/status`, which returns `pending`, `ok`, `warn`, `alert`, or `error`. Table freshness and row count monitors on the default schedule can't run on demand. Set a `crontab_override`, such as `not_scheduled`, first.
+The response returns the run ID in `data.id`:
+
+```json
+{ "data": { "id": "abc123def456", "type": "monitor_run" } }
+```
+
+Poll `GET /api/v2/data-observability/monitors/runs/<RUN_ID>/status` until `data.attributes.status` is no longer `pending`. The final status is `ok`, `warn`, `alert`, or `error`. When the status is `error`, `data.attributes.error_message` explains why.
## Troubleshooting
@@ -615,12 +666,24 @@ The monitor shows no data or no groups
The API rejects the threshold
: The `critical` threshold must equal the number in the query. For anomaly monitors, use `> 0` with `critical` set to `0`.
-`Measure 'nullness' is not supported for 'table' filters`
-: Column metrics need a `search for database_column` filter.
+`Measure 'nullness' is not supported for 'database_table' filters`
+: Column metrics need a `search for database_column` filter. The message names `table` instead if the filter uses `search for table`.
-The API rejects custom SQL with an error about extra columns
+`group_by_columns is required when custom_sql returns group columns`
: Every column the SQL returns other than `dd_value` must be listed in `group_by_columns`.
+`Unknown validation error` on a custom SQL monitor
+: Remove any `ORDER BY` from the query. If the query returns more than one row, list its grouping columns in `group_by_columns`.
+
+`job_type must be one of [...]`
+: Use a `job_type` from the table in [Failed runs](#failed-runs), or `custom.ol.<NAME>` for custom jobs.
+
+The monitor is created but never evaluates
+: Validation doesn't catch every mistake. Check that the filter matches assets in the Catalog, that custom SQL returns a numeric `dd_value` column, and that `job_type` matches the asset type in `jobs_query`.
+
+Terraform requests fail with an authentication error
+: The provider sends requests to US1 by default. Set `api_url` for your site. See [Configure the Terraform provider](#configure-the-terraform-provider).
+
Terraform reverts changes made in the UI
: Terraform resets a monitor to its configuration on each apply. Make changes in one place, either Terraform or the UI.
@@ -647,3 +710,5 @@ Resolving the monitor has no effect
[14]: /monitors/types/data_observability/#missing-data
[15]: /api/latest/data-observability/
[16]: /monitors/types/data_observability/#annotate-bounds
+[17]: /integrations/slack/
+[18]: /monitors/notify/
diff --git a/hugo/config/_default/menus/main.en.yaml b/hugo/config/_default/menus/main.en.yaml
index 0a9d46f..a790dec 100644
--- a/hugo/config/_default/menus/main.en.yaml
+++ b/hugo/config/_default/menus/main.en.yaml
@@ -5774,7 +5774,7 @@ menu:
identifier: quality_monitoring_monitors
parent: quality_monitoring
weight: 350000
- - name: How-To Guides
+ - name: Guides
url: data_observability/quality_monitoring/guides
identifier: quality_monitoring_guides
parent: quality_monitoringApply the review patch: Databricks group-by keys, dbt job types, Terraform provider site configuration, key permissions, validation limits, model configuration fields, on-demand run response, and exact error strings. Expand "Find an entity ID" with the Catalog URL format and a walkthrough of the MCP Server's Data Observability tools. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @traegerdog, this is a great pass. I applied the patch in fd136b1, with three exceptions:
I also expanded "Find an entity ID". It now covers the Catalog URL format and walks through looking up IDs with the MCP Server's Data Observability tools ( The four examples that changed pass validation. Your other questions are still open for the Data Observability team. |
DataDog/documentation PR 42071 adds the same quality_monitoring_guides_anomaly_detection entry, so keeping both would duplicate the identifier once both merge. This PR now adds only the monitors-as-code entry, weighted 2000000 so it sorts between Anomaly Detection (1000000) and the Metaplane migration guide (3000000). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tors-as-code-guide Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The left nav hides the children of an entry named exactly "Guides", so this PR's rename to "How-To Guides" is what makes every guide entry visible. This PR now carries all the guide entries that depend on it: Monitors with the API or Terraform (500000) and Anomaly Detection (1000000), which DataDog/documentation PR 42071 drops from its own menu edit. The Metaplane migration guide (3000000, PR 42066) sorts after them. The guides index lists this guide above Anomaly Detection to match the nav order, which also keeps the edit clear of the line PR 42066 adds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Match the monitor page's model configuration Preview callout. - Describe the Default schedule, limit Manual (not_scheduled) to custom SQL and column metric monitors as in the UI, note that Agent-based databases don't run Manual monitors, and state the 15-minute minimum as a UI limit. - Explain what the function setting does and that source to target monitors derive it from diff_type. - Note that freshness monitors don't apply minimum bound sizes, and that the API returns model_instructions with the monitor definition. - Spell out how each monitor type counts toward monitored tables. - Clarify @entity_id matching and the multi-value change_type form for schema change monitors. - Rename Failed runs to Job failure, add the run filter technology limit, pin the Terraform gaps to provider 4.31.0 and earlier, and explain how to confirm job group-by keys. - Drop the on-demand restriction to not_scheduled monitors, use the Data Catalog name and the Export menu label, rename the weekday schedule row, remove the case-sensitivity claim, and link Monitor schedule. - Link the guide from the Jobs Monitoring overview. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…guide' into kevinzenghu/do-monitors-as-code-guide Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What does this PR do? What is the motivation?
Adds a Quality Monitoring guide, Create Data Observability Monitors with the API or Terraform, that walks through each Data Observability monitor type and how to define it as code:
datadog_monitor_jsonjob_typeand group-by keys for each platformUsers who manage monitors as code currently have to piece this together from the monitor type page, the Monitors API reference, and the Terraform provider docs. This page keeps it in one place without changing the general monitor API docs.
Also adds sidebar entries under Quality Monitoring > Guides for this page and for the existing Anomaly Detection guide, which had no sidebar entry.
Every full JSON example on the page passes
POST /api/v1/monitor/validate, and the Terraform examples match terraform-provider-datadog v4.30.0.Merge readiness
AI assistance
Drafted with Claude Code. Field names and query formats were checked against the monitor validation endpoint and the Terraform provider schema, then reviewed by the author.
Additional notes
Reviewers from the Data Observability team: please confirm the phase labels (Preview banners on model configuration, source to target, schema change, and on-demand runs) and the job duration section.
not_scheduledon table freshness and row count: The Manual row now matches the monitor page. Use it for custom SQL and column metric monitors. Manual monitors don't run on databases that connect through the Datadog Agent.model_instructions: It's saved with the monitor definition and returned when you get the monitor. The guide still points todatadog_monitor_json, because the typed Terraform resource doesn't support the field.@change_type:(a OR b): The UI writes multiple change types in this form. The guide gives an example.function: It tells the model that the values are differences or percentage differences, and it doesn't change them. Source to target monitors derive it fromdiff_type.@entity_idin a schema change query matches changes to that asset only. To include a table's columns, use@table.not_scheduledmonitors can be triggered.run_filterapply to provider 4.31.0 and earlier.nameandenv, the keys existing Spark job monitors use.not_scheduled? If they can, widen the Manual row here and on the monitor page.crontab_overridethat runs more often than every 15 minutes supported when it's set through the API?min_lower_bound_sizeandmin_upper_bound_size? [Data Observability] Expand monitor page: schema change filters, schedules, Custom SQL, source to target #42077 updates the monitor page to match.functionas applied to the measure before the comparison. Should that description say it doesn't change the values?name,platform,workspace_id, andworkspace_namefor Databricks, andnameandenvfor Spark. Confirm these, and confirm whether dbt Core jobs carry aprojectvalue and which keys custom OpenLineage job monitors created in the UI use.Unknown validation errorentry for custom SQL (anORDER BY, or several rows withoutgroup_by_columns) is still left out. Confirm the cause before adding it.run_filtertodatadog_monitor. When one ships, update the two "4.31.0 and earlier" sentences.🤖 Generated with Claude Code