datadog-operator icon indicating copy to clipboard operation
datadog-operator copied to clipboard

Any plan for a ServiceMonitor-like CRD?

Open sebastien-prudhomme opened this issue 1 year ago • 9 comments

Hi,

Coming from Prometheus Operator, I find it's sometime not ideal to configure Datadog integrations for Kubernetes workload by using either annotations on pods or autodiscovery in Datadog agent config.

Is there any plan to implement a CRD that would allow configuring integrations throught Kubernetes labels selectors without modifying the original workload or the Datadog agent?

sebastien-prudhomme avatar Jan 07 '25 13:01 sebastien-prudhomme

@sebastien-prudhomme, thanks for submitting the issue!

Could you please provide more context about the request - what would be the CRD like, how would Operator use it and what gaps this setup could fill in current Autodiscovery mechanism?

levan-m avatar Mar 31 '25 18:03 levan-m

This issue has been automatically marked as stale because it has not had activity in the past 15 days.

It will be closed in 30 days if no further activity occurs. If this issue is still relevant, adding a comment will keep it open. Also, you can always reopen the issue if you missed the window.

Thank you for your contributions!

dd-octo-sts avatar Oct 14 '25 10:10 dd-octo-sts

I can add my 2c, since I would also like to see this feature. Currently for custom metrics, datadog annotations need to be added to a pod. Here is an example with cert-manager:

      ad.datadoghq.com/cert-manager-controller.checks: |
        {
          "openmetrics": {
            "init_config": {},
            "instances": [
              {
                "openmetrics_endpoint": "http://%%host%%:9402/metrics",
                "namespace": "cert_manager"
                "metrics": [
                  "certificate.expiration_timestamp",
                  "certificate.ready_status",
                  "certificate.renewal_timestamp"
                ],
                "tags": [
                  "component:controller",
                  "service:cert-manager",
                  "cluster_name:example-cluster",
                  "business:infra",
                  "env:prod"
                ]
              }
            ]
          }
        }

This is a lot of data to cram into an annotation. Furthermore, because annotations can be any string, there is no type or schema validation. This can lead to misconfigurations which become cumbersome to debug.

In a similar fashion, this is why the Kubernetes Ingress resource is being deprecated in favor of the Gateway API.

The breadth and flexibility of Ingress NGINX has caused maintenance challenges. Changing expectations about cloud native software have also added complications. What were once considered helpful options have sometimes come to be considered serious security flaws, such as the ability to add arbitrary NGINX configuration directives via the "snippets" annotations. Yesterday’s flexibility has become today’s insurmountable technical debt.

The quote above addresses the security flaws of snippet annotations, but as many Kubernetes cluster maintainers can attest to, the sheer amount of Ingress annotations that could add up caused maintenance issues as well.

Instead, Datadog should create a CRD called DatadogCustomMetric which can reference a pod. Something like:

apiVersion: datadoghq.com/v1alpha1
kind: DatadogCustomMetric
metadata:
  name: example-metric
  namespace: example
spec:
  container:
    endpoint: /metrics  # optional, defaults to /metrics
    name: cert-manager-controller  # required
    port: 8080  # optional, defaults to 8080
  datadogNamespacePrefix: cert_manager
  metrics:  # optional, defaults to all metrics
   - metricName: certificate.expiration_timestamp
   - metricName: certificate.ready_status
     datadogMetricName: certificate.ready  # optional, defaults to metricName
   - metricName: certificate.renewal_timestamp
  podSelector:  # required
    matchLabels:
      app: cert-manager
  tags:  # optional
    component:controller
    service:cert-manager
    cluster_name:example-cluster
    business:infra
    env:prod

starlightromero avatar Dec 22 '25 05:12 starlightromero

Hi folks. Thanks for your patience and sorry for the delayed response.

A Datadog check CRD is on our radar and we're actively investigating what that looks like in the near future. Thanks for sharing your thoughts, it really helps shape our work and I hope to be back with more details soon. 🙂

Mathew-Estafanous avatar Mar 25 '26 16:03 Mathew-Estafanous

I can add my 2c, since I would also like to see this feature. Currently for custom metrics, datadog annotations need to be added to a pod. Here is an example with cert-manager:

  ad.datadoghq.com/cert-manager-controller.checks: |
    {
      "openmetrics": {
        "init_config": {},
        "instances": [
          {
            "openmetrics_endpoint": "http://%%host%%:9402/metrics",
            "namespace": "cert_manager"
            "metrics": [
              "certificate.expiration_timestamp",
              "certificate.ready_status",
              "certificate.renewal_timestamp"
            ],
            "tags": [
              "component:controller",
              "service:cert-manager",
              "cluster_name:example-cluster",
              "business:infra",
              "env:prod"
            ]
          }
        ]
      }
    }

This is a lot of data to cram into an annotation. Furthermore, because annotations can be any string, there is no type or schema validation. This can lead to misconfigurations which become cumbersome to debug.

In a similar fashion, this is why the Kubernetes Ingress resource is being deprecated in favor of the Gateway API.

The breadth and flexibility of Ingress NGINX has caused maintenance challenges. Changing expectations about cloud native software have also added complications. What were once considered helpful options have sometimes come to be considered serious security flaws, such as the ability to add arbitrary NGINX configuration directives via the "snippets" annotations. Yesterday’s flexibility has become today’s insurmountable technical debt.

The quote above addresses the security flaws of snippet annotations, but as many Kubernetes cluster maintainers can attest to, the sheer amount of Ingress annotations that could add up caused maintenance issues as well.

Instead, Datadog should create a CRD called DatadogCustomMetric which can reference a pod. Something like:

apiVersion: datadoghq.com/v1alpha1 kind: DatadogCustomMetric metadata: name: example-metric namespace: example spec: container: endpoint: /metrics # optional, defaults to /metrics name: cert-manager-controller # required port: 8080 # optional, defaults to 8080 datadogNamespacePrefix: cert_manager metrics: # optional, defaults to all metrics

  • metricName: certificate.expiration_timestamp
  • metricName: certificate.ready_status datadogMetricName: certificate.ready # optional, defaults to metricName
  • metricName: certificate.renewal_timestamp podSelector: # required matchLabels: app: cert-manager tags: # optional component:controller service:cert-manager cluster_name:example-cluster business:infra env:prod

While I really like that approach, I would like to see it enhanced so that it also would be possible to "emulate" not only the PodMonitor but the ServiceMonitor as well.

stp-bsh avatar Mar 26 '26 09:03 stp-bsh

@stp-bsh There are fields in the PodMonitor and ServiceMonitor resources that wouldn't apply to Datadog custom metrics. What is the reason behind wanting to "emulate" these resources?

starlightromero avatar Mar 26 '26 16:03 starlightromero

@starlightromero I would like to see Pod and ServiceMonitors emulated, as many users in the Kubernetes environment use Prometheus and are familiar with these two types of monitors. This also means that, in most cases, the software and deployments are specifically designed for them. Ideally, the Datadog Agent should not create something entirely new, but rather support existing environments in a minimally invasive way - preferably by utilizing the current infrastructure, which in this case includes Pod and ServiceMonitors.

stp-bsh avatar Mar 27 '26 07:03 stp-bsh

@stp-bsh As much as I agree that many users use Prometheus, we shouldn't make the assumption that all users we have the Datadog Agent on their cluster will also have Prometheus. In other words, we don't want to make Prometheus a dependency of Datadog. This would mean not explicit using PodMonitors or ServiceMonitors.

However back to your emulation idea. I think it may be good to have the DatadogCustomMetric CRD have some similar fields to PodMonitor or ServiceMonitor CRDs. Although at this time I'm not sure which would be the most appropriate.

starlightromero avatar Mar 27 '26 16:03 starlightromero

Yes plz, the CRDs that are already in place work great for us, extending the usage would be much appreciated 🙏

Chr1stian avatar Jun 10 '26 07:06 Chr1stian