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

Add option to build on non-glibc env #32943

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/system-probe/modules/all_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build linux && !arm64
Copy link
Member

Choose a reason for hiding this comment

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

Go build tags are usually positive assertions, so let's use a glibc build tag instead and add it to the list of default build tags.

//go:build linux && !arm64 && !nonglibc

// Package modules is all the module definitions for system-probe
package modules
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/modules/all_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build linux && arm64
//go:build linux && arm64 && !nonglibc

// Package modules is all the module definitions for system-probe
package modules
Expand Down
37 changes: 37 additions & 0 deletions cmd/system-probe/modules/all_nonglibc_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build linux && !arm64 && nonglibc

// Package modules is all the module definitions for system-probe
package modules

import (
"time"

"github.com/DataDog/datadog-agent/cmd/system-probe/api/module"
)

// All System Probe modules should register their factories here
var All = []module.Factory{
EBPFProbe,
NetworkTracer,
TCPQueueLength,
OOMKillProbe,
// there is a dependency from EventMonitor -> NetworkTracer
// so EventMonitor has to follow NetworkTracer
EventMonitor,
Process,
DynamicInstrumentation,
LanguageDetectionModule,
ComplianceModule,
Pinger,
Traceroute,
DiscoveryModule,
}

func inactivityEventLog(_ time.Duration) {

}
38 changes: 38 additions & 0 deletions cmd/system-probe/modules/all_nonglibc_linux_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build linux && arm64 && nonglibc

// Package modules is all the module definitions for system-probe
package modules

import (
"time"

"github.com/DataDog/datadog-agent/cmd/system-probe/api/module"
)

// All System Probe modules should register their factories here
var All = []module.Factory{
EBPFProbe,
NetworkTracer,
TCPQueueLength,
OOMKillProbe,
// there is a dependency from EventMonitor -> NetworkTracer
// so EventMonitor has to follow NetworkTracer
EventMonitor,
Process,
DynamicInstrumentation,
LanguageDetectionModule,
ComplianceModule,
Pinger,
Traceroute,
DiscoveryModule,
GPUMonitoring, // GPU monitoring needs to be initialized afer EventMonitor, so that we have the event consumer ready
}

func inactivityEventLog(_ time.Duration) {

}
2 changes: 1 addition & 1 deletion cmd/system-probe/modules/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build linux
//go:build linux && !nonglibc

package modules

Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/gpu/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build linux
//go:build linux && !nonglibc

package gpu

Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/corechecks/gpu/gpu_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build !linux
//go:build !linux || nonglibc

package gpu

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
enhancements:
- |
Add an build option (`--non-glibc`) to build the agent on non-glibc environment like musl libc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Add an build option (`--non-glibc`) to build the agent on non-glibc environment like musl libc.
Add an build option (`--non-glibc`) to build the Agent on `non-glibc` environment like musl libc.

The option disables system-probe gpu module and corechecks gpu collector using
`github.com/NVIDIA/go-nvml` which depends on a glibc-extended definition.
4 changes: 4 additions & 0 deletions tasks/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def build(
bundle_ebpf=False,
agent_bin=None,
run_on=None, # noqa: U100, F841. Used by the run_on_devcontainer decorator
non_glibc=False,
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer a glibc=True argument for the invoke task and have --no-glibc be the command line option that gets you a non-glibc build.

Copy link
Contributor Author

@at-wat at-wat Jan 15, 2025

Choose a reason for hiding this comment

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

If someone may build the agent by go build directly without using invoke, gpu module/collector aren't enabled by default.
Is it ok?

):
"""
Build the agent. If the bits to include in the build are not specified,
Expand Down Expand Up @@ -219,6 +220,9 @@ def build(
all_tags |= set(build_tags)
build_tags = list(all_tags)

if non_glibc:
build_tags.append("nonglibc")

cmd = "go build -mod={go_mod} {race_opt} {build_type} -tags \"{go_build_tags}\" "

if not agent_bin:
Expand Down
7 changes: 7 additions & 0 deletions tasks/system_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,12 @@ def build(
ebpf_compiler='clang',
static=False,
fips_mode=False,
non_glibc=False,
):
"""
Build the system-probe
"""
raise NameError('test')
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this.

if not is_macos:
build_object_files(
ctx,
Expand All @@ -716,6 +718,7 @@ def build(
arch=arch,
static=static,
fips_mode=fips_mode,
non_glibc=non_glibc,
)


Expand Down Expand Up @@ -743,6 +746,7 @@ def build_sysprobe_binary(
strip_binary=False,
fips_mode=False,
static=False,
non_glibc=False,
) -> None:
arch_obj = Arch.from_str(arch)

Expand All @@ -765,6 +769,9 @@ def build_sysprobe_binary(
build_tags.extend(["osusergo", "netgo"])
build_tags = list(set(build_tags).difference({"netcgo"}))

if non_glibc:
build_tags.append("nonglibc")

if not is_windows and "pcap" in build_tags:
build_libpcap(ctx)
cgo_flags = get_libpcap_cgo_flags(ctx, install_path)
Expand Down
Loading