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

Kernel 6 build #5

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
pull_request:

env:
BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:buil-env-buildx

BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:build-env-k6
concurrency:
group: build-and-test-${{ github.event.pull_request_number || github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -117,6 +116,7 @@ jobs:
./build.sh k8s-relay

build-cloud-collector:
if: false
name: build-cloud-collector
runs-on: ubuntu-20.04
needs: [clang-format-check]
Expand Down
1 change: 1 addition & 0 deletions channel/tcp_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <channel/callbacks.h>
#include <channel/network_channel.h>
#include <platform/platform.h>
#include <memory>

#include <uv.h>

Expand Down
36 changes: 34 additions & 2 deletions cmake/aws-sdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,46 @@

include_guard()

find_package(OpenSSL REQUIRED)
message(STATUS "OpenSSL Include Dir: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL Libraries: ${OPENSSL_LIBRARIES}")
# Include OpenSSL 1.1.1n headers first
include_directories(BEFORE /root/install/openssl/include)
# Add OpenSSL installation directory to CMAKE_PREFIX_PATH
set(CMAKE_PREFIX_PATH "/root/install/openssl" ${CMAKE_PREFIX_PATH})


# Print for verification
message(STATUS "OpenSSL Include Directory: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")



find_package(AWSSDK REQUIRED)
set(AWS_SERVICES ec2 s3 core)
AWSSDK_DETERMINE_LIBS_TO_LINK(AWS_SERVICES AWSSDK_LIBS)

message(STATUS "aws-sdk include Libraries: ${AWSSDK_INCLUDE_DIR}")
list(APPEND AWSSDK_LIBS ${OPENSSL_LIBRARIES})
message(STATUS "aws-sdk Libraries: ${AWSSDK_LIBS}")
message(STATUS "cmake prefix Directory: ${CMAKE_PREFIX_PATH}")
message(STATUS "All Include Directories: ${CMAKE_INCLUDE_PATH}")
get_property(dirs DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "Include dir='${dir}'")
endforeach()



# list(APPEND AWSSDK_LIBS ${HOME}/openssl/lib/libssl.a ${HOME}/openssl/lib/libcrypto.a)
# message(STATUS "aws-sdk Libraries: ${AWSSDK_LIBS}")


# Unfortunately AWSSDK_DETERMINE_LIBS_TO_LINK will list SSL and Crypto libraries
# simply as "ssl" and "crypto", not using the full path with which the AWS SDK
# was configured inside the build-env.
list(TRANSFORM AWSSDK_LIBS REPLACE "^ssl$" OpenSSL::SSL)
list(TRANSFORM AWSSDK_LIBS REPLACE "^crypto$" OpenSSL::Crypto)
# list(TRANSFORM AWSSDK_LIBS REPLACE "^ssl$" OpenSSL::SSL)
# list(TRANSFORM AWSSDK_LIBS REPLACE "^crypto$" OpenSSL::Crypto)

add_library(aws-sdk-cpp INTERFACE)
target_link_libraries(
Expand All @@ -26,4 +57,5 @@ target_include_directories(
aws-sdk-cpp
INTERFACE
${AWSSDK_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
)
108 changes: 9 additions & 99 deletions cmake/bcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,104 +3,14 @@

include_guard()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/ext/bcc/cmake)
# Find the system-installed BCC package
find_package(PkgConfig REQUIRED)
pkg_check_modules(BCC REQUIRED libbcc)

# required libs, See bcc/cmake/clang_libs.cmake
set(
BCC_CLANG_LIBS
clangFrontend
clangSerialization
clangDriver
clangASTMatchers
clangParse
clangSema
clangCodeGen
clangAnalysis
clangRewrite
clangEdit
clangAST
clangLex
clangBasic
)
# Add BCC include directories and libraries
set(BCC_INCLUDE_DIRS ${BCC_INCLUDE_DIRS})
set(BCC_LIBS ${BCC_LIBRARIES})

# find the required clang libraries
foreach( LIB ${BCC_CLANG_LIBS} )
find_library(lib${LIB} NAMES ${LIB} HINTS ${LLVM_LIBRARY_DIRS})
if(lib${LIB} STREQUAL "lib${LIB}-NOTFOUND")
message(FATAL_ERROR "Unable to find clang library ${LIB}. Build container should already have that set up")
endif()
endforeach()

find_path(BCC_INCLUDE_DIRS bcc/libbpf.h)

# BCC libs, see the line that starts with "target_link_libraries(bcc-static"
# in bcc/src/cc/MakeLists.txt
find_library(BCC_LIBS NAMES "libbcc-combined.a")
if(${BCC_LIBS} STREQUAL "BCC_LIBS-NOTFOUND")
set(BCC_LIBS "")
foreach(LIB bcc bcc_bpf bcc-loader-static)
find_library(BCC_LIB_${LIB} NAMES "lib${LIB}.a")
if(${BCC_LIB_${LIB}} STREQUAL "BCC_LIB_${LIB}-NOTFOUND")
message(FATAL_ERROR "Unable to find BCC library ${LIB}. Build container should already have that set up")
endif()
list(APPEND BCC_LIBS ${BCC_LIB_${LIB}})
endforeach()
endif()

set(CMAKE_REQUIRED_INCLUDES ${BCC_INCLUDE_DIRS})
include(CheckIncludeFile)
check_include_file("bcc/bcc_syms.h" FOUND_BCC_SYMS_H)
if ( NOT FOUND_BCC_SYMS_H )
message ( FATAL_ERROR "Could not find bcc_syms.h while searching for bcc. Build container should already have that set up" )
endif ( NOT FOUND_BCC_SYMS_H )

FOREACH(LIB ${BCC_LIBS})
if ( NOT EXISTS ${LIB} )
message ( FATAL_ERROR "Could not find ${LIB}. Build container should already have that set up" )
endif ( NOT EXISTS ${LIB} )
ENDFOREACH()

message(STATUS "bcc libraries: ${BCC_LIBS}")
message(STATUS "bcc include dirs: ${BCC_INCLUDE_DIRS}")

add_library(bcc-static INTERFACE)
add_library(bcc-interface INTERFACE)
target_include_directories(
bcc-interface
INTERFACE
${BCC_INCLUDE_DIRS}
${LLVM_INCLUDE_DIRS}
)

# BCC LLVM libs, see bcc/src/cc/CMakeLists.txt
set(
BCC_LLVM_LIBNAMES
bitwriter
bpfcodegen
debuginfodwarf
irreader
linker
mcjit
objcarcopts
option
passes
lto
nativecodegen
coverage
coroutines
bpfasmparser
bpfdisassembler
)
llvm_map_components_to_libnames(BCC_LLVM_LIBS ${BCC_LLVM_LIBNAMES})
llvm_expand_dependencies(BCC_LLVM_LIBS_EXPANDED ${BCC_LLVM_LIBS})

target_compile_definitions(bcc-interface INTERFACE ${LLVM_DEFINITIONS})
target_link_libraries(bcc-static INTERFACE bcc-interface
${BCC_LIBS}
${BCC_CLANG_LIBS}
${BCC_LLVM_LIBS_EXPANDED}
libelf.a)

# LLVM is built with -ffunctions-sections -fdata-sections so we can remove unused functions
#target_compile_options(bcc-interface INTERFACE -ffunction-sections -fdata-sections)
#target_link_libraries(bcc-static INTERFACE -Wl,--gc-sections)
# Output found paths for debugging
message(STATUS "Found BCC include dirs: ${BCC_INCLUDE_DIRS}")
message(STATUS "Found BCC libraries: ${BCC_LIBS}")
2 changes: 1 addition & 1 deletion collector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ add_custom_target(collectors)
add_custom_target(collectors-docker)
add_custom_target(collectors-docker-registry)

add_subdirectory(cloud)
# add_subdirectory(cloud)
add_subdirectory(k8s)
add_subdirectory(kernel)
2 changes: 1 addition & 1 deletion collector/cloud/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM bitnami/minideb:bullseye
FROM bitnami/minideb:bookworm

LABEL org.label-schema.name="opentelemetry-ebpf-cloud-collector"
LABEL org.label-schema.description="OpenTelemetry eBPF cloud metadata collector"
Expand Down
2 changes: 1 addition & 1 deletion collector/cloud/enumerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void translate_interfaces_to_spans(
auto const &description = interface.GetDescription();

auto const add_entry = [&](IPv6Address const &ipv6) {
auto handle = index.aws_network_interface.by_key({.ip = ipv6.as_int()});
auto handle = index.aws_network_interface.by_key(ebpf_net::cloud_collector::keys::aws_network_interface{ipv6.as_int()});

LOG::trace(
"network_interface_info:"
Expand Down
2 changes: 1 addition & 1 deletion collector/k8s/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM bitnami/minideb:bullseye
FROM bitnami/minideb:bookworm

LABEL org.label-schema.name="opentelemetry-ebpf-k8s-relay"
LABEL org.label-schema.description="OpenTelemetry eBPF Kubernetes metadata collector relay service"
Expand Down
2 changes: 1 addition & 1 deletion collector/k8s/k8s-watcher/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM bitnami/minideb:bullseye
FROM bitnami/minideb:bookworm

LABEL org.label-schema.name="opentelemetry-ebpf-k8s-watcher"
LABEL org.label-schema.description="OpenTelemetry eBPF Kubernetes metadata collector watcher"
Expand Down
69 changes: 69 additions & 0 deletions collector/k8s/kubernetes_rpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <unordered_set>
#include <vector>

#include <spdlog/fmt/fmt.h>
#include <spdlog/formatter.h>

#include "channel/buffered_writer.h"
#include "generated/ebpf_net/ingest/writer.h"
#include "generated/kubernetes_info.pb.h"
Expand All @@ -22,6 +25,72 @@
#include "util/lookup3_hasher.h"
#include <util/protobuf_log.h>

// A libfmt formatter for ReplicaSetInfo, used to print addresses in LOG::trace
// etc.
namespace fmt {
template <> struct formatter<collector::OwnerInfo> {
// Parsing (optional, since we don't need custom specifiers)
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }

// Formatting method
template <typename FormatContext>
auto format(const collector::OwnerInfo &owner, FormatContext &ctx) {
return format_to(ctx.out(), "OwnerInfo(uid: {}, name: {}, kind: {})",
owner.uid(), owner.name(), owner.kind());
}
};
template <> struct formatter<collector::ContainerInfo> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const collector::ContainerInfo &container, FormatContext &ctx) {
return format_to(ctx.out(), "ContainerInfo(id: {}, name: {}, image: {})",
container.id(), container.name(), container.image());
}
};
template <> struct formatter<collector::PodInfo> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const collector::PodInfo &pod, FormatContext &ctx) {
// Format the containers and container_infos into a string
std::string containers_str;
for (const auto& container : pod.container_infos()) {
containers_str += fmt::format("{}", container);
containers_str += ", ";
}

return format_to(ctx.out(),
"PodInfo(uid: {}, ip: {}, name: {}, owner: {}, ns: {}, version: {}, is_host_network: {}, containers: [{}])",
pod.uid(), pod.ip(), pod.name(), pod.owner(), pod.ns(),
pod.version(), pod.is_host_network(), containers_str);
}
};
template <> struct formatter<collector::ReplicaSetInfo> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const collector::ReplicaSetInfo &replica_set, FormatContext &ctx) {
return format_to(ctx.out(), "ReplicaSetInfo(uid: {}, owner: {})",
replica_set.uid(), replica_set.owner());
}
};
template <> struct formatter<collector::JobInfo> {
template <typename ParseContext>
constexpr auto parse(ParseContext &ctx) { return ctx.begin(); }

template <typename FormatContext>
auto format(const collector::JobInfo &job, FormatContext &ctx) {
return format_to(ctx.out(), "JobInfo(uid: {}, owner: {})",
job.uid(), job.owner());
}
};
} // namespace fmt

namespace collector {
using ::grpc::ServerContext;
using ::grpc::ServerReaderWriter;
Expand Down
9 changes: 4 additions & 5 deletions collector/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ target_link_libraries(
agentxxdlib
fastpass_util
file_ops
bcc-interface
bcc-static
${BCC_LIBS} # System-installed BCC libraries
config_file
libuv-static
args_parser
Expand Down Expand Up @@ -92,12 +91,12 @@ target_include_directories(
SYSTEM
BEFORE
PUBLIC
/root/install/include/bcc/compat/
${BCC_INCLUDE_DIRS} # Use system-installed BCC include directories
)
target_link_libraries(
agentlib
PUBLIC
bcc-interface
${BCC_LIBS} # System-installed BCC libraries
render_ebpf_net_agent_internal_hash
render_ebpf_net_ingest_writer
render_ebpf_net_kernel_collector
Expand Down Expand Up @@ -299,4 +298,4 @@ endif()
#
add_unit_test(cgroup_handler LIBS agentlib test_channel)
add_unit_test(kernel_symbols LIBS agentlib)
add_ebpf_unit_test(kernel_collector LIBS signal_handler agentlib agentxxdlib fastpass_util file_ops bcc-interface bcc-static config_file libuv-static system_ops static-executable test_channel)
add_ebpf_unit_test(kernel_collector LIBS signal_handler agentlib agentxxdlib fastpass_util file_ops ${BCC_LIBS} config_file libuv-static system_ops static-executable test_channel)
7 changes: 6 additions & 1 deletion collector/kernel/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM bitnami/minideb:bullseye
FROM bitnami/minideb:bookworm

LABEL org.label-schema.name="opentelemetry-ebpf-kernel-collector"
LABEL org.label-schema.description="OpenTelemetry eBPF kernel information collector"
Expand All @@ -21,6 +21,11 @@ ENTRYPOINT [ "/srv/entrypoint.sh" ]
# required by kernel_headers.sh script
RUN install_packages coreutils curl sed tar dnf rpm


RUN echo deb http://cloudfront.debian.net/debian sid main >> /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y bpfcc-tools libbpfcc libbpfcc-dev

ARG BUILD_TYPE
RUN if [ "$BUILD_TYPE" = "Debug" ]; then \
install_packages bc cgdb gawk gdb gzip iputils-ping jq netcat-openbsd procps ripgrep vim valgrind; \
Expand Down
Loading
Loading