From fc0bdc8a30708e3b1f47afb0c3406acacb484030 Mon Sep 17 00:00:00 2001 From: Megh Bhatt Date: Fri, 20 May 2016 11:53:57 -0700 Subject: [PATCH] Log flow messages when dropped due to queue level When flow messages were being dropped due to queue level, they were not getting logged even if log_flow was enabled. Change-Id: Ib6c3ea717f3147f31f9879231cab518c7e57c991 Closes-Bug: #1583671 --- compiler/generate/t_cpp_generator.cc | 43 +++++++++++++++------------- library/cpp/sandesh.cc | 10 +++---- library/cpp/sandesh.h | 2 +- library/cpp/sandesh_client_sm.cc | 4 +-- library/cpp/sandesh_session.cc | 2 +- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/compiler/generate/t_cpp_generator.cc b/compiler/generate/t_cpp_generator.cc index 7a1b8187..edefaa22 100755 --- a/compiler/generate/t_cpp_generator.cc +++ b/compiler/generate/t_cpp_generator.cc @@ -1377,17 +1377,22 @@ void t_cpp_generator::generate_sandesh_async_creator_helper(ofstream &out, t_san indent_up(); out << indent() << "UpdateTxMsgFailStats(\"" << tsandesh->get_name() << "\", 0, SandeshTxDropReason::QueueLevel);" << endl; - if (!is_flow) { - out << indent() << "std::string drop_reason = \"SANDESH: Queue Drop:" - " \";" << endl; - out << indent() << "DropLog"; - if(use_sandesh) { - out << "(drop_reason, category, level, snh);" << endl; - out << indent() << "snh->Release();" << endl; - } else { - out << generate_sandesh_async_creator(tsandesh, false, false, false, "", - "", false, false, true) << "; " << endl; - } + if (is_flow) { + out << indent() << "if (IsLoggingDroppedAllowed(SandeshType::FLOW)) {" << endl; + indent_up(); + } + out << indent() << "std::string drop_reason = \"SANDESH: Queue Drop:" + " \";" << endl; + out << indent() << "DropLog"; + if (use_sandesh) { + out << "(drop_reason, category, level, snh);" << endl; + out << indent() << "snh->Release();" << endl; + } else { + out << generate_sandesh_async_creator(tsandesh, false, false, false, "", + "", false, false, true) << "; " << endl; + } + if (is_flow) { + scope_down(out); } out << indent() << "return;" << endl; scope_down(out); @@ -1445,15 +1450,13 @@ void t_cpp_generator::generate_sandesh_async_creators(ofstream &out, t_sandesh * generate_sandesh_async_creator_helper(out, tsandesh, false); // Generate DropLog - if (!is_flow) { - out << indent() << "static void DropLog" << - generate_sandesh_async_creator(tsandesh, true, false, false, "", "", false, false, true) << - " {" << endl; - indent_up(); - generate_sandesh_logger(out, tsandesh, sandesh_logger::DROP_LOG); - indent_down(); - indent(out) << "}" << endl << endl; - } + out << indent() << "static void DropLog" << + generate_sandesh_async_creator(tsandesh, true, false, false, "", "", false, false, true) << + " {" << endl; + indent_up(); + generate_sandesh_logger(out, tsandesh, sandesh_logger::DROP_LOG); + indent_down(); + indent(out) << "}" << endl << endl; // Generate WriteToBuffer if (is_system) { diff --git a/library/cpp/sandesh.cc b/library/cpp/sandesh.cc index 22975c58..877c4aa2 100644 --- a/library/cpp/sandesh.cc +++ b/library/cpp/sandesh.cc @@ -471,7 +471,7 @@ void Sandesh::DisableFlowCollection(bool disable) { bool Sandesh::Enqueue(SandeshQueue *queue) { if (!queue) { - if (IsLoggingDroppedAllowed()) { + if (IsLoggingDroppedAllowed(type())) { SANDESH_LOG(ERROR, __func__ << ": SandeshQueue NULL : Dropping Message: " << ToString()); } @@ -595,7 +595,7 @@ int32_t Sandesh::ReceiveBinaryMsg(u_int8_t *buf, u_int32_t buf_len, bool Sandesh::SendEnqueue() { if (!client_) { - if (IsLoggingDroppedAllowed()) { + if (IsLoggingDroppedAllowed(type())) { if (IsConnectToCollectorEnabled()) { SANDESH_LOG(ERROR, "SANDESH: No client: " << ToString()); } else { @@ -607,7 +607,7 @@ bool Sandesh::SendEnqueue() { return false; } if (!client_->SendSandesh(this)) { - if (IsLoggingDroppedAllowed()) { + if (IsLoggingDroppedAllowed(type())) { SANDESH_LOG(ERROR, "SANDESH: Send FAILED: " << ToString()); } UpdateTxMsgFailStats(name_, 0, @@ -710,8 +710,8 @@ bool Sandesh::IsLoggingAllowed() const { } } -bool Sandesh::IsLoggingDroppedAllowed() const { - if (type_ == SandeshType::FLOW) { +bool Sandesh::IsLoggingDroppedAllowed(SandeshType::type type) { + if (type == SandeshType::FLOW) { return enable_flow_log_; } else { return true; diff --git a/library/cpp/sandesh.h b/library/cpp/sandesh.h index 060db17c..d9135747 100644 --- a/library/cpp/sandesh.h +++ b/library/cpp/sandesh.h @@ -261,7 +261,7 @@ class Sandesh { virtual int32_t ReadBinary(u_int8_t *buf, u_int32_t buf_len, int *error); bool IsLoggingAllowed() const; - bool IsLoggingDroppedAllowed() const; + static bool IsLoggingDroppedAllowed(SandeshType::type); // Accessors static void set_source(std::string &source) { source_ = source; } diff --git a/library/cpp/sandesh_client_sm.cc b/library/cpp/sandesh_client_sm.cc index 1d7660a6..7345894a 100644 --- a/library/cpp/sandesh_client_sm.cc +++ b/library/cpp/sandesh_client_sm.cc @@ -495,7 +495,7 @@ struct ClientInit : public sc::state { SM_LOG(DEBUG, state_machine->StateName() << " : " << event.Name() << " : " << snh->Name()); if (dynamic_cast(snh)) { - if (snh->IsLoggingDroppedAllowed()) { + if (Sandesh::IsLoggingDroppedAllowed(snh->type())) { SANDESH_LOG(ERROR, "SANDESH: Send FAILED: " << snh->ToString()); } @@ -668,7 +668,7 @@ void SandeshClientSMImpl::OnIdle(const Ev &event) { template void SandeshClientSMImpl::ReleaseSandesh(const Ev &event) { Sandesh *snh(event.snh); - if (snh->IsLoggingDroppedAllowed()) { + if (Sandesh::IsLoggingDroppedAllowed(snh->type())) { SANDESH_LOG(ERROR, "SANDESH: Send FAILED: " << snh->ToString()); } Sandesh::UpdateTxMsgFailStats(snh->Name(), 0, diff --git a/library/cpp/sandesh_session.cc b/library/cpp/sandesh_session.cc index 61054a22..c52be8e5 100644 --- a/library/cpp/sandesh_session.cc +++ b/library/cpp/sandesh_session.cc @@ -355,7 +355,7 @@ bool SandeshSession::SendMsg(SandeshElement element) { Sandesh *sandesh = element.snh_; tbb::mutex::scoped_lock lock(send_mutex_); if (!IsEstablished()) { - if (sandesh->IsLoggingDroppedAllowed()) { + if (Sandesh::IsLoggingDroppedAllowed(sandesh->type())) { SANDESH_LOG(ERROR, __func__ << " Not Connected : Dropping Message: " << sandesh->ToString()); }