Skip to content

Commit ed91e0a

Browse files
discovery: update CGO bindings for static libdd_discovery
- 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
1 parent d600647 commit ed91e0a

File tree

9 files changed

+26
-35
lines changed

9 files changed

+26
-35
lines changed

omnibus/config/software/datadog-agent.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@
188188
copy 'bin/system-probe/system-probe.exe', "#{install_dir}/bin/agent"
189189
else
190190
copy "bin/system-probe/system-probe", "#{install_dir}/embedded/bin"
191-
if linux_target?
192-
mkdir "#{install_dir}/embedded/lib"
193-
copy 'pkg/discovery/module/rust/libdd_discovery.so', "#{install_dir}/embedded/lib"
194-
end
195191
end
196192

197193
# Add SELinux policy for system-probe

pkg/discovery/module/impl_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2024-present Datadog, Inc.
55

6-
//go:build !dd_discovery_cgo
6+
//go:build !dd_discovery_rust
77

88
package module
99

pkg/discovery/module/impl_linux_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// This doesn't need BPF, but it's built with this tag to only run with
77
// system-probe tests.
8-
//go:build test && linux_bpf && !dd_discovery_cgo
8+
//go:build test && linux_bpf && !dd_discovery_rust
99

1010
package module
1111

@@ -309,7 +309,6 @@ func newDiscovery() *discovery {
309309
return mod.(*discovery)
310310
}
311311

312-
313312
// addSockets adds only listening sockets to a map to be used for later looksups.
314313
func addSockets[P procfs.NetTCP | procfs.NetUDP](sockMap map[uint64]socketInfo, sockets P,
315314
family network.ConnectionFamily, ctype network.ConnectionType, state uint64,
@@ -402,6 +401,21 @@ func BenchmarkGetNSInfoOld(b *testing.B) {
402401
}
403402
}
404403

404+
func createTracerMemfd(t *testing.T, data []byte) int {
405+
t.Helper()
406+
fd, err := unix.MemfdCreate("datadog-tracer-info-xxx", 0)
407+
require.NoError(t, err)
408+
t.Cleanup(func() { unix.Close(fd) })
409+
err = unix.Ftruncate(fd, int64(len(data)))
410+
require.NoError(t, err)
411+
mappedData, err := unix.Mmap(fd, 0, len(data), unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED)
412+
require.NoError(t, err)
413+
copy(mappedData, data)
414+
err = unix.Munmap(mappedData)
415+
require.NoError(t, err)
416+
return fd
417+
}
418+
405419
func TestValidInvalidTracerMetadata(t *testing.T) {
406420
discovery := newDiscovery()
407421
require.NotEmpty(t, discovery)

pkg/discovery/module/impl_services_cgo_linux.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// CGO-backed getServices implementation using the Rust libdd_discovery static library.
77

8-
//go:build dd_discovery_cgo
8+
//go:build dd_discovery_rust
99

1010
package module
1111

@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/DataDog/datadog-agent/pkg/discovery/core"
2424
"github.com/DataDog/datadog-agent/pkg/discovery/model"
25-
"github.com/DataDog/datadog-agent/pkg/discovery/servicetype"
2625
"github.com/DataDog/datadog-agent/pkg/discovery/tracermetadata"
2726
"github.com/DataDog/datadog-agent/pkg/system-probe/api/module"
2827
sysconfigtypes "github.com/DataDog/datadog-agent/pkg/system-probe/config/types"
@@ -111,9 +110,6 @@ func (s *discovery) convertNativeResult(result *C.struct_dd_discovery_result, hb
111110
if !isHeartbeat && s.shouldIgnoreComm(int32(svc.PID)) {
112111
continue
113112
}
114-
if !isHeartbeat {
115-
svc.Type = string(servicetype.Detect(svc.TCPPorts, svc.UDPPorts))
116-
}
117113
response.Services = append(response.Services, svc)
118114
}
119115
}

pkg/discovery/module/impl_services_cgo_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// This doesn't need BPF, but it's built with this tag to only run with
77
// system-probe tests.
8-
//go:build test && linux_bpf && dd_discovery_cgo
8+
//go:build test && linux_bpf && dd_discovery_rust
99

1010
package module
1111

pkg/discovery/module/impl_services_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// This doesn't need BPF, but it's built with this tag to only run with
77
// system-probe tests.
8-
//go:build test && linux_bpf && !dd_discovery_cgo
8+
//go:build test && linux_bpf && !dd_discovery_rust
99

1010
package module
1111

@@ -51,7 +51,6 @@ func getServices(t require.TestingT, discovery *testDiscoveryModule) *model.Serv
5151
return makeRequest[model.ServicesResponse](t, discovery.client, location, params)
5252
}
5353

54-
5554
// Check that we get (only) listening processes for all expected protocols using the services endpoint.
5655
func (s *discoveryTestSuite) TestServicesBasic() {
5756
t := s.T()

pkg/discovery/module/impl_test_helpers_linux_test.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// This doesn't need BPF, but it's built with this tag to only run with
77
// system-probe tests.
8-
//go:build test && linux_bpf && dd_discovery_cgo
8+
//go:build test && linux_bpf && dd_discovery_rust
99

1010
package module
1111

@@ -25,7 +25,6 @@ import (
2525
gorillamux "github.com/gorilla/mux"
2626
"github.com/shirou/gopsutil/v4/process"
2727
"github.com/stretchr/testify/require"
28-
"golang.org/x/sys/unix"
2928

3029
"github.com/DataDog/datadog-agent/pkg/discovery/core"
3130
"github.com/DataDog/datadog-agent/pkg/discovery/model"
@@ -224,18 +223,3 @@ func startProcessWithFile(t *testing.T, f *os.File) *exec.Cmd {
224223

225224
return cmd
226225
}
227-
228-
func createTracerMemfd(t *testing.T, data []byte) int {
229-
t.Helper()
230-
fd, err := unix.MemfdCreate("datadog-tracer-info-xxx", 0)
231-
require.NoError(t, err)
232-
t.Cleanup(func() { unix.Close(fd) })
233-
err = unix.Ftruncate(fd, int64(len(data)))
234-
require.NoError(t, err)
235-
mappedData, err := unix.Mmap(fd, 0, len(data), unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED)
236-
require.NoError(t, err)
237-
copy(mappedData, data)
238-
err = unix.Munmap(mappedData)
239-
require.NoError(t, err)
240-
return fd
241-
}

tasks/build_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"crio",
4242
# Opt out of the ASM build requirements of dd-trace-go
4343
"datadog.no_waf",
44+
"dd_discovery_rust", # used to enable the Rust-backed libdd_discovery implementation in system-probe
4445
"docker",
4546
"ec2",
4647
"etcd",
@@ -78,7 +79,6 @@
7879
"zstd",
7980
"cel",
8081
"cws_instrumentation_injector_only", # used for building cws-instrumentation with only the injector code
81-
"dd_discovery_cgo", # used to enable the CGO-backed libdd_discovery implementation in system-probe
8282
}.union(COMMON_TAGS)
8383

8484
### Tag inclusion lists

tasks/system_probe.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def build_sysprobe_binary(
842842

843843
if not is_windows and not is_macos and not static:
844844
build_rust_cgo_libs(ctx, arch=arch_obj)
845-
build_tags.append("dd_discovery_cgo")
845+
build_tags.append("dd_discovery_rust")
846846

847847
if os.path.exists(binary):
848848
os.remove(binary)
@@ -1660,7 +1660,9 @@ def build_rust_cgo_libs(ctx: Context, arch: Arch):
16601660
platform_flag = f"--platforms={platform_map[arch.kmt_arch]}"
16611661

16621662
for source_path in RUST_BINARIES:
1663-
ctx.run(f"bazelisk run {platform_flag} -- @//{source_path}:install_cgo_libs --destdir={Path(source_path)}")
1663+
ctx.run(
1664+
f"bazelisk run --config=release {platform_flag} -- @//{source_path}:install_cgo_libs --destdir={Path(source_path)}"
1665+
)
16641666

16651667

16661668
def build_cws_object_files(

0 commit comments

Comments
 (0)