Skip to content

[CONTP-2023] Improve DatadogMonitor reconciliation at scale - #3381

Open
tbavelier wants to merge 4 commits into
mainfrom
tbavelier/contp-2023-thousands-of-monitors
Open

[CONTP-2023] Improve DatadogMonitor reconciliation at scale#3381
tbavelier wants to merge 4 commits into
mainfrom
tbavelier/contp-2023-thousands-of-monitors

Conversation

@tbavelier

@tbavelier tbavelier commented Aug 21, 2026

Copy link
Copy Markdown
Member

What does this PR do?

  • Adds configurable DatadogMonitor concurrency and status-polling cadence: c6af8bf
  • Makes scheduled status polling low priority, keeping create/update/delete work ahead of it: af9c7d5
  • Addresses review findings around retry timing and scheduled reconciliation: 42b8d62
  • Documents reconciliation priority and retry behavior inline: 5779096

Motivation

Large monitor collections can accumulate polling work and delay lifecycle operations.

Warning

For large DatadogMonitor fleets, we recommend disabling direct operator telemetry with --operatorMetricsEnabled=false (DD_OPERATOR_METRICS_ENABLED=false) for better performance. When enabled (default), every DatadogMonitor starts one metrics-forwarder goroutine.

Reconciliation and Kubernetes Events continue to work, but direct Datadog operator metrics datadog.operator.reconcile.success, datadog.operator.<resource>.custom_resource.count, etc.) and events for DatadogAgent, DatadogAgentInternal, and DatadogMonitor resources are disabled. THESE DO NOT AFFECT Agent telemetry, this is purely self-telemetry from the operator

If operator own telemetry must remain enabled, raise the --maximumGoroutines (DD_MAXIMUM_GOROUTINES) health-check threshold above the expected total goroutine count; its default is 500 and it is not a runtime goroutine limit.

QA

Manual scale and priority check:

  1. Deploy the operator with DatadogMonitor enabled and --datadogMonitorMaxConcurrentReconciles=10 (as well as operatorMetricsEnabled=false or maximumGoroutines=10000)
  2. Create 1,000 monitors at once with the helper below and verify they receive Datadog monitor IDs.
  3. Restart with --datadogMonitorMaxConcurrentReconciles=1 to accumulate scheduled status-polling work.
  4. Create one additional monitor and verify it is reconciled ahead of the polling backlog.
  5. Restore the worker count and delete the load-test monitors.
DatadogMonitor bulk load helper
#!/usr/bin/env bash
set -euo pipefail

ACTION="${1:-}"
COUNT="${2:-}"
NAMESPACE="${NAMESPACE:-default}"
PREFIX="${PREFIX:-datadogmonitor-load}"

if [[ "$ACTION" != create && "$ACTION" != delete ]] || ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then
  echo "usage: NAMESPACE=default PREFIX=datadogmonitor-load $0 {create|delete} <count>" >&2
  exit 1
fi

render() {
  local i name
  for ((i = 1; i <= COUNT; i++)); do
    name="${PREFIX}-${i}"
    cat <<EOF
---
apiVersion: datadoghq.com/v1alpha1
kind: DatadogMonitor
metadata:
  name: ${name}
spec:
  name: ${name}
  type: metric alert
  query: avg(last_5m):avg:system.load.1{*} > 100000
  message: DatadogMonitor controller load test
  tags:
    - generated:kubernetes
    - test:datadogmonitor-load
EOF
  done
}

case "$ACTION" in
  create) render | kubectl --namespace "$NAMESPACE" create --filename - ;;
  delete) render | kubectl --namespace "$NAMESPACE" delete --filename - --ignore-not-found ;;
esac
./datadogmonitor-load.sh create 1000
./datadogmonitor-load.sh delete 1000

The full batch is sent through one kubectl create or kubectl delete invocation.

@tbavelier tbavelier added this to the v1.31.0 milestone Aug 21, 2026
@tbavelier tbavelier added the enhancement New feature or request label Aug 21, 2026
@tbavelier
tbavelier force-pushed the tbavelier/contp-2023-thousands-of-monitors branch from f9b8943 to 33664a7 Compare August 21, 2026 10:07
@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Aug 21, 2026

Copy link
Copy Markdown

Code Coverage  Pipelines

🛑 Gate Violations

🎯 1 Code Coverage issue detected

A Patch coverage percentage gate may be blocking this PR.

Patch coverage: 69.70% (threshold: 80.00%)

ℹ️ Info

🎯 Code Coverage (details)
Patch Coverage: 69.70%
Overall Coverage: 50.19% (+0.07%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5779096 | Docs | View more details | Give us feedback!

@tbavelier
tbavelier force-pushed the tbavelier/contp-2023-thousands-of-monitors branch from 33664a7 to af9c7d5 Compare August 21, 2026 10:24
@tbavelier
tbavelier marked this pull request as ready for review August 21, 2026 10:25
@tbavelier
tbavelier requested a review from a team August 21, 2026 10:25
@tbavelier
tbavelier requested a review from a team as a code owner August 21, 2026 10:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af9c7d5002

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/controller/datadogmonitor/controller.go
Comment thread internal/controller/datadogmonitor_controller.go
Comment thread internal/controller/datadogmonitor/controller.go Outdated
Comment thread internal/controller/datadogmonitor/controller.go Outdated
@tbavelier

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 5779096b20

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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