Skip to content

[datadog_dashboard_v2] Add anomaly_detection to timeseries widget#3778

Open
yacomink wants to merge 1 commit into
masterfrom
yacomink/20260513-timeseries-anomaly-detection
Open

[datadog_dashboard_v2] Add anomaly_detection to timeseries widget#3778
yacomink wants to merge 1 commit into
masterfrom
yacomink/20260513-timeseries-anomaly-detection

Conversation

@yacomink
Copy link
Copy Markdown
Contributor

Summary

Syncs the anomaly_detection field from the Datadog OpenAPI spec (TimeseriesWidgetDefinition) into the datadog_dashboard_v2 FieldSpec mapping engine.

OpenAPI spec change: DataDog/datadog-api-spec#5680

Fields added:

HCL path Type Required
timeseries_definition.anomaly_detection Block (optional) No
timeseries_definition.anomaly_detection.detection_sensitivity String enum Yes

detection_sensitivity currently accepts only "never_detect" (disables anomaly detection).

HCL example

resource "datadog_dashboard_v2" "example" {
  title       = "Example"
  layout_type = "ordered"

  widget {
    timeseries_definition {
      title = "CPU"

      anomaly_detection {
        detection_sensitivity = "never_detect"
      }

      request {
        formula { formula_expression = "q1" }
        query {
          metric_query {
            data_source = "metrics"
            name        = "q1"
            query       = "avg:system.cpu.user{*}"
          }
        }
      }
    }
  }
}

Implementation

  • datadog/dashboardmapping/widgets.go: added timeseriesWidgetAnomalyDetectionFields (one Go slice per OpenAPI schema) and anomaly_detection TypeBlock entry on TimeseriesWidgetSpec
  • datadog/tests/resource_datadog_dashboard_v2_timeseries_anomaly_detection_test.go: acceptance test covering the new field
  • datadog/tests/provider_test.go: registered new test file
  • docs/: regenerated

Test plan

  • Record cassettes: OTEL_TRACES_EXPORTER= RECORD=true TESTARGS="-run TestAccDatadogDashboardV2TimeseriesAnomalyDetection$" make testacc
  • Verify replay: OTEL_TRACES_EXPORTER= RECORD=false TESTARGS="-run TestAccDatadogDashboardV2TimeseriesAnomalyDetection" make testacc
  • go build ./...
  • go vet ./datadog/dashboardmapping/...
  • Unit tests (make test) ✅
  • make check-docs ✅ (after committing regenerated docs)

Syncs the `anomaly_detection` field from the updated OpenAPI spec
(TimeseriesWidgetDefinition) into the FieldSpec mapping engine.

Adds `timeseriesWidgetAnomalyDetectionFields` (one required string field:
`detection_sensitivity` enum `never_detect`) and wires it into
`TimeseriesWidgetSpec` as an optional `TypeBlock`. Regenerates docs.
Adds acceptance test `TestAccDatadogDashboardV2TimeseriesAnomalyDetection`
with cassette to be recorded.
Copy link
Copy Markdown
Contributor

@maycmlee maycmlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a question


Required:

- `detection_sensitivity` (String) Sensitivity level for anomaly detection. Use `never_detect` to disable anomaly detection. Valid values are `never_detect`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like there should be different levels as value, but how come the only valid values are never_detect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants