Skip to content

Commit

Permalink
Merge pull request #5 from renukamanavalan/remanava_events
Browse files Browse the repository at this point in the history
Minor changes
  • Loading branch information
renukamanavalan authored Jul 15, 2022
2 parents dec3bc5 + b6484c2 commit 33eba65
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion files/build_templates/eventd.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ExecStop=/usr/bin/{{docker_container_name}}.sh stop
RestartSec=30

[Install]
WantedBy=sonic.target
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion rules/docker-config-engine-bullseye.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ $(DOCKER_CONFIG_ENGINE_BULLSEYE)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE_PY3)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_LOAD_DOCKERS += $(DOCKER_BASE_BULLSEYE)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(SWSS_VARS_TEMPLATE)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $(RSYSLOG_PLUGIN_CONF_J2)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(DOCKER_EVENTD)_PLUGIN)
$(DOCKER_CONFIG_ENGINE_BULLSEYE)_FILES += $($(SONIC_CTRMGRD)_CONTAINER_SCRIPT)

$(DOCKER_CONFIG_ENGINE_BULLSEYE)_DBG_DEPENDS = $($(DOCKER_BASE_BULLSEYE)_DBG_DEPENDS) \
Expand Down
1 change: 1 addition & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_CTRMGRD)) \
$(addprefix $(FILES_PATH)/,$($(SONIC_CTRMGRD)_FILES)) \
$(addprefix $(FILES_PATH)/,$($(DOCKER_EVENTD)_PLUGIN)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MGMT_PY3)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SYSTEM_HEALTH)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_HOST_SERVICES_PY3))
Expand Down
6 changes: 3 additions & 3 deletions src/sonic-eventd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RSYSLOG-PLUGIN_TEST := rsyslog_plugin_tests/tests
CP := cp
MKDIR := mkdir
CC := g++
MV := mv
CP := cp
LIBS := -levent -lhiredis -lswsscommon -lpthread -lboost_thread -lboost_system -lzmq -lboost_serialization -luuid
TEST_LIBS := -L/usr/src/gtest -lgtest -lgtest_main -lgmock -lgmock_main

Expand Down Expand Up @@ -69,8 +69,8 @@ rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS)

install:
$(MKDIR) -p $(DESTDIR)/usr/sbin
$(MV) $(EVENTD_TARGET) $(DESTDIR)/usr/sbin
$(MV) $(EVENTD_TOOL) $(DESTDIR)/usr/sbin
$(CP) $(EVENTD_TARGET) $(DESTDIR)/usr/sbin
$(CP) $(EVENTD_TOOL) $(DESTDIR)/usr/sbin

deinstall:
$(RM) $(DESTDIR)/usr/sbin/$(EVENTD_TARGET)
Expand Down
7 changes: 7 additions & 0 deletions src/sonic-eventd/src/eventd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ capture_service::do_capture()

switch(cap_state) {
case CAP_STATE_INIT:
/*
* In this state check against cache, if duplicate
* When duplicate or new one seen, remove the entry from pre-exist map
* Stay in this state, until the pre-exist cache is empty or as many
* messages as in cache are seen, as in worst case even if you see
* duplicate of each, it will end with first m_events.size()
*/
{
bool add = true;
init_cnt--;
Expand Down
22 changes: 13 additions & 9 deletions src/sonic-eventd/tools/events_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Note:\n\
]\n\
Default: <some test message>\n\
\n\
-c - Use offline cache in receive mode\n\
-o - O/p file to write received events\n\
Default: STDOUT\n";

Expand All @@ -86,7 +87,7 @@ t_map_to_str(const Map &m)
}

void
do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt=0, int pause=0)
do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt, int pause, bool use_cache)
{
int index=0, total_missed = 0;
ostream* fp = &cout;
Expand All @@ -99,7 +100,9 @@ do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt
printf("outfile=%s set\n", outfile.c_str());
}
}
event_handle_t h = events_init_subscriber(false, 100, filter.empty() ? NULL : &filter);
event_handle_t h = events_init_subscriber(use_cache, 2000, filter.empty() ? NULL : &filter);
printf("Subscribed with use_cache=%d timeout=2000 filter %s\n",
use_cache, filter.empty() ? "empty" : "non-empty");
ASSERT(h != NULL, "Failed to get subscriber handle");

while(!term_receive) {
Expand Down Expand Up @@ -130,10 +133,6 @@ do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt
break;
}
}
if (pause) {
/* Pause between two sends */
this_thread::sleep_for(chrono::milliseconds(pause));
}
}

events_deinit_subscriber(h);
Expand Down Expand Up @@ -277,15 +276,20 @@ void usage()

int main(int argc, char **argv)
{
bool use_cache = false;
int op = OP_INIT;
int cnt=0, pause=0;
string json_str_msg, outfile("STDOUT"), infile;
event_subscribe_sources_t filter;

for(;;)
{
switch(getopt(argc, argv, "srn:p:i:o:f:")) // note the colon (:) to indicate that 'b' has a parameter and is not a switch
switch(getopt(argc, argv, "srn:p:i:o:f:c")) // note the colon (:) to indicate that 'b' has a parameter and is not a switch
{
case 'c':
use_cache = true;
continue;

case 's':
op |= OP_SEND;
continue;
Expand Down Expand Up @@ -339,14 +343,14 @@ int main(int argc, char **argv)
op, cnt, pause, infile.c_str(), outfile.c_str());

if (op == OP_SEND_RECV) {
thread thr(&do_receive, filter, outfile, 0, 0);
thread thr(&do_receive, filter, outfile, 0, 0, use_cache);
do_send(infile, cnt, pause);
}
else if (op == OP_SEND) {
do_send(infile, cnt, pause);
}
else if (op == OP_RECV) {
do_receive(filter, outfile, cnt, pause);
do_receive(filter, outfile, cnt, pause, use_cache);
}
else {
ASSERT(false, "Elect -s for send or -r receive or both; Bailing out with no action\n");
Expand Down

0 comments on commit 33eba65

Please sign in to comment.