Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm64 missing libatomic #112

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
Expand Down Expand Up @@ -125,7 +126,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/third_party/libbpf-boo

add_subdirectory(third_party)
add_subdirectory(libebpfdiscovery)
add_subdirectory(libebpfdiscoveryproto)
add_subdirectory(libebpfdiscoveryshared)
add_subdirectory(libebpfdiscoveryskel)
add_subdirectory(libhttpparser)
Expand Down
1 change: 0 additions & 1 deletion conanfile.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[requires]
protobuf/3.21.9
ms-gsl/4.0.0
fmt/10.1.1
spdlog/1.12.0
Expand Down
4 changes: 4 additions & 0 deletions ebpfdiscoverysrv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ add_executable(${TARGET} ${SOURCES})
target_link_libraries(${TARGET} PRIVATE ebpfdiscovery)
target_link_options(${TARGET} PRIVATE "-static-libgcc" "-static-libstdc++")
target_compile_definitions(${TARGET} PUBLIC PROJECT_VERSION="${PROJECT_VERSION}")

if (BUILD_TESTS)
add_test(NAME binary_dependencies COMMAND bash ${TESTS_ROOT_DIR}/binary_dependencies.sh $<TARGET_FILE:${TARGET}>)
endif ()
1 change: 1 addition & 0 deletions ebpfdiscoverysrv/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <boost/program_options.hpp>

#include <atomic>
#include <mutex>
#include <filesystem>
#include <iostream>
#include <csignal>
Expand Down
11 changes: 11 additions & 0 deletions ebpfdiscoverysrv/test/dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

binary_path="${1}"
approved_binary_dependencies=("libelf|libz|libm|libdl|librt|libpthread|libc|ld-linux")

depenencies=$(objdump -p "${binary_path}" 2>/dev/null | grep NEEDED | grep -Ev "${approved_binary_dependencies}")

if [ ! -z "${depenencies}" ]; then
echo "Additional dependencies: ${depenencies}"
exit 1
fi
1 change: 0 additions & 1 deletion libebpfdiscovery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target_include_directories(${TARGET} PRIVATE src PUBLIC headers)
target_link_libraries(${TARGET}
PUBLIC
libpf-tools
ebpfdiscoveryproto
ebpfdiscoveryshared
ebpfdiscoveryskel
httpparser
Expand Down
9 changes: 1 addition & 8 deletions libebpfdiscovery/headers/ebpfdiscovery/Discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@
#include "service/Aggregator.h"
#include "service/IpAddressNetlinkChecker.h"

#include <atomic>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include <unordered_map>
#include <string_view>

namespace ebpfdiscovery {

Expand Down
3 changes: 0 additions & 3 deletions libebpfdiscovery/headers/ebpfdiscovery/DiscoveryBpfLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#include <bpf/libbpf.h>

#include <atomic>
#include <thread>

namespace ebpfdiscovery::bpflogging {

perf_buffer* setupLogging(int logPerfBufFd);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
/*
* Copyright 2023 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "ebpfdiscoveryproto/service.pb.h"
#include "service/Service.h"

#include <vector>

namespace proto {

ServicesList internalToProto(const std::vector<std::reference_wrapper<service::Service>>& services);

std::string protoToJson(const ServicesList& protoServices);

} // namespace proto
/*
* Copyright 2023 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <boost/json.hpp>
#include <boost/describe.hpp>
#include <string_view>

namespace boost::json {
template<typename T>
void tag_invoke(json::value_from_tag, json::value& v, std::reference_wrapper<T> const& wrapped) {
v = json::value_from(wrapped.get());
}
} // namespace boost::json

template<typename T>
boost::json::object toJson(std::string_view key, T convertibleValue) {
boost::json::object outJson{};
outJson[key] = boost::json::value_from(convertibleValue);
return outJson;
}
8 changes: 4 additions & 4 deletions libebpfdiscovery/src/Discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "ebpfdiscovery/Discovery.h"

#include "ebpfdiscovery/Session.h"
#include "ebpfdiscoveryproto/Translator.h"
#include "ebpfdiscovery/Json.h"
#include "logging/Logger.h"
#include "service/IpAddress.h"

Expand All @@ -32,6 +32,7 @@
#include <string>
#include <string_view>
#include <thread>
#include <iostream>

namespace ebpfdiscovery {

Expand Down Expand Up @@ -62,9 +63,8 @@ void Discovery::outputServicesToStdout() {
return;
}

const auto servicesProto{proto::internalToProto(services)};
const auto servicesJson{proto::protoToJson(servicesProto)};
std::cout << servicesJson << std::endl;

std::cout << toJson("services",services) << std::endl;
serviceAggregator.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*/

#include "ebpfdiscoveryproto/Translator.h"

#include "ebpfdiscovery/Json.h"
#include <gtest/gtest.h>

using namespace proto;
#include <iostream>
#include <string>
#include <vector>

class ProtobufTranslatorTest : public testing::Test {};
class Json : public testing::Test {};

TEST_F(ProtobufTranslatorTest, successfulTranslationToJson) {
TEST_F(Json, servicesToJson) {

std::vector<std::reference_wrapper<service::Service>> internalServices;
service::Service service1{.pid = 1, .endpoint = "/endpoint/1", .internalClientsNumber = 1, .externalClientsNumber = 2};
Expand All @@ -38,13 +39,18 @@ TEST_F(ProtobufTranslatorTest, successfulTranslationToJson) {
internalServices.push_back(service4);
internalServices.push_back(service5);

const auto proto{internalToProto(internalServices)};
const auto result{protoToJson(proto)};
const std::string expected{"{\"service\":[{\"pid\":1,\"endpoint\":\"/endpoint/"
"1\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},{\"pid\":2,\"endpoint\":\"/endpoint/"
"1\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},{\"pid\":3,\"endpoint\":\"/endpoint/"
"2\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},{\"pid\":4,\"endpoint\":\"google.com/"
"endpoint/3\",\"domain\":\"google.com\",\"scheme\":\"http\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},{\"pid\":5,\"endpoint\":\"dynatrace.com/"
"endpoint/4\",\"domain\":\"dynatrace.com\",\"scheme\":\"https\",\"internalClientsNumber\":1,\"externalClientsNumber\":2}]}"};
EXPECT_EQ(result, expected);
boost::json::object outJson{};
outJson["service"] = boost::json::value_from(internalServices);

std::stringstream buffer;
buffer << outJson;
// clang-format off
const std::string expected{"{\"service\":["
"{\"pid\":1,\"endpoint\":\"/endpoint/1\",\"domain\":\"\",\"scheme\":\"\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},"
"{\"pid\":2,\"endpoint\":\"/endpoint/1\",\"domain\":\"\",\"scheme\":\"\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},"
"{\"pid\":3,\"endpoint\":\"/endpoint/2\",\"domain\":\"\",\"scheme\":\"\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},"
"{\"pid\":4,\"endpoint\":\"google.com/endpoint/3\",\"domain\":\"google.com\",\"scheme\":\"http\",\"internalClientsNumber\":1,\"externalClientsNumber\":2},"
"{\"pid\":5,\"endpoint\":\"dynatrace.com/endpoint/4\",\"domain\":\"dynatrace.com\",\"scheme\":\"https\",\"internalClientsNumber\":1,\"externalClientsNumber\":2}]}"};
// clang-format on
EXPECT_EQ(buffer.str(), expected);
}
53 changes: 0 additions & 53 deletions libebpfdiscoveryproto/CMakeLists.txt

This file was deleted.

30 changes: 0 additions & 30 deletions libebpfdiscoveryproto/ebpfdiscoveryproto/service.proto

This file was deleted.

50 changes: 0 additions & 50 deletions libebpfdiscoveryproto/src/Translator.cpp

This file was deleted.

5 changes: 2 additions & 3 deletions libservice/headers/service/Aggregator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#include "ebpfdiscoveryshared/Types.h"
#include "httpparser/HttpRequestParser.h"

#include <atomic>
#include <cstdint>
#include <mutex>
#include <unordered_map>
#include <vector>

Expand All @@ -49,13 +47,14 @@ class Aggregator {
private:
using ServiceKey = std::pair<uint32_t, std::string>;
using ServiceStorage = std::unordered_map<ServiceKey, Service>;
using ServicesList = std::vector<std::reference_wrapper<Service>>;

public:
Aggregator(const service::IpAddressChecker& ipChecker);

void clear();
void newRequest(const httpparser::HttpRequest& request, const DiscoverySessionMeta& meta);
std::vector<std::reference_wrapper<Service>> collectServices();
ServicesList collectServices();

private:
const IpAddressChecker& ipChecker;
Expand Down
Loading