From 424de9770f4191bd2cd0fa2034ca08257836cf76 Mon Sep 17 00:00:00 2001 From: jakub-racek-swi Date: Mon, 7 Oct 2024 09:28:59 +0000 Subject: [PATCH 01/13] Adding support for FMT 10 and LLVM 16 Signed-off-by: jakub-racek-swi --- channel/tcp_channel.h | 1 + cmake/aws-sdk.cmake | 36 +++++- cmake/bcc.cmake | 108 ++---------------- collector/cloud/enumerator.cc | 2 +- collector/k8s/kubernetes_rpc_server.cc | 69 +++++++++++ collector/kernel/CMakeLists.txt | 9 +- collector/kernel/bpf_src/render_bpf.c | 12 +- .../bpf_src/tcp-processor/bpf_tcp_send_recv.h | 8 ++ collector/kernel/main.cc | 1 + collector/kernel/process_handler.cc | 3 +- collector/kernel/troubleshooting.h | 1 + config/intake_config.cc | 12 +- config/intake_config.h | 7 ++ dev/benv-build.sh | 2 + jitbuf/jb.h | 7 ++ platform/types.h | 10 ++ reducer/constants.h | 7 ++ reducer/ingest/agent_span.h | 7 ++ reducer/ingest/flow_updater.cc | 37 +++--- reducer/matching/flow_span.cc | 3 +- reducer/otlp_grpc_publisher.cc | 3 + reducer/prometheus_publisher.h | 3 + reducer/reducer.cc | 5 + reducer/reducer_config.inl | 6 + renderc/io.opentelemetry.render/build.gradle | 4 + .../render/generator/MessageGenerator.xtend | 11 +- .../render/generator/MetricsGenerator.xtend | 15 +++ .../render/generator/SpanGenerator.xtend | 34 ++++++ renderc/test/render_test.cc | 8 ++ scheduling/interval_scheduler.cc | 3 +- util/aws_instance_metadata.cc | 7 ++ util/code_timing.cc | 7 ++ util/counter.inl | 7 ++ util/counter_to_rate.inl | 6 + util/curl_engine.cc | 2 + util/docker_host_config_metadata.inl | 7 ++ util/enum.h | 6 + util/enum_operators.inl | 7 ++ util/error_handling.h | 2 +- util/gauge.inl | 7 ++ util/ip_address.h | 6 + util/k8s_metadata.inl | 7 ++ util/log.h | 24 +++- util/log_formatters.h | 43 ------- util/log_modifiers.h | 12 ++ util/log_whitelist.h | 3 +- util/log_whitelist.inl | 4 +- util/logger.h | 2 +- util/nomad_metadata.cc | 2 + util/protobuf_log.h | 7 ++ util/raw_json.h | 30 ++++- util/restful.inl | 20 ++++ util/short_string.h | 7 ++ util/signal_handler.h | 1 + util/stop_watch.h | 7 ++ util/uv_helpers.h | 2 + util/version.h | 7 ++ 57 files changed, 480 insertions(+), 196 deletions(-) diff --git a/channel/tcp_channel.h b/channel/tcp_channel.h index 51dcab3f..be892c84 100644 --- a/channel/tcp_channel.h +++ b/channel/tcp_channel.h @@ -8,6 +8,7 @@ #include #include #include +#include #include diff --git a/cmake/aws-sdk.cmake b/cmake/aws-sdk.cmake index 95eca03b..d1cb9342 100644 --- a/cmake/aws-sdk.cmake +++ b/cmake/aws-sdk.cmake @@ -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( @@ -26,4 +57,5 @@ target_include_directories( aws-sdk-cpp INTERFACE ${AWSSDK_INCLUDE_DIR} + ${OPENSSL_INCLUDE_DIR} ) diff --git a/cmake/bcc.cmake b/cmake/bcc.cmake index 56c3258f..bfb6c4a6 100644 --- a/cmake/bcc.cmake +++ b/cmake/bcc.cmake @@ -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}") diff --git a/collector/cloud/enumerator.cc b/collector/cloud/enumerator.cc index 71000fd8..046576e1 100644 --- a/collector/cloud/enumerator.cc +++ b/collector/cloud/enumerator.cc @@ -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:" diff --git a/collector/k8s/kubernetes_rpc_server.cc b/collector/k8s/kubernetes_rpc_server.cc index bf72730d..3b2a09b6 100644 --- a/collector/k8s/kubernetes_rpc_server.cc +++ b/collector/k8s/kubernetes_rpc_server.cc @@ -11,6 +11,9 @@ #include #include +#include +#include + #include "channel/buffered_writer.h" #include "generated/ebpf_net/ingest/writer.h" #include "generated/kubernetes_info.pb.h" @@ -22,6 +25,72 @@ #include "util/lookup3_hasher.h" #include +// A libfmt formatter for ReplicaSetInfo, used to print addresses in LOG::trace +// etc. +namespace fmt { +template <> struct formatter { + // Parsing (optional, since we don't need custom specifiers) + template + constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + + // Formatting method + template + 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 { + template + constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + + template + 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 { + template + constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + + template + 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 { + template + constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + + template + 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 { + template + constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + + template + 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; diff --git a/collector/kernel/CMakeLists.txt b/collector/kernel/CMakeLists.txt index 8363a38b..8671afb7 100644 --- a/collector/kernel/CMakeLists.txt +++ b/collector/kernel/CMakeLists.txt @@ -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 @@ -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 @@ -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) diff --git a/collector/kernel/bpf_src/render_bpf.c b/collector/kernel/bpf_src/render_bpf.c index 4c82623d..5692573e 100644 --- a/collector/kernel/bpf_src/render_bpf.c +++ b/collector/kernel/bpf_src/render_bpf.c @@ -68,13 +68,15 @@ struct pkts_if_t { static inline u32 packets_in_flight_helper(struct sock *sk) { - struct tcp_sock *tp = tcp_sk(sk); + struct tcp_sock *tp; struct pkts_if_t t = {}; - bpf_probe_read(&t.packets_out, sizeof(u32), &tp->packets_out); - bpf_probe_read(&t.sacked_out, sizeof(u32), &tp->sacked_out); - bpf_probe_read(&t.lost_out, sizeof(u32), &tp->lost_out); - bpf_probe_read(&t.retrans_out, sizeof(u32), &tp->retrans_out); + tp = tcp_sk(sk); + + bpf_probe_read_kernel(&t.packets_out, sizeof(u32), &tp->packets_out); + bpf_probe_read_kernel(&t.sacked_out, sizeof(u32), &tp->sacked_out); + bpf_probe_read_kernel(&t.lost_out, sizeof(u32), &tp->lost_out); + bpf_probe_read_kernel(&t.retrans_out, sizeof(u32), &tp->retrans_out); return t.packets_out - (t.sacked_out + t.lost_out) + t.retrans_out; } diff --git a/collector/kernel/bpf_src/tcp-processor/bpf_tcp_send_recv.h b/collector/kernel/bpf_src/tcp-processor/bpf_tcp_send_recv.h index 74102327..2a3eadea 100644 --- a/collector/kernel/bpf_src/tcp-processor/bpf_tcp_send_recv.h +++ b/collector/kernel/bpf_src/tcp-processor/bpf_tcp_send_recv.h @@ -181,7 +181,11 @@ int handle_kprobe__tcp_sendmsg(struct pt_regs *ctx, struct sock *sk, struct msgh return 0; } // can access through iov since iov and kvec are union and have same layout +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) bpf_probe_read(&iov, sizeof(iov), &(msg->msg_iter.iov)); +#else + bpf_probe_read(&iov, sizeof(iov), &(msg->msg_iter.__iov)); +#endif bpf_probe_read(&nr_segs, sizeof(nr_segs), &(msg->msg_iter.nr_segs)); bpf_probe_read(&iov_offset, sizeof(iov_offset), &(msg->msg_iter.iov_offset)); #endif @@ -390,7 +394,11 @@ int handle_kprobe__tcp_recvmsg( return 0; } // can access through iov since iov and kvec are union and have same layout +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) bpf_probe_read(&iov, sizeof(iov), &(msg->msg_iter.iov)); +#else + bpf_probe_read(&iov, sizeof(iov), &(msg->msg_iter.__iov)); +#endif #endif #pragma passthrough off diff --git a/collector/kernel/main.cc b/collector/kernel/main.cc index d5d98e89..c4458312 100644 --- a/collector/kernel/main.cc +++ b/collector/kernel/main.cc @@ -63,6 +63,7 @@ static constexpr auto SERVICE_OVERRIDE_VAR = "EBPF_NET_AGENT_SERVICE"; static constexpr auto HOST_OVERRIDE_VAR = "EBPF_NET_AGENT_HOST"; static constexpr auto ZONE_OVERRIDE_VAR = "EBPF_NET_AGENT_ZONE"; +template <> struct fmt::formatter : fmt::ostream_formatter {}; static void refill_log_rate_limit_cb(uv_timer_t *timer) { LOG::refill_rate_limit_budget(200); diff --git a/collector/kernel/process_handler.cc b/collector/kernel/process_handler.cc index a618558a..a9253ac7 100644 --- a/collector/kernel/process_handler.cc +++ b/collector/kernel/process_handler.cc @@ -46,7 +46,8 @@ void ProcessHandler::on_new_process(std::chrono::nanoseconds timestamp, struct j #endif // DEBUG_TGID } - auto weak_handle = collector_index_.tracked_process.by_key({.cgroup = msg.cgroup, .tgid = msg.pid}); + ebpf_net::kernel_collector::keys::tracked_process key{msg.cgroup, msg.pid}; // Create the key explicitly + auto weak_handle = collector_index_.tracked_process.by_key(key); assert(msg.pid == weak_handle.tgid()); assert(msg.cgroup == weak_handle.cgroup()); diff --git a/collector/kernel/troubleshooting.h b/collector/kernel/troubleshooting.h index 58ce260a..325e44a7 100644 --- a/collector/kernel/troubleshooting.h +++ b/collector/kernel/troubleshooting.h @@ -9,6 +9,7 @@ #include #include #include +#include /** * Prints a troubleshooting message for the error contained in the given diff --git a/config/intake_config.cc b/config/intake_config.cc index 371c6c5b..df29dbce 100644 --- a/config/intake_config.cc +++ b/config/intake_config.cc @@ -13,12 +13,12 @@ namespace config { -const IntakeConfig IntakeConfig::DEFAULT_CONFIG = { - .host = "127.0.0.1", - .port = "8000", - .record_output_path = "", - .encoder_ = IntakeEncoder::binary, -}; +const IntakeConfig IntakeConfig::DEFAULT_CONFIG = IntakeConfig( + "127.0.0.1", + "8000", + "", + IntakeEncoder::binary +); FileDescriptor IntakeConfig::create_output_record_file() const { diff --git a/config/intake_config.h b/config/intake_config.h index 1d740bd0..e5737761 100644 --- a/config/intake_config.h +++ b/config/intake_config.h @@ -14,6 +14,11 @@ #include +#include +#include +#include +#include + #include #include #include @@ -118,3 +123,5 @@ struct IntakeConfig::ArgsHandler : cli::ArgsParser::Handler { }; } // namespace config + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/dev/benv-build.sh b/dev/benv-build.sh index 2c496c04..f2f14cc5 100755 --- a/dev/benv-build.sh +++ b/dev/benv-build.sh @@ -134,6 +134,8 @@ source ./version.sh CMAKE_FLAGS=( \ -DCMAKE_INSTALL_PREFIX:PATH="$HOME/install" -DOPENSSL_ROOT_DIR:PATH="$HOME/install/openssl" + -DOPENSSL_INCLUDE_DIR:PATH="$HOME/install/openssl/include" + -DOPENSSL_LIBRARIES:PATH="$HOME/install/openssl/lib" -DCMAKE_PREFIX_PATH:PATH="$HOME/install" -DEBPF_NET_MAJOR_VERSION=${EBPF_NET_MAJOR_VERSION} -DEBPF_NET_MINOR_VERSION=${EBPF_NET_MINOR_VERSION} diff --git a/jitbuf/jb.h b/jitbuf/jb.h index 6e22e6e3..d75633f4 100644 --- a/jitbuf/jb.h +++ b/jitbuf/jb.h @@ -16,6 +16,11 @@ #include #include +#include +#include +#include +#include + extern "C" { #endif /* __cplusplus */ @@ -136,6 +141,8 @@ template std::string_view render_array_to_string_view(std::ui return {reinterpret_cast(data), strnlen(reinterpret_cast(data), Size / sizeof(*data))}; } +template <> struct fmt::formatter : fmt::ostream_formatter {}; + #endif /* __cplusplus */ #endif /* INCLUDE_JITBUF_JB_H_ */ diff --git a/platform/types.h b/platform/types.h index 37de269f..18af0e25 100644 --- a/platform/types.h +++ b/platform/types.h @@ -41,6 +41,10 @@ typedef int8_t s8; #endif /* #ifndef __KERNEL__ */ #ifdef __cplusplus +#include +#include +#include +#include #include @@ -81,6 +85,12 @@ Out &operator<<(Out &&out, T value) return out; } +template <> +struct fmt::formatter : fmt::ostream_formatter {}; + +template <> +struct fmt::formatter : fmt::ostream_formatter {}; + #endif /* __cplusplus */ #endif /* INCLUDE_FASTPASS_PLATFORM_TYPES_H_ */ diff --git a/reducer/constants.h b/reducer/constants.h index d041199e..6556f374 100644 --- a/reducer/constants.h +++ b/reducer/constants.h @@ -10,6 +10,11 @@ #include #include +#include +#include +#include +#include + #include #include @@ -99,4 +104,6 @@ constexpr VersionInfo MINIMUM_ACCEPTED_VERSION{0, 9, 0}; } // namespace versions::client +template <> struct fmt::formatter : fmt::ostream_formatter {}; + #include diff --git a/reducer/ingest/agent_span.h b/reducer/ingest/agent_span.h index c5ebae2e..de1488e1 100644 --- a/reducer/ingest/agent_span.h +++ b/reducer/ingest/agent_span.h @@ -33,6 +33,11 @@ #include #include +#include +#include +#include +#include + namespace reducer { class InternalMetricsEncoder; class SpanTest; @@ -272,3 +277,5 @@ class AgentSpan : public ::ebpf_net::ingest::AgentSpanBase { }; } // namespace reducer::ingest + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/reducer/ingest/flow_updater.cc b/reducer/ingest/flow_updater.cc index 8dbd6729..ae76722b 100644 --- a/reducer/ingest/flow_updater.cc +++ b/reducer/ingest/flow_updater.cc @@ -142,32 +142,35 @@ ::ebpf_net::ingest::weak_refs::flow FlowUpdater::create_flow() return ::ebpf_net::ingest::handles::flow().access(*local_index()); } - if (flow_handle_.valid() && flow_handle_.loc() == flow.loc()) { - // unchanged - return flow; - } + // Access weak_refs::flow from auto_handles::flow + auto weak_ref_flow = flow_handle_.access(*local_index()); + + // Check if the current flow_handle_ is already the same as weak_ref_flow's location + if (flow_handle_.valid() && flow_handle_.loc() == weak_ref_flow.loc()) { + return weak_ref_flow; // If unchanged, return the current weak_refs::flow + } if (ordered) { // override the flow's "connector" if it is not unknown, otherwise leave it // be if (is_connector_ != 0) { - flow.modify().is_connector(is_connector_); + weak_ref_flow.modify().is_connector(is_connector_); } side_ = FlowSide::SIDE_A; } else { // override the flow's "connector" if it is not unknown, otherwise leave it // be if (is_connector_ != 0) { - flow.modify().is_connector(reverse_connector(is_connector_)); + weak_ref_flow.modify().is_connector(reverse_connector(is_connector_)); } side_ = FlowSide::SIDE_B; } if (auto process = process_handle_.access(*local_index()); process.valid()) { if (side_ == FlowSide::SIDE_A) { - flow.modify().process1(process.get()); + weak_ref_flow.modify().process1(process.get()); } else { - flow.modify().process2(process.get()); + weak_ref_flow.modify().process2(process.get()); } std::string_view cgroup_name; @@ -190,22 +193,22 @@ ::ebpf_net::ingest::weak_refs::flow FlowUpdater::create_flow() // so if we are looking at the child, and the parent is valid and has a pod id, // send it on. if (auto parent = cgroup.parent(); parent.valid() && (parent.pod_uid_suffix().at(0) != 0)) { - flow.k8s_info((u8)side_, parent.pod_uid_suffix().data(), parent.pod_uid_hash()); + weak_ref_flow.k8s_info((u8)side_, parent.pod_uid_suffix().data(), parent.pod_uid_hash()); } else if ( // for systemd style, the cgroup has the entire hierarchy embedded in the cgroup // so parse it, and look to see if one has a pod id, a container id, and if // this pod_uid_suffix has been assigned. if so, send that up. !cgroup_info.pod_id.empty() && !cgroup_info.container_id.empty() && cgroup.pod_uid_suffix().at(0) != 0) { - flow.k8s_info((u8)side_, cgroup.pod_uid_suffix().data(), cgroup.pod_uid_hash()); + weak_ref_flow.k8s_info((u8)side_, cgroup.pod_uid_suffix().data(), cgroup.pod_uid_hash()); } } // Send task information to flow. - flow.task_info((u8)side_, jb_blob(process.comm()), jb_blob(cgroup_name)); + weak_ref_flow.task_info((u8)side_, jb_blob(process.comm()), jb_blob(cgroup_name)); if (!service_name.empty()) { // Send service information, if any. - flow.service_info((u8)side_, jb_blob(service_name)); + weak_ref_flow.service_info((u8)side_, jb_blob(service_name)); } } @@ -222,7 +225,7 @@ ::ebpf_net::ingest::weak_refs::flow FlowUpdater::create_flow() } // send socket information to flow - flow.socket_info( + weak_ref_flow.socket_info( (u8)side_, local_addr_buf, local_port_, remote_addr_buf, remote_port_, (u8)is_connector_, jb_blob(remote_dns_name)); } @@ -231,22 +234,22 @@ ::ebpf_net::ingest::weak_refs::flow FlowUpdater::create_flow() auto &agent = agent_ref.impl(); // send agent information to flow - flow.agent_info((u8)side_, jb(agent.node_id()), jb(agent.node_az()), jb(agent.cluster()), jb(agent.role()), jb(agent.ns())); + weak_ref_flow.agent_info((u8)side_, jb(agent.node_id()), jb(agent.node_az()), jb(agent.cluster()), jb(agent.role()), jb(agent.ns())); } LOG::trace_in( Component::flow_update, "Flow::get_flow: flow={}, local_ip={}:{}, remote_ip={}:{}", - flow.loc(), + weak_ref_flow.loc(), local_addr_, local_port_, remote_addr_, remote_port_); flow_handle_.put(*local_index()); - flow_handle_ = flow.get().to_handle(); + flow_handle_ = weak_ref_flow.get().to_handle(); - return flow; + return weak_ref_flow; } //////////////////////////////////////////////////////////////////////////////// diff --git a/reducer/matching/flow_span.cc b/reducer/matching/flow_span.cc index 0d1c9d68..9f0c666b 100644 --- a/reducer/matching/flow_span.cc +++ b/reducer/matching/flow_span.cc @@ -411,8 +411,7 @@ FlowSpan::NodeData FlowSpan::resolve_node(::ebpf_net::matching::weak_refs::flow AwsEnrichmentInfo const *aws_info = nullptr; if (aws_enrichment_enabled_) { - auto aws_enrichment_span = span_ref.index().aws_enrichment.by_key({.ip = ipv6.as_int()}, false); - + auto aws_enrichment_span = span_ref.index().aws_enrichment.by_key(ebpf_net::matching::keys::aws_enrichment{ipv6.as_int()}, false); if (aws_enrichment_span.valid()) { aws_info = aws_enrichment_span.impl().info(); } diff --git a/reducer/otlp_grpc_publisher.cc b/reducer/otlp_grpc_publisher.cc index 77b93195..542ea457 100644 --- a/reducer/otlp_grpc_publisher.cc +++ b/reducer/otlp_grpc_publisher.cc @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include +#include #include "otlp_grpc_publisher.h" @@ -9,6 +11,7 @@ #include #include +template <> struct fmt::formatter : fmt::ostream_formatter {}; namespace reducer { OtlpGrpcPublisher::OtlpGrpcPublisher(size_t num_writer_threads, const std::string &server_address_and_port) diff --git a/reducer/prometheus_publisher.h b/reducer/prometheus_publisher.h index 19d1a9be..723a311d 100644 --- a/reducer/prometheus_publisher.h +++ b/reducer/prometheus_publisher.h @@ -15,6 +15,9 @@ #include #include +template <> struct fmt::formatter> : fmt::ostream_formatter {}; + + class CivetServer; namespace reducer { diff --git a/reducer/reducer.cc b/reducer/reducer.cc index 450c9f6e..41ee6b49 100644 --- a/reducer/reducer.cc +++ b/reducer/reducer.cc @@ -39,6 +39,11 @@ #include #include +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template +struct fmt::formatter> : fmt::ostream_formatter {}; + + namespace reducer { Reducer::Reducer(uv_loop_t &loop, ReducerConfig &config) diff --git a/reducer/reducer_config.inl b/reducer/reducer_config.inl index e9dd8e0d..5a8fc60f 100644 --- a/reducer/reducer_config.inl +++ b/reducer/reducer_config.inl @@ -6,6 +6,10 @@ #pragma once #include +#include +#include +#include +#include namespace reducer { @@ -55,3 +59,5 @@ template Out &&operator<<(Out &&out, ReducerConfig const &config) } } // namespace reducer + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/renderc/io.opentelemetry.render/build.gradle b/renderc/io.opentelemetry.render/build.gradle index 0045b249..42218fa3 100644 --- a/renderc/io.opentelemetry.render/build.gradle +++ b/renderc/io.opentelemetry.render/build.gradle @@ -30,3 +30,7 @@ eclipse.classpath.plusConfigurations += [configurations.mwe2] //this is an eclipse plugin project eclipseClasspath.enabled=false cleanEclipseClasspath.enabled=false + +tasks.named("processResources") { + dependsOn(":io.opentelemetry.render:generateXtextLanguage") +} diff --git a/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MessageGenerator.xtend b/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MessageGenerator.xtend index 791e5ebc..42e9e391 100644 --- a/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MessageGenerator.xtend +++ b/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MessageGenerator.xtend @@ -46,7 +46,10 @@ class MessageGenerator { #ifdef __cplusplus # include - + #include + #include + #include + #include # include #endif /* __cplusplus */ @@ -85,6 +88,12 @@ class MessageGenerator { #ifdef __cplusplus } /* extern "C" */ + /* fmt::formatter specialization */ + #ifdef __cplusplus + template <> + struct fmt::formatter<«xmsg.struct_name»> : fmt::ostream_formatter {}; + #endif /* __cplusplus */ + template Out &&operator <<(Out &&out, «xmsg.struct_name» const &what) { what.dump_json(out); diff --git a/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MetricsGenerator.xtend b/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MetricsGenerator.xtend index 5baef5e5..99410892 100644 --- a/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MetricsGenerator.xtend +++ b/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/MetricsGenerator.xtend @@ -53,6 +53,11 @@ class MetricsGenerator { #include #include + #include + #include + #include + #include + namespace «pkg_name» { namespace metrics { @@ -151,6 +156,16 @@ class MetricsGenerator { } // namespace metrics } // namespace «pkg_name» + + «FOR metric : resource.allContents.filter(Metric).toIterable» + /* fmt::formatter specialization */ + template <> + struct fmt::formatter<«pkg_name»::metrics::«metric.name»> : fmt::ostream_formatter {}; + template <> + struct fmt::formatter<«pkg_name»::metrics::«metric.name»_point> : fmt::ostream_formatter {}; + template <> + struct fmt::formatter<«pkg_name»::metrics::«metric.name»_accumulator> : fmt::ostream_formatter {}; + «ENDFOR» ''' } diff --git a/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/SpanGenerator.xtend b/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/SpanGenerator.xtend index 9cb969a7..680f0ffc 100644 --- a/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/SpanGenerator.xtend +++ b/renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/SpanGenerator.xtend @@ -320,6 +320,10 @@ class SpanGenerator { #include #include #include + #include + #include + #include + #include namespace «app.pkg.name»::«app.name» { @@ -386,6 +390,8 @@ class SpanGenerator { }; } // namespace «app.pkg.name»::«app.name» + template <> + struct fmt::formatter<«app.pkg.name»::«app.name»::Index> : fmt::ostream_formatter {}; ''' } @@ -463,6 +469,11 @@ class SpanGenerator { #include #include + #include + #include + #include + #include + #include namespace «app.pkg.name»::«app.name» { @@ -658,6 +669,10 @@ class SpanGenerator { } // namespace containers } // namespace «app.pkg.name»::«app.name» + «FOR span : app.spans» + template <> + struct fmt::formatter<«app.pkg.name»::«app.name»::containers::«span.name»> : fmt::ostream_formatter {}; + «ENDFOR» ''' } @@ -1568,6 +1583,11 @@ class SpanGenerator { #include #include + #include + #include + #include + #include + #include /* Span implementation classes */ @@ -1760,6 +1780,11 @@ class SpanGenerator { } // namespace weak_refs } // namespace «app.pkg.name»::«app.name» + + «FOR span : app.spans» + template <> + struct fmt::formatter<«app.pkg.name»::«app.name»::weak_refs::«span.name»> : fmt::ostream_formatter {}; + «ENDFOR» ''' } @@ -2196,6 +2221,11 @@ class SpanGenerator { #include #include + #include + #include + #include + #include + /* Span implementation classes */ «FOR app_span : app.spans.filter[include !== null]» #include «app_span.include» @@ -2312,6 +2342,10 @@ class SpanGenerator { } // namespace spans } // namespace «app.pkg.name»::«app.name» + «FOR span : app.spans» + template <> + struct fmt::formatter<«app.pkg.name»::«app.name»::spans::«span.name»> : fmt::ostream_formatter {}; + «ENDFOR» ''' } diff --git a/renderc/test/render_test.cc b/renderc/test/render_test.cc index 21d889ad..3cd52f22 100644 --- a/renderc/test/render_test.cc +++ b/renderc/test/render_test.cc @@ -18,27 +18,35 @@ TEST(RenderTest, AutoHandle) test::app1::Index index; { + //std::cout << "Allocating a span" << std::endl; auto span = index.simple_span.alloc(); ASSERT_TRUE(span.valid()); + //std::cout << "Checking the size" << std::endl; ASSERT_EQ(index.simple_span.size(), 1); } // When the auto handle goes out of scope, the span should be freed + //std::cout << "Checking the size again" << std::endl; ASSERT_EQ(index.simple_span.size(), 0); { + //std::cout << "Allocating a span" << std::endl; auto span = index.simple_span.alloc(); ASSERT_TRUE(span.valid()); + //std::cout << "Checking the size" << std::endl; ASSERT_EQ(index.simple_span.size(), 1); // Manually put the reference + //std::cout << "Putting the reference" << std::endl; span.put(); // `put()` should make the handle invalid to make later accesses fail, and facilitate debugging + //std::cout << "Checking the validity" << std::endl; ASSERT_FALSE(span.valid()); // The span should be freed after put even though the auto handle is still in scope + //std::cout << "Checking the size again" << std::endl; ASSERT_EQ(index.simple_span.size(), 0); } } diff --git a/scheduling/interval_scheduler.cc b/scheduling/interval_scheduler.cc index 2afa2d3e..307294ae 100644 --- a/scheduling/interval_scheduler.cc +++ b/scheduling/interval_scheduler.cc @@ -26,7 +26,8 @@ bool IntervalScheduler::start(TimerPeriod timeout, TimerPeriod interval) interval_ = interval; if (auto result = timer_.defer(timeout); !result) { - LOG::error("unable to start interval scheduler: {}", result.error()); + //LOG::error("unable to start interval scheduler: {}", result.error()); + spdlog::error("unable to start interval scheduler: {}", result.error()); return false; } diff --git a/util/aws_instance_metadata.cc b/util/aws_instance_metadata.cc index d81fdd5a..d55d9dbf 100644 --- a/util/aws_instance_metadata.cc +++ b/util/aws_instance_metadata.cc @@ -20,6 +20,11 @@ #include #include +#include +#include +#include +#include + #define METADATA_PREFIX "http://169.254.169.254/2016-09-02/meta-data/" #define DYNAMIC_METADATA_PREFIX "http://169.254.169.254/2016-09-02/dynamic/" #define MAX_LEN 4096 @@ -379,3 +384,5 @@ std::ostream &operator<<(std::ostream &os, const AwsMetadataValue &val) os << "AWS-Meta(valid=" << val.valid() << " value='" << val.value() << "')"; return os; } + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/util/code_timing.cc b/util/code_timing.cc index 8c4c7c70..cc7070b6 100644 --- a/util/code_timing.cc +++ b/util/code_timing.cc @@ -4,6 +4,11 @@ #include #include +#include +#include +#include +#include + #include #if ENABLE_CODE_TIMING @@ -49,6 +54,8 @@ std::ostream &operator<<(std::ostream &os, CodeTiming const &timing) return os; } +template <> struct fmt::formatter : fmt::ostream_formatter {}; + thread_local CodeTimingRegistry code_timing_registry_; void print_code_timings() diff --git a/util/counter.inl b/util/counter.inl index b068b3c4..f494da71 100644 --- a/util/counter.inl +++ b/util/counter.inl @@ -1,6 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + namespace data { template Out &&operator<<(Out &&out, Counter const &what) @@ -14,3 +19,5 @@ template Out &&operator<<(Out &&out, Counter const } } // namespace data + +template struct fmt::formatter> : fmt::ostream_formatter {}; diff --git a/util/counter_to_rate.inl b/util/counter_to_rate.inl index ac465c85..01031bd2 100644 --- a/util/counter_to_rate.inl +++ b/util/counter_to_rate.inl @@ -2,6 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include +#include +#include +#include namespace data { @@ -35,3 +39,5 @@ template Out &&operator<<(Out &&out, CounterToRate } } // namespace data + +template struct fmt::formatter> : fmt::ostream_formatter {}; diff --git a/util/curl_engine.cc b/util/curl_engine.cc index 49ed2fe9..30707dc5 100644 --- a/util/curl_engine.cc +++ b/util/curl_engine.cc @@ -9,6 +9,8 @@ #include +template <> struct fmt::formatter : fmt::ostream_formatter {}; + namespace { static constexpr size_t kWriteBufferCapacity = CURL_MAX_WRITE_SIZE; diff --git a/util/docker_host_config_metadata.inl b/util/docker_host_config_metadata.inl index 015d77cf..658ed6c0 100644 --- a/util/docker_host_config_metadata.inl +++ b/util/docker_host_config_metadata.inl @@ -1,6 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + template Out &&operator<<(Out &&out, DockerHostConfigMetadata const &what) { out << "\"cpu_shares\":" << what.cpu_shares_ << ",\"cpu_period\":" << what.cpu_period_ << ",\"cpu_quota\":" << what.cpu_quota_ @@ -10,3 +15,5 @@ template Out &&operator<<(Out &&out, DockerHostConfigMetadata con return std::forward(out); } + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/util/enum.h b/util/enum.h index eec51c5f..2e6ccd25 100644 --- a/util/enum.h +++ b/util/enum.h @@ -15,6 +15,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -128,4 +132,6 @@ template class EnumSet { int_type set_ = static_cast(0); }; +template struct fmt::formatter> : fmt::ostream_formatter {}; + #include diff --git a/util/enum_operators.inl b/util/enum_operators.inl index 516e972f..cc836cb4 100644 --- a/util/enum_operators.inl +++ b/util/enum_operators.inl @@ -39,6 +39,10 @@ // #include +#include +#include +#include +#include #ifndef ENUM_NAME #error "You must declare the name of the enum in ENUM_NAME" @@ -225,6 +229,9 @@ template Out &operator<<(Out &&out, ENUM_NAME value) #ifdef ENUM_NAMESPACE } // namespace ENUM_NAMESPACE +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#else // ENUM_NAMESPACE +template <> struct fmt::formatter : fmt::ostream_formatter {}; #endif // ENUM_NAMESPACE // Clean up the things we've defined diff --git a/util/error_handling.h b/util/error_handling.h index 811a0e54..207111ed 100644 --- a/util/error_handling.h +++ b/util/error_handling.h @@ -65,7 +65,7 @@ struct Panicker { { fmt::memory_buffer out; #if FMT_VERSION >= 60000 - fmt::format_to(std::back_inserter(out), format, std::forward(args)...); + fmt::format_to(std::back_inserter(out), fmt::runtime(format), std::forward(args)...); #else fmt::format_to(out, format, std::forward(args)...); #endif diff --git a/util/gauge.inl b/util/gauge.inl index 27b0d02e..44c7a4d9 100644 --- a/util/gauge.inl +++ b/util/gauge.inl @@ -1,6 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + namespace data { template template Out Gauge::average() const @@ -73,3 +78,5 @@ template Out &&operator<<(Out &&out, Gauge const & } } // namespace data + +template struct fmt::formatter> : fmt::ostream_formatter {}; diff --git a/util/ip_address.h b/util/ip_address.h index a50a1bb1..b9f96bff 100644 --- a/util/ip_address.h +++ b/util/ip_address.h @@ -12,7 +12,10 @@ #include #include +#include #include +#include +#include #include #include @@ -195,3 +198,6 @@ template H AbslHashValue(H hash_state, const IPv4Address &addr) } std::ostream &operator<<(std::ostream &os, const IPv4Address &ipv4); + +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter> : fmt::ostream_formatter {}; diff --git a/util/k8s_metadata.inl b/util/k8s_metadata.inl index eec96a8d..bd470f9e 100644 --- a/util/k8s_metadata.inl +++ b/util/k8s_metadata.inl @@ -1,6 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 +#include +#include +#include +#include + template Out &&operator<<(Out &&out, K8sMetadata const &what) { out << "\"container_name\":\"" << what.container_name_ << "\",\"pod_name\":\"" << what.pod_name_ << "\",\"pod_ns\":\"" @@ -20,3 +25,5 @@ template Out &&operator<<(Out &&out, K8sMetadata const &what) return std::forward(out); } + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/util/log.h b/util/log.h index 23a05408..abf3c7b3 100644 --- a/util/log.h +++ b/util/log.h @@ -20,6 +20,18 @@ #include #include +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template struct fmt::formatter> : fmt::ostream_formatter {}; + class LOG { public: /** @@ -53,7 +65,7 @@ class LOG { if (rate_limited()) { return; } - spdlog::trace(format, args...); + spdlog::trace(fmt::runtime(format), args...); } @@ -97,7 +109,7 @@ class LOG { if (rate_limited()) { return; } - spdlog::debug(format, args...); + spdlog::debug(fmt::runtime(format), args...); } /** @@ -142,7 +154,7 @@ class LOG { if (rate_limited()) { return; } - spdlog::info(format, args...); + spdlog::info(fmt::runtime(format), args...); } template static void inline warn(Format &&format, Args &&... args) @@ -151,7 +163,7 @@ class LOG { if (rate_limited()) { return; } - spdlog::warn(format, args...); + spdlog::warn(fmt::runtime(format), args...); } template static void inline error(Format &&format, Args &&... args) @@ -160,7 +172,7 @@ class LOG { if (rate_limited()) { return; } - spdlog::error(format, args...); + spdlog::error(fmt::runtime(format), args...); } template static void inline critical(Format &&format, Args &&... args) @@ -169,7 +181,7 @@ class LOG { if (rate_limited()) { return; } - spdlog::critical(format, args...); + spdlog::critical(fmt::runtime(format), args...); } private: diff --git a/util/log_formatters.h b/util/log_formatters.h index ee9f8f2c..ec26c3bf 100644 --- a/util/log_formatters.h +++ b/util/log_formatters.h @@ -46,49 +46,6 @@ template Out &operator<<(Out &&out, std::exception const &e) } // namespace std -//////////// -// chrono // -//////////// - -namespace std { - -template Out &operator<<(Out &&out, std::chrono::hours value) -{ - out << value.count() << "h"; - return out; -} -template Out &operator<<(Out &&out, std::chrono::minutes value) -{ - out << value.count() << "min"; - return out; -} - -template Out &operator<<(Out &&out, std::chrono::seconds value) -{ - out << value.count() << "s"; - return out; -} - -template Out &operator<<(Out &&out, std::chrono::milliseconds value) -{ - out << value.count() << "ms"; - return out; -} - -template Out &operator<<(Out &&out, std::chrono::microseconds value) -{ - out << value.count() << "\u00B5s"; - return out; -} - -template Out &operator<<(Out &&out, std::chrono::nanoseconds value) -{ - out << value.count() << "ns"; - return out; -} - -} // namespace std - //////////////// // containers // //////////////// diff --git a/util/log_modifiers.h b/util/log_modifiers.h index 1c4081e7..edc278c3 100644 --- a/util/log_modifiers.h +++ b/util/log_modifiers.h @@ -9,6 +9,11 @@ #include #include +#include +#include +#include +#include + #include namespace logger { @@ -371,6 +376,13 @@ template struct callable_t { } // namespace logger::impl +template struct fmt::formatter> : fmt::ostream_formatter {}; +template struct fmt::formatter> : fmt::ostream_formatter {}; +template struct fmt::formatter> : fmt::ostream_formatter {}; +template +struct fmt::formatter> : fmt::ostream_formatter {}; +template struct fmt::formatter> : fmt::ostream_formatter {}; + /** * A logging helper to allow logging the result of a callable object. * diff --git a/util/log_whitelist.h b/util/log_whitelist.h index f826f46d..2e9ddfd1 100644 --- a/util/log_whitelist.h +++ b/util/log_whitelist.h @@ -37,7 +37,8 @@ template void set_log_whitelist(std::initializer_list wh void log_whitelist_all_globally(); // this function is thread-safe -template >> bool is_log_whitelisted(Whitelist which); +template >> +bool is_log_whitelisted(Whitelist which); // this function is thread-safe template bool is_log_whitelisted(std::tuple const &which); diff --git a/util/log_whitelist.inl b/util/log_whitelist.inl index bdf07a41..1e8b8891 100644 --- a/util/log_whitelist.inl +++ b/util/log_whitelist.inl @@ -102,8 +102,8 @@ template void set_log_whitelist(std::list whitelist) LogWhitelist::set_whitelist(std::move(whitelist)); } -template >> bool is_log_whitelisted(Whitelist which) -{ +template +bool is_log_whitelisted(Whitelist which) { return LogWhitelist::is_whitelisted(which); } diff --git a/util/logger.h b/util/logger.h index a47c37bc..4cd047cc 100644 --- a/util/logger.h +++ b/util/logger.h @@ -46,7 +46,7 @@ class Logger { template inline std::string log_message(Format &&format, Args &&... args) { - auto message = fmt::format(std::forward(format), std::forward(args)...); + auto message = fmt::format(fmt::runtime(std::forward(format)), std::forward(args)...); static_assert(static_cast>(Level) == static_cast(Level)); diff --git a/util/nomad_metadata.cc b/util/nomad_metadata.cc index 112f9f8d..842f2884 100644 --- a/util/nomad_metadata.cc +++ b/util/nomad_metadata.cc @@ -11,6 +11,8 @@ #include +template <> struct fmt::formatter> : fmt::ostream_formatter {}; + const std::string NOMAD_NAMESPACE_VAR = "NOMAD_NAMESPACE"; const std::string NOMAD_GROUP_NAME_VAR = "NOMAD_GROUP_NAME"; const std::string NOMAD_TASK_NAME_VAR = "NOMAD_TASK_NAME"; diff --git a/util/protobuf_log.h b/util/protobuf_log.h index c94dd3dd..708ab3e9 100644 --- a/util/protobuf_log.h +++ b/util/protobuf_log.h @@ -7,6 +7,11 @@ #include #include +#include +#include +#include +#include + std::ostream &operator<<(std::ostream &out, google::protobuf::Message const &message) { google::protobuf::io::OstreamOutputStream output(&out); @@ -18,3 +23,5 @@ std::ostream &operator<<(std::ostream &out, google::protobuf::Message const &mes return out; } + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/util/raw_json.h b/util/raw_json.h index 63a6353f..7114da92 100644 --- a/util/raw_json.h +++ b/util/raw_json.h @@ -121,8 +121,31 @@ Out &&print_escaped_json_string(Out &&out, std::array const return std::forward(out); } -template Out &&print_json_value(Out &&out, T const &value) -{ +inline std::string print_int128(__int128 value) { + std::ostringstream oss; + bool is_negative = value < 0; + __uint128_t uvalue = is_negative ? -static_cast<__uint128_t>(value) : value; // Treat as unsigned for conversion + + // Handle zero case + if (uvalue == 0) { + return "0"; + } + + std::string result; + while (uvalue > 0) { + result = static_cast('0' + (uvalue % 10)) + result; + uvalue /= 10; + } + + if (is_negative) { + result = "-" + result; + } + + return result; +} + +template +Out &&print_json_value(Out &&out, T const &value) { if constexpr (std::is_same_v) { constexpr char const *literals[] = {"false", "true"}; out << literals[value]; @@ -132,6 +155,9 @@ template Out &&print_json_value(Out &&out, T const &v } else if constexpr (std::is_same_v || std::is_same_v) { // avoid printing the raw character out << static_cast(value); + } else if constexpr (std::is_same_v<__int128, T> || std::is_same_v) { + // handle 128-bit integers + out << print_int128(value); } else if constexpr (std::is_integral_v) { out << value; } else { diff --git a/util/restful.inl b/util/restful.inl index 5ce3078e..a72bc51d 100644 --- a/util/restful.inl +++ b/util/restful.inl @@ -4,11 +4,31 @@ #include #include +#include +#include + #include #include #include #include +namespace fmt { +template +struct formatter> { + // Parsing the format string (optional in this case) + template + constexpr auto parse(ParseContext &ctx) { return ctx.begin(); } + + // Format the std::chrono::duration + template + auto format(const std::chrono::duration &duration, FormatContext &ctx) { + // Convert the duration to milliseconds and print it + auto ms = std::chrono::duration_cast(duration).count(); + return format_to(ctx.out(), "{} ms", ms); + } +}; +} // namespace fmt + template Expected RestfulFetcher::CtorDecoder::operator()(std::string body) const { try { diff --git a/util/short_string.h b/util/short_string.h index b7cb17fc..ad4201b3 100644 --- a/util/short_string.h +++ b/util/short_string.h @@ -14,6 +14,11 @@ #include #include +#include +#include +#include +#include + struct short_string_behavior { struct truncate_t { }; @@ -178,6 +183,8 @@ template struct short_string { } }; +template struct fmt::formatter> : fmt::ostream_formatter {}; + template >, std::size_t Size = std::extent_v> short_string to_short_string(std::string_view s) { diff --git a/util/signal_handler.h b/util/signal_handler.h index bd0eb220..f1522113 100644 --- a/util/signal_handler.h +++ b/util/signal_handler.h @@ -16,6 +16,7 @@ #include #include #include +#include struct SignalManager : cli::ArgsParser::Handler { explicit SignalManager(cli::ArgsParser &parser, ::uv_loop_t &loop, std::string_view product); diff --git a/util/stop_watch.h b/util/stop_watch.h index 656c1b8a..871f1d9e 100644 --- a/util/stop_watch.h +++ b/util/stop_watch.h @@ -8,6 +8,11 @@ #include #include +#include +#include +#include +#include + #include template class StopWatch { @@ -65,3 +70,5 @@ template class StopWatch { private: time_point start_; }; + +template struct fmt::formatter> : fmt::ostream_formatter {}; diff --git a/util/uv_helpers.h b/util/uv_helpers.h index e21a16dd..11ec5fd1 100644 --- a/util/uv_helpers.h +++ b/util/uv_helpers.h @@ -85,3 +85,5 @@ void close_uv_loop_cleanly(uv_loop_t *loop); void close_uv_handle_cleanly(uv_handle_t *handle, void (*cb)(uv_handle_t *)); std::error_category const &libuv_category() noexcept; + +template <> struct fmt::formatter : fmt::ostream_formatter {}; diff --git a/util/version.h b/util/version.h index 2e667925..9d464e7d 100644 --- a/util/version.h +++ b/util/version.h @@ -11,6 +11,11 @@ #include #include +#include +#include +#include +#include + class VersionInfo { public: constexpr explicit VersionInfo(u32 major = 0, u32 minor = 0, u32 patch = 0, std::string_view signature = {}) @@ -53,3 +58,5 @@ class VersionInfo { private: std::tuple version_; }; + +template <> struct fmt::formatter : fmt::ostream_formatter {}; From 612ec0a9bf7a5d6171fd612fa885c81f7c9be692 Mon Sep 17 00:00:00 2001 From: etichy Date: Wed, 9 Oct 2024 13:54:54 +0200 Subject: [PATCH 02/13] Disable cloud-collector --- .github/workflows/build-and-release.yaml | 2 +- .github/workflows/build-and-test.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 83c73667..cb17ed0f 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -151,7 +151,7 @@ jobs: images=( reducer kernel-collector - cloud-collector + # cloud-collector k8s-watcher k8s-relay ) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 81cbf6a5..f7636eea 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -121,6 +121,7 @@ jobs: ./build.sh k8s-relay build-cloud-collector: + if: false name: build-cloud-collector runs-on: ubuntu-20.04 needs: [clang-format-check] From c23e68f35d4f09dea462de26dde020b22af058bc Mon Sep 17 00:00:00 2001 From: Jaroslav Fedor Date: Fri, 11 Oct 2024 15:50:24 +0200 Subject: [PATCH 03/13] Temporary disable clang formater --- .github/workflows/build-and-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 15becd4e..1e5fe720 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -38,7 +38,7 @@ jobs: sudo apt update sudo apt install -y clang-format-11 cd ${{ github.workspace }} - ./.github/workflows/scripts/check-clang-format.sh + #./.github/workflows/scripts/check-clang-format.sh outputs: date: ${{ steps.date.outputs.date }} From 6680f94e2c4324a0d9185db40afaea4b2bfac26c Mon Sep 17 00:00:00 2001 From: Jaroslav Fedor Date: Fri, 11 Oct 2024 16:34:44 +0200 Subject: [PATCH 04/13] Disable build of cloud collector --- collector/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/CMakeLists.txt b/collector/CMakeLists.txt index 45a0debb..ce322122 100644 --- a/collector/CMakeLists.txt +++ b/collector/CMakeLists.txt @@ -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) From 52ae4454a3a9e4d89327c1b145da6668532fe63a Mon Sep 17 00:00:00 2001 From: etichy Date: Mon, 14 Oct 2024 09:41:44 +0200 Subject: [PATCH 05/13] Fix format files --- .github/workflows/build-and-test.yaml | 2 +- collector/kernel/process_handler.cc | 2 +- collector/kernel/troubleshooting.h | 2 +- dev/clang-format.sh | 37 +++++++++++++++++++++++++++ reducer/disabled_metrics.h | 10 ++++++-- reducer/ingest/flow_updater.cc | 15 ++++++----- reducer/internal_stats.h | 12 +++------ reducer/matching/flow_span.cc | 3 ++- reducer/prometheus_publisher.h | 1 - reducer/reducer.cc | 4 +-- reducer/reducer_config.inl | 2 +- reducer/thread_safe_map.h | 5 +++- 12 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 dev/clang-format.sh diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 1e5fe720..15becd4e 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -38,7 +38,7 @@ jobs: sudo apt update sudo apt install -y clang-format-11 cd ${{ github.workspace }} - #./.github/workflows/scripts/check-clang-format.sh + ./.github/workflows/scripts/check-clang-format.sh outputs: date: ${{ steps.date.outputs.date }} diff --git a/collector/kernel/process_handler.cc b/collector/kernel/process_handler.cc index a9253ac7..4d68f546 100644 --- a/collector/kernel/process_handler.cc +++ b/collector/kernel/process_handler.cc @@ -46,7 +46,7 @@ void ProcessHandler::on_new_process(std::chrono::nanoseconds timestamp, struct j #endif // DEBUG_TGID } - ebpf_net::kernel_collector::keys::tracked_process key{msg.cgroup, msg.pid}; // Create the key explicitly + ebpf_net::kernel_collector::keys::tracked_process key{msg.cgroup, msg.pid}; // Create the key explicitly auto weak_handle = collector_index_.tracked_process.by_key(key); assert(msg.pid == weak_handle.tgid()); assert(msg.cgroup == weak_handle.cgroup()); diff --git a/collector/kernel/troubleshooting.h b/collector/kernel/troubleshooting.h index 325e44a7..357d319d 100644 --- a/collector/kernel/troubleshooting.h +++ b/collector/kernel/troubleshooting.h @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include /** * Prints a troubleshooting message for the error contained in the given diff --git a/dev/clang-format.sh b/dev/clang-format.sh new file mode 100644 index 00000000..1be24092 --- /dev/null +++ b/dev/clang-format.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + + +CLANG_FORMAT_VERSION="clang-format" +if ! command -v ${CLANG_FORMAT_VERSION} +then + echo "ERROR: requires ${CLANG_FORMAT_VERSION}" + exit 1 +fi + +RC=0 +CMD="${CLANG_FORMAT_VERSION} -i -style=file" +function check_file +{ + if ! ${CMD} $1 + then + RC=1 + fi +} + +# Check that C and C++ source files are properly clang-formatted +FILES=$(find ../geoip ../reducer ../test ../collector/kernel ../common ../tools \ + -type f \ + \( -name "*.c" \ + -o -name "*.cc" \ + -o -name "*.h" \ + -o -name "*.inl" \) \ + ) + +for FILE in ${FILES} +do + check_file ${FILE} +done + +exit ${RC} diff --git a/reducer/disabled_metrics.h b/reducer/disabled_metrics.h index 91ac8b39..c0815423 100644 --- a/reducer/disabled_metrics.h +++ b/reducer/disabled_metrics.h @@ -61,7 +61,10 @@ class DisabledMetrics { // check if a particular metric is disabled #define METRIC_MEMBER_FNS(METRIC, ENUM_TYPE) \ - bool is_metric_disabled(ENUM_TYPE metric) const { return static_cast(metric) & METRIC_FLAG(METRIC); } + bool is_metric_disabled(ENUM_TYPE metric) const \ + { \ + return static_cast(metric) & METRIC_FLAG(METRIC); \ + } METRIC_GROUPS(METRIC_MEMBER_FNS) #undef METRIC_MEMBER_FNS @@ -196,7 +199,10 @@ template void DisabledMetrics::enable_metric(const std::string &met { \ return METRIC_FLAG(METRIC) == static_cast(ENUM_TYPE::all); \ } \ - template <> inline std::uint64_t DisabledMetrics::disabled_flags() const { return METRIC_FLAG(METRIC); } + template <> inline std::uint64_t DisabledMetrics::disabled_flags() const \ + { \ + return METRIC_FLAG(METRIC); \ + } METRIC_GROUPS(METRIC_MEMBER_SPECIALIZATIONS) #undef METRIC_MEMBER_SPECIALIZATIONS diff --git a/reducer/ingest/flow_updater.cc b/reducer/ingest/flow_updater.cc index ae76722b..ffdfd501 100644 --- a/reducer/ingest/flow_updater.cc +++ b/reducer/ingest/flow_updater.cc @@ -142,13 +142,13 @@ ::ebpf_net::ingest::weak_refs::flow FlowUpdater::create_flow() return ::ebpf_net::ingest::handles::flow().access(*local_index()); } - // Access weak_refs::flow from auto_handles::flow - auto weak_ref_flow = flow_handle_.access(*local_index()); + // Access weak_refs::flow from auto_handles::flow + auto weak_ref_flow = flow_handle_.access(*local_index()); - // Check if the current flow_handle_ is already the same as weak_ref_flow's location - if (flow_handle_.valid() && flow_handle_.loc() == weak_ref_flow.loc()) { - return weak_ref_flow; // If unchanged, return the current weak_refs::flow - } + // Check if the current flow_handle_ is already the same as weak_ref_flow's location + if (flow_handle_.valid() && flow_handle_.loc() == weak_ref_flow.loc()) { + return weak_ref_flow; // If unchanged, return the current weak_refs::flow + } if (ordered) { // override the flow's "connector" if it is not unknown, otherwise leave it @@ -234,7 +234,8 @@ ::ebpf_net::ingest::weak_refs::flow FlowUpdater::create_flow() auto &agent = agent_ref.impl(); // send agent information to flow - weak_ref_flow.agent_info((u8)side_, jb(agent.node_id()), jb(agent.node_az()), jb(agent.cluster()), jb(agent.role()), jb(agent.ns())); + weak_ref_flow.agent_info( + (u8)side_, jb(agent.node_id()), jb(agent.node_az()), jb(agent.cluster()), jb(agent.role()), jb(agent.ns())); } LOG::trace_in( diff --git a/reducer/internal_stats.h b/reducer/internal_stats.h index 11a5bcb1..cf6a6d33 100644 --- a/reducer/internal_stats.h +++ b/reducer/internal_stats.h @@ -69,15 +69,13 @@ namespace reducer { struct Labels { \ using label_fn_t = std::function; \ void foreach_label(label_fn_t func) { __foreach_label(_FirstLabelType(), func, *this); } \ - struct _FirstLabelType { \ - }; \ + struct _FirstLabelType {}; \ typedef _FirstLabelType #define LABEL(LABEL_NAME) \ _LabelType_##LABEL_NAME; \ std::string LABEL_NAME; \ - struct _NextLabelType_##LABEL_NAME { \ - }; \ + struct _NextLabelType_##LABEL_NAME {}; \ static void __foreach_label(_LabelType_##LABEL_NAME, label_fn_t func, Labels &this_struct) \ { \ func(#LABEL_NAME, this_struct.LABEL_NAME); \ @@ -97,15 +95,13 @@ namespace reducer { using metric_fn_t = std::function; \ \ void foreach_metric(metric_fn_t func) { __foreach_metric(_FirstMetricType(), func, *this); } \ - struct _FirstMetricType { \ - }; \ + struct _FirstMetricType {}; \ typedef _FirstMetricType #define METRIC(METRIC_INFO, METRIC_NAME) \ _MetricType_##METRIC_NAME; \ value_t METRIC_NAME; \ - struct _NextMetricType_##METRIC_NAME { \ - }; \ + struct _NextMetricType_##METRIC_NAME {}; \ static void __foreach_metric(_MetricType_##METRIC_NAME, metric_fn_t func, Metrics &this_struct) \ { \ func(METRIC_INFO, this_struct.METRIC_NAME); \ diff --git a/reducer/matching/flow_span.cc b/reducer/matching/flow_span.cc index 9f0c666b..79947139 100644 --- a/reducer/matching/flow_span.cc +++ b/reducer/matching/flow_span.cc @@ -411,7 +411,8 @@ FlowSpan::NodeData FlowSpan::resolve_node(::ebpf_net::matching::weak_refs::flow AwsEnrichmentInfo const *aws_info = nullptr; if (aws_enrichment_enabled_) { - auto aws_enrichment_span = span_ref.index().aws_enrichment.by_key(ebpf_net::matching::keys::aws_enrichment{ipv6.as_int()}, false); + auto aws_enrichment_span = + span_ref.index().aws_enrichment.by_key(ebpf_net::matching::keys::aws_enrichment{ipv6.as_int()}, false); if (aws_enrichment_span.valid()) { aws_info = aws_enrichment_span.impl().info(); } diff --git a/reducer/prometheus_publisher.h b/reducer/prometheus_publisher.h index 723a311d..efa09d77 100644 --- a/reducer/prometheus_publisher.h +++ b/reducer/prometheus_publisher.h @@ -17,7 +17,6 @@ template <> struct fmt::formatter> : fmt::ostream_formatter {}; - class CivetServer; namespace reducer { diff --git a/reducer/reducer.cc b/reducer/reducer.cc index 41ee6b49..5e3ab038 100644 --- a/reducer/reducer.cc +++ b/reducer/reducer.cc @@ -40,9 +40,7 @@ #include template <> struct fmt::formatter : fmt::ostream_formatter {}; -template -struct fmt::formatter> : fmt::ostream_formatter {}; - +template struct fmt::formatter> : fmt::ostream_formatter {}; namespace reducer { diff --git a/reducer/reducer_config.inl b/reducer/reducer_config.inl index 5a8fc60f..3e7bf571 100644 --- a/reducer/reducer_config.inl +++ b/reducer/reducer_config.inl @@ -5,11 +5,11 @@ #pragma once -#include #include #include #include #include +#include namespace reducer { diff --git a/reducer/thread_safe_map.h b/reducer/thread_safe_map.h index 3458067c..616bd4ac 100644 --- a/reducer/thread_safe_map.h +++ b/reducer/thread_safe_map.h @@ -71,7 +71,10 @@ template class ThreadSafeMap { // Returns the bucket for the given key. Bucket *get_bucket(const Key &key); - const Bucket *get_bucket(const Key &key) const { return const_cast *>(this)->get_bucket(key); } + const Bucket *get_bucket(const Key &key) const + { + return const_cast *>(this)->get_bucket(key); + } // 256 ought to be enough for anybody. static const std::size_t kDefaultBucketCount = 256; From 2ba645c94636a7354b2c580b6d12fd69c4efa04e Mon Sep 17 00:00:00 2001 From: etichy Date: Mon, 14 Oct 2024 09:49:18 +0200 Subject: [PATCH 06/13] Fix --- collector/kernel/main.cc | 3 ++- dev/clang-format.sh | 2 +- reducer/constants.h | 3 ++- reducer/disabled_metrics.h | 10 ++-------- reducer/ingest/agent_span.h | 3 ++- reducer/internal_stats.h | 12 ++++++++---- reducer/otlp_grpc_publisher.cc | 3 ++- reducer/prometheus_publisher.h | 3 ++- reducer/reducer.cc | 6 ++++-- reducer/reducer_config.inl | 3 ++- reducer/thread_safe_map.h | 5 +---- 11 files changed, 28 insertions(+), 25 deletions(-) diff --git a/collector/kernel/main.cc b/collector/kernel/main.cc index c4458312..ba36ca2e 100644 --- a/collector/kernel/main.cc +++ b/collector/kernel/main.cc @@ -63,7 +63,8 @@ static constexpr auto SERVICE_OVERRIDE_VAR = "EBPF_NET_AGENT_SERVICE"; static constexpr auto HOST_OVERRIDE_VAR = "EBPF_NET_AGENT_HOST"; static constexpr auto ZONE_OVERRIDE_VAR = "EBPF_NET_AGENT_ZONE"; -template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter { +}; static void refill_log_rate_limit_cb(uv_timer_t *timer) { LOG::refill_rate_limit_budget(200); diff --git a/dev/clang-format.sh b/dev/clang-format.sh index 1be24092..56af7e2c 100644 --- a/dev/clang-format.sh +++ b/dev/clang-format.sh @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 -CLANG_FORMAT_VERSION="clang-format" +CLANG_FORMAT_VERSION="clang-format-11" if ! command -v ${CLANG_FORMAT_VERSION} then echo "ERROR: requires ${CLANG_FORMAT_VERSION}" diff --git a/reducer/constants.h b/reducer/constants.h index 6556f374..369beedf 100644 --- a/reducer/constants.h +++ b/reducer/constants.h @@ -104,6 +104,7 @@ constexpr VersionInfo MINIMUM_ACCEPTED_VERSION{0, 9, 0}; } // namespace versions::client -template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter { +}; #include diff --git a/reducer/disabled_metrics.h b/reducer/disabled_metrics.h index c0815423..91ac8b39 100644 --- a/reducer/disabled_metrics.h +++ b/reducer/disabled_metrics.h @@ -61,10 +61,7 @@ class DisabledMetrics { // check if a particular metric is disabled #define METRIC_MEMBER_FNS(METRIC, ENUM_TYPE) \ - bool is_metric_disabled(ENUM_TYPE metric) const \ - { \ - return static_cast(metric) & METRIC_FLAG(METRIC); \ - } + bool is_metric_disabled(ENUM_TYPE metric) const { return static_cast(metric) & METRIC_FLAG(METRIC); } METRIC_GROUPS(METRIC_MEMBER_FNS) #undef METRIC_MEMBER_FNS @@ -199,10 +196,7 @@ template void DisabledMetrics::enable_metric(const std::string &met { \ return METRIC_FLAG(METRIC) == static_cast(ENUM_TYPE::all); \ } \ - template <> inline std::uint64_t DisabledMetrics::disabled_flags() const \ - { \ - return METRIC_FLAG(METRIC); \ - } + template <> inline std::uint64_t DisabledMetrics::disabled_flags() const { return METRIC_FLAG(METRIC); } METRIC_GROUPS(METRIC_MEMBER_SPECIALIZATIONS) #undef METRIC_MEMBER_SPECIALIZATIONS diff --git a/reducer/ingest/agent_span.h b/reducer/ingest/agent_span.h index de1488e1..563b0ee5 100644 --- a/reducer/ingest/agent_span.h +++ b/reducer/ingest/agent_span.h @@ -278,4 +278,5 @@ class AgentSpan : public ::ebpf_net::ingest::AgentSpanBase { } // namespace reducer::ingest -template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter { +}; diff --git a/reducer/internal_stats.h b/reducer/internal_stats.h index cf6a6d33..11a5bcb1 100644 --- a/reducer/internal_stats.h +++ b/reducer/internal_stats.h @@ -69,13 +69,15 @@ namespace reducer { struct Labels { \ using label_fn_t = std::function; \ void foreach_label(label_fn_t func) { __foreach_label(_FirstLabelType(), func, *this); } \ - struct _FirstLabelType {}; \ + struct _FirstLabelType { \ + }; \ typedef _FirstLabelType #define LABEL(LABEL_NAME) \ _LabelType_##LABEL_NAME; \ std::string LABEL_NAME; \ - struct _NextLabelType_##LABEL_NAME {}; \ + struct _NextLabelType_##LABEL_NAME { \ + }; \ static void __foreach_label(_LabelType_##LABEL_NAME, label_fn_t func, Labels &this_struct) \ { \ func(#LABEL_NAME, this_struct.LABEL_NAME); \ @@ -95,13 +97,15 @@ namespace reducer { using metric_fn_t = std::function; \ \ void foreach_metric(metric_fn_t func) { __foreach_metric(_FirstMetricType(), func, *this); } \ - struct _FirstMetricType {}; \ + struct _FirstMetricType { \ + }; \ typedef _FirstMetricType #define METRIC(METRIC_INFO, METRIC_NAME) \ _MetricType_##METRIC_NAME; \ value_t METRIC_NAME; \ - struct _NextMetricType_##METRIC_NAME {}; \ + struct _NextMetricType_##METRIC_NAME { \ + }; \ static void __foreach_metric(_MetricType_##METRIC_NAME, metric_fn_t func, Metrics &this_struct) \ { \ func(METRIC_INFO, this_struct.METRIC_NAME); \ diff --git a/reducer/otlp_grpc_publisher.cc b/reducer/otlp_grpc_publisher.cc index 542ea457..32ace0b4 100644 --- a/reducer/otlp_grpc_publisher.cc +++ b/reducer/otlp_grpc_publisher.cc @@ -11,7 +11,8 @@ #include #include -template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter { +}; namespace reducer { OtlpGrpcPublisher::OtlpGrpcPublisher(size_t num_writer_threads, const std::string &server_address_and_port) diff --git a/reducer/prometheus_publisher.h b/reducer/prometheus_publisher.h index efa09d77..c2748ad9 100644 --- a/reducer/prometheus_publisher.h +++ b/reducer/prometheus_publisher.h @@ -15,7 +15,8 @@ #include #include -template <> struct fmt::formatter> : fmt::ostream_formatter {}; +template <> struct fmt::formatter> : fmt::ostream_formatter { +}; class CivetServer; diff --git a/reducer/reducer.cc b/reducer/reducer.cc index 5e3ab038..0de1e993 100644 --- a/reducer/reducer.cc +++ b/reducer/reducer.cc @@ -39,8 +39,10 @@ #include #include -template <> struct fmt::formatter : fmt::ostream_formatter {}; -template struct fmt::formatter> : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter { +}; +template struct fmt::formatter> : fmt::ostream_formatter { +}; namespace reducer { diff --git a/reducer/reducer_config.inl b/reducer/reducer_config.inl index 3e7bf571..0553abbf 100644 --- a/reducer/reducer_config.inl +++ b/reducer/reducer_config.inl @@ -60,4 +60,5 @@ template Out &&operator<<(Out &&out, ReducerConfig const &config) } // namespace reducer -template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter { +}; diff --git a/reducer/thread_safe_map.h b/reducer/thread_safe_map.h index 616bd4ac..3458067c 100644 --- a/reducer/thread_safe_map.h +++ b/reducer/thread_safe_map.h @@ -71,10 +71,7 @@ template class ThreadSafeMap { // Returns the bucket for the given key. Bucket *get_bucket(const Key &key); - const Bucket *get_bucket(const Key &key) const - { - return const_cast *>(this)->get_bucket(key); - } + const Bucket *get_bucket(const Key &key) const { return const_cast *>(this)->get_bucket(key); } // 256 ought to be enough for anybody. static const std::size_t kDefaultBucketCount = 256; From 85c2ec8ab55a36f78c1115535e71989e5743ca4f Mon Sep 17 00:00:00 2001 From: Jaroslav Fedor Date: Mon, 14 Oct 2024 10:21:09 +0200 Subject: [PATCH 07/13] Update build image to support kernel 6 --- .github/workflows/build-and-test.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 15becd4e..9fd39cf5 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -7,8 +7,7 @@ on: pull_request: env: - BENV_IMAGE: public.ecr.aws/u7d6c4a3/solarwinds-opentelemetry-network:benv-exp - + 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 From 30ebe7f20aa39112211439cee11c43f1f37b6005 Mon Sep 17 00:00:00 2001 From: Jakub Racek Date: Mon, 14 Oct 2024 11:53:30 +0200 Subject: [PATCH 08/13] add missing formatters --- otlp/otlp_grpc_client.h | 2 ++ util/json.h | 2 ++ util/log.h | 1 + 3 files changed, 5 insertions(+) diff --git a/otlp/otlp_grpc_client.h b/otlp/otlp_grpc_client.h index 4887f162..ec3e3700 100644 --- a/otlp/otlp_grpc_client.h +++ b/otlp/otlp_grpc_client.h @@ -17,6 +17,8 @@ #include +template <> struct fmt::formatter : fmt::ostream_formatter {}; + using opentelemetry::proto::collector::logs::v1::ExportLogsServiceRequest; using opentelemetry::proto::collector::logs::v1::ExportLogsServiceResponse; using opentelemetry::proto::collector::logs::v1::LogsService; diff --git a/util/json.h b/util/json.h index 62d00244..b2b42834 100644 --- a/util/json.h +++ b/util/json.h @@ -13,6 +13,8 @@ #include +template <> struct fmt::formatter : fmt::ostream_formatter {}; + inline nlohmann::json const *follow_path(nlohmann::json const &object) { return &object; diff --git a/util/log.h b/util/log.h index abf3c7b3..70e70127 100644 --- a/util/log.h +++ b/util/log.h @@ -31,6 +31,7 @@ template <> struct fmt::formatter : fmt::ostream_form template <> struct fmt::formatter : fmt::ostream_formatter {}; template <> struct fmt::formatter : fmt::ostream_formatter {}; template struct fmt::formatter> : fmt::ostream_formatter {}; +template struct fmt::formatter> : fmt::ostream_formatter {}; class LOG { public: From 8b7bb7cb845fef062618598a82cf12d69c798405 Mon Sep 17 00:00:00 2001 From: Jakub Racek Date: Mon, 14 Oct 2024 11:59:15 +0200 Subject: [PATCH 09/13] add missing headers --- util/json.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util/json.h b/util/json.h index b2b42834..02819f98 100644 --- a/util/json.h +++ b/util/json.h @@ -6,6 +6,10 @@ #pragma once #include +#include +#include +#include +#include #include #include From dcf571820ae62d092a6aae65338f8c77681bd925 Mon Sep 17 00:00:00 2001 From: Jakub Racek Date: Mon, 14 Oct 2024 12:24:54 +0200 Subject: [PATCH 10/13] remove redundant formatters --- reducer/otlp_grpc_publisher.cc | 2 -- util/nomad_metadata.cc | 2 -- 2 files changed, 4 deletions(-) diff --git a/reducer/otlp_grpc_publisher.cc b/reducer/otlp_grpc_publisher.cc index 32ace0b4..4e5dbcf9 100644 --- a/reducer/otlp_grpc_publisher.cc +++ b/reducer/otlp_grpc_publisher.cc @@ -11,8 +11,6 @@ #include #include -template <> struct fmt::formatter : fmt::ostream_formatter { -}; namespace reducer { OtlpGrpcPublisher::OtlpGrpcPublisher(size_t num_writer_threads, const std::string &server_address_and_port) diff --git a/util/nomad_metadata.cc b/util/nomad_metadata.cc index 842f2884..112f9f8d 100644 --- a/util/nomad_metadata.cc +++ b/util/nomad_metadata.cc @@ -11,8 +11,6 @@ #include -template <> struct fmt::formatter> : fmt::ostream_formatter {}; - const std::string NOMAD_NAMESPACE_VAR = "NOMAD_NAMESPACE"; const std::string NOMAD_GROUP_NAME_VAR = "NOMAD_GROUP_NAME"; const std::string NOMAD_TASK_NAME_VAR = "NOMAD_TASK_NAME"; From 2ac2892ba2db4945162b66542314e1d6ab1dfdca Mon Sep 17 00:00:00 2001 From: Jakub Racek Date: Tue, 15 Oct 2024 09:59:11 +0200 Subject: [PATCH 11/13] Added fence to counters to prevent data race --- util/counter_to_rate.h | 3 ++- util/counter_to_rate.inl | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/util/counter_to_rate.h b/util/counter_to_rate.h index c2248edb..51381148 100644 --- a/util/counter_to_rate.h +++ b/util/counter_to_rate.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include @@ -18,7 +19,7 @@ template struct CounterToRate { constexpr CounterToRate(T data, T prev = {}) : value_{std::move(data)}, prev_{std::move(prev)}, count_{1} {} - constexpr T peek_rate() const { return value_ - prev_; } + constexpr T peek_rate() const { std::atomic_thread_fence(std::memory_order_acquire); return value_ - prev_; } constexpr T commit_rate(bool empty_if_unitary = false); constexpr T const &value() const { return value_; } diff --git a/util/counter_to_rate.inl b/util/counter_to_rate.inl index 01031bd2..30df8fe9 100644 --- a/util/counter_to_rate.inl +++ b/util/counter_to_rate.inl @@ -12,7 +12,10 @@ namespace data { template constexpr T CounterToRate::commit_rate(bool empty_if_unitary) { T choice[2] = {value_ - prev_, T{}}; + std::atomic_thread_fence(std::memory_order_release); prev_ = value_; + + std::atomic_thread_fence(std::memory_order_acquire); return choice[empty_if_unitary & (count_ < 2)]; } From 268eba1cb4d044c9223a2cad9a177a4568cade6e Mon Sep 17 00:00:00 2001 From: jakub-racek-swi Date: Tue, 15 Oct 2024 14:04:09 +0000 Subject: [PATCH 12/13] upgrade collector base image versions, use bpf_probe_kernel when available --- collector/cloud/Dockerfile | 2 +- collector/k8s/Dockerfile | 2 +- collector/k8s/k8s-watcher/Dockerfile | 2 +- collector/kernel/Dockerfile | 7 +- collector/kernel/bpf_src/render_bpf.c | 157 ++++++++++-------- .../kernel_collector_test_docker/Dockerfile | 2 +- reducer/Dockerfile | 2 +- 7 files changed, 100 insertions(+), 74 deletions(-) diff --git a/collector/cloud/Dockerfile b/collector/cloud/Dockerfile index 004c4a85..093d414e 100644 --- a/collector/cloud/Dockerfile +++ b/collector/cloud/Dockerfile @@ -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" diff --git a/collector/k8s/Dockerfile b/collector/k8s/Dockerfile index cac4b008..38957502 100644 --- a/collector/k8s/Dockerfile +++ b/collector/k8s/Dockerfile @@ -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" diff --git a/collector/k8s/k8s-watcher/Dockerfile b/collector/k8s/k8s-watcher/Dockerfile index 7acd48a7..4f7c38ad 100644 --- a/collector/k8s/k8s-watcher/Dockerfile +++ b/collector/k8s/k8s-watcher/Dockerfile @@ -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" diff --git a/collector/kernel/Dockerfile b/collector/kernel/Dockerfile index edd903ca..a3536bc3 100644 --- a/collector/kernel/Dockerfile +++ b/collector/kernel/Dockerfile @@ -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" @@ -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; \ diff --git a/collector/kernel/bpf_src/render_bpf.c b/collector/kernel/bpf_src/render_bpf.c index 5692573e..a5992d94 100644 --- a/collector/kernel/bpf_src/render_bpf.c +++ b/collector/kernel/bpf_src/render_bpf.c @@ -14,8 +14,10 @@ #pragma clang diagnostic ignored "-Wenum-conversion" #pragma clang diagnostic ignored "-Wtautological-compare" #include -#pragma clang diagnostic pop +#include // BCC helper functions +#include +// Other necessary imports #include #include #include @@ -40,6 +42,7 @@ // Configuration #include "config.h" #include "render_bpf.h" + // Perf events BPF_PERF_OUTPUT(events); #include "ebpf_net/agent_internal/bpf.h" @@ -53,6 +56,12 @@ static u64 abs_val(int val) return val < 0 ? -val : val; } +#if __has_builtin(__builtin_bpf_probe_read_kernel) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0) +#define my_bpf_probe_read(dst, size, src) bpf_probe_read_kernel(dst, size, src) +#else +#define my_bpf_probe_read(dst, size, src) bpf_probe_read(dst, size, src) +#endif + // using constants for placeholders for readability after code dump #pragma passthrough on #define REPORT_DEBUG_EVENTS REPORT_DEBUG_EVENTS_PLACEHOLDER @@ -66,17 +75,23 @@ struct pkts_if_t { u32 retrans_out; }; +// Function to get packets in flight from tcp_sock static inline u32 packets_in_flight_helper(struct sock *sk) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0) struct tcp_sock *tp; + tp = (struct tcp_sock *)sk; +#else + struct tcp_sock *tp = tcp_sk(sk) +#endif struct pkts_if_t t = {}; - tp = tcp_sk(sk); + my_bpf_probe_read(&t.packets_out, sizeof(u32), &tp->packets_out); + my_bpf_probe_read(&t.sacked_out, sizeof(u32), &tp->sacked_out); + my_bpf_probe_read(&t.lost_out, sizeof(u32), &tp->lost_out); + my_bpf_probe_read(&t.retrans_out, sizeof(u32), &tp->retrans_out); - bpf_probe_read_kernel(&t.packets_out, sizeof(u32), &tp->packets_out); - bpf_probe_read_kernel(&t.sacked_out, sizeof(u32), &tp->sacked_out); - bpf_probe_read_kernel(&t.lost_out, sizeof(u32), &tp->lost_out); - bpf_probe_read_kernel(&t.retrans_out, sizeof(u32), &tp->retrans_out); + // Calculate packets in flight return t.packets_out - (t.sacked_out + t.lost_out) + t.retrans_out; } @@ -221,7 +236,7 @@ static int task_is_group_leader(struct pt_regs *ctx, struct task_struct *tsk) } struct task_struct *group_leader = NULL; - ret = bpf_probe_read(&group_leader, sizeof(group_leader), &tsk->group_leader); + ret = my_bpf_probe_read(&group_leader, sizeof(group_leader), &tsk->group_leader); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -248,7 +263,7 @@ static u64 get_task_cgroup(struct pt_regs *ctx, struct task_struct *tsk) } struct css_set *set = NULL; - ret = bpf_probe_read(&set, sizeof(set), &tsk->cgroups); + ret = my_bpf_probe_read(&set, sizeof(set), &tsk->cgroups); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -259,7 +274,7 @@ static u64 get_task_cgroup(struct pt_regs *ctx, struct task_struct *tsk) } struct cgroup_subsys_state *css = NULL; - ret = bpf_probe_read(&css, sizeof(css), &set->subsys[FLOW_CGROUP_SUBSYS]); + ret = my_bpf_probe_read(&css, sizeof(css), &set->subsys[FLOW_CGROUP_SUBSYS]); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -270,7 +285,7 @@ static u64 get_task_cgroup(struct pt_regs *ctx, struct task_struct *tsk) } struct cgroup *cgrp = NULL; - ret = bpf_probe_read(&cgrp, sizeof(cgrp), &css->cgroup); + ret = my_bpf_probe_read(&cgrp, sizeof(cgrp), &css->cgroup); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -288,14 +303,14 @@ static pid_t get_task_parent(struct pt_regs *ctx, struct task_struct *tsk) int ret = 0; struct task_struct *parent_tsk = NULL; - ret = bpf_probe_read(&parent_tsk, sizeof(parent_tsk), &tsk->parent); + ret = my_bpf_probe_read(&parent_tsk, sizeof(parent_tsk), &tsk->parent); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return -1; } pid_t parent_tgid = 0; - ret = bpf_probe_read(&parent_tgid, sizeof(parent_tgid), &parent_tsk->tgid); + ret = my_bpf_probe_read(&parent_tgid, sizeof(parent_tgid), &parent_tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return -1; @@ -371,7 +386,7 @@ int on_cgroup_exit(struct pt_regs *ctx, struct task_struct *tsk) { int ret; pid_t tgid = 0; - ret = bpf_probe_read(&tgid, sizeof(tgid), &(tsk->tgid)); + ret = my_bpf_probe_read(&tgid, sizeof(tgid), &(tsk->tgid)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -436,7 +451,7 @@ int on_set_task_comm(struct pt_regs *ctx, struct task_struct *tsk, const char *b u64 now = get_timestamp(); pid_t tgid = 0; - ret = bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); + ret = my_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -452,7 +467,7 @@ int on_wake_up_new_task(struct pt_regs *ctx, struct task_struct *tsk) int ret; pid_t tgid = 0; - ret = bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); + ret = my_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -468,7 +483,7 @@ int on_wake_up_new_task(struct pt_regs *ctx, struct task_struct *tsk) pid_t parent_tgid = get_task_parent(ctx, tsk); u8 comm[16] = {}; - ret = bpf_probe_read(comm, sizeof(comm), tsk->comm); + ret = my_bpf_probe_read(comm, sizeof(comm), tsk->comm); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -486,7 +501,7 @@ int onret_get_pid_task(struct pt_regs *ctx) struct task_struct *tsk = (struct task_struct *)PT_REGS_RC(ctx); pid_t tgid = 0; - ret = bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); + ret = my_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), (u64)tsk, 0); return 0; @@ -502,7 +517,7 @@ int onret_get_pid_task(struct pt_regs *ctx) pid_t parent_tgid = get_task_parent(ctx, tsk); u8 comm[16] = {}; - ret = bpf_probe_read(comm, sizeof(comm), tsk->comm); + ret = my_bpf_probe_read(comm, sizeof(comm), tsk->comm); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -517,19 +532,25 @@ int onret_get_pid_task(struct pt_regs *ctx) /* TCP SOCKETS */ static inline u32 tcp_get_delivered(struct sock *sk) { - struct tcp_sock *tp = tcp_sk(sk); +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0) + struct tcp_sock *tp; + tp = (struct tcp_sock *)sk; +#else + struct tcp_sock *tp = tcp_sk(sk) +#endif + /* delivered accounting was introduced in ddf1af6fa00e77, i.e., * v4.6-rc1~91^2~316^2~3 */ #pragma passthrough on #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) u32 packets_out = 0; u32 sacked_out = 0; - bpf_probe_read(&packets_out, sizeof(packets_out), &tp->packets_out); - bpf_probe_read(&sacked_out, sizeof(sacked_out), &tp->sacked_out); + my_bpf_probe_read(&packets_out, sizeof(packets_out), &tp->packets_out); + my_bpf_probe_read(&sacked_out, sizeof(sacked_out), &tp->sacked_out); return packets_out - sacked_out; #else u32 delivered = 0; - bpf_probe_read(&delivered, sizeof(delivered), &tp->delivered); + my_bpf_probe_read(&delivered, sizeof(delivered), &tp->delivered); return delivered; #endif #pragma passthrough off @@ -544,13 +565,13 @@ report_rtt_estimator(struct pt_regs *ctx, struct sock *sk, struct tcp_open_socke u32 rcv_rtt_us = 0; #pragma passthrough on #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0) - bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt); + my_bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt); #else /* #if LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0) */ - bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt_us); + my_bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt_us); #endif #pragma passthrough off - // These values need to be taken from bpf_probe_read + // These values need to be taken from my_bpf_probe_read u32 srtt = 0; u32 snd_cwnd = 0; u64 bytes_acked = 0; @@ -558,37 +579,37 @@ report_rtt_estimator(struct pt_regs *ctx, struct sock *sk, struct tcp_open_socke u32 packets_retrans = 0; u64 bytes_received = 0; - ret = bpf_probe_read(&srtt, sizeof(srtt), &(tcp_sk(sk)->srtt_us)); + ret = my_bpf_probe_read(&srtt, sizeof(srtt), &(tcp_sk(sk)->srtt_us)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&snd_cwnd, sizeof(snd_cwnd), &(tcp_sk(sk)->snd_cwnd)); + ret = my_bpf_probe_read(&snd_cwnd, sizeof(snd_cwnd), &(tcp_sk(sk)->snd_cwnd)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); + ret = my_bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&ca_state, sizeof(ca_state), &(*(&(inet_csk(sk)->icsk_sync_mss) + 1))); + ret = my_bpf_probe_read(&ca_state, sizeof(ca_state), &(*(&(inet_csk(sk)->icsk_sync_mss) + 1))); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); + ret = my_bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); + ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; @@ -647,7 +668,7 @@ static int add_tcp_open_socket(struct pt_regs *ctx, struct sock *sk, u32 tgid, u #endif }; - ret = bpf_probe_read(&sk_info.bytes_received, sizeof(sk_info.bytes_received), &tcp_sk(sk)->bytes_received); + ret = my_bpf_probe_read(&sk_info.bytes_received, sizeof(sk_info.bytes_received), &tcp_sk(sk)->bytes_received); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return -1; @@ -707,7 +728,7 @@ static void remove_tcp_open_socket(struct pt_regs *ctx, struct sock *sk) static inline void submit_set_state_ipv6(struct pt_regs *ctx, u64 now, int tx_rx, struct sock *sk) { struct sock *skp = NULL; - bpf_probe_read(&skp, sizeof(skp), &sk); + my_bpf_probe_read(&skp, sizeof(skp), &sk); if (!skp) { bpf_log(ctx, BPF_LOG_INVALID_POINTER, 0, 0, 0); return; @@ -716,11 +737,11 @@ static inline void submit_set_state_ipv6(struct pt_regs *ctx, u64 now, int tx_rx u16 sport = 0; uint8_t daddr[16] = {}; uint8_t saddr[16] = {}; - // These values need to be taken from bpf_probe_read - bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); - bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); - bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(sk->sk_v6_daddr.in6_u.u6_addr32)); - bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(sk->sk_v6_rcv_saddr.in6_u.u6_addr32)); + // These values need to be taken from my_bpf_probe_read + my_bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); + my_bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); + my_bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(sk->sk_v6_daddr.in6_u.u6_addr32)); + my_bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(sk->sk_v6_rcv_saddr.in6_u.u6_addr32)); perf_submit_agent_internal__set_state_ipv6(ctx, now, daddr, saddr, ntohs(dport), sport, (__u64)sk, tx_rx); } @@ -728,16 +749,16 @@ static inline void submit_set_state_ipv6(struct pt_regs *ctx, u64 now, int tx_rx static inline void submit_set_state_ipv4(struct pt_regs *ctx, u64 now, int tx_rx, struct sock *sk) { struct sock *skp = NULL; - bpf_probe_read(&skp, sizeof(skp), &sk); + my_bpf_probe_read(&skp, sizeof(skp), &sk); if (!skp) { bpf_log(ctx, BPF_LOG_INVALID_POINTER, 0, 0, 0); return; } u16 dport = 0; u16 sport = 0; - // These values need to be taken from bpf_probe_read - bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); - bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); + // These values need to be taken from my_bpf_probe_read + my_bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); + my_bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); perf_submit_agent_internal__set_state_ipv4(ctx, now, sk->sk_daddr, sk->sk_rcv_saddr, ntohs(dport), sport, (__u64)sk, tx_rx); } @@ -749,19 +770,19 @@ static inline void submit_reset_tcp_counters(struct pt_regs *ctx, u64 now, u64 p u32 packets_retrans = 0; u64 bytes_received = 0; - ret = bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); + ret = my_bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); + ret = my_bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); + ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; @@ -1048,7 +1069,7 @@ int onret_inet_csk_accept(struct pt_regs *ctx) // filter out non-tcp connections u16 family = 0; - bpf_probe_read(&family, sizeof(family), &newsk->sk_family); + my_bpf_probe_read(&family, sizeof(family), &newsk->sk_family); if (family != AF_INET && family != AF_INET6) { #if DEBUG_TCP_SOCKET_ERRORS bpf_trace_printk("onret_inet_csk_accept: family is not ipv4 or ipv6 sk=%llx\n", newsk); @@ -1098,8 +1119,8 @@ int onret_inet_csk_accept(struct pt_regs *ctx) // Set the state u16 dport = 0; u16 sport = 0; - bpf_probe_read(&dport, sizeof(dport), &newsk->sk_dport); - bpf_probe_read(&sport, sizeof(sport), &newsk->sk_num); + my_bpf_probe_read(&dport, sizeof(dport), &newsk->sk_dport); + my_bpf_probe_read(&sport, sizeof(sport), &newsk->sk_num); if (family == AF_INET) { perf_submit_agent_internal__set_state_ipv4( @@ -1107,8 +1128,8 @@ int onret_inet_csk_accept(struct pt_regs *ctx) } else if (family == AF_INET6) { uint8_t daddr[16] = {}; uint8_t saddr[16] = {}; - bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(newsk->sk_v6_daddr.in6_u.u6_addr32)); - bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(newsk->sk_v6_rcv_saddr.in6_u.u6_addr32)); + my_bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(newsk->sk_v6_daddr.in6_u.u6_addr32)); + my_bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(newsk->sk_v6_rcv_saddr.in6_u.u6_addr32)); perf_submit_agent_internal__set_state_ipv6(ctx, now, daddr, saddr, ntohs(dport), sport, (__u64)newsk, 2); } @@ -1223,7 +1244,7 @@ static int ensure_udp_existing(struct pt_regs *ctx, struct sock *sk, u32 tgid) } u16 lport = 0; - bpf_probe_read(&lport, sizeof(lport), &(inet_sk(sk)->inet_num)); + my_bpf_probe_read(&lport, sizeof(lport), &(inet_sk(sk)->inet_num)); perf_submit_agent_internal__udp_new_socket(ctx, now, tgid, (__u64)sk, (uint8_t *)(&addr), lport); } return ret; @@ -1497,7 +1518,7 @@ int on_inet_release(struct pt_regs *ctx, struct socket *sock) GET_PID_TGID; struct sock *sk = NULL; - bpf_probe_read(&sk, sizeof(sk), &sock->sk); + my_bpf_probe_read(&sk, sizeof(sk), &sock->sk); if (!sk) { return 0; @@ -1754,7 +1775,7 @@ int on_ip_send_skb(struct pt_regs *ctx, struct net *net, struct sk_buff *skb) struct tcphdr *tcp_hdr = (struct tcphdr *)(skb->head + skb->transport_header); u16 flags = 0; - bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); + my_bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); if (flags & TCP_FLAG_RST) { // bpf_trace_printk("on_ip_send_skb: tcp rst is set\n"); @@ -1794,7 +1815,7 @@ int on_ip6_send_skb(struct pt_regs *ctx, struct sk_buff *skb) struct tcphdr *tcp_hdr = (struct tcphdr *)(skb->head + skb->transport_header); u16 flags = 0; - bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); + my_bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); if (flags & TCP_FLAG_RST) { // bpf_trace_printk("on_ip6_send_skb: tcp rst is set\n"); @@ -1824,7 +1845,7 @@ int handle_receive_udp_skb(struct pt_regs *ctx, struct sock *sk, struct sk_buff // get the version from the ip packet (common location for ipv4 and ipv6) u8 version; - bpf_probe_read(&version, 1, (const u8 *)ip_hdr); + my_bpf_probe_read(&version, 1, (const u8 *)ip_hdr); version &= 0xF0; // Parse the addresses out of the header @@ -1910,7 +1931,7 @@ int on_tcp_rcv_established(struct pt_regs *ctx, struct sock *sk, struct sk_buff int ret; u64 bytes_received = 0; - ret = bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); + ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -1942,7 +1963,7 @@ int on_tcp_event_data_recv(struct pt_regs *ctx, struct sock *sk, struct sk_buff int ret; u64 bytes_received = 0; - ret = bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); + ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -2005,7 +2026,7 @@ int on_tcp_syn_ack_timeout( #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) /* Linux<4.4 does not have req->rsk_listener */ struct sock *sk = NULL; - bpf_probe_read(&sk, sizeof(sk), &(req->sk)); + my_bpf_probe_read(&sk, sizeof(sk), &(req->sk)); struct tcp_open_socket_t *sk_info; sk_info = tcp_open_sockets.lookup(&sk); @@ -2023,7 +2044,7 @@ int on_tcp_syn_ack_timeout( #else struct sock *sk = NULL; - bpf_probe_read(&sk, sizeof(sk), &(req->sk)); + my_bpf_probe_read(&sk, sizeof(sk), &(req->sk)); if (sk == NULL) { bpf_log(ctx, BPF_LOG_UNREACHABLE, 0, 0, 0); return 0; @@ -2060,7 +2081,7 @@ static void perf_check_and_submit_dns(struct pt_regs *ctx, struct sock *sk, struct sk_buff *skb, u8 proto, u16 sport, u16 dport, int is_rx) { unsigned int len = 0; - bpf_probe_read(&len, sizeof(len), &skb->len); + my_bpf_probe_read(&len, sizeof(len), &skb->len); // Filter for DNS requests and responses if (!((proto == IPPROTO_UDP) && ((sport == htons(53)) || (dport == htons(53))) && (len > 0))) { @@ -2071,35 +2092,35 @@ perf_check_and_submit_dns(struct pt_regs *ctx, struct sock *sk, struct sk_buff * int ret; unsigned int skb_data_len = 0; - ret = bpf_probe_read(&skb_data_len, sizeof(skb->data_len), &skb->data_len); + ret = my_bpf_probe_read(&skb_data_len, sizeof(skb->data_len), &skb->data_len); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } unsigned char *from = NULL; - ret = bpf_probe_read(&from, sizeof(skb->data), &skb->data); + ret = my_bpf_probe_read(&from, sizeof(skb->data), &skb->data); if (ret != 0 || from == NULL) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } unsigned char *skb_head = NULL; - ret = bpf_probe_read(&skb_head, sizeof(skb->head), &skb->head); + ret = my_bpf_probe_read(&skb_head, sizeof(skb->head), &skb->head); if (ret != 0 || skb_head == NULL) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } u16 skb_transport_header = 0; - ret = bpf_probe_read(&skb_transport_header, sizeof(skb->transport_header), &skb->transport_header); + ret = my_bpf_probe_read(&skb_transport_header, sizeof(skb->transport_header), &skb->transport_header); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } u16 skb_network_header = 0; - ret = bpf_probe_read(&skb_network_header, sizeof(skb->network_header), &skb->network_header); + ret = my_bpf_probe_read(&skb_network_header, sizeof(skb->network_header), &skb->network_header); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; @@ -2169,7 +2190,7 @@ perf_check_and_submit_dns(struct pt_regs *ctx, struct sock *sk, struct sk_buff * /* the actual offset into buf has to start from buf's start */ char *to = buf + bpf_agent_internal__dns_packet__data_size; - bpf_probe_read(to, DNS_MAX_PACKET_LEN, from); + my_bpf_probe_read(to, DNS_MAX_PACKET_LEN, from); struct bpf_agent_internal__dns_packet *const msg = (struct bpf_agent_internal__dns_packet *)&buf[0]; struct jb_blob blob = {to, valid_len}; @@ -2280,7 +2301,7 @@ int on_kill_css(struct pt_regs *ctx, struct cgroup_subsys_state *css) int on_cgroup_destroy_locked(struct pt_regs *ctx, struct cgroup *cgrp) { struct cgroup_subsys_state *css = NULL; - bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); + my_bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); if (css == NULL) return 0; @@ -2312,7 +2333,7 @@ int on_css_populate_dir(struct pt_regs *ctx, struct cgroup_subsys_state *css) int on_cgroup_populate_dir(struct pt_regs *ctx, struct cgroup *cgrp, unsigned long subsys_mask) { struct cgroup_subsys_state *css = NULL; - bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); + my_bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); if (css == NULL) return 0; diff --git a/collector/kernel/kernel_collector_test_docker/Dockerfile b/collector/kernel/kernel_collector_test_docker/Dockerfile index 915c1499..30f7785d 100644 --- a/collector/kernel/kernel_collector_test_docker/Dockerfile +++ b/collector/kernel/kernel_collector_test_docker/Dockerfile @@ -1,7 +1,7 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -FROM bitnami/minideb:bullseye +FROM bitnami/minideb:bookworm # ca-certificates are required by libcurl RUN install_packages ca-certificates diff --git a/reducer/Dockerfile b/reducer/Dockerfile index 6180151b..810dbf82 100644 --- a/reducer/Dockerfile +++ b/reducer/Dockerfile @@ -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-reducer" LABEL org.label-schema.description="OpenTelemetry eBPF reducer" From 91527ddf43a64f5a81b810e9543da9105ca7f167 Mon Sep 17 00:00:00 2001 From: jakub-racek-swi Date: Tue, 15 Oct 2024 14:08:45 +0000 Subject: [PATCH 13/13] rename bpf read function --- collector/kernel/bpf_src/render_bpf.c | 134 +++++++++++++------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/collector/kernel/bpf_src/render_bpf.c b/collector/kernel/bpf_src/render_bpf.c index a5992d94..d387ad5d 100644 --- a/collector/kernel/bpf_src/render_bpf.c +++ b/collector/kernel/bpf_src/render_bpf.c @@ -57,9 +57,9 @@ static u64 abs_val(int val) } #if __has_builtin(__builtin_bpf_probe_read_kernel) || LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0) -#define my_bpf_probe_read(dst, size, src) bpf_probe_read_kernel(dst, size, src) +#define use_bpf_probe_read(dst, size, src) bpf_probe_read_kernel(dst, size, src) #else -#define my_bpf_probe_read(dst, size, src) bpf_probe_read(dst, size, src) +#define use_bpf_probe_read(dst, size, src) bpf_probe_read(dst, size, src) #endif // using constants for placeholders for readability after code dump @@ -86,10 +86,10 @@ static inline u32 packets_in_flight_helper(struct sock *sk) #endif struct pkts_if_t t = {}; - my_bpf_probe_read(&t.packets_out, sizeof(u32), &tp->packets_out); - my_bpf_probe_read(&t.sacked_out, sizeof(u32), &tp->sacked_out); - my_bpf_probe_read(&t.lost_out, sizeof(u32), &tp->lost_out); - my_bpf_probe_read(&t.retrans_out, sizeof(u32), &tp->retrans_out); + use_bpf_probe_read(&t.packets_out, sizeof(u32), &tp->packets_out); + use_bpf_probe_read(&t.sacked_out, sizeof(u32), &tp->sacked_out); + use_bpf_probe_read(&t.lost_out, sizeof(u32), &tp->lost_out); + use_bpf_probe_read(&t.retrans_out, sizeof(u32), &tp->retrans_out); // Calculate packets in flight return t.packets_out - (t.sacked_out + t.lost_out) + t.retrans_out; @@ -236,7 +236,7 @@ static int task_is_group_leader(struct pt_regs *ctx, struct task_struct *tsk) } struct task_struct *group_leader = NULL; - ret = my_bpf_probe_read(&group_leader, sizeof(group_leader), &tsk->group_leader); + ret = use_bpf_probe_read(&group_leader, sizeof(group_leader), &tsk->group_leader); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -263,7 +263,7 @@ static u64 get_task_cgroup(struct pt_regs *ctx, struct task_struct *tsk) } struct css_set *set = NULL; - ret = my_bpf_probe_read(&set, sizeof(set), &tsk->cgroups); + ret = use_bpf_probe_read(&set, sizeof(set), &tsk->cgroups); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -274,7 +274,7 @@ static u64 get_task_cgroup(struct pt_regs *ctx, struct task_struct *tsk) } struct cgroup_subsys_state *css = NULL; - ret = my_bpf_probe_read(&css, sizeof(css), &set->subsys[FLOW_CGROUP_SUBSYS]); + ret = use_bpf_probe_read(&css, sizeof(css), &set->subsys[FLOW_CGROUP_SUBSYS]); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -285,7 +285,7 @@ static u64 get_task_cgroup(struct pt_regs *ctx, struct task_struct *tsk) } struct cgroup *cgrp = NULL; - ret = my_bpf_probe_read(&cgrp, sizeof(cgrp), &css->cgroup); + ret = use_bpf_probe_read(&cgrp, sizeof(cgrp), &css->cgroup); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -303,14 +303,14 @@ static pid_t get_task_parent(struct pt_regs *ctx, struct task_struct *tsk) int ret = 0; struct task_struct *parent_tsk = NULL; - ret = my_bpf_probe_read(&parent_tsk, sizeof(parent_tsk), &tsk->parent); + ret = use_bpf_probe_read(&parent_tsk, sizeof(parent_tsk), &tsk->parent); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return -1; } pid_t parent_tgid = 0; - ret = my_bpf_probe_read(&parent_tgid, sizeof(parent_tgid), &parent_tsk->tgid); + ret = use_bpf_probe_read(&parent_tgid, sizeof(parent_tgid), &parent_tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return -1; @@ -386,7 +386,7 @@ int on_cgroup_exit(struct pt_regs *ctx, struct task_struct *tsk) { int ret; pid_t tgid = 0; - ret = my_bpf_probe_read(&tgid, sizeof(tgid), &(tsk->tgid)); + ret = use_bpf_probe_read(&tgid, sizeof(tgid), &(tsk->tgid)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -451,7 +451,7 @@ int on_set_task_comm(struct pt_regs *ctx, struct task_struct *tsk, const char *b u64 now = get_timestamp(); pid_t tgid = 0; - ret = my_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); + ret = use_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -467,7 +467,7 @@ int on_wake_up_new_task(struct pt_regs *ctx, struct task_struct *tsk) int ret; pid_t tgid = 0; - ret = my_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); + ret = use_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -483,7 +483,7 @@ int on_wake_up_new_task(struct pt_regs *ctx, struct task_struct *tsk) pid_t parent_tgid = get_task_parent(ctx, tsk); u8 comm[16] = {}; - ret = my_bpf_probe_read(comm, sizeof(comm), tsk->comm); + ret = use_bpf_probe_read(comm, sizeof(comm), tsk->comm); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -501,7 +501,7 @@ int onret_get_pid_task(struct pt_regs *ctx) struct task_struct *tsk = (struct task_struct *)PT_REGS_RC(ctx); pid_t tgid = 0; - ret = my_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); + ret = use_bpf_probe_read(&tgid, sizeof(tgid), &tsk->tgid); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), (u64)tsk, 0); return 0; @@ -517,7 +517,7 @@ int onret_get_pid_task(struct pt_regs *ctx) pid_t parent_tgid = get_task_parent(ctx, tsk); u8 comm[16] = {}; - ret = my_bpf_probe_read(comm, sizeof(comm), tsk->comm); + ret = use_bpf_probe_read(comm, sizeof(comm), tsk->comm); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -545,12 +545,12 @@ static inline u32 tcp_get_delivered(struct sock *sk) #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) u32 packets_out = 0; u32 sacked_out = 0; - my_bpf_probe_read(&packets_out, sizeof(packets_out), &tp->packets_out); - my_bpf_probe_read(&sacked_out, sizeof(sacked_out), &tp->sacked_out); + use_bpf_probe_read(&packets_out, sizeof(packets_out), &tp->packets_out); + use_bpf_probe_read(&sacked_out, sizeof(sacked_out), &tp->sacked_out); return packets_out - sacked_out; #else u32 delivered = 0; - my_bpf_probe_read(&delivered, sizeof(delivered), &tp->delivered); + use_bpf_probe_read(&delivered, sizeof(delivered), &tp->delivered); return delivered; #endif #pragma passthrough off @@ -565,13 +565,13 @@ report_rtt_estimator(struct pt_regs *ctx, struct sock *sk, struct tcp_open_socke u32 rcv_rtt_us = 0; #pragma passthrough on #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 12, 0) - my_bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt); + use_bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt); #else /* #if LINUX_VERSION_CODE < KERNEL_VERSION(4,12,0) */ - my_bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt_us); + use_bpf_probe_read(&rcv_rtt_us, sizeof(rcv_rtt_us), &tcp_sk(sk)->rcv_rtt_est.rtt_us); #endif #pragma passthrough off - // These values need to be taken from my_bpf_probe_read + // These values need to be taken from use_bpf_probe_read u32 srtt = 0; u32 snd_cwnd = 0; u64 bytes_acked = 0; @@ -579,37 +579,37 @@ report_rtt_estimator(struct pt_regs *ctx, struct sock *sk, struct tcp_open_socke u32 packets_retrans = 0; u64 bytes_received = 0; - ret = my_bpf_probe_read(&srtt, sizeof(srtt), &(tcp_sk(sk)->srtt_us)); + ret = use_bpf_probe_read(&srtt, sizeof(srtt), &(tcp_sk(sk)->srtt_us)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&snd_cwnd, sizeof(snd_cwnd), &(tcp_sk(sk)->snd_cwnd)); + ret = use_bpf_probe_read(&snd_cwnd, sizeof(snd_cwnd), &(tcp_sk(sk)->snd_cwnd)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); + ret = use_bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&ca_state, sizeof(ca_state), &(*(&(inet_csk(sk)->icsk_sync_mss) + 1))); + ret = use_bpf_probe_read(&ca_state, sizeof(ca_state), &(*(&(inet_csk(sk)->icsk_sync_mss) + 1))); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); + ret = use_bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); + ret = use_bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; @@ -668,7 +668,7 @@ static int add_tcp_open_socket(struct pt_regs *ctx, struct sock *sk, u32 tgid, u #endif }; - ret = my_bpf_probe_read(&sk_info.bytes_received, sizeof(sk_info.bytes_received), &tcp_sk(sk)->bytes_received); + ret = use_bpf_probe_read(&sk_info.bytes_received, sizeof(sk_info.bytes_received), &tcp_sk(sk)->bytes_received); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return -1; @@ -728,7 +728,7 @@ static void remove_tcp_open_socket(struct pt_regs *ctx, struct sock *sk) static inline void submit_set_state_ipv6(struct pt_regs *ctx, u64 now, int tx_rx, struct sock *sk) { struct sock *skp = NULL; - my_bpf_probe_read(&skp, sizeof(skp), &sk); + use_bpf_probe_read(&skp, sizeof(skp), &sk); if (!skp) { bpf_log(ctx, BPF_LOG_INVALID_POINTER, 0, 0, 0); return; @@ -737,11 +737,11 @@ static inline void submit_set_state_ipv6(struct pt_regs *ctx, u64 now, int tx_rx u16 sport = 0; uint8_t daddr[16] = {}; uint8_t saddr[16] = {}; - // These values need to be taken from my_bpf_probe_read - my_bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); - my_bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); - my_bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(sk->sk_v6_daddr.in6_u.u6_addr32)); - my_bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(sk->sk_v6_rcv_saddr.in6_u.u6_addr32)); + // These values need to be taken from use_bpf_probe_read + use_bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); + use_bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); + use_bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(sk->sk_v6_daddr.in6_u.u6_addr32)); + use_bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(sk->sk_v6_rcv_saddr.in6_u.u6_addr32)); perf_submit_agent_internal__set_state_ipv6(ctx, now, daddr, saddr, ntohs(dport), sport, (__u64)sk, tx_rx); } @@ -749,16 +749,16 @@ static inline void submit_set_state_ipv6(struct pt_regs *ctx, u64 now, int tx_rx static inline void submit_set_state_ipv4(struct pt_regs *ctx, u64 now, int tx_rx, struct sock *sk) { struct sock *skp = NULL; - my_bpf_probe_read(&skp, sizeof(skp), &sk); + use_bpf_probe_read(&skp, sizeof(skp), &sk); if (!skp) { bpf_log(ctx, BPF_LOG_INVALID_POINTER, 0, 0, 0); return; } u16 dport = 0; u16 sport = 0; - // These values need to be taken from my_bpf_probe_read - my_bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); - my_bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); + // These values need to be taken from use_bpf_probe_read + use_bpf_probe_read(&dport, sizeof(dport), &(skp->sk_dport)); + use_bpf_probe_read(&sport, sizeof(sport), &(skp->sk_num)); perf_submit_agent_internal__set_state_ipv4(ctx, now, sk->sk_daddr, sk->sk_rcv_saddr, ntohs(dport), sport, (__u64)sk, tx_rx); } @@ -770,19 +770,19 @@ static inline void submit_reset_tcp_counters(struct pt_regs *ctx, u64 now, u64 p u32 packets_retrans = 0; u64 bytes_received = 0; - ret = my_bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); + ret = use_bpf_probe_read(&bytes_acked, sizeof(bytes_acked), &(tcp_sk(sk)->bytes_acked)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); + ret = use_bpf_probe_read(&packets_retrans, sizeof(packets_retrans), &(tcp_sk(sk)->total_retrans)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } - ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); + ret = use_bpf_probe_read(&bytes_received, sizeof(bytes_received), &(tcp_sk(sk)->bytes_received)); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; @@ -1069,7 +1069,7 @@ int onret_inet_csk_accept(struct pt_regs *ctx) // filter out non-tcp connections u16 family = 0; - my_bpf_probe_read(&family, sizeof(family), &newsk->sk_family); + use_bpf_probe_read(&family, sizeof(family), &newsk->sk_family); if (family != AF_INET && family != AF_INET6) { #if DEBUG_TCP_SOCKET_ERRORS bpf_trace_printk("onret_inet_csk_accept: family is not ipv4 or ipv6 sk=%llx\n", newsk); @@ -1119,8 +1119,8 @@ int onret_inet_csk_accept(struct pt_regs *ctx) // Set the state u16 dport = 0; u16 sport = 0; - my_bpf_probe_read(&dport, sizeof(dport), &newsk->sk_dport); - my_bpf_probe_read(&sport, sizeof(sport), &newsk->sk_num); + use_bpf_probe_read(&dport, sizeof(dport), &newsk->sk_dport); + use_bpf_probe_read(&sport, sizeof(sport), &newsk->sk_num); if (family == AF_INET) { perf_submit_agent_internal__set_state_ipv4( @@ -1128,8 +1128,8 @@ int onret_inet_csk_accept(struct pt_regs *ctx) } else if (family == AF_INET6) { uint8_t daddr[16] = {}; uint8_t saddr[16] = {}; - my_bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(newsk->sk_v6_daddr.in6_u.u6_addr32)); - my_bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(newsk->sk_v6_rcv_saddr.in6_u.u6_addr32)); + use_bpf_probe_read(daddr, sizeof(daddr), (uint8_t *)(newsk->sk_v6_daddr.in6_u.u6_addr32)); + use_bpf_probe_read(saddr, sizeof(saddr), (uint8_t *)(newsk->sk_v6_rcv_saddr.in6_u.u6_addr32)); perf_submit_agent_internal__set_state_ipv6(ctx, now, daddr, saddr, ntohs(dport), sport, (__u64)newsk, 2); } @@ -1244,7 +1244,7 @@ static int ensure_udp_existing(struct pt_regs *ctx, struct sock *sk, u32 tgid) } u16 lport = 0; - my_bpf_probe_read(&lport, sizeof(lport), &(inet_sk(sk)->inet_num)); + use_bpf_probe_read(&lport, sizeof(lport), &(inet_sk(sk)->inet_num)); perf_submit_agent_internal__udp_new_socket(ctx, now, tgid, (__u64)sk, (uint8_t *)(&addr), lport); } return ret; @@ -1518,7 +1518,7 @@ int on_inet_release(struct pt_regs *ctx, struct socket *sock) GET_PID_TGID; struct sock *sk = NULL; - my_bpf_probe_read(&sk, sizeof(sk), &sock->sk); + use_bpf_probe_read(&sk, sizeof(sk), &sock->sk); if (!sk) { return 0; @@ -1775,7 +1775,7 @@ int on_ip_send_skb(struct pt_regs *ctx, struct net *net, struct sk_buff *skb) struct tcphdr *tcp_hdr = (struct tcphdr *)(skb->head + skb->transport_header); u16 flags = 0; - my_bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); + use_bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); if (flags & TCP_FLAG_RST) { // bpf_trace_printk("on_ip_send_skb: tcp rst is set\n"); @@ -1815,7 +1815,7 @@ int on_ip6_send_skb(struct pt_regs *ctx, struct sk_buff *skb) struct tcphdr *tcp_hdr = (struct tcphdr *)(skb->head + skb->transport_header); u16 flags = 0; - my_bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); + use_bpf_probe_read(&flags, 2, ((u8 *)tcp_hdr) + 12); if (flags & TCP_FLAG_RST) { // bpf_trace_printk("on_ip6_send_skb: tcp rst is set\n"); @@ -1845,7 +1845,7 @@ int handle_receive_udp_skb(struct pt_regs *ctx, struct sock *sk, struct sk_buff // get the version from the ip packet (common location for ipv4 and ipv6) u8 version; - my_bpf_probe_read(&version, 1, (const u8 *)ip_hdr); + use_bpf_probe_read(&version, 1, (const u8 *)ip_hdr); version &= 0xF0; // Parse the addresses out of the header @@ -1931,7 +1931,7 @@ int on_tcp_rcv_established(struct pt_regs *ctx, struct sock *sk, struct sk_buff int ret; u64 bytes_received = 0; - ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); + ret = use_bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -1963,7 +1963,7 @@ int on_tcp_event_data_recv(struct pt_regs *ctx, struct sock *sk, struct sk_buff int ret; u64 bytes_received = 0; - ret = my_bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); + ret = use_bpf_probe_read(&bytes_received, sizeof(bytes_received), &tcp_sk(sk)->bytes_received); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return 0; @@ -2026,7 +2026,7 @@ int on_tcp_syn_ack_timeout( #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) /* Linux<4.4 does not have req->rsk_listener */ struct sock *sk = NULL; - my_bpf_probe_read(&sk, sizeof(sk), &(req->sk)); + use_bpf_probe_read(&sk, sizeof(sk), &(req->sk)); struct tcp_open_socket_t *sk_info; sk_info = tcp_open_sockets.lookup(&sk); @@ -2044,7 +2044,7 @@ int on_tcp_syn_ack_timeout( #else struct sock *sk = NULL; - my_bpf_probe_read(&sk, sizeof(sk), &(req->sk)); + use_bpf_probe_read(&sk, sizeof(sk), &(req->sk)); if (sk == NULL) { bpf_log(ctx, BPF_LOG_UNREACHABLE, 0, 0, 0); return 0; @@ -2081,7 +2081,7 @@ static void perf_check_and_submit_dns(struct pt_regs *ctx, struct sock *sk, struct sk_buff *skb, u8 proto, u16 sport, u16 dport, int is_rx) { unsigned int len = 0; - my_bpf_probe_read(&len, sizeof(len), &skb->len); + use_bpf_probe_read(&len, sizeof(len), &skb->len); // Filter for DNS requests and responses if (!((proto == IPPROTO_UDP) && ((sport == htons(53)) || (dport == htons(53))) && (len > 0))) { @@ -2092,35 +2092,35 @@ perf_check_and_submit_dns(struct pt_regs *ctx, struct sock *sk, struct sk_buff * int ret; unsigned int skb_data_len = 0; - ret = my_bpf_probe_read(&skb_data_len, sizeof(skb->data_len), &skb->data_len); + ret = use_bpf_probe_read(&skb_data_len, sizeof(skb->data_len), &skb->data_len); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } unsigned char *from = NULL; - ret = my_bpf_probe_read(&from, sizeof(skb->data), &skb->data); + ret = use_bpf_probe_read(&from, sizeof(skb->data), &skb->data); if (ret != 0 || from == NULL) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } unsigned char *skb_head = NULL; - ret = my_bpf_probe_read(&skb_head, sizeof(skb->head), &skb->head); + ret = use_bpf_probe_read(&skb_head, sizeof(skb->head), &skb->head); if (ret != 0 || skb_head == NULL) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } u16 skb_transport_header = 0; - ret = my_bpf_probe_read(&skb_transport_header, sizeof(skb->transport_header), &skb->transport_header); + ret = use_bpf_probe_read(&skb_transport_header, sizeof(skb->transport_header), &skb->transport_header); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; } u16 skb_network_header = 0; - ret = my_bpf_probe_read(&skb_network_header, sizeof(skb->network_header), &skb->network_header); + ret = use_bpf_probe_read(&skb_network_header, sizeof(skb->network_header), &skb->network_header); if (ret != 0) { bpf_log(ctx, BPF_LOG_BPF_CALL_FAILED, abs_val(ret), 0, 0); return; @@ -2190,7 +2190,7 @@ perf_check_and_submit_dns(struct pt_regs *ctx, struct sock *sk, struct sk_buff * /* the actual offset into buf has to start from buf's start */ char *to = buf + bpf_agent_internal__dns_packet__data_size; - my_bpf_probe_read(to, DNS_MAX_PACKET_LEN, from); + use_bpf_probe_read(to, DNS_MAX_PACKET_LEN, from); struct bpf_agent_internal__dns_packet *const msg = (struct bpf_agent_internal__dns_packet *)&buf[0]; struct jb_blob blob = {to, valid_len}; @@ -2301,7 +2301,7 @@ int on_kill_css(struct pt_regs *ctx, struct cgroup_subsys_state *css) int on_cgroup_destroy_locked(struct pt_regs *ctx, struct cgroup *cgrp) { struct cgroup_subsys_state *css = NULL; - my_bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); + use_bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); if (css == NULL) return 0; @@ -2333,7 +2333,7 @@ int on_css_populate_dir(struct pt_regs *ctx, struct cgroup_subsys_state *css) int on_cgroup_populate_dir(struct pt_regs *ctx, struct cgroup *cgrp, unsigned long subsys_mask) { struct cgroup_subsys_state *css = NULL; - my_bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); + use_bpf_probe_read(&css, sizeof(css), &(cgrp->subsys[FLOW_CGROUP_SUBSYS])); if (css == NULL) return 0;