Skip to content

discovery: use libdd_discovery CGO bindings for service discovery#46876

Draft
martavicentenavarro wants to merge 3 commits intomainfrom
marta/load_library
Draft

discovery: use libdd_discovery CGO bindings for service discovery#46876
martavicentenavarro wants to merge 3 commits intomainfrom
marta/load_library

Conversation

@martavicentenavarro
Copy link
Contributor

@martavicentenavarro martavicentenavarro commented Feb 24, 2026

What does this PR do?

Replaces the pure-Go service discovery implementation with a CGO-backed one that delegates to the Rust libdd_discovery shared library. The original Go implementation is preserved as a fallback when the dd_discovery_cgo build tag is not set.

impl_module_linux.go and impl_test_helpers_linux_test.go mainly contain logic that previously lived in impl_linux.go and the Linux test files, reorganized so CGO and non-CGO paths can share it without intended behavior changes.

Motivation

DSCVR-369

Describe how you validated your changes

I validated the change by building the Rust shared library (libdd_discovery.so) and running discovery module tests in both execution modes: the CGO path (dd_discovery_cgo) and the non-CGO path (!dd_discovery_cgo).

Additional Notes

The new path delegates all service discovery logic to the Rust libdd_discovery library. As a result, there are known intentional differences with the non-CGO fallback path that will be resolved before the fallback is removed:

  • PID detection: only available in the new path, as it is implemented in the Rust library. The previous path always returns an empty GPUPIDs list.
  • Language detection and privilegedDetector: the privilegedDetector field in the shared discovery struct is only initialized and used in the previous path. It will be removed once libdd_discovery covers full feature parity with the Go implementation.

@martavicentenavarro martavicentenavarro added changelog/no-changelog No changelog entry needed qa/done QA done before merge and regressions are covered by tests team/agent-discovery labels Feb 24, 2026
@dd-octo-sts dd-octo-sts bot added the internal Identify a non-fork PR label Feb 24, 2026
@github-actions github-actions bot added the long review PR is complex, plan time to review it label Feb 24, 2026
@martavicentenavarro martavicentenavarro self-assigned this Feb 26, 2026
@martavicentenavarro martavicentenavarro force-pushed the marta/load_library branch 2 times, most recently from bbcce02 to b587da9 Compare February 27, 2026 14:08
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Mar 2, 2026

Files inventory check summary

File checks results against ancestor d4c34bbf:

Results for datadog-agent_7.78.0~devel.git.681.0ca2870.pipeline.103318857-1_amd64.deb:

No change detected

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Mar 2, 2026

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor d4c34bb
📊 Static Quality Gates Dashboard
🔗 SQG Job

Successful checks

Info

Quality gate Change Size (prev → curr → max)
agent_deb_amd64 +811.38 KiB (0.11% increase) 748.899 → 749.692 → 750.720
agent_deb_amd64_fips +807.41 KiB (0.11% increase) 707.261 → 708.049 → 711.230
agent_rpm_amd64 +811.38 KiB (0.11% increase) 748.883 → 749.675 → 750.690
agent_rpm_amd64_fips +807.41 KiB (0.11% increase) 707.244 → 708.033 → 711.210
agent_rpm_arm64 +687.12 KiB (0.09% increase) 727.394 → 728.065 → 732.890
agent_rpm_arm64_fips +683.16 KiB (0.10% increase) 688.706 → 689.373 → 694.440
agent_suse_amd64 +811.38 KiB (0.11% increase) 748.883 → 749.675 → 750.690
agent_suse_amd64_fips +807.41 KiB (0.11% increase) 707.244 → 708.033 → 711.210
agent_suse_arm64 +687.12 KiB (0.09% increase) 727.394 → 728.065 → 732.890
agent_suse_arm64_fips +683.16 KiB (0.10% increase) 688.706 → 689.373 → 694.440
docker_agent_amd64 +811.38 KiB (0.10% increase) 809.230 → 810.022 → 813.040
docker_agent_arm64 +687.13 KiB (0.08% increase) 812.543 → 813.214 → 819.570
docker_agent_jmx_amd64 +811.37 KiB (0.08% increase) 1000.145 → 1000.938 → 1003.920
docker_agent_jmx_arm64 +687.12 KiB (0.07% increase) 992.237 → 992.908 → 999.170
16 successful checks with minimal change (< 2 KiB)
Quality gate Current Size
agent_heroku_amd64 312.820 MiB
docker_cluster_agent_amd64 203.680 MiB
docker_cluster_agent_arm64 218.167 MiB
docker_cws_instrumentation_amd64 7.142 MiB
docker_cws_instrumentation_arm64 6.689 MiB
docker_dogstatsd_amd64 39.199 MiB
docker_dogstatsd_arm64 37.445 MiB
dogstatsd_deb_amd64 29.843 MiB
dogstatsd_deb_arm64 27.995 MiB
dogstatsd_rpm_amd64 29.843 MiB
dogstatsd_suse_amd64 29.843 MiB
iot_agent_deb_amd64 43.065 MiB
iot_agent_deb_arm64 40.124 MiB
iot_agent_deb_armhf 40.860 MiB
iot_agent_rpm_amd64 43.066 MiB
iot_agent_suse_amd64 43.066 MiB
On-wire sizes (compressed)
Quality gate Change Size (prev → curr → max)
agent_deb_amd64 +223.9 KiB (0.13% increase) 174.215 → 174.434 → 177.700
agent_deb_amd64_fips +345.24 KiB (0.20% increase) 165.162 → 165.499 → 172.230
agent_heroku_amd64 -3.74 KiB (0.00% reduction) 74.902 → 74.898 → 79.970
agent_rpm_amd64 +408.05 KiB (0.23% increase) 177.100 → 177.498 → 180.780
agent_rpm_amd64_fips +479.18 KiB (0.28% increase) 167.168 → 167.636 → 173.370
agent_rpm_arm64 +169.38 KiB (0.10% increase) 159.669 → 159.834 → 161.610
agent_rpm_arm64_fips +307.36 KiB (0.20% increase) 151.255 → 151.555 → 155.910
agent_suse_amd64 +408.05 KiB (0.23% increase) 177.100 → 177.498 → 180.780
agent_suse_amd64_fips +479.18 KiB (0.28% increase) 167.168 → 167.636 → 173.370
agent_suse_arm64 +169.38 KiB (0.10% increase) 159.669 → 159.834 → 161.610
agent_suse_arm64_fips +307.36 KiB (0.20% increase) 151.255 → 151.555 → 155.910
docker_agent_amd64 +430.15 KiB (0.16% increase) 267.193 → 267.613 → 271.240
docker_agent_arm64 +437.13 KiB (0.17% increase) 254.485 → 254.912 → 259.800
docker_agent_jmx_amd64 +430.59 KiB (0.13% increase) 335.840 → 336.261 → 339.870
docker_agent_jmx_arm64 +438.96 KiB (0.13% increase) 319.124 → 319.553 → 324.390
docker_cluster_agent_amd64 neutral 71.289 MiB → 72.920
docker_cluster_agent_arm64 neutral 66.927 MiB → 68.220
docker_cws_instrumentation_amd64 neutral 2.999 MiB → 3.330
docker_cws_instrumentation_arm64 neutral 2.729 MiB → 3.090
docker_dogstatsd_amd64 neutral 15.151 MiB → 15.820
docker_dogstatsd_arm64 neutral 14.479 MiB → 14.830
dogstatsd_deb_amd64 neutral 7.884 MiB → 8.790
dogstatsd_deb_arm64 neutral 6.770 MiB → 7.710
dogstatsd_rpm_amd64 neutral 7.894 MiB → 8.800
dogstatsd_suse_amd64 neutral 7.894 MiB → 8.800
iot_agent_deb_amd64 neutral 11.349 MiB → 12.040
iot_agent_deb_arm64 neutral 9.665 MiB → 10.450
iot_agent_deb_armhf neutral 9.894 MiB → 10.620
iot_agent_rpm_amd64 neutral 11.368 MiB → 12.060
iot_agent_suse_amd64 neutral 11.368 MiB → 12.060

@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Mar 2, 2026

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 239a826a-c94f-4ea3-8127-d94b2f36ce23

Baseline: d98e355
Comparison: ed91e0a
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization -0.41 [-3.47, +2.64] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
tcp_syslog_to_blackhole ingress throughput +0.99 [+0.86, +1.13] 1 Logs
quality_gate_metrics_logs memory utilization +0.95 [+0.72, +1.19] 1 Logs bounds checks dashboard
file_tree memory utilization +0.64 [+0.59, +0.69] 1 Logs
docker_containers_memory memory utilization +0.58 [+0.51, +0.66] 1 Logs
quality_gate_idle_all_features memory utilization +0.58 [+0.54, +0.61] 1 Logs bounds checks dashboard
quality_gate_idle memory utilization +0.16 [+0.11, +0.21] 1 Logs bounds checks dashboard
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization +0.09 [+0.03, +0.15] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.01 [-0.19, +0.21] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.00 [-0.08, +0.08] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.11, +0.11] 1 Logs
uds_dogstatsd_to_api_v3 ingress throughput -0.01 [-0.21, +0.19] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.01 [-0.49, +0.47] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.01 [-0.44, +0.42] 1 Logs
ddot_metrics_sum_cumulative memory utilization -0.02 [-0.16, +0.12] 1 Logs
ddot_logs memory utilization -0.08 [-0.13, -0.02] 1 Logs
file_to_blackhole_500ms_latency egress throughput -0.11 [-0.51, +0.29] 1 Logs
ddot_metrics_sum_delta memory utilization -0.12 [-0.29, +0.04] 1 Logs
ddot_metrics_sum_cumulativetodelta_exporter memory utilization -0.17 [-0.39, +0.06] 1 Logs
otlp_ingest_metrics memory utilization -0.19 [-0.35, -0.04] 1 Logs
otlp_ingest_logs memory utilization -0.29 [-0.39, -0.20] 1 Logs
docker_containers_cpu % cpu utilization -0.41 [-3.47, +2.64] 1 Logs
ddot_metrics memory utilization -0.51 [-0.69, -0.32] 1 Logs
quality_gate_logs % cpu utilization -1.37 [-2.96, +0.21] 1 Logs bounds checks dashboard

Bounds Checks: ❌ Failed

perf experiment bounds_check_name replicates_passed observed_value links
docker_containers_cpu simple_check_run 10/10 722 ≥ 26
docker_containers_memory memory_usage 10/10 276.94MiB ≤ 370MiB
docker_containers_memory simple_check_run 10/10 721 ≥ 26
file_to_blackhole_0ms_latency memory_usage 10/10 0.19GiB ≤ 1.20GiB
file_to_blackhole_0ms_latency missed_bytes 10/10 0B = 0B
file_to_blackhole_1000ms_latency memory_usage 10/10 0.23GiB ≤ 1.20GiB
file_to_blackhole_1000ms_latency missed_bytes 10/10 0B = 0B
file_to_blackhole_100ms_latency memory_usage 10/10 0.19GiB ≤ 1.20GiB
file_to_blackhole_100ms_latency missed_bytes 10/10 0B = 0B
file_to_blackhole_500ms_latency memory_usage 10/10 0.21GiB ≤ 1.20GiB
file_to_blackhole_500ms_latency missed_bytes 10/10 0B = 0B
quality_gate_idle intake_connections 10/10 3 = 3 bounds checks dashboard
quality_gate_idle memory_usage 9/10 175.13MiB > 175MiB bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 2 ≤ 3 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 490.46MiB ≤ 550MiB bounds checks dashboard
quality_gate_logs intake_connections 10/10 4 ≤ 6 bounds checks dashboard
quality_gate_logs memory_usage 10/10 201.63MiB ≤ 220MiB bounds checks dashboard
quality_gate_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 340.11 ≤ 2000 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 4 ≤ 6 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 408.38MiB ≤ 475MiB bounds checks dashboard
quality_gate_metrics_logs missed_bytes 10/10 0B = 0B bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Failed. Some Quality Gates were violated.

  • quality_gate_idle, bounds check memory_usage: 9/10 replicas passed. Failed 1 which is > 0. Gate FAILED.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.

@martavicentenavarro martavicentenavarro force-pushed the marta/load_library branch 4 times, most recently from 8934a6f to aa30b5f Compare March 5, 2026 12:26
@martavicentenavarro
Copy link
Contributor Author

@codex review

Copy link

@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: aa30b5f346

ℹ️ 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 on lines +843 to +845
if not is_windows and not is_macos:
build_rust_cgo_libs(ctx, arch=arch_obj)
build_tags.append("dd_discovery_cgo")

Choose a reason for hiding this comment

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

P2 Badge Skip CGO discovery tag for static system-probe builds

build_sysprobe_binary now always enables dd_discovery_cgo on Linux, which forces linking against libdd_discovery even when --static is requested. In the static path, get_build_flags adds -extldflags=-static (tasks/libs/common/utils.py), so the linker expects static archives, but this change wires in a shared-library workflow (libdd_discovery.so), causing static system-probe builds to fail. This regresses users/CI paths that rely on dda inv system-probe.build-sysprobe-binary --static.

Useful? React with 👍 / 👎.

@martavicentenavarro martavicentenavarro force-pushed the marta/load_library branch 2 times, most recently from bce5f79 to 57c6b45 Compare March 10, 2026 09:45
@martavicentenavarro martavicentenavarro force-pushed the marta/load_library branch 2 times, most recently from b8cc610 to a922591 Compare March 11, 2026 16:09
"zstd",
"cel",
"cws_instrumentation_injector_only", # used for building cws-instrumentation with only the injector code
"dd_discovery_rust", # used to enable the Rust-backed libdd_discovery implementation in system-probe
Copy link
Member

Choose a reason for hiding this comment

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

Nit: appart from the two last entries, that set seems sorted. I would try to keep it this way, it makes it easier to see which build tag is used when building as they are said in this set's order.

platform_flag = f"--platforms={platform_map[arch.kmt_arch]}"

for source_path in RUST_LIBS:
ctx.run(f"bazelisk run {platform_flag} -- @//{source_path}:install_libs --destdir={Path(source_path)}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ctx.run(f"bazelisk run {platform_flag} -- @//{source_path}:install_libs --destdir={Path(source_path)}")
ctx.run(f"bazelisk run --config=release {platform_flag} -- @//{source_path}:install_libs --destdir={Path(source_path)}")

platform_flag = f"--platforms={platform_map[arch.kmt_arch]}"

for source_path in RUST_LIBS:
ctx.run(f"bazelisk run {platform_flag} -- @//{source_path}:install_libs --destdir={Path(source_path)}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ctx.run(f"bazelisk run {platform_flag} -- @//{source_path}:install_libs --destdir={Path(source_path)}")
ctx.run(f"bazelisk run --config=release {platform_flag} -- @//{source_path}:install_libs --destdir={Path(source_path)}")

@martavicentenavarro martavicentenavarro force-pushed the marta/load_library branch 3 times, most recently from e9eae15 to ed91e0a Compare March 18, 2026 10:00
Improves

discovery: use dd_discovery_cgo build tag instead of built-in cgo

fix omnibus build for CGo library integration

Implement some improvements
- Rename build tag dd_discovery_cgo -> dd_discovery_rust
- Link against static library (add -lpthread -ldl -lm linker flags)
- Remove libdd_discovery.so copy step from omnibus (no longer needed)
- Add --config=release to bazelisk build command
- Fix test build tags to avoid duplicate definitions with !dd_discovery_rust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed component/system-probe internal Identify a non-fork PR long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/agent-build team/agent-devx team/agent-discovery team/ebpf-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants