From 2e1d8f954b482944ebb6bc2bec0192ada2f0630d Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Fri, 15 Jul 2022 13:39:32 +0000 Subject: [PATCH 1/2] Updated target; Added plugin dependency to image --- files/build_templates/eventd.service.j2 | 2 +- rules/docker-config-engine-bullseye.mk | 1 - slave.mk | 1 + src/sonic-eventd/src/eventd.cpp | 7 +++++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/files/build_templates/eventd.service.j2 b/files/build_templates/eventd.service.j2 index 0ad7f52ee83d..1aaedefd1227 100644 --- a/files/build_templates/eventd.service.j2 +++ b/files/build_templates/eventd.service.j2 @@ -14,4 +14,4 @@ ExecStop=/usr/bin/{{docker_container_name}}.sh stop RestartSec=30 [Install] -WantedBy=sonic.target +WantedBy=multi-user.target diff --git a/rules/docker-config-engine-bullseye.mk b/rules/docker-config-engine-bullseye.mk index 727449ce2250..7e649b987c93 100644 --- a/rules/docker-config-engine-bullseye.mk +++ b/rules/docker-config-engine-bullseye.mk @@ -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) \ diff --git a/slave.mk b/slave.mk index 76274b21b39e..e884aa4416e4 100644 --- a/slave.mk +++ b/slave.mk @@ -1076,6 +1076,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)) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index a379e824a930..9b164fbe38b3 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -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--; From b6484c2953c6f73119ebe2fc74c1b7e738ec057e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Fri, 15 Jul 2022 17:44:11 +0000 Subject: [PATCH 2/2] tool update --- src/sonic-eventd/Makefile | 6 +++--- src/sonic-eventd/tools/events_tool.cpp | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index ed54ea170e7d..16aced1716bd 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -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 @@ -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) diff --git a/src/sonic-eventd/tools/events_tool.cpp b/src/sonic-eventd/tools/events_tool.cpp index 4e42591d4596..8da0a8bf396e 100644 --- a/src/sonic-eventd/tools/events_tool.cpp +++ b/src/sonic-eventd/tools/events_tool.cpp @@ -61,6 +61,7 @@ Note:\n\ ]\n\ Default: \n\ \n\ +-c - Use offline cache in receive mode\n\ -o - O/p file to write received events\n\ Default: STDOUT\n"; @@ -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; @@ -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) { @@ -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); @@ -277,6 +276,7 @@ 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; @@ -284,8 +284,12 @@ int main(int argc, char **argv) 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; @@ -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");