Skip to content

Commit

Permalink
Add Tx and Rx drop stats in pysandesh
Browse files Browse the repository at this point in the history
- Update drop stats in Tx and Rx path
- Unit test for sandesh_stats module

Change-Id: I9d38c51740cb054828f9f98cbe63d9b277be5f05
Partial-Bug: #1472106
  • Loading branch information
Sundaresan Rajangam committed Jul 28, 2015
1 parent 0808b1d commit a1acb24
Show file tree
Hide file tree
Showing 22 changed files with 563 additions and 180 deletions.
2 changes: 1 addition & 1 deletion compiler/generate/t_cpp_generator.cc
Expand Up @@ -1217,7 +1217,7 @@ void t_cpp_generator::generate_sandesh_async_creators(ofstream &out, t_sandesh *
out << indent() << "if (level >= SendingLevel()) {" << endl;
indent_up();
out << indent() << "UpdateTxMsgFailStats(\"" << tsandesh->get_name() <<
"\", 0, Sandesh::DropReason::Send::QueueLevel);" << endl;
"\", 0, SandeshTxDropReason::QueueLevel);" << endl;
if (!is_flow) {
out << indent() << "DropLog" <<
generate_sandesh_async_creator(tsandesh, false, false, false, "", "", false, false) <<
Expand Down
27 changes: 27 additions & 0 deletions library/common/sandesh.sandesh
Expand Up @@ -57,6 +57,33 @@ enum SandeshLevel {
INVALID = 0x7fffffff
}

enum SandeshTxDropReason {
MinDropReason = 0,
NoDrop,
ValidationFailed,
QueueLevel,
NoClient,
NoSession,
NoQueue,
ClientSendFailed,
HeaderWriteFailed,
WriteFailed,
SessionNotConnected,
WrongClientSMState,
MaxDropReason
}

enum SandeshRxDropReason {
MinDropReason = 0,
NoDrop,
QueueLevel,
NoQueue,
ControlMsgFailed,
CreateFailed,
DecodingFailed,
MaxDropReason
}

const i32 SANDESH_KEY_HINT = 0x1
const i32 SANDESH_CONTROL_HINT = 0x2
const i32 SANDESH_SYNC_HINT = 0x4
Expand Down
2 changes: 2 additions & 0 deletions library/common/sandesh_uve.sandesh
Expand Up @@ -30,6 +30,7 @@ struct SandeshMessageStats {
57: u64 messages_sent_dropped_header_write_failed;
58: u64 messages_sent_dropped_write_failed;
59: u64 messages_sent_dropped_wrong_client_sm_state;
60: u64 messages_sent_dropped_validation_failed;
// Bytes
81: u64 bytes_sent_dropped_no_queue;
82: u64 bytes_sent_dropped_no_client;
Expand All @@ -40,6 +41,7 @@ struct SandeshMessageStats {
87: u64 bytes_sent_dropped_header_write_failed;
88: u64 bytes_sent_dropped_write_failed;
89: u64 bytes_sent_dropped_wrong_client_sm_state;
90: u64 bytes_sent_dropped_validation_failed;
// Receive
// Messages
101: u64 messages_received_dropped_no_queue;
Expand Down
16 changes: 8 additions & 8 deletions library/cpp/sandesh.cc
Expand Up @@ -447,7 +447,7 @@ bool Sandesh::Enqueue(SandeshQueue *queue) {
SANDESH_LOG(ERROR, __func__ << ": SandeshQueue NULL : Dropping Message: "
<< ToString());
}
UpdateTxMsgFailStats(name_, 0, Sandesh::DropReason::Send::NoQueue);
UpdateTxMsgFailStats(name_, 0, SandeshTxDropReason::NoQueue);
Release();
return false;
}
Expand Down Expand Up @@ -584,7 +584,7 @@ bool Sandesh::SendEnqueue() {
Log();
}
}
UpdateTxMsgFailStats(name_, 0, Sandesh::DropReason::Send::NoClient);
UpdateTxMsgFailStats(name_, 0, SandeshTxDropReason::NoClient);
Release();
return false;
}
Expand All @@ -593,7 +593,7 @@ bool Sandesh::SendEnqueue() {
SANDESH_LOG(ERROR, "SANDESH: Send FAILED: " << ToString());
}
UpdateTxMsgFailStats(name_, 0,
Sandesh::DropReason::Send::ClientSendFailed);
SandeshTxDropReason::ClientSendFailed);
Release();
return false;
}
Expand Down Expand Up @@ -648,7 +648,7 @@ bool SandeshUVE::Dispatch(SandeshConnection * sconn) {
if (!client_->SendSandeshUVE(this)) {
SANDESH_LOG(ERROR, "SandeshUVE : Send FAILED: " << ToString());
UpdateTxMsgFailStats(Name(), 0,
Sandesh::DropReason::Send::ClientSendFailed);
SandeshTxDropReason::ClientSendFailed);
Release();
return false;
}
Expand All @@ -659,15 +659,15 @@ bool SandeshUVE::Dispatch(SandeshConnection * sconn) {
} else {
Log();
}
UpdateTxMsgFailStats(Name(), 0, Sandesh::DropReason::Send::NoClient);
UpdateTxMsgFailStats(Name(), 0, SandeshTxDropReason::NoClient);
Release();
return false;
}

bool SandeshRequest::Enqueue(SandeshRxQueue *queue) {
if (!queue) {
SANDESH_LOG(ERROR, "SandeshRequest: No RxQueue: " << ToString());
UpdateRxMsgFailStats(Name(), 0, Sandesh::DropReason::Recv::NoQueue);
UpdateRxMsgFailStats(Name(), 0, SandeshRxDropReason::NoQueue);
Release();
return false;
}
Expand Down Expand Up @@ -733,7 +733,7 @@ void Sandesh::UpdateRxMsgStats(const std::string &msg_name,
}

void Sandesh::UpdateRxMsgFailStats(const std::string &msg_name,
uint64_t bytes, Sandesh::DropReason::Recv::type dreason) {
uint64_t bytes, SandeshRxDropReason::type dreason) {
tbb::mutex::scoped_lock lock(stats_mutex_);
msg_stats_.UpdateRecvFailed(msg_name, bytes, dreason);
}
Expand All @@ -745,7 +745,7 @@ void Sandesh::UpdateTxMsgStats(const std::string &msg_name,
}

void Sandesh::UpdateTxMsgFailStats(const std::string &msg_name,
uint64_t bytes, Sandesh::DropReason::Send::type dreason) {
uint64_t bytes, SandeshTxDropReason::type dreason) {
tbb::mutex::scoped_lock lock(stats_mutex_);
msg_stats_.UpdateSendFailed(msg_name, bytes, dreason);
}
Expand Down
35 changes: 2 additions & 33 deletions library/cpp/sandesh.h
Expand Up @@ -137,37 +137,6 @@ class Sandesh {
Test,
};
};
struct DropReason {
struct Send {
enum type {
MinDropReason,
NoDrop = MinDropReason,
QueueLevel,
NoClient,
NoSession,
NoQueue,
ClientSendFailed,
HeaderWriteFailed,
WriteFailed,
SessionNotConnected,
WrongClientSMState,
MaxDropReason,
};
};
struct Recv {
enum type {
MinDropReason,
NoDrop = MinDropReason,
QueueLevel,
NoQueue,
ControlMsgFailed,
CreateFailed,
DecodingFailed,
MaxDropReason,
};
};
};

typedef boost::tuple<size_t, SandeshLevel::type, bool, bool> QueueWaterMarkInfo;
typedef boost::function<void (std::string serviceName, uint8_t numbOfInstances,
DiscoveryServiceClient::ServiceHandler)> CollectorSubFn;
Expand Down Expand Up @@ -252,10 +221,10 @@ class Sandesh {
static bool SendReady(SandeshConnection * sconn = NULL);
static void UpdateRxMsgStats(const std::string &msg_name, uint64_t bytes);
static void UpdateRxMsgFailStats(const std::string &msg_name,
uint64_t bytes, DropReason::Recv::type dreason);
uint64_t bytes, SandeshRxDropReason::type dreason);
static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes);
static void UpdateTxMsgFailStats(const std::string &msg_name,
uint64_t bytes, DropReason::Send::type dreason);
uint64_t bytes, SandeshTxDropReason::type dreason);
static void GetMsgStats(
std::vector<SandeshMessageTypeStats> *mtype_stats,
SandeshMessageStats *magg_stats);
Expand Down
6 changes: 3 additions & 3 deletions library/cpp/sandesh_client.cc
Expand Up @@ -161,7 +161,7 @@ bool SandeshClient::ReceiveMsg(const std::string& msg,
Sandesh::UpdateRxMsgStats(sandesh_name, msg.size());
} else {
Sandesh::UpdateRxMsgFailStats(sandesh_name, msg.size(),
Sandesh::DropReason::Recv::ControlMsgFailed);
SandeshRxDropReason::ControlMsgFailed);
}
return success;
}
Expand All @@ -171,7 +171,7 @@ bool SandeshClient::ReceiveMsg(const std::string& msg,
if (sandesh == NULL) {
SANDESH_LOG(ERROR, __func__ << ": Unknown sandesh: " << sandesh_name);
Sandesh::UpdateRxMsgFailStats(sandesh_name, msg.size(),
Sandesh::DropReason::Recv::CreateFailed);
SandeshRxDropReason::CreateFailed);
return true;
}
boost::shared_ptr<sandesh_trans::TMemoryBuffer> btrans =
Expand All @@ -184,7 +184,7 @@ bool SandeshClient::ReceiveMsg(const std::string& msg,
if (xfer < 0) {
SANDESH_LOG(ERROR, __func__ << ": Decoding " << sandesh_name << " FAILED");
Sandesh::UpdateRxMsgFailStats(sandesh_name, msg.size(),
Sandesh::DropReason::Recv::DecodingFailed);
SandeshRxDropReason::DecodingFailed);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions library/cpp/sandesh_client_sm.cc
Expand Up @@ -500,7 +500,7 @@ struct ClientInit : public sc::state<ClientInit, SandeshClientSMImpl> {
snh->ToString());
}
Sandesh::UpdateTxMsgFailStats(snh->Name(), 0,
Sandesh::DropReason::Send::WrongClientSMState);
SandeshTxDropReason::WrongClientSMState);
SM_LOG(INFO, "Received UVE message in wrong state : " << snh->Name());
snh->Release();
return discard_event();
Expand Down Expand Up @@ -672,7 +672,7 @@ void SandeshClientSMImpl::ReleaseSandesh(const Ev &event) {
SANDESH_LOG(ERROR, "SANDESH: Send FAILED: " << snh->ToString());
}
Sandesh::UpdateTxMsgFailStats(snh->Name(), 0,
Sandesh::DropReason::Send::WrongClientSMState);
SandeshTxDropReason::WrongClientSMState);
SM_LOG(DEBUG, "Wrong state: " << StateName() << " for event: " <<
event.Name() << " message: " << snh->Name());
snh->Release();
Expand Down
6 changes: 3 additions & 3 deletions library/cpp/sandesh_session.cc
Expand Up @@ -106,7 +106,7 @@ void SandeshWriter::SendMsg(Sandesh *sandesh, bool more) {
" Sequence Number:" << sandesh->seqnum());
session_->increment_send_msg_fail();
Sandesh::UpdateTxMsgFailStats(sandesh->Name(), 0,
Sandesh::DropReason::Send::HeaderWriteFailed);
SandeshTxDropReason::HeaderWriteFailed);
sandesh->Release();
return;
}
Expand All @@ -119,7 +119,7 @@ void SandeshWriter::SendMsg(Sandesh *sandesh, bool more) {
" Sequence Number:" << sandesh->seqnum());
session_->increment_send_msg_fail();
Sandesh::UpdateTxMsgFailStats(sandesh->Name(), 0,
Sandesh::DropReason::Send::WriteFailed);
SandeshTxDropReason::WriteFailed);
sandesh->Release();
return;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ bool SandeshSession::SendMsg(Sandesh *sandesh) {
}
increment_send_msg_fail();
Sandesh::UpdateTxMsgFailStats(sandesh->Name(), 0,
Sandesh::DropReason::Send::SessionNotConnected);
SandeshTxDropReason::SessionNotConnected);
sandesh->Release();
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions library/cpp/sandesh_state_machine.cc
Expand Up @@ -610,7 +610,7 @@ void SandeshStateMachine::UpdateRxMsgStats(const std::string &msg_name,
}

void SandeshStateMachine::UpdateRxMsgFailStats(const std::string &msg_name,
size_t msg_size, Sandesh::DropReason::Recv::type dreason) {
size_t msg_size, SandeshRxDropReason::type dreason) {
tbb::mutex::scoped_lock lock(smutex_);
message_stats_.UpdateRecvFailed(msg_name, msg_size, dreason);
}
Expand All @@ -626,7 +626,7 @@ void SandeshStateMachine::OnSandeshMessage(SandeshSession *session,
if (DoDropSandeshMessage(header, message_drop_level_)) {
// Update message statistics
UpdateRxMsgFailStats(message_type, msg.size(),
Sandesh::DropReason::Recv::QueueLevel);
SandeshRxDropReason::QueueLevel);
delete xmessage;
return;
}
Expand All @@ -643,7 +643,7 @@ void SandeshStateMachine::OnSandeshMessage(SandeshSession *session,
<< ret << ")");
// Update message statistics
UpdateRxMsgFailStats(message_type, msg.size(),
Sandesh::DropReason::Recv::ControlMsgFailed);
SandeshRxDropReason::ControlMsgFailed);
delete xmessage;
return;
}
Expand Down
2 changes: 1 addition & 1 deletion library/cpp/sandesh_state_machine.h
Expand Up @@ -176,7 +176,7 @@ class SandeshStateMachine :
void UpdateRxMsgStats(const std::string &msg_name,
size_t msg_size);
void UpdateRxMsgFailStats(const std::string &msg_name,
size_t msg_size, Sandesh::DropReason::Recv::type dreason);
size_t msg_size, SandeshRxDropReason::type dreason);
void UpdateEventDequeue(const sc::event_base &event);
void UpdateEventDequeueFail(const sc::event_base &event);
void UpdateEventEnqueue(const sc::event_base &event);
Expand Down

0 comments on commit a1acb24

Please sign in to comment.