Skip to content

Commit

Permalink
migrate from conan 1 to conan 2
Browse files Browse the repository at this point in the history
  • Loading branch information
copperlight committed Nov 23, 2024
1 parent 4c1c431 commit 1b70e02
Show file tree
Hide file tree
Showing 50 changed files with 271 additions and 309 deletions.
68 changes: 17 additions & 51 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,31 @@ jobs:
build:
if: ${{ github.repository == 'Netflix-Skunkworks/spectatord' }}
runs-on: ubuntu-latest
env:
BUILD_DIR: "cmake-build"
BUILD_TYPE: "Debug"
CC: "gcc-11"
CXX: "g++-11"
LANG: "en_US.UTF-8"
steps:
- uses: actions/checkout@v4

- name: Conan+Cmake Cache
uses: actions/cache@v4
- name: Restore .conan2 Cache
id: cache-conan2-restore
uses: actions/cache/restore@v4
with:
path: |
~/.conan
~/work/spectatord/spectatord/cmake-build
key: ${{ runner.os }}-conan-cmake
path: /home/runner/.conan2
key: ${{ runner.os }}-conan2

- name: Install System Dependencies
run: |
pwd
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update && sudo apt-get install -y binutils-dev g++-11 libiberty-dev
sudo apt-get update && sudo apt-get install -y binutils-dev g++-13 libiberty-dev
echo "==== cmake ===="
cmake -version
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
- name: Build
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
./setup-venv.sh
source venv/bin/activate
./build.sh
- name: Install Source Dependencies
run: |
NFLX_INTERNAL=OFF conan source .
- name: Generate Version
run: |
tools/generate_version.sh > spectator/version.h
- name: Build spectatord
run: |
cd $BUILD_DIR
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DNFLX_INTERNAL=OFF ..
cmake --build .
echo "==== ldd ===="
ldd bin/spectatord_main || true
- name: Test spectatord
run: |
cd $BUILD_DIR
GTEST_COLOR=1 ctest --verbose
- name: Save .conan2 Cache
id: cache-conan2-save
uses: actions/cache/save@v4
with:
path: /home/runner/.conan2
key: ${{ steps.cache-conan2-restore.outputs.cache-primary-key }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
**/*.inc
.DS_Store
.idea/
cmake-build-debug
.newt-cache/
CMakeUserPresets.json
cmake-build-debug/
cmake-build/
metatron/auth_context.pb.cc
metatron/auth_context.pb.h
Expand Down
55 changes: 30 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@ project(spectatord)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
#-- Conan 1.x support for MacOS >= 14.7 compilers is not ready yet
set(CONAN_DISABLE_CHECK_COMPILER 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(benchmark REQUIRED)
find_package(fmt REQUIRED)
find_package(GTest REQUIRED)
find_package(CURL REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Poco REQUIRED)
find_package(protobuf REQUIRED)
find_package(RapidJSON REQUIRED)
find_package(spdlog REQUIRED)
find_package(tsl-hopscotch-map REQUIRED)
find_package(xxHash REQUIRED)
find_package(ZLIB REQUIRED)

add_subdirectory(admin)
add_subdirectory(bench)
Expand All @@ -30,12 +43,11 @@ file(GLOB spectator_test_source_files
"spectator/test_utils.*"
)
add_executable(spectator_test ${spectator_test_source_files})
target_include_directories(spectator_test PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(spectator_test
sample_cfg
spectator
util
${CONAN_LIBS}
Backward::Backward
)
add_test(
NAME spectator_test
Expand All @@ -52,11 +64,10 @@ add_executable(spectatord_test
"spectator/test_utils.cc"
"spectator/test_utils.h"
)
target_include_directories(spectatord_test PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(spectatord_test
admin_server
spectatord
${CONAN_LIBS}
Backward::Backward
)
add_test(
NAME spectatord_test
Expand All @@ -67,39 +78,33 @@ add_test(
#-- spectatord_main executable
option(NFLX_INTERNAL "Netflix internal build" OFF)
add_executable(spectatord_main "bin/spectatord_main.cc")
target_include_directories(spectatord_main PRIVATE
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/server
)
if(NFLX_INTERNAL)
message(STATUS "Using Netflix config")
target_link_libraries(spectatord_main
netflix_cfg
spectatord
admin_server
${CONAN_LIBS}
spectatord
Backward::Backward
)
else()
message(STATUS "Using sample config")
target_link_libraries(spectatord_main
sample_cfg
spectatord
admin_server
${CONAN_LIBS}
spectatord
Backward::Backward
)
endif()
target_link_options(spectatord_main PRIVATE
"$<$<CONFIG:Release>:-static-libstdc++>"
)

#-- metrics_gen executable
add_executable(metrics_gen
"server/local.h"
"tools/metrics_gen.cc"
)
target_include_directories(metrics_gen PRIVATE
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/server
target_link_libraries(metrics_gen
abseil::abseil
asio::asio
fmt::fmt
spdlog::spdlog
)
target_link_libraries(metrics_gen ${CONAN_LIBS})
target_link_options(metrics_gen PRIVATE -pthread)
6 changes: 3 additions & 3 deletions admin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ add_library(admin_server
"admin_server.cc"
"admin_server.h"
)
target_include_directories(admin_server PRIVATE
${CMAKE_SOURCE_DIR}
target_link_libraries(admin_server
spectator
Poco::Poco
)
target_link_libraries(admin_server ${CONAN_LIBS})
6 changes: 3 additions & 3 deletions admin/admin_server.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "admin_server.h"
#include "server/spectatord.h"
#include "spectator/version.h"
#include "../server/spectatord.h"
#include "../spectator/version.h"
#include <Poco/JSON/Parser.h>
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
Expand Down Expand Up @@ -265,7 +265,7 @@ spectator::Id parse_id(const std::string& id_str) {

// optionally get tags
if (id_str[pos] == ',') {
while (id_str[pos] != std::string_view::npos) {
while (pos != std::string_view::npos) {
++pos;
auto k_pos = id_str.find('=', pos);
if (k_pos == std::string_view::npos) break;
Expand Down
7 changes: 4 additions & 3 deletions admin/admin_server.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "spectator/registry.h"
#include "../spectator/registry.h"
#include "../util/logger.h"
#include <Poco/Net/HTTPServer.h>
#include <Poco/Net/HTTPRequestHandler.h>

Expand Down Expand Up @@ -43,12 +44,12 @@ class RequestHandlerFactory: public HTTPRequestHandlerFactory {

class AdminServer {
std::shared_ptr<HTTPServer> instance;
Registry &registry;
// Registry &registry;

public:
AdminServer(Registry &r, int p):
registry{r},
instance{std::make_shared<HTTPServer>(new RequestHandlerFactory(r), SocketAddress("localhost", p), new HTTPServerParams)} {}
// registry{r} {}
void Start() { instance->start(); }
void Stop() { instance->stop(); }
};
Expand Down
46 changes: 10 additions & 36 deletions admin/admin_server_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "../spectator/config.h"
#include "../spectator/registry.h"
#include "admin_server.h"
#include "util/logger.h"
#include "gtest/gtest.h"
#include "spectator/config.h"
#include "spectator/registry.h"
#include <Poco/JSON/Parser.h>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPServerRequest.h>
Expand Down Expand Up @@ -290,30 +289,21 @@ Object::Ptr get_common_tags() {

Parser parser;
Var result {parser.parse(rr)};
Object::Ptr object = result.extract<Object::Ptr>();
const auto& object = result.extract<Object::Ptr>();
Var common_tags = object->get("common_tags");
return common_tags.extract<Object::Ptr>();
}

TEST_F(AdminServerTest, set_common_tags) {
// start with zero common tags
Object::Ptr subObject = get_common_tags();

int count = 0;
for (auto &it : *subObject) {
count += 1;
}
EXPECT_EQ(count, 0);
EXPECT_EQ(subObject->size(), 0);

// set three common tags
post("/config/common_tags", R"({"mantisJobId": "foo", "mantisJobName": "bar", "mantisUser": "baz"})");
subObject = get_common_tags();

count = 0;
for (auto &it : *subObject) {
count += 1;
}
EXPECT_EQ(count, 3);
EXPECT_EQ(subObject->size(), 3);
EXPECT_EQ("foo", subObject->get("mantisJobId"));
EXPECT_EQ("bar", subObject->get("mantisJobName"));
EXPECT_EQ("baz", subObject->get("mantisUser"));
Expand All @@ -322,23 +312,15 @@ TEST_F(AdminServerTest, set_common_tags) {
post("/config/common_tags", R"({"mantisJobName": "quux", "mantisUser": ""})");
subObject = get_common_tags();

count = 0;
for (auto &it : *subObject) {
count += 1;
}
EXPECT_EQ(count, 2);
EXPECT_EQ(subObject->size(), 2);
EXPECT_EQ("foo", subObject->get("mantisJobId"));
EXPECT_EQ("quux", subObject->get("mantisJobName"));

// reset all tags
post("/config/common_tags", R"({"mantisJobId": "", "mantisJobName": ""})");
subObject = get_common_tags();

count = 0;
for (auto &it : *subObject) {
count += 1;
}
EXPECT_EQ(count, 0);
EXPECT_EQ(subObject->size(), 0);
}

Poco::JSON::Array::Ptr get_metrics(const std::string& type) {
Expand All @@ -350,7 +332,7 @@ Poco::JSON::Array::Ptr get_metrics(const std::string& type) {

Parser parser;
Var result {parser.parse(rr)};
Object::Ptr object = result.extract<Object::Ptr>();
const auto& object = result.extract<Object::Ptr>();
Var metrics;
if (type == "A") {
metrics = object->get("age_gauges");
Expand Down Expand Up @@ -382,11 +364,7 @@ HTTPResponse delete_age_gauge(const std::string& id) {
TEST_F(AdminServerTest, delete_meters) {
// start with three pre-populated age gauges
Poco::JSON::Array::Ptr subArr = get_metrics("A");
int count = 0;
for (auto &it : *subArr) {
count += 1;
}
EXPECT_EQ(count, 3);
EXPECT_EQ(subArr->size(), 3);

HTTPResponse res;

Expand All @@ -408,11 +386,7 @@ TEST_F(AdminServerTest, delete_meters) {
EXPECT_EQ(200, res.getStatus());

subArr = get_metrics("A");
count = 0;
for (auto &it : *subArr) {
count += 1;
}
EXPECT_EQ(count, 0);
EXPECT_EQ(subArr->size(), 0);
}

}
Loading

0 comments on commit 1b70e02

Please sign in to comment.