Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api/datadoghq/v2alpha1: add support for SSI targets #1670

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

knusbaum
Copy link
Collaborator

@knusbaum knusbaum commented Feb 7, 2025

What does this PR do?

We want to allow the datadog-operator to configure SSI targets in the cluster agent.
The config we want to add is here.

Motivation

See: INPLAT-424

Minimum Agent Versions

This change supports a new feature in the cluster agent, and is harmless to older cluster agents.

  • Cluster Agent: Requires Cluster Agent 7.64.0

Describe your test plan

I setup minikube locally with a registry. I ran the following to install my operator based on the docs:

# Build
make IMG=localhost:5000/test/operator:test IMG_CHECK=localhost:5000/test/operator-check:test docker-build

# Push
make IMG=localhost:5000/test/operator:test IMG_CHECK=localhost:5000/test/operator-check:test docker-push

# Deploy
make IMG=localhost:5000/test/operator:test IMG_CHECK=localhost:5000/test/operator-check:test deploy

I then added the following config to examples/datadogagent/datadog-agent-minimum.yaml and ran the script for a DatadogAgent resource:

apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
  name: datadog
spec:
  override:
    clusterAgent:
      image:
        name: registry.ddbuild.io/ci/datadog-agent/cluster-agent:v55563759-d8db7b1b-amd64
        tag: v55563759-d8db7b1b-amd64
  global:
    clusterName: my-example-cluster
    credentials:
      apiKey: <YOUR-API-KEY-HERE>
  features:
    apm:
      instrumentation:
        targets:
          - name: "sometarget"
            podSelector:
              matchLabels:
                key: value
              matchExpressions:
                - key: somekey
                  operator: In
                  values:
                    - value1
                    - value2
            namespaceSelector:
              matchNames:
                - name1
                - name2
              matchLabels:
                key1: val1
                key2: val2
              matchExpressions:
                - key: somekey1
                  operator: In
                  values:
                    - value1
                    - value2
            ddTraceVersions:
              java: "1"
              dotnet: "2"
        enabled: true
        enabledNamespaces:
          - "test-1"

Finally, I exec'd into the cluster agent pod and verified that the expected environment variable is set:

$ kubectl -n system exec -ti datadog-cluster-agent-897578d6d-ljm5v -- bash
root@datadog-cluster-agent-897578d6d-ljm5v:/# env | grep DD_APM
DD_APM_INSTRUMENTATION_ENABLED_NAMESPACES=["test-1"]
DD_APM_INSTRUMENTATION_ENABLED=true
DD_APM_INSTRUMENTATION_TARGETS=[{"name":"sometarget","podSelector":{"matchLabels":{"key":"value"},"matchExpressions":[{"key":"somekey","operator":"In","values":["value1","value2"]}]},"namespaceSelector":{"matchNames":["name1","name2"],"matchLabels":{"key1":"val1","key2":"val2"},"matchExpressions":[{"key":"somekey1","operator":"In","values":["value1","value2"]}]},"ddTraceVersions":{"dotnet":"2","java":"1"}}]

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 50.44%. Comparing base (b073d93) to head (3f10318).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...nal/controller/datadogagent/feature/apm/feature.go 70.00% 2 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (75.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1670      +/-   ##
==========================================
+ Coverage   49.48%   50.44%   +0.96%     
==========================================
  Files         218      218              
  Lines       21240    22028     +788     
==========================================
+ Hits        10511    11113     +602     
- Misses      10182    10327     +145     
- Partials      547      588      +41     
Flag Coverage Δ
unittests 50.44% <75.00%> (+0.96%) ⬆️

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

Files with missing lines Coverage Δ
pkg/testutils/builder.go 91.69% <100.00%> (+0.01%) ⬆️
...nal/controller/datadogagent/feature/apm/feature.go 65.66% <70.00%> (+0.14%) ⬆️

... and 37 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 b073d93...3f10318. Read the comment docs.

@knusbaum knusbaum force-pushed the knusbaum/ssi-targets branch 2 times, most recently from f88199e to a66ab69 Compare February 7, 2025 18:15
@knusbaum knusbaum added this to the v1.13.0 milestone Feb 11, 2025
@knusbaum knusbaum added the enhancement New feature or request label Feb 11, 2025
@knusbaum knusbaum marked this pull request as ready for review February 11, 2025 22:24
@knusbaum knusbaum requested review from a team as code owners February 11, 2025 22:24
@knusbaum knusbaum force-pushed the knusbaum/ssi-targets branch from 22e4ec5 to a261331 Compare February 11, 2025 22:26
@knusbaum knusbaum force-pushed the knusbaum/ssi-targets branch from a261331 to 6701f26 Compare February 11, 2025 22:34
Copy link

@aliciascott aliciascott left a comment

Choose a reason for hiding this comment

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

Just a small suggestion but approved

docs/configuration.v2alpha1.md Show resolved Hide resolved
Copy link
Member

@betterengineering betterengineering left a comment

Choose a reason for hiding this comment

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

🚀

betterengineering and others added 3 commits February 12, 2025 10:46
This commit adds the tracer config options we've just added.
Comment on lines +175 to +176
// used. If no target matches, the auto instrumentation will not be applied. Full config key:
// apm_config.instrumentation.targets
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't have a precedence of referencing the datadog.yaml config keys in this file; do you think it's needed?

(in general, a goal of the operator is to obscure some of the complicated config when setting up the agent)

// TracerConfigs is a list of configuration options to use for the installed tracers. These options will be added
// as environment variables in addition to the injected tracer. Full config key:
// apm_config.instrumentation.targets[].ddTraceConfigs
TracerConfigs []TracerConfig `json:"ddTraceConfigs"`
Copy link
Contributor

Choose a reason for hiding this comment

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

are all of these parameters required? they don't have +optional or omitempty

// PodSelector is a reconstruction of the metav1.LabelSelector struct to be able to unmarshal the configuration. It
// can be converted to a metav1.LabelSelector using the AsLabelSelector method. Full config key:
// apm_config.instrumentation.targets[].selector
type PodSelector struct {
Copy link
Contributor

Choose a reason for hiding this comment

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


// TracerConfig is a struct that stores configuration options for a tracer. These will be injected as environment
// variables to the workload that matches targeting.
type TracerConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

[]corev1.EnvVar could be used instead

@levan-m levan-m modified the milestones: v1.13.0, v1.14.0 Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants