Skip to content

Commit

Permalink
Merge "Add ability to set the sandesh message rate limit Its made par…
Browse files Browse the repository at this point in the history
…t of SandeshLoggingParamsSet struct Closes-Bug:#1606664"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Oct 3, 2016
2 parents 5fd7ac0 + f436660 commit afc40cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions library/common/sandesh_uve.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ request sandesh SandeshLoggingParamsSet {
3: optional string log_level;
4: optional bool trace_print;
5: optional bool enable_flow_log;
6: optional u32 sandesh_throttling_rate;
}

request sandesh SandeshLoggingParamsStatus {
Expand Down Expand Up @@ -143,6 +144,7 @@ response sandesh SandeshLoggingParams {
3: string log_level;
4: bool trace_print;
5: bool enable_flow_log;
6: u32 sandesh_throttling_rate;
}

request sandesh SandeshSendQueueSet {
Expand Down
4 changes: 4 additions & 0 deletions library/cpp/sandesh_req.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ void Sandesh::SendLoggingResponse(std::string context) {
slogger->set_trace_print(IsTracePrintEnabled());
slogger->set_enable_flow_log(IsFlowLoggingEnabled());
slogger->set_context(context);
slogger->set_sandesh_throttling_rate(Sandesh::get_send_rate_limit());
slogger->Response();
}

Expand All @@ -78,6 +79,9 @@ void SandeshLoggingParamsSet::HandleRequest() const {
if (__isset.enable_flow_log) {
Sandesh::SetFlowLogging(get_enable_flow_log());
}
if (__isset.sandesh_throttling_rate) {
Sandesh::set_send_rate_limit(sandesh_throttling_rate);
}
// Send response
Sandesh::SendLoggingResponse(context());
}
Expand Down
19 changes: 13 additions & 6 deletions library/cpp/test/sandesh_request_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,25 @@ class SandeshRequestTest : public ::testing::Test {

static SandeshLoggingParamsSet* PrepareLoggingParamsSetReq(bool enable,
std::string category, std::string log_level, bool enable_trace_print,
bool enable_flow_log, int called_from_line) {
bool enable_flow_log, uint32_t sandesh_send_throttling_rate, int called_from_line) {
SandeshLoggingParamsSet *req(new SandeshLoggingParamsSet);
req->set_enable(enable);
req->set_category(category);
req->set_log_level(log_level);
req->set_trace_print(enable_trace_print);
req->set_enable_flow_log(enable_flow_log);
req->set_sandesh_throttling_rate(sandesh_send_throttling_rate);
Sandesh::set_response_callback(
boost::bind(ValidateLoggingParamsResponse, _1, enable, category,
log_level, enable_trace_print, enable_flow_log, called_from_line));
log_level, enable_trace_print, enable_flow_log, sandesh_send_throttling_rate,
called_from_line));
return req;
}

static void ValidateLoggingParamsResponse(Sandesh *response,
bool enable_local_log, std::string category, std::string level,
bool enable_trace_print, bool enable_flow_log, int called_from_line) {
bool enable_trace_print, bool enable_flow_log, uint32_t sandesh_send_throttling_rate,
int called_from_line) {
cout << "From line number: " << called_from_line << endl;
cout << "*****************************************************" << endl;
SandeshLoggingParams *lresponse(
Expand All @@ -96,6 +99,8 @@ class SandeshRequestTest : public ::testing::Test {
EXPECT_EQ(level, lresponse->get_log_level());
EXPECT_EQ(enable_trace_print, lresponse->get_trace_print());
EXPECT_EQ(enable_flow_log, lresponse->get_enable_flow_log());
EXPECT_EQ(sandesh_send_throttling_rate,
lresponse->get_sandesh_throttling_rate());
validate_done_ = true;
cout << "*****************************************************" << endl;
}
Expand Down Expand Up @@ -193,14 +198,16 @@ TEST_F(SandeshRequestTest, LoggingParams) {
std::string o_log_level(Sandesh::LevelToString(Sandesh::LoggingLevel()));
bool o_enable_trace_print(Sandesh::IsTracePrintEnabled());
bool o_enable_flow_log(Sandesh::IsFlowLoggingEnabled());
uint32_t o_sandesh_send_rate_limit(Sandesh::get_send_rate_limit());
// Set
bool enable(false);
std::string category("SandeshRequest");
std::string log_level("SYS_NOTICE");
bool enable_trace_print(true);
bool enable_flow_log(true);
uint32_t sandesh_send_rate_limit(25);
SandeshLoggingParamsSet *req(PrepareLoggingParamsSetReq(enable, category,
log_level, enable_trace_print, enable_flow_log, __LINE__));
log_level, enable_trace_print, enable_flow_log, sandesh_send_rate_limit, __LINE__));
validate_done_ = false;
req->HandleRequest();
req->Release();
Expand All @@ -210,7 +217,7 @@ TEST_F(SandeshRequestTest, LoggingParams) {
SandeshLoggingParamsStatus *req1(new SandeshLoggingParamsStatus);
Sandesh::set_response_callback(boost::bind(ValidateLoggingParamsResponse,
_1, enable, category, log_level, enable_trace_print, enable_flow_log,
__LINE__));
sandesh_send_rate_limit, __LINE__));
validate_done_ = false;
req1->HandleRequest();
req1->Release();
Expand All @@ -219,7 +226,7 @@ TEST_F(SandeshRequestTest, LoggingParams) {
// Set to original
SandeshLoggingParamsSet *req2(PrepareLoggingParamsSetReq(o_enable,
o_category, o_log_level, o_enable_trace_print, o_enable_flow_log,
__LINE__));
o_sandesh_send_rate_limit, __LINE__));
validate_done_ = false;
req2->HandleRequest();
req2->Release();
Expand Down
9 changes: 7 additions & 2 deletions library/python/pysandesh/sandesh_req_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
SandeshTraceBufferEnableDisableReq, SandeshTraceBufferEnableDisableRes, \
SandeshTraceBufStatusInfo
from pysandesh.gen_py.sandesh_uve.ttypes import SandeshQueueStats
from pysandesh.sandesh_base import *

class SandeshReqImpl(object):

Expand Down Expand Up @@ -97,12 +98,15 @@ def sandesh_logging_params_set_handle_request(self, sandesh_req):
self._sandesh.set_logging_category(sandesh_req.category)
if sandesh_req.log_level is not None:
self._sandesh.set_logging_level(sandesh_req.log_level)
if sandesh_req.sandesh_throttling_rate is not None:
SandeshSystem.set_sandesh_send_rate_limit(sandesh_req.sandesh_throttling_rate)
# Return the logging params
sandesh_logging_resp = SandeshLoggingParams(
enable=self._sandesh.is_local_logging_enabled(),
category=self._sandesh.logging_category(
),
log_level=SandeshLevel._VALUES_TO_NAMES[self._sandesh.logging_level()])
log_level=SandeshLevel._VALUES_TO_NAMES[self._sandesh.logging_level()],
sandesh_throttling_rate=SandeshSystem.get_sandesh_send_rate_limit())
sandesh_logging_resp.response(sandesh_req.context(),
sandesh=self._sandesh)
# end sandesh_logging_params_set_handle_request
Expand All @@ -113,7 +117,8 @@ def sandesh_logging_params_status_handle_request(self, sandesh_req):
enable=self._sandesh.is_local_logging_enabled(),
category=self._sandesh.logging_category(
),
log_level=SandeshLevel._VALUES_TO_NAMES[self._sandesh.logging_level()])
log_level=SandeshLevel._VALUES_TO_NAMES[self._sandesh.logging_level()],
sandesh_throttling_rate=SandeshSystem.get_sandesh_send_rate_limit())
sandesh_logging_resp.response(sandesh_req.context(),
sandesh=self._sandesh)
# end sandesh_logging_params_status_handle_request
Expand Down

0 comments on commit afc40cd

Please sign in to comment.