From 1b70e02273c4977372712ecd8ab304313be7b56c Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Thu, 21 Nov 2024 19:32:32 -0500 Subject: [PATCH] migrate from conan 1 to conan 2 --- .github/workflows/build.yml | 68 ++++++++--------------------- .gitignore | 4 +- CMakeLists.txt | 55 ++++++++++++----------- admin/CMakeLists.txt | 6 +-- admin/admin_server.cc | 6 +-- admin/admin_server.h | 7 +-- admin/admin_server_test.cc | 46 +++++-------------- bench/CMakeLists.txt | 38 ++++++++-------- bench/bench_tags.cc | 2 +- bench/get_measurement_bench.cc | 2 +- bench/measurements_fmt_bench.cc | 3 +- bench/parse_bench.cc | 2 +- bench/statsd_bench.cc | 2 +- bench/to_valid_bench.cc | 2 +- bin/spectatord_main.cc | 18 ++++---- bin/test_main.cc | 5 +-- build.sh | 49 +++++++++++---------- conanfile.py | 42 +++++++++--------- metatron/CMakeLists.txt | 12 ++--- metatron/metatron_sample.cc | 2 +- requirements.txt | 2 +- server/CMakeLists.txt | 8 +++- server/expiring_cache.h | 2 +- server/local_server.cc | 2 +- server/proc_utils.cc | 2 +- server/spectatord.cc | 4 -- server/spectatord.h | 6 +-- server/spectatord_test.cc | 7 ++- server/udp_server.cc | 2 +- spectator/CMakeLists.txt | 16 ++++++- spectator/compressed_buffer.h | 2 + spectator/counter.cc | 2 +- spectator/detail/perc_policy.h | 3 +- spectator/gauge_test.cc | 4 +- spectator/gzip.cc | 2 - spectator/http_client.h | 2 +- spectator/http_server.cc | 9 ++-- spectator/perc_dist_summary_test.cc | 31 +++++++------ spectator/perc_timer_test.cc | 42 +++++++++--------- spectator/publisher.h | 8 ++-- spectator/registry.cc | 3 +- spectator/registry.h | 5 ++- spectator/smile.cc | 10 +++-- spectator/string_intern.h | 8 ++-- spectator/string_intern_test.cc | 3 +- spectator/tags_test.cc | 10 ++--- tools/gen_perc_bucket_tags.cc | 2 +- tools/metrics_gen.cc | 8 ++-- util/CMakeLists.txt | 2 +- util/files.h | 2 +- 50 files changed, 271 insertions(+), 309 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 09246a5..61eb8f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index c896401..7c4df87 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index ab5ce64..91bbaf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 "$<$:-fsanitize=address>") -add_link_options(-fno-omit-frame-pointer "$<$:-fsanitize=address>") +add_compile_options(-pedantic -Werror -Wall -Wno-missing-braces -fno-omit-frame-pointer "$<$:-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) @@ -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 @@ -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 @@ -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 - "$<$:-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) diff --git a/admin/CMakeLists.txt b/admin/CMakeLists.txt index d35f842..575aeb6 100644 --- a/admin/CMakeLists.txt +++ b/admin/CMakeLists.txt @@ -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}) diff --git a/admin/admin_server.cc b/admin/admin_server.cc index 93cb54f..765d2c1 100644 --- a/admin/admin_server.cc +++ b/admin/admin_server.cc @@ -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 #include #include @@ -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; diff --git a/admin/admin_server.h b/admin/admin_server.h index ff923b2..f4a8436 100644 --- a/admin/admin_server.h +++ b/admin/admin_server.h @@ -1,6 +1,7 @@ #pragma once -#include "spectator/registry.h" +#include "../spectator/registry.h" +#include "../util/logger.h" #include #include @@ -43,12 +44,12 @@ class RequestHandlerFactory: public HTTPRequestHandlerFactory { class AdminServer { std::shared_ptr instance; - Registry ®istry; +// Registry ®istry; public: AdminServer(Registry &r, int p): - registry{r}, instance{std::make_shared(new RequestHandlerFactory(r), SocketAddress("localhost", p), new HTTPServerParams)} {} +// registry{r} {} void Start() { instance->start(); } void Stop() { instance->stop(); } }; diff --git a/admin/admin_server_test.cc b/admin/admin_server_test.cc index a60f38a..1498150 100644 --- a/admin/admin_server_test.cc +++ b/admin/admin_server_test.cc @@ -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 #include #include @@ -290,7 +289,7 @@ Object::Ptr get_common_tags() { Parser parser; Var result {parser.parse(rr)}; - Object::Ptr object = result.extract(); + const auto& object = result.extract(); Var common_tags = object->get("common_tags"); return common_tags.extract(); } @@ -298,22 +297,13 @@ Object::Ptr get_common_tags() { 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")); @@ -322,11 +312,7 @@ 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")); @@ -334,11 +320,7 @@ TEST_F(AdminServerTest, set_common_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) { @@ -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(); + const auto& object = result.extract(); Var metrics; if (type == "A") { metrics = object->get("age_gauges"); @@ -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; @@ -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); } } diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index afb64bb..13277b8 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -1,40 +1,40 @@ #-- fmt_bench test executable add_executable(fmt_bench "measurements_fmt_bench.cc") -target_include_directories(fmt_bench PRIVATE - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/server +target_link_libraries(fmt_bench + spectatord + benchmark::benchmark_main ) -target_link_libraries(fmt_bench spectatord ${CONAN_LIBS}) #-- parse_bench test executable add_executable(parse_bench "parse_bench.cc") -target_include_directories(parse_bench PRIVATE - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/server +target_link_libraries(parse_bench + spectatord + benchmark::benchmark_main ) -target_link_libraries(parse_bench spectatord ${CONAN_LIBS}) #-- ms_bench test executable add_executable(ms_bench "get_measurement_bench.cc") -target_include_directories(ms_bench PRIVATE - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/server +target_link_libraries(ms_bench + spectatord + benchmark::benchmark_main ) -target_link_libraries(ms_bench spectatord ${CONAN_LIBS}) #-- statsd_bench test executable add_executable(statsd_bench "statsd_bench.cc") -target_include_directories(statsd_bench PRIVATE - ${CMAKE_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/server +target_link_libraries(statsd_bench + spectatord + benchmark::benchmark_main ) -target_link_libraries(statsd_bench spectatord ${CONAN_LIBS}) #-- tags_bench test executable add_executable(tags_bench "bench_tags.cc") -target_include_directories(tags_bench PRIVATE ${CMAKE_SOURCE_DIR}) -target_link_libraries(tags_bench spectator ${CONAN_LIBS}) +target_link_libraries(tags_bench + spectator + benchmark::benchmark_main +) #-- to_valid_chars test executable add_executable(to_valid_chars "to_valid_bench.cc") -target_link_libraries(to_valid_chars ${CONAN_LIBS}) +target_link_libraries(to_valid_chars + benchmark::benchmark_main +) diff --git a/bench/bench_tags.cc b/bench/bench_tags.cc index 75a0d01..45e86c6 100644 --- a/bench/bench_tags.cc +++ b/bench/bench_tags.cc @@ -1,8 +1,8 @@ // Benchmarks different implementations for Tags +#include "../ska/flat_hash_map.hpp" #include #include -#include #include #include diff --git a/bench/get_measurement_bench.cc b/bench/get_measurement_bench.cc index e7b2863..137f22d 100644 --- a/bench/get_measurement_bench.cc +++ b/bench/get_measurement_bench.cc @@ -22,8 +22,8 @@ bench_get_measurement_strchr 2729 ns 2729 ns 252424 bench_get_measurement_strview 2488 ns 2488 ns 284401 */ +#include "../server/spectatord.h" #include -#include "spectatord.h" using spectator::Id; using spectatord::measurement; diff --git a/bench/measurements_fmt_bench.cc b/bench/measurements_fmt_bench.cc index bb1bbb6..76f5be6 100644 --- a/bench/measurements_fmt_bench.cc +++ b/bench/measurements_fmt_bench.cc @@ -20,8 +20,9 @@ bench_get_measurement_orig 4036 ns 4032 ns 169057 bench_get_measurement_new 3951 ns 3947 ns 176396 */ +#include "../server/spectatord.h" #include -#include "spectatord.h" + using spectator::Id; using spectatord::measurement; diff --git a/bench/parse_bench.cc b/bench/parse_bench.cc index bd9d990..1a83e40 100644 --- a/bench/parse_bench.cc +++ b/bench/parse_bench.cc @@ -1,7 +1,7 @@ +#include "../server/spectatord.h" #include #include #include -#include "spectatord.h" static std::vector get_measurements() { std::vector measurements; diff --git a/bench/statsd_bench.cc b/bench/statsd_bench.cc index 20bbc75..2f15a74 100644 --- a/bench/statsd_bench.cc +++ b/bench/statsd_bench.cc @@ -1,7 +1,7 @@ +#include "../server/spectatord.h" #include #include #include -#include "spectatord.h" class dummy_server : public spectatord::Server { public: diff --git a/bench/to_valid_bench.cc b/bench/to_valid_bench.cc index 13248d7..be2fafd 100644 --- a/bench/to_valid_bench.cc +++ b/bench/to_valid_bench.cc @@ -1,5 +1,5 @@ -#include #include +#include static constexpr std::array kAtlasChars128 = { {'_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', diff --git a/bin/spectatord_main.cc b/bin/spectatord_main.cc index 4941dc4..c2525e9 100644 --- a/bin/spectatord_main.cc +++ b/bin/spectatord_main.cc @@ -1,17 +1,16 @@ -#include "backward.hpp" -#include "util/logger.h" -#include "spectatord.h" -#include "spectator/registry.h" -#include "spectator/version.h" -#include +#include "../admin/admin_server.h" +#include "../server/spectatord.h" +#include "../spectator/version.h" #include "absl/flags/flag.h" -#include "absl/flags/parse.h" #include "absl/flags/internal/program_name.h" +#include "absl/flags/parse.h" #include "absl/flags/usage.h" #include "absl/flags/usage_config.h" #include "absl/strings/str_split.h" #include "absl/time/time.h" -#include "admin/admin_server.h" +#include "backward.hpp" + +#include #include auto GetSpectatorConfig() -> std::unique_ptr; @@ -33,8 +32,7 @@ auto AbslUnparseFlag(PortNumber p) -> std::string { // Parses a PortNumber from the command line flag value `text`. // Returns true and sets `*p` on success; returns false and sets `*error` // on failure. -auto AbslParseFlag(absl::string_view text, PortNumber* p, std::string* error) - -> bool { +auto AbslParseFlag(absl::string_view text, PortNumber* p, std::string* error) -> bool { // Convert from text to int using the int-flag parser. if (!absl::ParseFlag(text, &p->port, error)) { return false; diff --git a/bin/test_main.cc b/bin/test_main.cc index 9865185..5efedc6 100644 --- a/bin/test_main.cc +++ b/bin/test_main.cc @@ -4,9 +4,8 @@ int main(int argc, char** argv) { using backward::SignalHandling; auto signals = SignalHandling::make_default_signals(); - // default signals with the exception of SIGABRT - signals.erase(std::remove(signals.begin(), signals.end(), SIGABRT), - signals.end()); + // default signals except for SIGABRT + signals.erase(std::remove(signals.begin(), signals.end(), SIGABRT), signals.end()); SignalHandling sh{signals}; testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/build.sh b/build.sh index 1219f78..acc8c7a 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash -# usage: ./build.sh [clean|clean --force|skiptest] +set -e + +# usage: ./build.sh [clean|clean --confirm|skiptest] BUILD_DIR=cmake-build # Choose: Debug, Release, RelWithDebInfo and MinSizeRel @@ -20,29 +22,28 @@ if [[ "$1" == "clean" ]]; then rm -rf ska rm -f spectator/*.inc rm -f spectator/netflix_config.cc - if [[ "$2" == "--force" ]]; then - # remove all packages and binaries from the local cache, to allow swapping between Debug/Release builds - conan remove '*' --force + if [[ "$2" == "--confirm" ]]; then + # remove all packages from the conan cache, to allow swapping between Release/Debug builds + conan remove "*" --confirm fi fi if [[ "$OSTYPE" == "linux-gnu"* ]]; then - export CC=gcc-11 - export CXX=g++-11 + export CC=gcc-13 + export CXX=g++-13 fi -if [[ ! -d $BUILD_DIR ]]; then - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - echo -e "${BLUE}==== configure default profile ====${NC}" - conan profile new default --detect - conan profile update settings.compiler.libcxx=libstdc++11 default - fi +if [[ ! -f "$HOME/.conan2/profiles/default" ]]; then + echo -e "${BLUE}==== create default profile ====${NC}" + conan profile detect +fi +if [[ ! -d $BUILD_DIR ]]; then echo -e "${BLUE}==== install required dependencies ====${NC}" if [[ "$BUILD_TYPE" == "Debug" ]]; then - conan install . --build --install-folder $BUILD_DIR --profile ./sanitized + conan install . --output-folder=$BUILD_DIR --build="*" --settings=build_type=$BUILD_TYPE --profile=./sanitized else - conan install . --build=missing --install-folder $BUILD_DIR + conan install . --output-folder=$BUILD_DIR --build=missing fi echo -e "${BLUE}==== install source dependencies ====${NC}" @@ -52,22 +53,24 @@ if [[ ! -d $BUILD_DIR ]]; then NFLX_INTERNAL=$NFLX_INTERNAL conan source . fi -pushd $BUILD_DIR || exit 1 +pushd $BUILD_DIR -echo -e "${BLUE}==== generate build files ====${NC}" -if [[ "$NFLX_INTERNAL" == "ON" ]]; then - NFLX_INTERNAL="-DNFLX_INTERNAL=ON" -else - NFLX_INTERNAL="-DNFLX_INTERNAL=OFF" +echo -e "${BLUE}==== configure conan environment to access tools ====${NC}" +source conanbuild.sh + +if [[ $OSTYPE == "darwin"* ]]; then + export MallocNanoZone=0 fi -cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE $NFLX_INTERNAL .. || exit 1 + +echo -e "${BLUE}==== generate build files ====${NC}" +cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DNFLX_INTERNAL="$NFLX_INTERNAL" echo -e "${BLUE}==== build ====${NC}" -cmake --build . || exit 1 +cmake --build . if [[ "$1" != "skiptest" ]]; then echo -e "${BLUE}==== test ====${NC}" GTEST_COLOR=1 ctest --verbose fi -popd || exit 1 +popd diff --git a/conanfile.py b/conanfile.py index 5e485e6..e0148a7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -4,8 +4,8 @@ from dataclasses import dataclass from typing import Optional -from conans import ConanFile -from conans.tools import download, unzip, check_sha256 +from conan import ConanFile +from conan.tools.files import download, unzip, check_sha256 @dataclass @@ -18,24 +18,24 @@ class NflxConfig: class SpectatorDConan(ConanFile): settings = "os", "compiler", "build_type", "arch" requires = ( - "abseil/20230125.3", - "asio/1.28.1", + "abseil/20240116.2", + "asio/1.32.0", "backward-cpp/1.6", "benchmark/1.8.3", - "fmt/10.1.1", - "gtest/1.14.0", - "libcurl/8.4.0", - "openssl/3.2.0", - "poco/1.12.5p2", - "protobuf/3.21.12", + "fmt/11.0.2", + "gtest/1.15.0", + "libcurl/8.10.1", + "openssl/3.3.2", + "poco/1.13.3", + "protobuf/5.27.0", "rapidjson/cci.20230929", - "spdlog/1.12.0", + "spdlog/1.15.0", "tsl-hopscotch-map/2.3.1", "xxhash/0.8.2", - "zlib/1.3" + "zlib/1.3.1" ) - generators = "cmake" - default_options = {} + tool_requires = () + generators = "CMakeDeps", "CMakeToolchain" def configure(self): self.options["libcurl"].with_c_ares = True @@ -77,12 +77,12 @@ def get_flat_hash_map(self): zip_name = repo.replace("skarupke/", "") + f"-{commit}.zip" self.maybe_remove_file(zip_name) - download(f"https://github.com/{repo}/archive/{commit}.zip", zip_name) - check_sha256(zip_name, "513efb9c2f246b6df9fa16c5640618f09804b009e69c8f7bd18b3099a11203d5") + download(self, f"https://github.com/{repo}/archive/{commit}.zip", zip_name) + check_sha256(self, zip_name, "513efb9c2f246b6df9fa16c5640618f09804b009e69c8f7bd18b3099a11203d5") dir_name = "ska" self.maybe_remove_dir(dir_name) - unzip(zip_name, destination=dir_name, strip_root=True) + unzip(self, zip_name, destination=dir_name, strip_root=True) os.unlink(zip_name) @@ -93,11 +93,11 @@ def get_netflix_spectator_cppconf(self, nflx_cfg: NflxConfig) -> None: self.maybe_remove_file(zip_name) self.download(nflx_cfg, repo, commit, zip_name) - check_sha256(zip_name, "b8a202ccafb5389dbda02cb9750cb0bfcd44369c69e015eb55a10b5f8759d73a") + check_sha256(self, zip_name, "b8a202ccafb5389dbda02cb9750cb0bfcd44369c69e015eb55a10b5f8759d73a") dir_name = repo.replace("corp/", "") self.maybe_remove_dir(dir_name) - unzip(zip_name, destination=dir_name, strip_root=True) + unzip(self, zip_name, destination=dir_name, strip_root=True) self.maybe_remove_file("spectator/netflix_config.cc") shutil.move(f"{dir_name}/netflix_config.cc", "spectator") @@ -111,11 +111,11 @@ def get_spectatord_metatron(self, nflx_cfg: NflxConfig) -> None: self.maybe_remove_file(zip_name) self.download(nflx_cfg, repo, commit, zip_name) - check_sha256(zip_name, "a8be6a7ac2c8704f4b0c6d121de64db96855354eea2ef463d3e3c629c459fc04") + check_sha256(self, zip_name, "a8be6a7ac2c8704f4b0c6d121de64db96855354eea2ef463d3e3c629c459fc04") dir_name = repo.replace("corp/", "") self.maybe_remove_dir(dir_name) - unzip(zip_name, destination=dir_name, strip_root=True) + unzip(self, zip_name, destination=dir_name, strip_root=True) self.maybe_remove_file("metatron/auth_context.proto") self.maybe_remove_file("metatron/metatron_config.cc") shutil.move(f"{dir_name}/metatron/auth_context.proto", "metatron") diff --git a/metatron/CMakeLists.txt b/metatron/CMakeLists.txt index 84f828f..3d1c2e6 100644 --- a/metatron/CMakeLists.txt +++ b/metatron/CMakeLists.txt @@ -12,15 +12,15 @@ else() "metatron_sample.cc" ) endif() - -target_include_directories(metatron PRIVATE - ${CMAKE_SOURCE_DIR} +target_link_libraries(metatron util + CURL::libcurl + openssl::openssl + protobuf::protobuf ) -target_link_libraries(metatron util ${CONAN_LIBS}) #-- protobuf generated files must exist in both the SOURCE_DIR and the BINARY_DIR add_custom_command( OUTPUT auth_context.pb.cc auth_context.pb.h - COMMAND ${CONAN_PROTOBUF_ROOT}/bin/protoc --proto_path=${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${CMAKE_CURRENT_SOURCE_DIR} auth_context.proto - COMMAND ${CONAN_PROTOBUF_ROOT}/bin/protoc --proto_path=${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${CMAKE_CURRENT_BINARY_DIR} auth_context.proto + COMMAND protoc --proto_path=${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${CMAKE_CURRENT_SOURCE_DIR} auth_context.proto + COMMAND protoc --proto_path=${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${CMAKE_CURRENT_BINARY_DIR} auth_context.proto ) diff --git a/metatron/metatron_sample.cc b/metatron/metatron_sample.cc index ce547bc..0057017 100644 --- a/metatron/metatron_sample.cc +++ b/metatron/metatron_sample.cc @@ -1,5 +1,5 @@ #include "metatron_config.h" -#include "util/logger.h" +#include "../util/logger.h" namespace metatron { diff --git a/requirements.txt b/requirements.txt index 3c851a0..5b02ca9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -conan==1.65.0 +conan==2.9.2 diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 7dfe5ed..55df28d 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -12,5 +12,9 @@ add_library(spectatord "udp_server.cc" "udp_server.h" ) -target_include_directories(spectatord PRIVATE ${CMAKE_SOURCE_DIR}) -target_link_libraries(spectatord spectator util ${CONAN_LIBS}) +target_link_libraries(spectatord + spectator + util + abseil::abseil + asio::asio +) diff --git a/server/expiring_cache.h b/server/expiring_cache.h index d3fba22..2cac0f4 100644 --- a/server/expiring_cache.h +++ b/server/expiring_cache.h @@ -2,7 +2,7 @@ #include "absl/base/thread_annotations.h" #include "absl/synchronization/mutex.h" -#include "spectator/registry.h" +#include "../spectator/registry.h" #include #include diff --git a/server/local_server.cc b/server/local_server.cc index 8169b75..a3cdf28 100644 --- a/server/local_server.cc +++ b/server/local_server.cc @@ -1,5 +1,5 @@ #include "local_server.h" -#include "util/logger.h" +#include "../util/logger.h" #include "proc_utils.h" namespace spectatord { diff --git a/server/proc_utils.cc b/server/proc_utils.cc index 27cede3..911423d 100644 --- a/server/proc_utils.cc +++ b/server/proc_utils.cc @@ -1,5 +1,5 @@ #include "proc_utils.h" -#include "util/files.h" +#include "../util/files.h" #include #include #include "absl/strings/numbers.h" diff --git a/server/spectatord.cc b/server/spectatord.cc index 55f54f8..0207e8d 100644 --- a/server/spectatord.cc +++ b/server/spectatord.cc @@ -1,10 +1,6 @@ #include "spectatord.h" #include "local_server.h" -#include "util/logger.h" #include "proc_utils.h" -#include "spectator/percentile_distribution_summary.h" -#include "spectator/percentile_timer.h" -#include "spectator/registry.h" #include "udp_server.h" #include diff --git a/server/spectatord.h b/server/spectatord.h index 427547c..a95115b 100644 --- a/server/spectatord.h +++ b/server/spectatord.h @@ -2,9 +2,9 @@ #include "expiring_cache.h" #include "handler.h" -#include "spectator/percentile_distribution_summary.h" -#include "spectator/percentile_timer.h" -#include "spectator/registry.h" +#include "../spectator/percentile_distribution_summary.h" +#include "../spectator/percentile_timer.h" +#include "../spectator/registry.h" namespace spectatord { diff --git a/server/spectatord_test.cc b/server/spectatord_test.cc index 75a97ea..9b979b0 100644 --- a/server/spectatord_test.cc +++ b/server/spectatord_test.cc @@ -1,10 +1,9 @@ -#include +#include "../spectator/test_utils.h" +#include "gtest/gtest.h" #include "local.h" -#include "util/logger.h" #include "spectatord.h" -#include "spectator/test_utils.h" -#include "gtest/gtest.h" +#include namespace { diff --git a/server/udp_server.cc b/server/udp_server.cc index c8cc86e..5136902 100644 --- a/server/udp_server.cc +++ b/server/udp_server.cc @@ -1,5 +1,5 @@ #include "udp_server.h" -#include "util/logger.h" +#include "../util/logger.h" #include "proc_utils.h" using asio::ip::udp; diff --git a/spectator/CMakeLists.txt b/spectator/CMakeLists.txt index 8e04e98..9ef260d 100644 --- a/spectator/CMakeLists.txt +++ b/spectator/CMakeLists.txt @@ -64,8 +64,20 @@ add_library(spectator OBJECT "valid_chars.inc" "version.h" ) -target_include_directories(spectator PRIVATE ${CMAKE_SOURCE_DIR}) -target_link_libraries(spectator metatron util ${CONAN_LIBS}) +target_link_libraries(spectator + metatron + util + abseil::abseil + asio::asio + CURL::libcurl + fmt::fmt + gtest::gtest + rapidjson + spdlog::spdlog + tsl::hopscotch_map + xxHash::xxhash + ZLIB::ZLIB +) #-- file generators, must exist where the outputs are referenced add_custom_command( diff --git a/spectator/compressed_buffer.h b/spectator/compressed_buffer.h index 42e7693..2cd5c66 100644 --- a/spectator/compressed_buffer.h +++ b/spectator/compressed_buffer.h @@ -1,6 +1,8 @@ #pragma once + #include "gzip.h" #include +#include #include #include diff --git a/spectator/counter.cc b/spectator/counter.cc index 93600f3..0804622 100644 --- a/spectator/counter.cc +++ b/spectator/counter.cc @@ -1,6 +1,6 @@ #include "counter.h" #include "atomicnumber.h" -#include "spectator/common_refs.h" +#include "common_refs.h" namespace spectator { diff --git a/spectator/detail/perc_policy.h b/spectator/detail/perc_policy.h index d85fd29..9bd43ca 100644 --- a/spectator/detail/perc_policy.h +++ b/spectator/detail/perc_policy.h @@ -1,11 +1,12 @@ #pragma once + #include "../percentile_buckets.h" #include "../registry.h" #include namespace spectator::detail { -#include "spectator/percentile_bucket_tags.inc" +#include "../percentile_bucket_tags.inc" using counters_t = std::array, PercentileBucketsLength()>; diff --git a/spectator/gauge_test.cc b/spectator/gauge_test.cc index 544cd27..80ccf7a 100644 --- a/spectator/gauge_test.cc +++ b/spectator/gauge_test.cc @@ -1,5 +1,5 @@ -#include "../spectator/gauge.h" -#include "spectator/common_refs.h" +#include "gauge.h" +#include "common_refs.h" #include namespace { diff --git a/spectator/gzip.cc b/spectator/gzip.cc index bace170..4399d38 100644 --- a/spectator/gzip.cc +++ b/spectator/gzip.cc @@ -1,7 +1,5 @@ #include "gzip.h" -#include - #ifndef z_const #define z_const #endif diff --git a/spectator/http_client.h b/spectator/http_client.h index 01d3ac5..ed9adfd 100644 --- a/spectator/http_client.h +++ b/spectator/http_client.h @@ -2,7 +2,7 @@ #include "absl/time/time.h" #include "compressed_buffer.h" -#include "metatron/metatron_config.h" +#include "../metatron/metatron_config.h" #include #include #include diff --git a/spectator/http_server.cc b/spectator/http_server.cc index 7830170..636b604 100644 --- a/spectator/http_server.cc +++ b/spectator/http_server.cc @@ -1,10 +1,9 @@ -#include "http_server.h" +#include "../util/logger.h" #include "absl/strings/ascii.h" -#include "spectator/gzip.h" -#include "util/logger.h" +#include "gzip.h" +#include "http_server.h" #include -#include #include #include #include @@ -224,7 +223,7 @@ void http_server::accept_request(int client) { std::this_thread::sleep_for(read_sleep_); } - // TODO handle 404s + // TODO: handle 404s const auto& response = path_response_[path]; // hack for /getheader - just echo the headers that start with X- back diff --git a/spectator/perc_dist_summary_test.cc b/spectator/perc_dist_summary_test.cc index a9cf837..8b18122 100644 --- a/spectator/perc_dist_summary_test.cc +++ b/spectator/perc_dist_summary_test.cc @@ -14,6 +14,16 @@ std::unique_ptr getDS(Registry* r) { using Implementations = testing::Types; +// satisfy -Wgnu-zero-variadic-macro-arguments in TYPED_TEST_SUITE +class NameGenerator { + public: + template + static std::string GetName(int) { + if constexpr (std::is_same_v) return "PercentileDistributionSummary"; + return "unknownType"; + } +}; + template class PercentileDistributionSummaryTest : public ::testing::Test { protected: @@ -27,7 +37,7 @@ class PercentileDistributionSummaryTest : public ::testing::Test { T restricted_ds; }; -TYPED_TEST_SUITE(PercentileDistributionSummaryTest, Implementations); +TYPED_TEST_SUITE(PercentileDistributionSummaryTest, Implementations, NameGenerator); TYPED_TEST(PercentileDistributionSummaryTest, Percentile) { auto& ds = this->ds; @@ -51,9 +61,7 @@ TYPED_TEST(PercentileDistributionSummaryTest, Measure) { auto expected = std::map{}; auto percentileTag = kDistTags.at(PercentileBucketIndexOf(42)); - expected[fmt::format("ds|percentile={}|statistic=percentile", - percentileTag)] = 1; - + expected[fmt::format("ds|percentile={}|statistic=percentile", percentileTag)] = 1; expected["ds|statistic=count"] = 1; expected["ds|statistic=max"] = 42; expected["ds|statistic=totalAmount"] = 42; @@ -71,8 +79,7 @@ TYPED_TEST(PercentileDistributionSummaryTest, CountTotal) { } EXPECT_EQ(this->ds->Count(), 100); - EXPECT_EQ(this->ds->TotalAmount(), - 100 * 99 / 2); // sum(1,n) = n * (n - 1) / 2 + EXPECT_EQ(this->ds->TotalAmount(), 100 * 99 / 2); // sum(1,n) = n * (n - 1) / 2 } TYPED_TEST(PercentileDistributionSummaryTest, Restrict) { @@ -96,12 +103,9 @@ TYPED_TEST(PercentileDistributionSummaryTest, Restrict) { auto percTag = kDistTags.at(PercentileBucketIndexOf(10)); auto name = ds.MeterId().Name().Get(); - expected[fmt::format("{}|percentile={}|statistic=percentile", name, - minPercTag)] = 1; - expected[fmt::format("{}|percentile={}|statistic=percentile", name, - maxPercTag)] = 1; - expected[fmt::format("{}|percentile={}|statistic=percentile", name, - percTag)] = 1; + expected[fmt::format("{}|percentile={}|statistic=percentile", name, minPercTag)] = 1; + expected[fmt::format("{}|percentile={}|statistic=percentile", name, maxPercTag)] = 1; + expected[fmt::format("{}|percentile={}|statistic=percentile", name, percTag)] = 1; expected[fmt::format("{}|statistic=count", name)] = 3; auto totalSq = 10 * 10 + 10000 * 10000; @@ -111,8 +115,7 @@ TYPED_TEST(PercentileDistributionSummaryTest, Restrict) { ASSERT_EQ(expected.size(), actual.size()); for (const auto& expected_m : expected) { - EXPECT_DOUBLE_EQ(expected_m.second, actual[expected_m.first]) - << expected_m.first; + EXPECT_DOUBLE_EQ(expected_m.second, actual[expected_m.first]) << expected_m.first; } } } // namespace diff --git a/spectator/perc_timer_test.cc b/spectator/perc_timer_test.cc index a3c69da..222e01d 100644 --- a/spectator/perc_timer_test.cc +++ b/spectator/perc_timer_test.cc @@ -15,20 +15,29 @@ std::unique_ptr getTimer(Registry* r) { using Implementations = testing::Types; +// satisfy -Wgnu-zero-variadic-macro-arguments in TYPED_TEST_SUITE +class NameGenerator { + public: + template + static std::string GetName(int) { + if constexpr (std::is_same_v) return "PercentileTimer"; + return "unknownType"; + } +}; + template class PercentileTimerTest : public ::testing::Test { protected: PercentileTimerTest() : r{GetConfiguration(), spectatord::Logger()}, timer{getTimer(&r)}, - restricted_timer{&r, Id::Of("t2"), absl::Milliseconds(5), - absl::Seconds(2)} {} + restricted_timer{&r, Id::Of("t2"), absl::Milliseconds(5), absl::Seconds(2)} {} Registry r; std::unique_ptr timer; T restricted_timer; }; -TYPED_TEST_SUITE(PercentileTimerTest, Implementations); +TYPED_TEST_SUITE(PercentileTimerTest, Implementations, NameGenerator); TYPED_TEST(PercentileTimerTest, Percentile) { for (auto i = 0; i < 100000; ++i) { @@ -53,8 +62,7 @@ TYPED_TEST(PercentileTimerTest, Measure) { auto expected = std::map{}; auto percentileTag = kTimerTags.at(PercentileBucketIndexOf(elapsed_nanos)); - expected[fmt::format("t|percentile={}|statistic=percentile", percentileTag)] = - 1; + expected[fmt::format("t|percentile={}|statistic=percentile", percentileTag)] = 1; expected["t|statistic=count"] = 1; auto elapsed_secs = elapsed_nanos / 1e9; @@ -64,8 +72,7 @@ TYPED_TEST(PercentileTimerTest, Measure) { ASSERT_EQ(expected.size(), actual.size()); for (const auto& expected_m : expected) { - EXPECT_DOUBLE_EQ(expected_m.second, actual[expected_m.first]) - << expected_m.first; + EXPECT_DOUBLE_EQ(expected_m.second, actual[expected_m.first]) << expected_m.first; } } @@ -75,8 +82,7 @@ TYPED_TEST(PercentileTimerTest, CountTotal) { } EXPECT_EQ(this->timer->Count(), 100); - EXPECT_EQ(this->timer->TotalTime(), - 100 * 99 / 2); // sum(1,n) = n * (n - 1) / 2 + EXPECT_EQ(this->timer->TotalTime(), 100 * 99 / 2); // sum(1,n) = n * (n - 1) / 2 } TYPED_TEST(PercentileTimerTest, Restrict) { @@ -87,8 +93,7 @@ TYPED_TEST(PercentileTimerTest, Restrict) { t.Record(absl::Milliseconds(10)); // not restricted here - auto total = - absl::Milliseconds(1) + absl::Seconds(10) + absl::Milliseconds(10); + auto total = absl::Milliseconds(1) + absl::Seconds(10) + absl::Milliseconds(10); EXPECT_EQ(t.TotalTime(), absl::ToInt64Nanoseconds(total)); EXPECT_EQ(t.Count(), 3); @@ -99,18 +104,14 @@ TYPED_TEST(PercentileTimerTest, Restrict) { // 5ms auto minPercTag = kTimerTags.at(PercentileBucketIndexOf(5l * 1000 * 1000)); // 2s - auto maxPercTag = - kTimerTags.at(PercentileBucketIndexOf(2l * 1000 * 1000 * 1000)); + auto maxPercTag = kTimerTags.at(PercentileBucketIndexOf(2l * 1000 * 1000 * 1000)); // 10ms --> not restricted auto percTag = kTimerTags.at(PercentileBucketIndexOf(10l * 1000 * 1000)); std::string name = t.MeterId().Name().Get(); - expected[fmt::format("{}|percentile={}|statistic=percentile", name, - minPercTag)] = 1; - expected[fmt::format("{}|percentile={}|statistic=percentile", name, - maxPercTag)] = 1; - expected[fmt::format("{}|percentile={}|statistic=percentile", name, - percTag)] = 1; + expected[fmt::format("{}|percentile={}|statistic=percentile", name, minPercTag)] = 1; + expected[fmt::format("{}|percentile={}|statistic=percentile", name, maxPercTag)] = 1; + expected[fmt::format("{}|percentile={}|statistic=percentile", name, percTag)] = 1; expected[fmt::format("{}|statistic=count", name)] = 3; auto elapsed_secs = absl::ToDoubleSeconds(total); @@ -121,8 +122,7 @@ TYPED_TEST(PercentileTimerTest, Restrict) { ASSERT_EQ(expected.size(), actual.size()); for (const auto& expected_m : expected) { - EXPECT_DOUBLE_EQ(expected_m.second, actual[expected_m.first]) - << expected_m.first; + EXPECT_DOUBLE_EQ(expected_m.second, actual[expected_m.first]) << expected_m.first; } } } // namespace diff --git a/spectator/publisher.h b/spectator/publisher.h index e0fd583..57231ae 100644 --- a/spectator/publisher.h +++ b/spectator/publisher.h @@ -1,14 +1,15 @@ #pragma once -#include "absl/time/time.h" +#include "../metatron/metatron_config.h" +#include "../ska/flat_hash_map.hpp" +#include "../util/logger.h" #include "absl/synchronization/blocking_counter.h" +#include "absl/time/time.h" #include "common_refs.h" #include "config.h" #include "counter.h" #include "http_client.h" -#include "util/logger.h" #include "measurement.h" -#include "metatron/metatron_config.h" #include "smile.h" #include @@ -18,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/spectator/registry.cc b/spectator/registry.cc index 046e6ba..88514f4 100644 --- a/spectator/registry.cc +++ b/spectator/registry.cc @@ -1,7 +1,6 @@ #include "registry.h" -#include "util/logger.h" -#include +#include #include namespace spectator { diff --git a/spectator/registry.h b/spectator/registry.h index 40fa3ca..936b239 100644 --- a/spectator/registry.h +++ b/spectator/registry.h @@ -11,14 +11,15 @@ #include "max_gauge.h" #include "monotonic_counter.h" #include "monotonic_counter_uint.h" +#include "monotonic_sampled.h" #include "publisher.h" #include "timer.h" -#include "spectator/monotonic_sampled.h" + #include +#include #include #include #include -#include namespace spectator { diff --git a/spectator/smile.cc b/spectator/smile.cc index d8909f8..9b3006e 100644 --- a/spectator/smile.cc +++ b/spectator/smile.cc @@ -60,12 +60,14 @@ void SmilePayload::Append(size_t n) { buffer_.Append(kByteInt32, static_cast(i >> 7U), b3, b2, b1, b0); } +union LongDouble { + double d; + uint64_t l; +}; + void SmilePayload::Append(double value) { buffer_.Append(kByteFloat64); - union LongDouble { - double d; - uint64_t l; - } ld = {.d = value}; + LongDouble ld{value}; auto l = ld.l; // Handle first 29 bits (single bit first, then 4 x 7 bits) diff --git a/spectator/string_intern.h b/spectator/string_intern.h index 3e6a0bf..a71491c 100644 --- a/spectator/string_intern.h +++ b/spectator/string_intern.h @@ -50,11 +50,9 @@ struct hash { }; } // namespace std -template <> -struct fmt::formatter : fmt::formatter { - template - auto format(const spectator::StrRef& s, FormatContext& context) { +template <> struct fmt::formatter: formatter { + auto format(const spectator::StrRef& s, format_context& ctx) const -> format_context::iterator { std::string_view str_view{s.Get(), s.Length()}; - return fmt::formatter::format(str_view, context); + return fmt::formatter::format(str_view, ctx); } }; diff --git a/spectator/string_intern_test.cc b/spectator/string_intern_test.cc index eeb30cb..9bc409c 100644 --- a/spectator/string_intern_test.cc +++ b/spectator/string_intern_test.cc @@ -1,8 +1,9 @@ +#include "string_intern.h" #include #include -#include "spectator/string_intern.h" namespace { + using spectator::intern_str; using spectator::StrRef; diff --git a/spectator/tags_test.cc b/spectator/tags_test.cc index 0859c95..238dc48 100644 --- a/spectator/tags_test.cc +++ b/spectator/tags_test.cc @@ -1,4 +1,4 @@ -#include "spectator/tags.h" +#include "tags.h" #include #include @@ -52,14 +52,14 @@ TEST(Tags, At) { } // add n tags of the form K = V -auto prepare_tags(Tags* tags, int n) -> void { +auto prepare_tags(Tags* tags) -> void { for (auto i = 0; i < 16; ++i) { tags->add(fmt::format("K{}", i), fmt::format("V{}", i)); } } auto verify_tags(const Tags& tags, int n) -> void { - ASSERT_TRUE(tags.capacity() >= n); + ASSERT_TRUE(tags.capacity() >= (size_t)n); for (auto i = n - 1; i >= 0; --i) { auto k = spectator::intern_str(fmt::format("K{}", i)); auto v = spectator::intern_str(fmt::format("V{}", i)); @@ -70,7 +70,7 @@ auto verify_tags(const Tags& tags, int n) -> void { TEST(Tags, Copy) { for (auto size = 1; size < 16; ++size) { Tags t; - prepare_tags(&t, size); + prepare_tags(&t); Tags t2{t}; ASSERT_EQ(t2.size(), t.size()); @@ -84,7 +84,7 @@ TEST(Tags, Copy_Add) { using spectator::intern_str; for (auto size = 15; size < 16; ++size) { Tags t; - prepare_tags(&t, size); + prepare_tags(&t); Tags t2{t}; // add to the end diff --git a/tools/gen_perc_bucket_tags.cc b/tools/gen_perc_bucket_tags.cc index eaf9410..7eba4aa 100644 --- a/tools/gen_perc_bucket_tags.cc +++ b/tools/gen_perc_bucket_tags.cc @@ -15,7 +15,7 @@ void output_array(std::ostream& os, size_t size, char prefix, } else { first = false; } - sprintf(tag, "\"%c%04zX\"", prefix, i); + snprintf(tag, sizeof tag, "\"%c%04zX\"", prefix, i); os << tag; } os << "}};\n"; diff --git a/tools/metrics_gen.cc b/tools/metrics_gen.cc index 7dcfced..36ce717 100644 --- a/tools/metrics_gen.cc +++ b/tools/metrics_gen.cc @@ -1,13 +1,11 @@ -#include "local.h" +#include "../server/local.h" #include "absl/strings/numbers.h" - #include -#include -#include #include -#include +#include #include #include +#include using metrics_t = std::vector; using asio::ip::udp; diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index ed03d50..cd93ce1 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -4,4 +4,4 @@ add_library(util OBJECT "logger.cc" "logger.h" ) -target_link_libraries(util ${CONAN_LIBS}) +target_link_libraries(util spdlog::spdlog) diff --git a/util/files.h b/util/files.h index 78922c3..85bf15c 100644 --- a/util/files.h +++ b/util/files.h @@ -1,6 +1,6 @@ #pragma once -#include "util/logger.h" +#include "logger.h" #include namespace spectatord {