From c2d6dbb3a558fe26ed119f0fe502e5cade96c3d2 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Tue, 3 Oct 2023 10:56:46 -0700 Subject: [PATCH] wip: config shared_ptr --- bin/spectatord_main.cc | 5 ++++- conanfile.py | 4 ++-- server/spectatord.h | 1 + spectator/config.h | 2 +- spectator/http_client_test.cc | 3 ++- spectator/registry.cc | 2 +- spectator/registry.h | 4 ++-- spectator/registry_test.cc | 2 +- spectator/sample_config.cc | 6 +++--- 9 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bin/spectatord_main.cc b/bin/spectatord_main.cc index ec0e40f..df0d08e 100644 --- a/bin/spectatord_main.cc +++ b/bin/spectatord_main.cc @@ -142,7 +142,10 @@ auto main(int argc, char** argv) -> int { logger->info("Unable to load signal handling for stacktraces"); } - spectator::Registry registry{std::move(cfg), std::move(spectator_logger)}; + spectator::Registry internal_registry{cfg, spectator_logger}; + internal_registry.Start(); + + spectator::Registry registry{cfg, spectator_logger}; registry.Start(); std::optional socket_path; diff --git a/conanfile.py b/conanfile.py index 41bb5f3..4954ea8 100644 --- a/conanfile.py +++ b/conanfile.py @@ -55,10 +55,10 @@ def get_netflix_spectator_cppconf(): if os.environ.get("NFLX_INTERNAL") != "ON": return dir_name = "netflix_spectator_cppconf" - commit = "246d24b72071ae2bb769b13d65f131d72cbbe0b4" + commit = "e2e3903c08918282bbc933f0f7a3e68c90ec33b2" zip_name = f"nflx_spectator_cppconf-{commit}.zip" download(f"https://stash.corp.netflix.com/rest/api/latest/projects/CLDMTA/repos/netflix-spectator-cppconf/archive?at={commit}&format=zip", zip_name) - check_sha256(zip_name, "93b9f318bccfe256bcf0e9d3ddb7a8baa637c0e374693ac07ebc30a37de9081c") + check_sha256(zip_name, "0280c3b25369d068ba36764c032fd9e46d51aedd46a327dac1276e9e35530358") unzip(zip_name, destination=dir_name) shutil.move(f"{dir_name}/netflix_config.cc", "spectator") os.unlink(zip_name) diff --git a/server/spectatord.h b/server/spectatord.h index 38289b9..acf5379 100644 --- a/server/spectatord.h +++ b/server/spectatord.h @@ -27,6 +27,7 @@ class Server { std::optional statsd_port_number_; std::optional socket_path_; spectator::Registry* registry_; + spectator::Registry* internal_registry_; std::shared_ptr parsed_count_; std::shared_ptr parse_errors_; std::shared_ptr logger_; diff --git a/spectator/config.h b/spectator/config.h index 52fcc37..4b61f35 100644 --- a/spectator/config.h +++ b/spectator/config.h @@ -49,6 +49,6 @@ class Config { }; // Get a new spectator configuration. -auto GetConfiguration() -> std::unique_ptr; +auto GetConfiguration() -> std::shared_ptr; } // namespace spectator diff --git a/spectator/http_client_test.cc b/spectator/http_client_test.cc index 7555edc..3ba735e 100644 --- a/spectator/http_client_test.cc +++ b/spectator/http_client_test.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -44,7 +45,7 @@ const Timer* find_timer(Registry* registry, const std::string& name, class TestRegistry : public Registry { public: - explicit TestRegistry(std::unique_ptr config) + explicit TestRegistry(std::shared_ptr config) : Registry(std::move(config), spectatord::Logger()) {} }; diff --git a/spectator/registry.cc b/spectator/registry.cc index 3a927cd..3433e13 100644 --- a/spectator/registry.cc +++ b/spectator/registry.cc @@ -6,7 +6,7 @@ namespace spectator { -Registry::Registry(std::unique_ptr config, +Registry::Registry(std::shared_ptr config, Registry::logger_ptr logger) noexcept : should_stop_{true}, age_gauge_first_warn_{true}, diff --git a/spectator/registry.h b/spectator/registry.h index e462814..be72ccc 100644 --- a/spectator/registry.h +++ b/spectator/registry.h @@ -253,7 +253,7 @@ class Registry { using measurements_callback = std::function&)>; - Registry(std::unique_ptr config, logger_ptr logger) noexcept; + Registry(std::shared_ptr config, logger_ptr logger) noexcept; Registry(const Registry&) = delete; Registry(Registry&&) = delete; auto operator=(const Registry&) -> Registry& = delete; @@ -347,7 +347,7 @@ class Registry { std::thread expirer_thread_; int64_t meter_ttl_; // in nanos - std::unique_ptr config_; + std::shared_ptr config_; logger_ptr logger_; detail::all_meters all_meters_; diff --git a/spectator/registry_test.cc b/spectator/registry_test.cc index 537340a..48fbd4b 100644 --- a/spectator/registry_test.cc +++ b/spectator/registry_test.cc @@ -117,7 +117,7 @@ TEST(Registry, MeasurementTest) { } struct ExpRegistry : public Registry { - explicit ExpRegistry(std::unique_ptr cfg) + explicit ExpRegistry(std::shared_ptr cfg) : Registry(std::move(cfg), spectatord::Logger()) {} void expire() { remove_expired_meters(); } diff --git a/spectator/sample_config.cc b/spectator/sample_config.cc index 7908775..21460c0 100644 --- a/spectator/sample_config.cc +++ b/spectator/sample_config.cc @@ -3,14 +3,14 @@ namespace spectator { // used in tests -auto GetConfiguration() -> std::unique_ptr { - auto config = std::make_unique(); +auto GetConfiguration() -> std::shared_ptr { + auto config = std::make_shared(); config->age_gauge_limit = 10; return config; } } // namespace spectator -auto GetSpectatorConfig() -> std::unique_ptr { +auto GetSpectatorConfig() -> std::shared_ptr { return spectator::GetConfiguration(); }