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

Commit

Permalink
KEP-847: Update audit module and clean logs
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelsavannah committed Dec 1, 2018
1 parent dc6eb93 commit 5de3158
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 707 deletions.
2 changes: 1 addition & 1 deletion audit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_library(audit
audit.cpp
)

target_link_libraries(audit proto)
target_link_libraries(audit utils proto)
add_dependencies(audit jsoncpp)
target_include_directories(audit PRIVATE ${JSONCPP_INCLUDE_DIRS} ${PROTO_INCLUDE_DIR})
add_subdirectory(test)
284 changes: 39 additions & 245 deletions audit/audit.cpp

Large diffs are not rendered by default.

32 changes: 3 additions & 29 deletions audit/audit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,85 +33,59 @@ namespace bzn
, std::optional<boost::asio::ip::udp::endpoint>
, bzn::uuid_t uuid
, size_t mem_size
, bool use_pbft);
);

size_t error_count() const override;

const std::list<std::string>& error_strings() const override;


void handle(const bzn::json_message& message, std::shared_ptr<bzn::session_base> session) override;
void handle_raft_commit(const raft_commit_notification&) override;
void handle_leader_status(const leader_status&) override;
void handle(const bzn_envelope& message, std::shared_ptr<bzn::session_base> session) override;

void handle_pbft_commit(const pbft_commit_notification&) override;
void handle_primary_status(const primary_status&) override;

void handle_failure_detected(const failure_detected&) override;

size_t current_memory_size();

void start() override;

private:

void handle_leader_alive_timeout(const boost::system::error_code& ec);
void handle_primary_alive_timeout(const boost::system::error_code& ec);
void handle_leader_progress_timeout(const boost::system::error_code& ec);

void reset_leader_alive_timer();
void reset_primary_alive_timer();
void reset_leader_progress_timer();
void clear_leader_progress_timer();

void report_error(const std::string& metric_name, const std::string& error_description);
void send_to_monitor(const std::string& stat);

void handle_leader_data(const leader_status&);
void handle_leader_made_progress(const leader_status&);

void raft_specific_init();
void pbft_specific_init();

void trim();
const bzn::uuid_t uuid;

std::list<std::string> recorded_errors;
const std::shared_ptr<bzn::node_base> node;
const std::shared_ptr<bzn::asio::io_context_base> io_context;

uint leader_dead_count = 0;
uint primary_dead_count = 0;
uint leader_stuck_count = 0;

std::map<uint64_t, bzn::uuid_t> recorded_leaders;
std::map<uint64_t, std::string> recorded_raft_commits;

std::map<uint64_t, bzn::uuid_t> recorded_primaries;
std::map<uint64_t, std::string> recorded_pbft_commits;

std::once_flag start_once;
std::mutex audit_lock;
std::unique_ptr<bzn::asio::steady_timer_base> leader_alive_timer;
std::unique_ptr<bzn::asio::steady_timer_base> leader_progress_timer;
std::unique_ptr<bzn::asio::steady_timer_base> primary_alive_timer;

// TODO: Make this configurable
std::chrono::milliseconds leader_timeout{std::chrono::milliseconds(30000)};
std::chrono::milliseconds primary_timeout{std::chrono::milliseconds(30000)};

bzn::uuid_t last_leader = "";
uint64_t last_leader_commit_index = 0;
bool leader_has_uncommitted_entries = false;

size_t forgotten_error_count = 0;
std::optional<boost::asio::ip::udp::endpoint> monitor_endpoint;
std::unique_ptr<bzn::asio::udp_socket_base> socket;

const std::string statsd_namespace_prefix;

size_t mem_size;

const bool use_pbft;
};

}
13 changes: 1 addition & 12 deletions audit/audit_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@

namespace bzn
{
const std::string LEADER_CONFLICT_METRIC_NAME = "raft.safety.leader_conflict";
const std::string RAFT_COMMIT_CONFLICT_METRIC_NAME = "raft.safety.commit_conflict";
const std::string LEADER_STUCK_METRIC_NAME = "raft.liveness.leader_stuck";
const std::string NO_LEADER_METRIC_NAME = "raft.liveness.no_leader";
const std::string RAFT_COMMIT_METRIC_NAME = "raft.stats.commit_heard";
const std::string NEW_LEADER_METRIC_NAME = "raft.stats.new_leader_heard";

const std::string PBFT_COMMIT_METRIC_NAME = "pbft.stats.commit_heard";
const std::string PRIMARY_HEARD_METRIC_NAME = "pbft.stats.primary_heard";
const std::string FAILURE_DETECTED_METRIC_NAME = "pbft.stats.failure_detected";
Expand All @@ -53,11 +46,7 @@ namespace bzn

virtual const std::list<std::string> &error_strings() const = 0;

virtual void handle(const bzn::json_message& msg, std::shared_ptr<bzn::session_base> session) = 0;

virtual void handle_raft_commit(const raft_commit_notification&) = 0;

virtual void handle_leader_status(const leader_status&) = 0;
virtual void handle(const bzn_envelope& msg, std::shared_ptr<bzn::session_base> session) = 0;

virtual void handle_pbft_commit(const pbft_commit_notification&) = 0;

Expand Down
Loading

0 comments on commit 5de3158

Please sign in to comment.