Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
KEP-1505 swarm stats need to include stack name
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruck committed Jun 12, 2019
1 parent 9918b6b commit 1725b57
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion bootstrap/test/bootstrap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ TEST_F(bootstrap_file_test, test_duplicate_peers)
ASSERT_EQ(bootstrap_peers.get_peers().size(), 1U);
}

// flaky tests...

TEST(bootstrap_net_test, DISABLED_test_fetch_data)
{
Expand All @@ -150,7 +151,7 @@ TEST(bootstrap_net_test, DISABLED_test_fetch_data_with_protocol)
}


TEST(bootstrap_net_test, test_fetch_peers_from_solidity)
TEST(bootstrap_net_test, DISABLED_test_fetch_peers_from_solidity)
{
bzn::bootstrap_peers bootstrap_peers;
bzn::uuid_t swarm_id{"BluzelleSwarm"};
Expand Down
2 changes: 2 additions & 0 deletions mocks/mock_options_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class mock_options_base : public options_base {
std::string());
MOCK_CONST_METHOD0(get_swarm_info_esr_url,
std::string());
MOCK_CONST_METHOD0(get_stack,
std::string());
};

} // namespace bzn
6 changes: 3 additions & 3 deletions monitor/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace bzn;

namespace
{
std::unordered_map<statistic, std::string> statistic_names{
const std::unordered_map<statistic, std::string> statistic_names{
{
{statistic::hash_computed, "crypto.hashes_computed"},
{statistic::hash_computed_bytes, "crypto.bytes_hashed"},
Expand Down Expand Up @@ -52,7 +52,7 @@ monitor::monitor(std::shared_ptr<bzn::options_base> options, std::shared_ptr<bzn
, clock(std::move(clock))
, socket(this->context->make_unique_udp_socket())
, monitor_endpoint(this->options->get_monitor_endpoint(this->context))
, scope_prefix("com.bluzelle.swarm.singleton.node." + this->options->get_uuid())
, scope_prefix("com.bluzelle." + this->options->get_stack() + "." + this->options->get_swarm_id() + ".swarmdb." + this->options->get_uuid())
{
if (this->monitor_endpoint)
{
Expand Down Expand Up @@ -170,4 +170,4 @@ monitor::maybe_send()
this->accumulated_stats.clear();
this->time_last_sent = this->clock->microseconds_since_epoch();
}
}
}
4 changes: 3 additions & 1 deletion monitor/test/monitor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class monitor_test : public Test
{
EXPECT_CALL(*(this->options), get_uuid()).WillRepeatedly(Return("uuid"));
EXPECT_CALL(*(this->options), get_monitor_endpoint(_)).WillRepeatedly(Invoke([&](auto){return this->ep;}));
EXPECT_CALL(*(this->options), get_stack()).WillRepeatedly(Return("utest"));
EXPECT_CALL(*(this->options), get_swarm_id()).WillRepeatedly(Return("0"));
this->soptions.set(bzn::option_names::MONITOR_MAX_TIMERS, "100");
this->soptions.set(bzn::option_names::MONITOR_COLLATE, "false");
EXPECT_CALL(*(this->options), get_simple_options()).WillRepeatedly(Invoke(
Expand Down Expand Up @@ -164,7 +166,7 @@ TEST_F(monitor_test, test_timer_with_duplicate_triggers)

TEST_F(monitor_test, test_no_endpoint)
{
auto options2 = std::make_shared<bzn::mock_options_base>();
auto options2 = std::make_shared<NiceMock<bzn::mock_options_base>>();
EXPECT_CALL(*options2, get_monitor_endpoint(_)).WillRepeatedly(Return(std::nullopt));
auto monitor2 = std::make_shared<bzn::monitor>(options2, io_context, clock);

Expand Down
7 changes: 7 additions & 0 deletions options/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,10 @@ options::get_swarm_info_esr_url() const
{
return this->raw_opts.get<std::string>(SWARM_INFO_ESR_URL);
}


std::string
options::get_stack() const
{
return this->raw_opts.get<std::string>(STACK);
}
2 changes: 2 additions & 0 deletions options/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ namespace bzn

std::string get_swarm_info_esr_url() const override;

std::string get_stack() const override;

private:
size_t parse_size(const std::string& key) const;

Expand Down
16 changes: 16 additions & 0 deletions options/options_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,60 +47,70 @@ namespace bzn
*/
virtual const simple_options& get_simple_options() const = 0;


/**
* @return the raw_options container for accessing simple options
*/
virtual simple_options& get_mutable_simple_options() = 0;


/**
* Get the address and port for the node to listen on
* @return endpoint
*/
virtual boost::asio::ip::tcp::endpoint get_listener() const = 0;


/**
* The address and port to send stats.d data to, if this is enabled
* @return optional<endpoint>
*/
virtual std::optional<boost::asio::ip::udp::endpoint> get_monitor_endpoint(
std::shared_ptr<bzn::asio::io_context_base> context) const = 0;


/**
* Get the url to fetch initial peers from
* @return url
*/
virtual std::string get_bootstrap_peers_url() const = 0;


/**
* Get the file to fetch initial peers from
* @return filename
*/
virtual std::string get_bootstrap_peers_file() const = 0;


/**
* Debug logging level?
* @return true if we should log debug entries
*/
virtual bool get_debug_logging() const = 0;


/**
* Log to terminal instead of disk.
* @return true if we log to stdout
*/
virtual bool get_log_to_stdout() const = 0;


/**
* Get the peer's unique id
* @return uuid
*/
virtual bzn::uuid_t get_uuid() const = 0;


/**
* Get the swarm id this peer belongs to
* @return swarm_id
*/
virtual bzn::swarm_id_t get_swarm_id() const = 0;


/**
* Get the websocket activity timeout
* @return seconds
Expand Down Expand Up @@ -190,5 +200,11 @@ namespace bzn
* @return string containing the url of the server
*/
virtual std::string get_swarm_info_esr_url() const = 0;

/**
* Retrieve the name of the stack the swarm is using
* @return string stack name
*/
virtual std::string get_stack() const = 0;
};
} // bzn
5 changes: 4 additions & 1 deletion options/simple_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ simple_options::build_options()
"Address of ESR Swarm Info contract")
(SWARM_INFO_ESR_URL.c_str(),
po::value<std::string>()->default_value(bzn::utils::ROPSTEN_URL),
"url of ESR Swarm Info contract server");
"url of ESR Swarm Info contract server")
(STACK.c_str(),
po::value<std::string>()->required(),
"software stack used by swarm");

po::options_description logging("Logging");
logging.add_options()
Expand Down
2 changes: 2 additions & 0 deletions options/simple_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace bzn::option_names

const std::string SWARM_INFO_ESR_ADDRESS = "swarm_info_esr_address";
const std::string SWARM_INFO_ESR_URL = "swarm_info_esr_url";

const std::string STACK = "stack";
}

namespace bzn
Expand Down
2 changes: 2 additions & 0 deletions options/test/options_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace
" \"bootstrap_url\" : \"example.org/peers.json\",\n"
" \"uuid\" : \"c05c0dff-3c27-4532-96de-36f53d8a278e\",\n"
" \"swarm_id\" : \"utest\",\n"
" \"stack\" : \"utest\", \n"
" \"debug_logging\" : true,"
" \"log_to_stdout\" : true,"
" \"state_dir\" : \"./daemon_state/\","
Expand Down Expand Up @@ -142,6 +143,7 @@ TEST_F(options_file_test, test_that_loading_of_default_config_file)
ASSERT_EQ(true, options.get_debug_logging());
ASSERT_EQ(true, options.get_log_to_stdout());
EXPECT_EQ("utest", options.get_swarm_id());
EXPECT_EQ("utest", options.get_stack());
EXPECT_EQ("./daemon_state/", options.get_state_dir());
EXPECT_EQ("peers.json", options.get_bootstrap_peers_file());
EXPECT_EQ("example.org/peers.json", options.get_bootstrap_peers_url());
Expand Down
3 changes: 2 additions & 1 deletion swarm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ init_peers(bzn::bootstrap_peers& peers, const std::string& peers_file, const std
return true;
}

LOG(warning) << "Etherium Smart Contract Registry contained no peer listing for the swarm with id " << swarm_id << " checking other sources";
LOG(warning) << "Ethereum Swarm Registry contained no peer listing for the swarm with id " << swarm_id << " checking other sources";
}

if (!peers_file.empty())
Expand Down Expand Up @@ -184,6 +184,7 @@ print_banner(const bzn::options& options)
<< " Local IP Address: " << options.get_listener().address().to_string() << "\n"
<< " On port: " << options.get_listener().port() << "\n"
<< " Maximum Swarm Storage: " << options.get_max_swarm_storage() << " Bytes" << "\n"
<< " Stack: " << options.get_stack() << "\n"
<< '\n';

LOG(info) << ss.str();
Expand Down

0 comments on commit 1725b57

Please sign in to comment.