Skip to content

Commit

Permalink
Merge pull request #221 from msgmaxim/reason
Browse files Browse the repository at this point in the history
Record the reason for test failure
  • Loading branch information
msgmaxim committed Jul 11, 2019
2 parents 37c2279 + 642cc63 commit b206ae9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
14 changes: 8 additions & 6 deletions httpserver/service_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,18 +774,19 @@ void ServiceNode::send_storage_test_req(const sn_record_t& testee,

auto callback = [testee, item, height = this->block_height_,
this](sn_response_t&& res) {
bool success = false;
ResultType result = ResultType::OTHER;

if (res.error_code == SNodeError::NO_ERROR && res.body) {
if (*res.body == item.data) {
LOKI_LOG(debug,
"Storage test is successful for: {} at height: {}",
testee, height);
success = true;
result = ResultType::OK;
} else {

LOKI_LOG(warn, "Test answer doesn't match for: {} at height {}",
testee, height);
result = ResultType::MISMATCH;

#ifdef INTEGRATION_TEST
LOKI_LOG(warn, "got: {} expected: {}", *res.body, item.data);
Expand All @@ -802,7 +803,7 @@ void ServiceNode::send_storage_test_req(const sn_record_t& testee,
// abort_if_integration_test();
}

this->all_stats_.record_storage_test_result(testee, success);
this->all_stats_.record_storage_test_result(testee, result);
};

nlohmann::json json_body;
Expand Down Expand Up @@ -857,7 +858,7 @@ void ServiceNode::process_blockchain_test_response(
"Processing blockchain test response from: {} at height: {}",
testee, bc_height);

bool success = false;
ResultType result = ResultType::OTHER;

if (res.error_code == SNodeError::NO_ERROR && res.body) {

Expand All @@ -867,9 +868,10 @@ void ServiceNode::process_blockchain_test_response(
uint64_t their_height = body.at("res_height").get<uint64_t>();

if (our_answer.res_height == their_height) {
success = true;
result = ResultType::OK;
LOKI_LOG(debug, "Success.");
} else {
result = ResultType::MISMATCH;
LOKI_LOG(debug, "Failed: incorrect answer.");
}

Expand All @@ -882,7 +884,7 @@ void ServiceNode::process_blockchain_test_response(
testee);
}

this->all_stats_.record_blockchain_test_result(testee, success);
this->all_stats_.record_blockchain_test_result(testee, result);
}

// Deterministically selects two random swarm members; returns true on success
Expand Down
4 changes: 2 additions & 2 deletions httpserver/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace loki {

void to_json(nlohmann::json& j, const test_result_t& val) {
j["timestamp"] = val.timestamp;
j["success"] = val.success;
j["result"] = to_str(val.result);
}

std::string all_stats_t::to_json(bool pretty) const {
Expand Down Expand Up @@ -47,7 +47,7 @@ static void cleanup_old(std::deque<test_result_t>& tests, time_t cutoff_time) {
tests.erase(tests.begin(), it);
}

static constexpr std::chrono::seconds ROLLING_WINDOW_SIZE = 60min;
static constexpr std::chrono::seconds ROLLING_WINDOW_SIZE = 120min;

void all_stats_t::cleanup() {

Expand Down
29 changes: 24 additions & 5 deletions httpserver/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@ struct time_entry_t {
time_t timestamp;
};

enum class ResultType {
OK,
MISMATCH,
OTHER
};

struct test_result_t {

// seconds since Epoch when entry was recorded
time_t timestamp;
bool success;
ResultType result;
};

inline const char* to_str(ResultType result) {
switch (result) {
case ResultType::OK:
return "OK";
case ResultType::MISMATCH:
return "MISMATCH";
case ResultType::OTHER:
default:
return "OTHER";
}
}

// Stats per peer
struct peer_stats_t {

Expand Down Expand Up @@ -53,13 +72,13 @@ class all_stats_t {
peer_report_[sn].pushes_failed++;
}

void record_storage_test_result(const sn_record_t& sn, bool success) {
test_result_t res = {std::time(nullptr), success};
void record_storage_test_result(const sn_record_t& sn, ResultType result) {
test_result_t res = {std::time(nullptr), result};
peer_report_[sn].storage_tests.push_back(res);
}

void record_blockchain_test_result(const sn_record_t& sn, bool success) {
test_result_t t = {std::time(nullptr), success};
void record_blockchain_test_result(const sn_record_t& sn, ResultType result) {
test_result_t t = {std::time(nullptr), result};
peer_report_[sn].blockchain_tests.push_back(t);
}

Expand Down

0 comments on commit b206ae9

Please sign in to comment.