Skip to content

[CONTP-1569] Add KSM labels_as_tags / annotations_as_tags / tags to CRD#2937

Open
zhuminyi wants to merge 1 commit intomainfrom
minyi/contp-1569-ksm-yaml-fields
Open

[CONTP-1569] Add KSM labels_as_tags / annotations_as_tags / tags to CRD#2937
zhuminyi wants to merge 1 commit intomainfrom
minyi/contp-1569-ksm-yaml-fields

Conversation

@zhuminyi
Copy link
Copy Markdown
Contributor

@zhuminyi zhuminyi commented Apr 25, 2026

Adds three additive fields to KubeStateMetricsCoreFeatureConfig that emit into the KSM check-instance YAML.

Field Type Default Effect
labelsAsTags map[string]map[string]string nil per-resource-kind label → Datadog-tag mapping (emits as labels_as_tags: in check instance)
annotationsAsTags map[string]map[string]string nil per-resource-kind annotation → Datadog-tag mapping
tags []string nil static tags applied to all KSM metrics; emitted via YAML encoder so values with colons, slashes, or other YAML-special characters are quoted safely

Introduces a small writeYAMLBlock helper in configmap.go used by all three emission sites. No RBAC changes, no collector-list changes, no behavior change on upgrade for users who do not set any of the three new fields — the rendered ConfigMap is byte-identical
to today's output when the new fields are unset.

Example

DatadogAgent CR using the three new fields alongside the existing collectCrMetrics:

apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
  name: datadog
spec:
  features:
    kubeStateMetricsCore:
      enabled: true
      collectCrMetrics:                 # existing field — unchanged behavior
        - groupVersionKind:
            group: argoproj.io
            version: v1alpha1
            kind: Application
      labelsAsTags:                     # new
        pod:
          app: app
        node:
          zone: zone
      annotationsAsTags:                # new
        pod:
          tags_datadoghq_com_version: version  # KSM annotation-name transform applied
      tags:                             # new
        - env:prod
        - team:cont-p

Rendered KSM check instance (datadog-kube-state-metrics-core-config ConfigMap, new sections only — rest of instances[0] is byte-identical to today's output):

instances:
  - skip_leader_election: true
    collectors:
      ...   # unchanged
    labels_as_tags:
      pod:
        app: app
      node:
        zone: zone
    annotations_as_tags:
      pod:
        tags_datadoghq_com_version: version
    custom_resource:
      spec:
        resources:
          - groupVersionKind:
              group: argoproj.io
              version: v1alpha1
              kind: Application
    tags:
      - env:prod
      - team:cont-p

Notes

  • Shape of labelsAsTags / annotationsAsTags matches the Helm chart (helm charts/charts/datadog/values.yaml) exactly so users can copy values between the two configs.
  // helm-chart config
  datadog:
    kubeStateMetricsCore:                  # <-- this section
      enabled: true
      collectCrMetrics: []                  # already in operator
      labelsAsTags: {}                      # ✅ this PR
      annotationsAsTags: {}                 # ✅ this PR 
      tags: []                              # ✅ this PR

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.00%. Comparing base (039572f) to head (bab3433).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2937      +/-   ##
==========================================
+ Coverage   40.69%   41.00%   +0.31%     
==========================================
  Files         321      324       +3     
  Lines       28413    29152     +739     
==========================================
+ Hits        11563    11955     +392     
- Misses      16015    16332     +317     
- Partials      835      865      +30     
Flag Coverage Δ
unittests 41.00% <100.00%> (+0.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...adogagent/feature/kubernetesstatecore/configmap.go 97.64% <100.00%> (+0.42%) ⬆️
...atadogagent/feature/kubernetesstatecore/feature.go 80.95% <100.00%> (+1.69%) ⬆️
pkg/testutils/builder.go 4.00% <100.00%> (+4.00%) ⬆️

... and 14 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 039572f...bab3433. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@datadog-datadog-prod-us1-2
Copy link
Copy Markdown

datadog-datadog-prod-us1-2 Bot commented Apr 25, 2026

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 41.06% (+0.04%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bab3433 | Docs | Datadog PR Page | Give us feedback!

@zhuminyi zhuminyi force-pushed the minyi/contp-1569-ksm-yaml-fields branch 2 times, most recently from b8a4a37 to 8c34275 Compare April 25, 2026 18:37
@zhuminyi zhuminyi marked this pull request as ready for review April 27, 2026 15:11
@zhuminyi zhuminyi requested a review from a team April 27, 2026 15:11
@zhuminyi zhuminyi requested review from a team as code owners April 27, 2026 15:11
Copy link
Copy Markdown

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

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: 8c3427579b

ℹ️ 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/datadogagent/feature/kubernetesstatecore/feature.go Outdated
Copy link
Copy Markdown
Contributor

@drichards-87 drichards-87 left a comment

Choose a reason for hiding this comment

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

Left some suggestions from Docs and approved the PR.

Comment thread docs/configuration_public.md Outdated
Comment thread docs/configuration_public.md Outdated
Comment thread docs/configuration.v2alpha1.md Outdated
Comment thread docs/configuration.v2alpha1.md Outdated
@zhuminyi zhuminyi force-pushed the minyi/contp-1569-ksm-yaml-fields branch 3 times, most recently from e32a677 to 4e4f0c6 Compare April 27, 2026 19:38
First split-out of CONTP-1569 (Operator <-> Helm chart parity). Adds three
KubeStateMetricsCoreFeatureConfig fields that write into the KSM check
instance YAML:

- LabelsAsTags (map[string]map[string]string): per-resource-kind label->tag
  mapping.
- AnnotationsAsTags (map[string]map[string]string): per-resource-kind
  annotation->tag mapping.
- Tags ([]string): static tags applied to all KSM metrics; emitted via YAML
  encoder so values containing colons, slashes, or other YAML-special
  characters are quoted safely.

Introduces a small writeYAMLBlock helper in configmap.go used by all three
sites. No RBAC changes, no collector list changes, no behavior change on
upgrade for users who don't set any of the three new fields.

Sub-task of CONTP-1446. Follow-up PRs will add CollectSecretMetrics and
CollectConfigMaps (those touch RBAC and have an upgrade-reconcile note).
@zhuminyi zhuminyi force-pushed the minyi/contp-1569-ksm-yaml-fields branch from 4e4f0c6 to bab3433 Compare April 28, 2026 03:59
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.

3 participants