Skip to content

Commit

Permalink
migrate conan 1 to conan 2
Browse files Browse the repository at this point in the history
  • Loading branch information
copperlight committed Nov 24, 2024
1 parent 1354653 commit 2d934c8
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 227 deletions.
108 changes: 53 additions & 55 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,81 +10,79 @@ jobs:
build:
if: ${{ github.repository == 'Netflix-Skunkworks/atlas-system-agent' }}
runs-on: ubuntu-latest
env:
BUILD_DIR: "cmake-build"
BUILD_TYPE: "Debug"
CC: "gcc-11"
CXX: "g++-11"
LANG: "en_US.UTF-8"
strategy:
matrix:
agent: [system, titus]
steps:
- uses: actions/checkout@v4

- name: Conan+Cmake Cache
uses: actions/cache@v4
with:
path: |
~/.conan
~/work/atlas-system-agent/atlas-system-agent/cmake-build
key: ${{ runner.os }}-conan-cmake

- name: Install System Dependencies
run: |
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update && sudo apt-get install -y binutils-dev g++-11 libcap-dev libiberty-dev
sudo apt-get update && sudo apt-get install -y binutils-dev g++-13 libcap-dev libiberty-dev
echo "==== cmake ===="
cmake -version
# ==== atlas-system-agent ====

echo "==== python ===="
python3 -V
echo "==== conan ===="
pip install -r requirements.txt
conan --version
if [[ ! -f ~/.conan/profiles/default ]]; then conan profile new default --detect; fi
conan profile update settings.compiler.libcxx=libstdc++11 default
- name: Install Project Dependencies
run: |
if [[ "$BUILD_TYPE" == "Debug" ]]; then
conan install . --build --install-folder $BUILD_DIR --profile ./sanitized
else
conan install . --build=missing --install-folder $BUILD_DIR
fi
- name: Install Source Dependencies
run: |
conan source .
- name: Restore Conan Cache (system)
if: ${{ startsWith(matrix.agent, 'system') }}
id: conan-cache-restore-system
uses: actions/cache/restore@v4
with:
path: |
/home/runner/.conan2
/home/runner/work/atlas-system-agent/atlas-system-agent/cmake-build
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/spectator
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/tools
key: ${{ runner.os }}-conan-system

- name: Build atlas-system-agent
if: ${{ startsWith(matrix.agent, 'system') }}
run: |
cd $BUILD_DIR
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DTITUS_SYSTEM_SERVICE=OFF ..
cmake --build .
echo "==== ldd ===="
ldd bin/atlas_system_agent || true
./setup-venv.sh
source venv/bin/activate
TITUS_SYSTEM_SERVICE=OFF ./build.sh
- name: Test atlas-system-agent
- name: Save Conan Cache (system)
if: ${{ startsWith(matrix.agent, 'system') }}
run: |
cd $BUILD_DIR
GTEST_COLOR=1 ctest --verbose
id: conan-cache-save-system
uses: actions/cache/save@v4
with:
path: |
/home/runner/.conan2
/home/runner/work/atlas-system-agent/atlas-system-agent/cmake-build
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/spectator
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/tools
key: ${{ steps.conan-cache-restore-system.outputs.cache-primary-key }}

# ==== atlas-titus-agent ====

- name: Restore Conan Cache (titus)
if: ${{ startsWith(matrix.agent, 'titus') }}
id: conan-cache-restore-titus
uses: actions/cache/restore@v4
with:
path: |
/home/runner/.conan2
/home/runner/work/atlas-system-agent/atlas-system-agent/cmake-build
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/spectator
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/tools
key: ${{ runner.os }}-conan-titus

- name: Build atlas-titus-agent
if: ${{ startsWith(matrix.agent, 'titus') }}
run: |
cd $BUILD_DIR
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DTITUS_SYSTEM_SERVICE=ON ..
cmake --build .
echo "==== ldd ===="
ldd bin/atlas_system_agent || true
./setup-venv.sh
source venv/bin/activate
TITUS_SYSTEM_SERVICE=ON ./build.sh
- name: Test atlas-titus-agent
- name: Save Conan Cache (titus)
if: ${{ startsWith(matrix.agent, 'titus') }}
run: |
cd $BUILD_DIR
GTEST_COLOR=1 ctest --verbose
id: conan-cache-save-titus
uses: actions/cache/save@v4
with:
path: |
/home/runner/.conan2
/home/runner/work/atlas-system-agent/atlas-system-agent/cmake-build
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/spectator
/home/runner/work/atlas-system-agent/atlas-system-agent/lib/tools
key: ${{ steps.conan-cache-restore-titus.outputs.cache-primary-key }}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
**/*.inc
.DS_Store
.idea/
cmake-build-debug
CMakeUserPresets.json
cmake-build-debug/
cmake-build/
lib/spectator/
spectator-cpp-*.zip
venv/
lib/tools/
venv/
39 changes: 24 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.23)

project(atlas-system-agent)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

add_compile_options(-fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>")
add_link_options(-fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>")
add_compile_options(-pedantic -Werror -Wall -Wno-missing-braces -fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>")

include(CTest)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(absl REQUIRED)
find_package(asio REQUIRED)
find_package(Backward REQUIRED)
find_package(fmt REQUIRED)
find_package(GTest REQUIRED)
find_package(CURL REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(RapidJSON REQUIRED)
find_package(spdlog REQUIRED)
find_package(ZLIB REQUIRED)

option(TITUS_SYSTEM_SERVICE "Titus System Service" OFF)
if(TITUS_SYSTEM_SERVICE)
Expand All @@ -31,8 +41,10 @@ file(GLOB sysagent_test_source_files
"lib/measurement_utils.*"
)
add_executable(sysagent_test ${sysagent_test_source_files})
target_include_directories(sysagent_test PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(sysagent_test sysagent ${CONAN_LIBS})
target_link_libraries(sysagent_test
sysagent
gtest::gtest
)
add_test(
NAME sysagent_test
COMMAND sysagent_test
Expand All @@ -41,11 +53,8 @@ add_test(

#-- atlas_system_agent executable
add_executable(atlas_system_agent "bin/atlas-agent.cc")
target_include_directories(atlas_system_agent PRIVATE
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/lib
)
target_link_libraries(atlas_system_agent sysagent ${CONAN_LIBS})
target_link_options(atlas_system_agent PRIVATE
"$<$<CONFIG:Release>:-static-libstdc++>"
)
target_link_libraries(atlas_system_agent sysagent)

#-- test_nvml executable
add_executable(test_nvml "bin/test_nvml.cc")
target_link_libraries(test_nvml sysagent)
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ An agent that reports metrics for EC2 instances or [Titus] containers.

[Titus]: https://github.com/Netflix/titus/

## Local Development
## Local & IDE Configuration

This agent was designed for Linux systems, and as a result, it does not compile cleanly on macOS. It
This agent was designed for Linux systems, and as a result, it does not compile cleanly on MacOS. It
is best to build on a Linux machine:

```shell
# setup python venv and activate, to gain access to conan cli
./setup-venv.sh
source venv/bin/activate

# link clion default build directory to our build directory
ln -s cmake-build cmake-build-debug

./build.sh # [clean|clean --force|skiptest]
./build.sh # [clean|clean --confirm|skiptest]
```

* CLion > Preferences > Plugins > Marketplace > Conan > Install
* CLion > Preferences > Build, Execution, Deploy > Conan > Conan Executable: $PROJECT_HOME/venv/bin/conan
* Install the Conan plugin for CLion.
* CLion > Settings > Plugins > Marketplace > Conan > Install
* Configure the Conan plugin.
* The easiest way to configure CLion to work with Conan is to build the project first from the command line.
* This will establish the `$PROJECT_HOME/CMakeUserPresets.json` file, which will allow you to choose the custom
CMake configuration created by Conan when creating a new CMake project. Using this custom profile will ensure
that sources are properly indexed and explorable.
* Open the project. The wizard will show three CMake profiles.
* Disable the default Cmake `Debug` profile.
* Enable the CMake `conan-debug` profile.
* CLion > View > Tool Windows > Conan > (gear) > Conan Executable: `$PROJECT_HOME/venv/bin/conan`

## Debugging

Expand Down
38 changes: 17 additions & 21 deletions bin/atlas-agent.cc
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#ifdef __linux__
#include "contain/contain.h"
#include "../contain/contain.h"
#include <sys/vfs.h>
#endif
#include "aws.h"
#include "cgroup.h"
#include "cpufreq.h"
#include "disk.h"
#include "ethtool.h"
#include "gpumetrics.h"
#include "logger.h"
#include "ntp.h"
#include "nvml.h"
#include "perfmetrics.h"
#include "pressure_stall.h"
#include "proc.h"
#include "tagger.h"
#include "../lib/aws.h"
#include "../lib/cgroup.h"
#include "../lib/cpufreq.h"
#include "../lib/disk.h"
#include "../lib/ethtool.h"
#include "../lib/gpumetrics.h"
#include "../lib/ntp.h"
#include "../lib/perfmetrics.h"
#include "../lib/pressure_stall.h"
#include "../lib/proc.h"
#include "backward.hpp"
#include "spectator/registry.h"
#include <condition_variable>
#include <csignal>
#include <fmt/chrono.h>
Expand Down Expand Up @@ -48,7 +44,7 @@ std::unique_ptr<GpuMetrics> init_gpu(TaggingRegistry* registry, std::unique_ptr<
fprintf(stderr, "Will not collect GPU metrics: %s\n", e.what());
}
}
return std::unique_ptr<GpuMetrics>();
return {};
}

#if defined(TITUS_SYSTEM_SERVICE)
Expand Down Expand Up @@ -96,7 +92,7 @@ static void gather_slow_system_metrics(Proc* proc, Disk* disk, Ethtool* ethtool,
#endif

struct terminator {
terminator() noexcept {}
terminator() noexcept = default;

// returns false if killed:
template <class R, class P>
Expand Down Expand Up @@ -140,7 +136,7 @@ static void handle_signal(int signal) {
}

static void init_signals() {
struct sigaction sa;
struct sigaction sa{};
sa.sa_handler = &handle_signal;
sa.sa_flags = SA_RESETHAND; // remove the handler after the first signal
sigfillset(&sa.sa_mask);
Expand Down Expand Up @@ -227,7 +223,7 @@ void collect_titus_metrics(TaggingRegistry* registry, std::unique_ptr<Nvml> nvid
}
#else
void collect_system_metrics(TaggingRegistry* registry, std::unique_ptr<atlasagent::Nvml> nvidia_lib,
spectator::Tags net_tags) {
const spectator::Tags& net_tags) {
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using std::chrono::seconds;
Expand Down Expand Up @@ -378,10 +374,10 @@ int main(int argc, char* const argv[]) {
TaggingRegistry registry{&spectator_registry, maybe_tagger.value_or(atlasagent::Tagger::Nop())};
#if defined(TITUS_SYSTEM_SERVICE)
Logger()->info("Start gathering Titus system metrics");
collect_titus_metrics(&registry, std::move(nvidia_lib), std::move(options.network_tags));
collect_titus_metrics(&registry, std::move(nvidia_lib), options.network_tags);
#else
Logger()->info("Start gathering EC2 system metrics");
collect_system_metrics(&registry, std::move(nvidia_lib), std::move(options.network_tags));
collect_system_metrics(&registry, std::move(nvidia_lib), options.network_tags);
#endif
logger->info("Shutting down spectator registry");
atlasagent::HttpClient<>::GlobalShutdown();
Expand Down
10 changes: 5 additions & 5 deletions bin/test_nvml.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "lib/nvml.h"
#include "lib/logger.h"
#include "../lib/logger.h"
#include "../lib/nvml.h"
#include <iostream>

using atlasagent::Logger;
Expand Down Expand Up @@ -28,11 +28,11 @@ int main() {
if (nvml.get_name(handle, &name)) {
logger->info(" Name={}", name);
}
atlasagent::NvmlMemory memory;
atlasagent::NvmlMemory memory{};
if (nvml.get_memory_info(handle, &memory)) {
logger->info(" Mem total={}, free={}, used={}", memory.total, memory.free, memory.used);
}
atlasagent::NvmlUtilization utilization;
atlasagent::NvmlUtilization utilization{};
if (nvml.get_utilization_rates(handle, &utilization)) {
logger->info(" gpu={} memory={}", utilization.gpu, utilization.memory);
}
Expand All @@ -51,6 +51,6 @@ int main() {
}
}
} catch (const atlasagent::NvmlException& exception) {
Logger()->error("Caught NvmlException {}", exception.what());
logger->error("Caught NvmlException {}", exception.what());
}
}
Loading

0 comments on commit 2d934c8

Please sign in to comment.