Skip to content

Commit

Permalink
wip: config shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
copperlight committed Oct 19, 2023
1 parent a01a271 commit c2d6dbb
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion bin/spectatord_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> socket_path;
Expand Down
4 changes: 2 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions server/spectatord.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Server {
std::optional<int> statsd_port_number_;
std::optional<std::string> socket_path_;
spectator::Registry* registry_;
spectator::Registry* internal_registry_;
std::shared_ptr<spectator::Counter> parsed_count_;
std::shared_ptr<spectator::Counter> parse_errors_;
std::shared_ptr<spdlog::logger> logger_;
Expand Down
2 changes: 1 addition & 1 deletion spectator/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ class Config {
};

// Get a new spectator configuration.
auto GetConfiguration() -> std::unique_ptr<Config>;
auto GetConfiguration() -> std::shared_ptr<Config>;

} // namespace spectator
3 changes: 2 additions & 1 deletion spectator/http_client_test.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <atomic>
#include <utility>
#include <gtest/gtest.h>
#include <zlib.h>

Expand Down Expand Up @@ -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> config)
explicit TestRegistry(std::shared_ptr<Config> config)
: Registry(std::move(config), spectatord::Logger()) {}
};

Expand Down
2 changes: 1 addition & 1 deletion spectator/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace spectator {

Registry::Registry(std::unique_ptr<Config> config,
Registry::Registry(std::shared_ptr<Config> config,
Registry::logger_ptr logger) noexcept
: should_stop_{true},
age_gauge_first_warn_{true},
Expand Down
4 changes: 2 additions & 2 deletions spectator/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Registry {
using measurements_callback =
std::function<void(const std::vector<Measurement>&)>;

Registry(std::unique_ptr<Config> config, logger_ptr logger) noexcept;
Registry(std::shared_ptr<Config> config, logger_ptr logger) noexcept;
Registry(const Registry&) = delete;
Registry(Registry&&) = delete;
auto operator=(const Registry&) -> Registry& = delete;
Expand Down Expand Up @@ -347,7 +347,7 @@ class Registry {
std::thread expirer_thread_;
int64_t meter_ttl_; // in nanos

std::unique_ptr<Config> config_;
std::shared_ptr<Config> config_;
logger_ptr logger_;

detail::all_meters all_meters_;
Expand Down
2 changes: 1 addition & 1 deletion spectator/registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TEST(Registry, MeasurementTest) {
}

struct ExpRegistry : public Registry {
explicit ExpRegistry(std::unique_ptr<spectator::Config> cfg)
explicit ExpRegistry(std::shared_ptr<spectator::Config> cfg)
: Registry(std::move(cfg), spectatord::Logger()) {}

void expire() { remove_expired_meters(); }
Expand Down
6 changes: 3 additions & 3 deletions spectator/sample_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace spectator {

// used in tests
auto GetConfiguration() -> std::unique_ptr<Config> {
auto config = std::make_unique<Config>();
auto GetConfiguration() -> std::shared_ptr<Config> {
auto config = std::make_shared<Config>();
config->age_gauge_limit = 10;
return config;
}

} // namespace spectator

auto GetSpectatorConfig() -> std::unique_ptr<spectator::Config> {
auto GetSpectatorConfig() -> std::shared_ptr<spectator::Config> {
return spectator::GetConfiguration();
}

0 comments on commit c2d6dbb

Please sign in to comment.