summaryrefslogtreecommitdiffstats
path: root/netdata-installer.sh
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2024-04-24 09:17:23 +0300
committerGitHub <noreply@github.com>2024-04-24 09:17:23 +0300
commitaa6d30384d26c6df33acd67dc8402ae9e3195297 (patch)
tree26cd1570fd2f6ed573970bf6d7bba9494a3ad92d /netdata-installer.sh
parent7a597929028192e37751c98ce18aea1c32a899b7 (diff)
Move libbpf and eBPF CO-RE bundling into CMake. (#17484)
* Move libbpf and eBPF CO-RE bundling into CMake. * Silence CMP0135 warnings. * Fix handling of legacy eBPF code. * Only enable eBPF by default on Linux. * Correctly auto-detect the need for legacy libbpf. * Fix include paths for libbpf linking. * Add coreutils dependency on Alpine. * Fix ebpf code handling. * Fix lib path handling for libbpf.a. * Correctly fix libbpf lib directory handling. * Use correct comparison type.
Diffstat (limited to 'netdata-installer.sh')
-rwxr-xr-xnetdata-installer.sh248
1 files changed, 39 insertions, 209 deletions
diff --git a/netdata-installer.sh b/netdata-installer.sh
index 82acb524de..717012533d 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -245,13 +245,16 @@ USAGE: ${PROGRAM} [options]
HEREDOC
}
+if [ "$(uname -s)" = "Linux" ]; then
+ ENABLE_EBPF=1
+fi
+
DONOTSTART=0
DONOTWAIT=0
NETDATA_PREFIX=
LIBS_ARE_HERE=0
NETDATA_ENABLE_ML=""
ENABLE_DBENGINE=1
-ENABLE_EBPF=1
ENABLE_GO=1
ENABLE_H2O=1
ENABLE_CLOUD=1
@@ -323,14 +326,8 @@ while [ -n "${1}" ]; do
# XXX: No longer supported.
;;
"--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
- "--enable-ebpf")
- ENABLE_EBPF=1
- NETDATA_DISABLE_EBPF=0
- ;;
- "--disable-ebpf")
- ENABLE_EBPF=0
- NETDATA_DISABLE_EBPF=1
- ;;
+ "--enable-ebpf") ENABLE_EBPF=1 ;;
+ "--disable-ebpf") ENABLE_EBPF=0 ;;
"--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
"--one-time-build")
# XXX: No longer supported
@@ -557,199 +554,6 @@ fi
trap build_error EXIT
# -----------------------------------------------------------------------------
-
-get_kernel_version() {
- r="$(uname -r | cut -f 1 -d '-')"
-
- tmpfile="$(mktemp)"
- echo "${r}" | tr '.' ' ' > "${tmpfile}"
-
- read -r maj min patch _ < "${tmpfile}"
-
- rm -f "${tmpfile}"
-
- printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
-}
-
-detect_libc() {
- libc=
- if ldd --version 2>&1 | grep -q -i glibc; then
- echo >&2 " Detected GLIBC"
- libc="glibc"
- elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
- echo >&2 " Detected GLIBC"
- libc="glibc"
- elif ldd --version 2>&1 | grep -q -i musl; then
- echo >&2 " Detected musl"
- libc="musl"
- else
- cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
- if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
- echo >&2 " Detected GLIBC"
- libc="glibc"
- fi
- fi
-
- if [ -z "$libc" ]; then
- warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
- return 1
- fi
-
- echo "${libc}"
- return 0
-}
-
-build_libbpf() {
- cd "${1}/src" > /dev/null || return 1
- mkdir root build
- # shellcheck disable=SC2086
- run env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
- cd - > /dev/null || return 1
-}
-
-copy_libbpf() {
- target_dir="${PWD}/externaldeps/libbpf"
-
- if [ "$(uname -m)" = x86_64 ]; then
- lib_subdir="lib64"
- else
- lib_subdir="lib"
- fi
-
- run mkdir -p "${target_dir}" || return 1
-
- run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
- run cp -r "${1}/usr/include" "${target_dir}" || return 1
- run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
-}
-
-bundle_libbpf() {
- if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
- ENABLE_EBPF=0
- NETDATA_DISABLE_EBPF=1
- return 0
- fi
-
- if [ -z "${make}" ]; then
- warning "No usable copy of Make found, which is required to bundle libbpf. Disabling eBPF support."
- ENABLE_EBPF=0
- NETDATA_DISABLE_EBPF=1
- return 0
- fi
-
- # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
- libc="${EBPF_LIBC:-"$(detect_libc)"}"
- if [ -z "$libc" ]; then
- NETDATA_DISABLE_EBPF=1
- ENABLE_EBPF=0
- return 0
- fi
-
- [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
-
- progress "Prepare libbpf"
-
- if [ "$(get_kernel_version)" -ge "004014000" ]; then
- LIBBPF_PACKAGE_VERSION="$(cat packaging/current_libbpf.version)"
- LIBBPF_PACKAGE_COMPONENT="current_libbpf"
- else
- LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf_0_0_9.version)"
- LIBBPF_PACKAGE_COMPONENT="libbpf_0_0_9"
- fi
-
- tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
- LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
-
- if fetch_and_verify "${LIBBPF_PACKAGE_COMPONENT}" \
- "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
- "${LIBBPF_PACKAGE_BASENAME}" \
- "${tmp}" \
- "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
- if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
- build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
- copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
- rm -rf "${tmp}"; then
- run_ok "libbpf built and prepared."
- ENABLE_EBPF=1
- else
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
- fatal "failed to build libbpf." I0005
- else
- run_failed "Failed to build libbpf. eBPF support will be disabled"
- ENABLE_EBPF=0
- NETDATA_DISABLE_EBPF=1
- fi
- fi
- else
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
- fatal "Failed to fetch sources for libbpf." I0006
- else
- run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
- ENABLE_EBPF=0
- NETDATA_DISABLE_EBPF=1
- fi
- fi
-
- [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
-}
-
-bundle_libbpf
-
-copy_co_re() {
- cp -R "${1}/includes" "src/libnetdata/ebpf/"
-}
-
-bundle_ebpf_co_re() {
- if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
- return 0
- fi
-
- [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
-
- progress "eBPF CO-RE"
-
- CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
-
- tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
- CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
-
- if fetch_and_verify "ebpf-co-re" \
- "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
- "${CORE_PACKAGE_BASENAME}" \
- "${tmp}" \
- "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
- if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
- copy_co_re "${tmp}" &&
- rm -rf "${tmp}"; then
- run_ok "libbpf built and prepared."
- ENABLE_EBPF=1
- else
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
- fatal "Failed to get eBPF CO-RE files." I0007
- else
- run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
- NETDATA_DISABLE_EBPF=1
- ENABLE_EBPF=0
- enable_feature PLUGIN_EBPF 0
- fi
- fi
- else
- if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
- fatal "Failed to fetch eBPF CO-RE files." I0008
- else
- run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
- NETDATA_DISABLE_EBPF=1
- ENABLE_EBPF=0
- enable_feature PLUGIN_EBPF 0
- fi
- fi
-
- [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
-}
-
-bundle_ebpf_co_re
-
-# -----------------------------------------------------------------------------
build_fluentbit() {
env_cmd="env CFLAGS='-w' CXXFLAGS='-w' LDFLAGS="
@@ -1249,15 +1053,41 @@ fi
[ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
+detect_libc() {
+ libc=
+ if ldd --version 2>&1 | grep -q -i glibc; then
+ echo >&2 " Detected GLIBC"
+ libc="glibc"
+ elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
+ echo >&2 " Detected GLIBC"
+ libc="glibc"
+ elif ldd --version 2>&1 | grep -q -i musl; then
+ echo >&2 " Detected musl"
+ libc="musl"
+ else
+ cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
+ if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
+ echo >&2 " Detected GLIBC"
+ libc="glibc"
+ fi
+ fi
+
+ if [ -z "$libc" ]; then
+ warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
+ return 1
+ fi
+
+ echo "${libc}"
+}
+
should_install_ebpf() {
- if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
- run_failed "eBPF has been explicitly disabled, it will not be available in this install."
+ if [ "${ENABLE_EBPF:-0}" -eq 0 ]; then
return 1
fi
- if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
- if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
- run_failed "Currently eBPF is only supported on Linux on X86_64."
+ if [ "$(uname -m)" != "x86_64" ]; then
+ if [ "${ENABLE_EBPF:-0}" -eq 1 ]; then
+ run_failed "Currently eBPF is only supported on Linux on x86_64."
fi
return 1
@@ -1328,10 +1158,10 @@ install_ebpf() {
remove_old_ebpf
- progress "Installing eBPF plugin"
+ progress "Installing eBPF programs"
# Detect libc
- libc="${EBPF_LIBC:-"$(detect_libc)"}"
+ libc="$(detect_libc)"
EBPF_VERSION="$(cat packaging/ebpf.version)"
EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"