From a2adc12306dda0f353e9cb21104c64b41c3a2397 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Fri, 22 Jul 2022 22:46:06 +0000 Subject: [PATCH 001/137] Stats for total published & cache-overflow --- src/sonic-eventd/src/eventd.cpp | 167 +++++++++++++++++++++++++++----- src/sonic-eventd/src/eventd.h | 77 +++++++++++++++ 2 files changed, 221 insertions(+), 23 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 9b164fbe38b3..422478e55d1c 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -1,16 +1,23 @@ #include #include "eventd.h" +#include "dbconnector.h" /* - * There are 3 threads, including the main + * There are 5 threads, including the main * - * main thread -- Runs eventd service that accepts commands event_req_type_t + * (0) main thread -- Runs eventd service that accepts commands event_req_type_t * This can be used to control caching events and a no-op echo service. * - * capture/cache service - * Saves all the events between cache start & stop + * (1) capture/cache service + * Saves all the events between cache start & stop. + * Update missed cached counter in memory. + * + * (2) Main proxy service that runs XSUB/XPUB ends + * + * (3) Get stats for total published counter in memory. + * + * (4) Thread to update counters from memory to redis periodically. * - * Main proxy service that runs XSUB/XPUB ends */ #define MB(N) ((N) * 1024 * 1024) @@ -23,6 +30,13 @@ #define VEC_SIZE(p) ((int)p.size()) +/* stat counters */ +typedef uint64_t counters_t; + +/* Sock read timeout in milliseconds, to enable look for control signals */ +#define CAPTURE_SOCK_TIMEOUT 300 +#define STATS_COLLECTOR_TIMEOUT 1000 + int eventd_proxy::init() { @@ -65,6 +79,108 @@ eventd_proxy::run() } +int +stats_collector::start() +{ + int rc = 0; + + m_counters_db = make_shared("COUNTERS_DB", 0); + RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); + + m_stats_table = make_shared(counters_db.get(), COUNTERS_EVENTS_TABLE); + RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); + + subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); + RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); + + m_thr_collector = thread(&stats_collector::run_collector, this); + m_thr_writer = thread(&stats_collector::run_writer, this); +out: + return rc; +} + +void +stats_collector::run_writer() +{ + while (true) { + if (m_updated.exchange(false)) { + /* Update if there had been any update */ + for (const kvmap_t *kvp = m_lst_kvmap; kvp->key != NULL; ++kvp) { + vector fv; + + fv.emplace_back(field_name, kvp->val); + + m_stats_table->set(kvp->key, fv); + } + } + if (m_shutdown) { + break; + } + this_thread::sleep_for(chrono::milliseconds(10)); + /* + * After sleep always do an update if needed before checking + * shutdown flag, as any counters collected during sleep + * needs to be updated. + */ + } + + m_stats_table.reset(); + m_counters_dbl.reset(); +} + +void +stats_collector::run_collector() +{ + /* + * Though we can count off of capture socket, then we need to duplicate + * code in event_receive which has the logic to count all missed per + * runtime id. It also has logic to retire closed runtime IDs. + * + * So use regular subscriber API w/o cache but timeout to enable + * exit, upon shutdown. + */ + /* + * The collector service runs until shutdown. + * The only task is to update total_published & total_missed_internal. + * The write of these counters into redis is done by another thread. + */ + + while(!m_shutdown) { + event_receive_op_t op = event_receive(handle); + + /* Missed cnt is initialized and independent of rc. */ + increment_missed_internal(op.missed_cnt); + + if (op.rc == 0) { + increment_published(1+op.missed_cnt); + } + else { + if (op.missed_cnt != 0) { + increment_published(op.missed_cnt); + } + if (op.rc < 0) { + SWSS_LOG_ERROR( + "event_receive failed with rc=%d; stats:published(%ul) missed(%ul)", + total_published, total_missed_internal); + } + } + } + + /* + * NOTE: A shutdown could lose messages in cache. + * But consider, that eventd shutdown is a critical shutdown as it would + * bring down all other features. Hence done only at system level shutdown, + * hence losing few messages in flight is acceptable. Any more complex code + * to handle is unwanted. + */ + /* + * Close handle on shutdown + */ + events_deinit_subscriber(m_subs_handle); + m_subs_handle = NULL; + return; +} + capture_service::~capture_service() { stop_capture(); @@ -110,10 +226,6 @@ validate_event(const internal_event_t &event, runtime_id_t &rid, sequence_t &seq void capture_service::init_capture_cache(const event_serialized_lst_t &lst) { - /* clean any pre-existing cache */ - runtime_id_t rid; - sequence_t seq; - /* Cache given events as initial stock. * Save runtime ID with last seen seq to avoid duplicates, while reading * from capture socket. @@ -123,6 +235,9 @@ capture_service::init_capture_cache(const event_serialized_lst_t &lst) internal_event_t event; if (deserialize(*itc, event) == 0) { + runtime_id_t rid; + sequence_t seq; + if (validate_event(event, rid, seq)) { m_pre_exist_id[rid] = seq; m_events.push_back(*itc); @@ -139,10 +254,10 @@ void capture_service::do_capture() { int rc; - int block_ms=300; + int block_ms=CAPTURE_SOCK_TIMEOUT; int init_cnt; - event_handle_t subs_handle = NULL; void *sock = NULL; + counters_t total_overflow = 0; typedef enum { /* @@ -161,13 +276,9 @@ capture_service::do_capture() cap_state_t cap_state = CAP_STATE_INIT; /* - * Need subscription for publishers to publish. Start one. - * As we are reading off of capture socket, we don't read from - * this handle. Not reading is a not a concern, as zmq will cache - * few initial messages and rest it will drop. + * Need subscription for publishers to publish. + * The stats collector service already has active subscriber for all. */ - subs_handle = events_init_subscriber(); - RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); sock = zmq_socket(m_ctx, ZMQ_SUB); RET_ON_ERR(sock != NULL, "failing to get ZMQ_SUB socket"); @@ -268,6 +379,9 @@ capture_service::do_capture() m_events.push_back(evt_str); if (VEC_SIZE(m_events) >= m_cache_max) { cap_state = CAP_STATE_LAST; + /* Clear the map, created to ensure memory space available */ + m_last_events.clear(); + m_last_events_init = true; } break; } @@ -282,12 +396,9 @@ capture_service::do_capture() } case CAP_STATE_LAST: - if (!m_last_events_init) { - /* Clear the map, created to ensure memory space available */ - m_last_events.clear(); - m_last_events_init = true; - } + total_overflow++; m_last_events[rid] = evt_str; + total_missed_cache = m_total_overflow - m_last_events.size(); break; } } @@ -297,7 +408,6 @@ capture_service::do_capture() * Capture stop will close the socket which fail the read * and hence bail out. */ - events_deinit_subscriber(subs_handle); zmq_close(sock); m_cap_run = false; return; @@ -385,8 +495,11 @@ run_eventd_service() int code = 0; int cache_max; event_service service; + stats_collector stats_instance; eventd_proxy *proxy = NULL; capture_service *capture = NULL; + thread thrCollector; + bool shutdown = false; event_serialized_lst_t capture_fifo_events; last_events_t capture_last_events; @@ -406,6 +519,8 @@ run_eventd_service() RET_ON_ERR(service.init_server(zctx) == 0, "Failed to init service"); + RET_ON_ERR(stats_instance.start(), "Failed to start stats collector"); + /* * Start cache service, right upon eventd starts so as not to lose * events until telemetry starts. @@ -516,13 +631,19 @@ run_eventd_service() "Failed to write response back"); } out: + shutdown = true; service.close_service(); + stats_instance.stop(); + if (proxy != NULL) { delete proxy; } if (capture != NULL) { delete capture; } + if (thrCollector.joinable()) { + thrCollector.join(); + } if (zctx != NULL) { zmq_ctx_term(zctx); } diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 6273497b0cc2..ca04d51cd1c6 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -4,6 +4,8 @@ #include "events_service.h" #include "events.h" +#define ARRAY_SIZE(l) (sizeof(l)/sizeof((l)[0])) + typedef map last_events_t; /* @@ -42,6 +44,81 @@ class eventd_proxy }; +class stats_collector +{ + public: + stats_collector() : m_total_published(0), m_total_missed_cache(0), + m_shutdown(false), m_subs_handle(NULL) + { + m_updated = false; + } + + ~stats_collector() { stop(); } + + int start(); + + int stop() { + m_shutdown = true; + + if (m_thr_collector.joinable()) { + m_thr_collector.join(); + } + + if (m_thr_writer.joinable()) { + m_thr_writer.join(); + } + + events_deinit_subscriber(m_subs_handle); + m_subs_handle = NULL; + } + + void increment_published(counters_t val) { + _update_stats(m_total_published, val); + } + + void increment_missed_cache(counters_t val) { + _update_stats(m_total_missed_cache, val); + } + + private: + void _update_stats(counters_t &cntr, counters_t val) { + cntr += val; + m_updated = true; + } + + void run_collector(); + + void run_writer(); + + + atomic m_updated(false); + + counters_t m_total_published; + counters_t m_total_missed_cache; + + typedef struct { + const char *key; + counters_t &val; + } kvmap_t; + + static const char *field_name = "count" + + kvmap_t m_lst_kvmap[] = { + { COUNTERS_EVENTS_PUBLISHED, m_total_published }, + { COUNTERS_EVENTS_MISSED_CACHE, m_total_missed_cache }, + { NULL, m_total_missed_cache }}; + + bool m_shutdown; + + thread m_thr_collector; + thread m_thr_writer; + + shared_ptr m_counters_dbl; + shared_ptr m_stats_table; + + event_handle_t m_subs_handse; +}; + /* * Capture/Cache service * From 1eef1fcc5d4f4d1aaf0badebbc424df62467be30 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 15:03:34 +0000 Subject: [PATCH 002/137] adapt to signature change --- src/sonic-eventd/src/eventd.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 422478e55d1c..c0c63899c4a5 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -146,23 +146,20 @@ stats_collector::run_collector() */ while(!m_shutdown) { - event_receive_op_t op = event_receive(handle); + event_receive_op_t op; - /* Missed cnt is initialized and independent of rc. */ - increment_missed_internal(op.missed_cnt); + int rc = event_receive(handle, op); - if (op.rc == 0) { + if rc == 0) { increment_published(1+op.missed_cnt); + + increment_missed_internal(op.missed_cnt); + } - else { - if (op.missed_cnt != 0) { - increment_published(op.missed_cnt); - } - if (op.rc < 0) { - SWSS_LOG_ERROR( - "event_receive failed with rc=%d; stats:published(%ul) missed(%ul)", - total_published, total_missed_internal); - } + else if (rc < 0) { + SWSS_LOG_ERROR( + "event_receive failed with rc=%d; stats:published(%ul) missed(%ul)", + total_published, total_missed_internal); } } From 789b579aaf92b7f7e54d9b6c5c84b4f87a1d0d75 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 20:10:51 +0000 Subject: [PATCH 003/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 3 --- src/sonic-eventd/src/eventd.h | 3 +++ src/sonic-eventd/tests/eventd_ut.cpp | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index c0c63899c4a5..020aa4a3a732 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -30,9 +30,6 @@ #define VEC_SIZE(p) ((int)p.size()) -/* stat counters */ -typedef uint64_t counters_t; - /* Sock read timeout in milliseconds, to enable look for control signals */ #define CAPTURE_SOCK_TIMEOUT 300 #define STATS_COLLECTOR_TIMEOUT 1000 diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index ca04d51cd1c6..9ca0f078fc8f 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -8,6 +8,9 @@ typedef map last_events_t; +/* stat counters */ +typedef uint64_t counters_t; + /* * Started by eventd_service. * Creates XPUB & XSUB end points. diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index d6f07f23de0f..0ba054272651 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -12,8 +12,6 @@ using namespace std; -#define ARRAY_SIZE(p) ((int)(sizeof(p) / sizeof((p)[0]))) - typedef struct { int id; string source; From ec3e80b013f7615c89880230cfc123afc4401e31 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 21:11:49 +0000 Subject: [PATCH 004/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 16 +++++++++++++--- src/sonic-eventd/src/eventd.h | 31 ++++++++++++------------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 020aa4a3a732..cfac4aa0a277 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -34,6 +34,15 @@ #define CAPTURE_SOCK_TIMEOUT 300 #define STATS_COLLECTOR_TIMEOUT 1000 + +static const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { + "EVENTS_COUNTERS:published", + "EVENTS_COUNTERS:cache_overflow" +}; + +#define EVENTS_STATS_FIELD_NAME "value" + + int eventd_proxy::init() { @@ -102,12 +111,13 @@ stats_collector::run_writer() while (true) { if (m_updated.exchange(false)) { /* Update if there had been any update */ - for (const kvmap_t *kvp = m_lst_kvmap; kvp->key != NULL; ++kvp) { + + for (int i = 0; i < COUNTERS_EVENTS_TOTAL; ++i) { vector fv; - fv.emplace_back(field_name, kvp->val); + fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); - m_stats_table->set(kvp->key, fv); + m_stats_table->set(counter_keys[i], fv); } } if (m_shutdown) { diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 9ca0f078fc8f..671181543e62 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -11,6 +11,12 @@ typedef map last_events_t; /* stat counters */ typedef uint64_t counters_t; +enum { + COUNTERS_EVENTS_PUBLISHED, + COUNTERS_EVENTS_MISSED_CACHE, + COUNTERS_EVENTS_TOTAL +}; + /* * Started by eventd_service. * Creates XPUB & XSUB end points. @@ -76,16 +82,16 @@ class stats_collector } void increment_published(counters_t val) { - _update_stats(m_total_published, val); + _update_stats(COUNTERS_EVENTS_PUBLISHED, val); } void increment_missed_cache(counters_t val) { - _update_stats(m_total_missed_cache, val); + _update_stats(COUNTERS_EVENTS_MISSED_CACHE, val); } private: - void _update_stats(counters_t &cntr, counters_t val) { - cntr += val; + void _update_stats(int index, counters_t val) { + m_lst_counters[index] += val; m_updated = true; } @@ -94,22 +100,9 @@ class stats_collector void run_writer(); - atomic m_updated(false); - - counters_t m_total_published; - counters_t m_total_missed_cache; - - typedef struct { - const char *key; - counters_t &val; - } kvmap_t; - - static const char *field_name = "count" + atomic m_updated; - kvmap_t m_lst_kvmap[] = { - { COUNTERS_EVENTS_PUBLISHED, m_total_published }, - { COUNTERS_EVENTS_MISSED_CACHE, m_total_missed_cache }, - { NULL, m_total_missed_cache }}; + counters_t m_lst_counters; bool m_shutdown; From 9f9c1693ce1dae204267fe8909e31ffbbe0acdae Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 21:12:39 +0000 Subject: [PATCH 005/137] compile fix --- slave.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/slave.mk b/slave.mk index 0a4b45697e1d..8a400a8c88c4 100644 --- a/slave.mk +++ b/slave.mk @@ -1088,7 +1088,6 @@ $(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)) From 23239af99fd3c8b5f81046bc3397681396461be9 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 21:51:48 +0000 Subject: [PATCH 006/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 13 +++++++------ src/sonic-eventd/src/eventd.h | 18 ++++++++++++------ src/sonic-eventd/tools/events_tool.cpp | 9 +++++---- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index cfac4aa0a277..a1be6b626824 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -159,9 +159,6 @@ stats_collector::run_collector() if rc == 0) { increment_published(1+op.missed_cnt); - - increment_missed_internal(op.missed_cnt); - } else if (rc < 0) { SWSS_LOG_ERROR( @@ -402,7 +399,7 @@ capture_service::do_capture() case CAP_STATE_LAST: total_overflow++; m_last_events[rid] = evt_str; - total_missed_cache = m_total_overflow - m_last_events.size(); + m_total_missed_cache = total_overflow - m_last_events.size(); break; } } @@ -479,7 +476,7 @@ capture_service::set_control(capture_control_t ctrl, event_serialized_lst_t *lst int capture_service::read_cache(event_serialized_lst_t &lst_fifo, - last_events_t &lst_last) + last_events_t &lst_last, counters_t &overflow_cnt) { lst_fifo.swap(m_events); if (m_last_events_init) { @@ -489,6 +486,7 @@ capture_service::read_cache(event_serialized_lst_t &lst_fifo, } last_events_t().swap(m_last_events); event_serialized_lst_t().swap(m_events); + overflow_cnt = m_total_missed_cache; return 0; } @@ -575,7 +573,10 @@ run_eventd_service() } resp = capture->set_control(STOP_CAPTURE); if (resp == 0) { - resp = capture->read_cache(capture_fifo_events, capture_last_events); + counters_t overflow; + resp = capture->read_cache(capture_fifo_events, capture_last_events, + overflow); + stats_instance.increment_missed_cache(overflow); } delete capture; capture = NULL; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 671181543e62..c44e4607d49c 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -1,6 +1,7 @@ /* * Header file for eventd daemon */ +#include "table.h" #include "events_service.h" #include "events.h" @@ -56,9 +57,11 @@ class eventd_proxy class stats_collector { public: - stats_collector() : m_total_published(0), m_total_missed_cache(0), - m_shutdown(false), m_subs_handle(NULL) + stats_collector() : m_shutdown(false), m_subs_handle(NULL) { + for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { + m_lst_counters[i] = 0; + } m_updated = false; } @@ -109,10 +112,10 @@ class stats_collector thread m_thr_collector; thread m_thr_writer; - shared_ptr m_counters_dbl; + shared_ptr m_counters_db; shared_ptr m_stats_table; - event_handle_t m_subs_handse; + event_handle_t m_subs_handle; }; /* @@ -168,7 +171,8 @@ class capture_service { public: capture_service(void *ctx, int cache_max) : m_ctx(ctx), m_cap_run(false), - m_ctrl(NEED_INIT), m_cache_max(cache_max), m_last_events_init(false) + m_ctrl(NEED_INIT), m_cache_max(cache_max), m_last_events_init(false), + m_total_missed_cache(0) {} ~capture_service(); @@ -176,7 +180,7 @@ class capture_service int set_control(capture_control_t ctrl, event_serialized_lst_t *p=NULL); int read_cache(event_serialized_lst_t &lst_fifo, - last_events_t &lst_last); + last_events_t &lst_last, counters_t &overflow_cnt); private: void init_capture_cache(const event_serialized_lst_t &lst); @@ -199,6 +203,8 @@ class capture_service typedef map pre_exist_id_t; pre_exist_id_t m_pre_exist_id; + counters_t m_total_missed_cache; + }; diff --git a/src/sonic-eventd/tools/events_tool.cpp b/src/sonic-eventd/tools/events_tool.cpp index 68cf39dd2f25..97b17c1d7566 100644 --- a/src/sonic-eventd/tools/events_tool.cpp +++ b/src/sonic-eventd/tools/events_tool.cpp @@ -109,14 +109,15 @@ do_receive(const event_subscribe_sources_t filter, const string outfile, int cnt event_receive_op_t evt; map_str_str_t evtOp; - evt = event_receive(h); - if (evt.rc != 0) { - ASSERT(evt.rc == EAGAIN, "Failed to receive rc=%d index=%d\n", - evt.rc, index); + int rc = event_receive(h, evt); + if (rc != 0) { + ASSERT(rc == EAGAIN, "Failed to receive rc=%d index=%d\n", + rc, index); continue; } ASSERT(!evt.key.empty(), "received EMPTY key"); ASSERT(evt.missed_cnt >= 0, "Missed count uninitialized"); + ASSERT(evt.publish_epoch_ms > 0, "publish_epoch_ms uninitialized"); total_missed += evt.missed_cnt; From 8de3cdeba6c6fa28c053c1e63215e519bc9b8872 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 22:13:05 +0000 Subject: [PATCH 007/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 6 +++--- src/sonic-eventd/src/eventd.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index a1be6b626824..d42a80e98f16 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -35,9 +35,9 @@ #define STATS_COLLECTOR_TIMEOUT 1000 -static const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { - "EVENTS_COUNTERS:published", - "EVENTS_COUNTERS:cache_overflow" +static string counter_keys[COUNTERS_EVENTS_TOTAL] = { + string(COUNTERS_EVENTS_TABLE) + ":" + COUNTERS_EVENTS_PUBLISHED, + string(COUNTERS_EVENTS_TABLE) + ":" + COUNTERS_EVENTS_MISSED_CACHE }; #define EVENTS_STATS_FIELD_NAME "value" diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index c44e4607d49c..e11cdce83b0e 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -13,8 +13,8 @@ typedef map last_events_t; typedef uint64_t counters_t; enum { - COUNTERS_EVENTS_PUBLISHED, - COUNTERS_EVENTS_MISSED_CACHE, + INDEX_COUNTERS_EVENTS_PUBLISHED, + INDEX_COUNTERS_EVENTS_MISSED_CACHE, COUNTERS_EVENTS_TOTAL }; @@ -85,11 +85,11 @@ class stats_collector } void increment_published(counters_t val) { - _update_stats(COUNTERS_EVENTS_PUBLISHED, val); + _update_stats(INDEX_COUNTERS_EVENTS_PUBLISHED, val); } void increment_missed_cache(counters_t val) { - _update_stats(COUNTERS_EVENTS_MISSED_CACHE, val); + _update_stats(INDEX_COUNTERS_EVENTS_MISSED_CACHE, val); } private: From b426d503f75cade5c940ca9defa9597b8970d109 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 22:24:21 +0000 Subject: [PATCH 008/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 9 ++++++--- src/sonic-eventd/src/eventd.h | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index d42a80e98f16..1addb38e5ef6 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -20,6 +20,9 @@ * */ +using namespace std; +using namespace swss; + #define MB(N) ((N) * 1024 * 1024) #define EVT_SIZE_AVG 150 @@ -93,11 +96,11 @@ stats_collector::start() m_counters_db = make_shared("COUNTERS_DB", 0); RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); - m_stats_table = make_shared(counters_db.get(), COUNTERS_EVENTS_TABLE); + m_stats_table = make_shared(m_counters_db.get(), COUNTERS_EVENTS_TABLE); RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); - subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); - RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); + m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); + RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); m_thr_collector = thread(&stats_collector::run_collector, this); m_thr_writer = thread(&stats_collector::run_writer, this); diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index e11cdce83b0e..54300ec4a21c 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -69,7 +69,7 @@ class stats_collector int start(); - int stop() { + void stop() { m_shutdown = true; if (m_thr_collector.joinable()) { @@ -105,7 +105,7 @@ class stats_collector atomic m_updated; - counters_t m_lst_counters; + counters_t m_lst_counters[COUNTERS_EVENTS_TOTAL]; bool m_shutdown; From 0d92b83a8acfc4cb3c4029f3529975e461a220a0 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 22:28:09 +0000 Subject: [PATCH 009/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 1addb38e5ef6..17c7468c8c66 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -135,7 +135,7 @@ stats_collector::run_writer() } m_stats_table.reset(); - m_counters_dbl.reset(); + m_counters_db.reset(); } void @@ -158,9 +158,9 @@ stats_collector::run_collector() while(!m_shutdown) { event_receive_op_t op; - int rc = event_receive(handle, op); + int rc = event_receive(m_subs_handle, op); - if rc == 0) { + if (rc == 0) { increment_published(1+op.missed_cnt); } else if (rc < 0) { From 2762bf9a3a5ab3c39a8018175f378172421da95e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 22:30:34 +0000 Subject: [PATCH 010/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 17c7468c8c66..e929a48d3a87 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -165,8 +165,8 @@ stats_collector::run_collector() } else if (rc < 0) { SWSS_LOG_ERROR( - "event_receive failed with rc=%d; stats:published(%ul) missed(%ul)", - total_published, total_missed_internal); + "event_receive failed with rc=%d; stats:published(%ul)", + m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } } From 59802a524291e1054efb20dad4e3d1afa7b57f5f Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 23:28:37 +0000 Subject: [PATCH 011/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index e929a48d3a87..a1480c61c3c3 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -165,7 +165,7 @@ stats_collector::run_collector() } else if (rc < 0) { SWSS_LOG_ERROR( - "event_receive failed with rc=%d; stats:published(%ul)", + "event_receive failed with rc=%d; stats:published(%ul)", rc, m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } } @@ -504,7 +504,6 @@ run_eventd_service() eventd_proxy *proxy = NULL; capture_service *capture = NULL; thread thrCollector; - bool shutdown = false; event_serialized_lst_t capture_fifo_events; last_events_t capture_last_events; From d865f8bd9e035b3ef28d9b67e03c8aa32ad83129 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 23:33:44 +0000 Subject: [PATCH 012/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index a1480c61c3c3..4e723f8dd180 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -165,7 +165,7 @@ stats_collector::run_collector() } else if (rc < 0) { SWSS_LOG_ERROR( - "event_receive failed with rc=%d; stats:published(%ul)", rc, + "event_receive failed with rc=%d; stats:published(%lu)", rc, m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } } @@ -638,7 +638,6 @@ run_eventd_service() "Failed to write response back"); } out: - shutdown = true; service.close_service(); stats_instance.stop(); From 4c80afdb0855756acf96a8f3f5f73d6b8a8a3d9f Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 23:47:20 +0000 Subject: [PATCH 013/137] compile fix --- src/sonic-eventd/tests/eventd_ut.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 0ba054272651..c2db78d2d978 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -326,6 +326,7 @@ TEST(eventd, capture) /* startup strings; expected list & read list from capture */ event_serialized_lst_t evts_start, evts_expect, evts_read; last_events_t last_evts_exp, last_evts_read; + counters_t overflow, overflow_exp = 0; void *zctx = zmq_ctx_new(); EXPECT_TRUE(NULL != zctx); @@ -350,7 +351,7 @@ TEST(eventd, capture) EXPECT_EQ(0, pcap->set_control(INIT_CAPTURE)); EXPECT_TRUE(init_cache > 1); - EXPECT_TRUE((cache_max+3) < ARRAY_SIZE(ldata)); + EXPECT_TRUE((cache_max+3) < (int)ARRAY_SIZE(ldata)); /* Collect few serailized strings of events for startup cache */ for(int i=0; i < init_cache; ++i) { @@ -367,7 +368,7 @@ TEST(eventd, capture) * Hence i=1, when first init_cache events are already * in crash. */ - for(int i=1; i < ARRAY_SIZE(ldata); ++i) { + for(int i=1; i < (int)ARRAY_SIZE(ldata); ++i) { internal_event_t ev(create_ev(ldata[i])); string evt_str; @@ -383,6 +384,7 @@ TEST(eventd, capture) } else { /* collect last entries for overflow */ last_evts_exp[ldata[i].rid] = evt_str; + overflow_exp++; } } @@ -404,13 +406,14 @@ TEST(eventd, capture) term_sub = true; /* Read the cache */ - EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read)); + EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read, overflow)); #ifdef DEBUG_TEST if ((evts_read.size() != evts_expect.size()) || (last_evts_read.size() != last_evts_exp.size())) { printf("size: sub_evts_sz=%d sub_evts=%d\n", sub_evts_sz, (int)sub_evts.size()); printf("init_cache=%d cache_max=%d\n", init_cache, cache_max); + printf("overflow=%ul overflow_exp=%ul\n", overflow, overflow_exp); printf("evts_start=%d evts_expect=%d evts_read=%d\n", (int)evts_start.size(), (int)evts_expect.size(), (int)evts_read.size()); printf("last_evts_exp=%d last_evts_read=%d\n", (int)last_evts_exp.size(), @@ -422,6 +425,7 @@ TEST(eventd, capture) EXPECT_EQ(evts_read, evts_expect); EXPECT_EQ(last_evts_read.size(), last_evts_exp.size()); EXPECT_EQ(last_evts_read, last_evts_exp); + EXPECT_EQ(overflow, overflow_exp); delete pxy; pxy = NULL; From b4295ffd7d64b0787b5b37cca3f48fc715b3f64f Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 23:51:18 +0000 Subject: [PATCH 014/137] compile fix --- src/sonic-eventd/tests/eventd_ut.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index c2db78d2d978..d27ac639a7e9 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -469,6 +469,7 @@ TEST(eventd, captureCacheMax) /* startup strings; expected list & read list from capture */ event_serialized_lst_t evts_start, evts_expect, evts_read; last_events_t last_evts_read; + counters_t overflow; void *zctx = zmq_ctx_new(); EXPECT_TRUE(NULL != zctx); @@ -537,7 +538,7 @@ TEST(eventd, captureCacheMax) term_sub = true; /* Read the cache */ - EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read)); + EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read, overflow)); #ifdef DEBUG_TEST if ((evts_read.size() != evts_expect.size()) || @@ -547,11 +548,13 @@ TEST(eventd, captureCacheMax) printf("evts_start=%d evts_expect=%d evts_read=%d\n", (int)evts_start.size(), (int)evts_expect.size(), (int)evts_read.size()); printf("last_evts_read=%d\n", (int)last_evts_read.size()); + printf("overflow=%ul overflow_exp=%ul\n", overflow, overflow_exp); } #endif EXPECT_EQ(evts_read, evts_expect); EXPECT_TRUE(last_evts_read.empty()); + EXPECT_EQ(overflow, 0); delete pxy; pxy = NULL; From 8a0974e2b97b3bd9f7b8fed615a12ef0f2143d89 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 23:52:12 +0000 Subject: [PATCH 015/137] compile fix --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index d27ac639a7e9..61cbfbb6dfc9 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -505,7 +505,7 @@ TEST(eventd, captureCacheMax) * Collect events to publish for capture to cache * re-publishing some events sent in cache. */ - for(int i=1; i < ARRAY_SIZE(ldata); ++i) { + for(int i=1; i < (int)ARRAY_SIZE(ldata); ++i) { internal_event_t ev(create_ev(ldata[i])); string evt_str; From 66ae64918f07ed262fa6c075f764cae2c561b82b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 28 Jul 2022 23:55:53 +0000 Subject: [PATCH 016/137] compile fix --- src/sonic-eventd/tests/eventd_ut.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 61cbfbb6dfc9..a62774027363 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -387,6 +387,7 @@ TEST(eventd, capture) overflow_exp++; } } + overflow_exp -= (int)last_evts_exp.size(); EXPECT_EQ(0, pcap->set_control(START_CAPTURE, &evts_start)); From 1fc17039785b4a252ef3250314033d9a4441537e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Fri, 29 Jul 2022 00:12:44 +0000 Subject: [PATCH 017/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 10 +++++++--- src/sonic-eventd/src/eventd.h | 2 +- src/sonic-eventd/src/main.cpp | 2 +- src/sonic-eventd/tests/eventd_ut.cpp | 4 +++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 4e723f8dd180..d3471ffa0572 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -495,7 +495,7 @@ capture_service::read_cache(event_serialized_lst_t &lst_fifo, void -run_eventd_service() +run_eventd_service(bool skip_stats) { int code = 0; int cache_max; @@ -523,7 +523,9 @@ run_eventd_service() RET_ON_ERR(service.init_server(zctx) == 0, "Failed to init service"); - RET_ON_ERR(stats_instance.start(), "Failed to start stats collector"); + if (!skip_stats) { + RET_ON_ERR(stats_instance.start(), "Failed to start stats collector"); + } /* * Start cache service, right upon eventd starts so as not to lose @@ -639,7 +641,9 @@ run_eventd_service() } out: service.close_service(); - stats_instance.stop(); + if (!skip_stats) { + stats_instance.stop(); + } if (proxy != NULL) { delete proxy; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 54300ec4a21c..dcfca6be6aaf 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -221,6 +221,6 @@ class capture_service * for cache read, returns the collected events in chunks. * */ -void run_eventd_service(); +void run_eventd_service(bool skip_stats); diff --git a/src/sonic-eventd/src/main.cpp b/src/sonic-eventd/src/main.cpp index ea058d5fac14..ab5268c644e5 100644 --- a/src/sonic-eventd/src/main.cpp +++ b/src/sonic-eventd/src/main.cpp @@ -7,7 +7,7 @@ int main() { SWSS_LOG_INFO("The eventd service started"); - run_eventd_service(); + run_eventd_service(false); SWSS_LOG_INFO("The eventd service exited"); diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index a62774027363..387717cbd1a7 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -600,7 +600,7 @@ TEST(eventd, service) * It uses its own zmq context * It starts to capture too. */ - thread thread_service(&run_eventd_service); + thread thread_service(&run_eventd_service, true); /* Need client side service to interact with server side */ EXPECT_EQ(0, service.init_client(zctx)); @@ -682,3 +682,5 @@ TEST(eventd, service) printf("Service TEST completed\n"); } + +// TODO -- Add unit tests for stats From 28f85c45752151d6a6f942de4b9cf13b857cd1a5 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Fri, 29 Jul 2022 17:40:14 +0000 Subject: [PATCH 018/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 76 +++++++++++++++++----------- src/sonic-eventd/src/eventd.h | 5 +- src/sonic-eventd/src/main.cpp | 2 +- src/sonic-eventd/tests/eventd_ut.cpp | 21 +++----- 4 files changed, 58 insertions(+), 46 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index d3471ffa0572..98e2f16ef7eb 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -45,6 +45,7 @@ static string counter_keys[COUNTERS_EVENTS_TOTAL] = { #define EVENTS_STATS_FIELD_NAME "value" +static bool s_unit_testing = false; int eventd_proxy::init() @@ -91,19 +92,26 @@ eventd_proxy::run() int stats_collector::start() { - int rc = 0; - - m_counters_db = make_shared("COUNTERS_DB", 0); - RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); - - m_stats_table = make_shared(m_counters_db.get(), COUNTERS_EVENTS_TABLE); - RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); + int rc = -1; + /* + * A subscriber is required to set a subscription. Else all published + * events will be dropped at the point of publishing itself. + */ m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); + if (!s_unit_testing) { + m_counters_db = make_shared("COUNTERS_DB", 0); + RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); + + m_stats_table = make_shared(m_counters_db.get(), COUNTERS_EVENTS_TABLE); + RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); + + m_thr_writer = thread(&stats_collector::run_writer, this); + } m_thr_collector = thread(&stats_collector::run_collector, this); - m_thr_writer = thread(&stats_collector::run_writer, this); + rc = 0; out: return rc; } @@ -157,8 +165,19 @@ stats_collector::run_collector() while(!m_shutdown) { event_receive_op_t op; + int rc = 0; - int rc = event_receive(m_subs_handle, op); + try { + rc = event_receive(m_subs_handle, op); + } + catch (exception& e) + { + rc = -1; + stringstream ss; + ss << e.what(); + SWSS_LOG_ERROR("Cache save event failed with %s", + ss.str().c_str()); + } if (rc == 0) { increment_published(1+op.missed_cnt); @@ -177,11 +196,6 @@ stats_collector::run_collector() * hence losing few messages in flight is acceptable. Any more complex code * to handle is unwanted. */ - /* - * Close handle on shutdown - */ - events_deinit_subscriber(m_subs_handle); - m_subs_handle = NULL; return; } @@ -260,7 +274,7 @@ capture_service::do_capture() int rc; int block_ms=CAPTURE_SOCK_TIMEOUT; int init_cnt; - void *sock = NULL; + void *cap_sub_sock = NULL; counters_t total_overflow = 0; typedef enum { @@ -284,16 +298,16 @@ capture_service::do_capture() * The stats collector service already has active subscriber for all. */ - sock = zmq_socket(m_ctx, ZMQ_SUB); - RET_ON_ERR(sock != NULL, "failing to get ZMQ_SUB socket"); + cap_sub_sock = zmq_socket(m_ctx, ZMQ_SUB); + RET_ON_ERR(cap_sub_sock != NULL, "failing to get ZMQ_SUB socket"); - rc = zmq_connect(sock, get_config(string(CAPTURE_END_KEY)).c_str()); + rc = zmq_connect(cap_sub_sock, get_config(string(CAPTURE_END_KEY)).c_str()); RET_ON_ERR(rc == 0, "Failing to bind capture SUB to %s", get_config(string(CAPTURE_END_KEY)).c_str()); - rc = zmq_setsockopt(sock, ZMQ_SUBSCRIBE, "", 0); + rc = zmq_setsockopt(cap_sub_sock, ZMQ_SUBSCRIBE, "", 0); RET_ON_ERR(rc == 0, "Failing to ZMQ_SUBSCRIBE"); - rc = zmq_setsockopt(sock, ZMQ_RCVTIMEO, &block_ms, sizeof (block_ms)); + rc = zmq_setsockopt(cap_sub_sock, ZMQ_RCVTIMEO, &block_ms, sizeof (block_ms)); RET_ON_ERR(rc == 0, "Failed to ZMQ_RCVTIMEO to %d", block_ms); m_cap_run = true; @@ -325,7 +339,7 @@ capture_service::do_capture() internal_event_t event; string source, evt_str; - if ((rc = zmq_message_read(sock, 0, source, event)) != 0) { + if ((rc = zmq_message_read(cap_sub_sock, 0, source, event)) != 0) { /* * The capture socket captures SUBSCRIBE requests too. * The messge could contain subscribe filter strings and binary code. @@ -412,7 +426,7 @@ capture_service::do_capture() * Capture stop will close the socket which fail the read * and hence bail out. */ - zmq_close(sock); + zmq_close(cap_sub_sock); m_cap_run = false; return; } @@ -495,7 +509,7 @@ capture_service::read_cache(event_serialized_lst_t &lst_fifo, void -run_eventd_service(bool skip_stats) +run_eventd_service() { int code = 0; int cache_max; @@ -508,7 +522,7 @@ run_eventd_service(bool skip_stats) event_serialized_lst_t capture_fifo_events; last_events_t capture_last_events; - SWSS_LOG_ERROR("Eventd service starting\n"); + SWSS_LOG_INFO("Eventd service starting\n"); void *zctx = zmq_ctx_new(); RET_ON_ERR(zctx != NULL, "Failed to get zmq ctx"); @@ -523,9 +537,7 @@ run_eventd_service(bool skip_stats) RET_ON_ERR(service.init_server(zctx) == 0, "Failed to init service"); - if (!skip_stats) { - RET_ON_ERR(stats_instance.start(), "Failed to start stats collector"); - } + RET_ON_ERR(stats_instance.start() == 0, "Failed to start stats collector"); /* * Start cache service, right upon eventd starts so as not to lose @@ -641,9 +653,7 @@ run_eventd_service(bool skip_stats) } out: service.close_service(); - if (!skip_stats) { - stats_instance.stop(); - } + stats_instance.stop(); if (proxy != NULL) { delete proxy; @@ -660,3 +670,9 @@ run_eventd_service(bool skip_stats) SWSS_LOG_ERROR("Eventd service exiting\n"); } +void set_unit_testing(bool b) +{ + s_unit_testing = b; +} + + diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index dcfca6be6aaf..0bb3223d4d7c 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -221,6 +221,7 @@ class capture_service * for cache read, returns the collected events in chunks. * */ -void run_eventd_service(bool skip_stats); - +void run_eventd_service(); +/* To help skip redis access during unit testing */ +void set_unit_testing(bool b); diff --git a/src/sonic-eventd/src/main.cpp b/src/sonic-eventd/src/main.cpp index ab5268c644e5..ea058d5fac14 100644 --- a/src/sonic-eventd/src/main.cpp +++ b/src/sonic-eventd/src/main.cpp @@ -7,7 +7,7 @@ int main() { SWSS_LOG_INFO("The eventd service started"); - run_eventd_service(false); + run_eventd_service(); SWSS_LOG_INFO("The eventd service exited"); diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 387717cbd1a7..503090bfc1fc 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -26,16 +26,8 @@ internal_event_t create_ev(const test_data_t &data) { internal_event_t event_data; - { - string param_str; - - EXPECT_EQ(0, serialize(data.params, param_str)); - - map_str_str_t event_str_map = { { data.source + ":" + data.tag, param_str}}; - - EXPECT_EQ(0, serialize(event_str_map, event_data[EVENT_STR_DATA])); - } - + event_data[EVENT_STR_DATA] = convert_to_json( + data.source + ":" + data.tag, data.params); event_data[EVENT_RUNTIME_ID] = data.rid; event_data[EVENT_SEQUENCE] = data.seq; @@ -227,12 +219,12 @@ void run_pub(void *mock_pub, const string wr_source, internal_events_lst_t &lst) void debug_on() { /* compile with -D DEBUG_TEST or add "#define DEBUG_TEST" to include. */ -#ifdef DEBUG_TEST +// #ifdef DEBUG_TEST /* Direct log messages to stdout */ string dummy, op("STDOUT"); swss::Logger::swssOutputNotify(dummy, op); swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG); -#endif +// #endif } TEST(eventd, proxy) @@ -600,7 +592,9 @@ TEST(eventd, service) * It uses its own zmq context * It starts to capture too. */ - thread thread_service(&run_eventd_service, true); + + set_unit_testing(true); + thread thread_service(&run_eventd_service); /* Need client side service to interact with server side */ EXPECT_EQ(0, service.init_client(zctx)); @@ -609,6 +603,7 @@ TEST(eventd, service) /* eventd_service starts cache too; Test this caching */ /* Init pub connection */ void *mock_pub = init_pub(zctx); + EXPECT_TRUE(NULL != mock_pub); internal_events_lst_t wr_evts; int wr_sz = 2; From ce339072f83fb9098167d9dd8a0e10a827a0ba05 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Fri, 29 Jul 2022 17:46:59 +0000 Subject: [PATCH 019/137] compile fix --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 503090bfc1fc..a64206fca3d2 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -219,12 +219,12 @@ void run_pub(void *mock_pub, const string wr_source, internal_events_lst_t &lst) void debug_on() { /* compile with -D DEBUG_TEST or add "#define DEBUG_TEST" to include. */ -// #ifdef DEBUG_TEST +#ifdef DEBUG_TEST /* Direct log messages to stdout */ string dummy, op("STDOUT"); swss::Logger::swssOutputNotify(dummy, op); swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG); -// #endif +#endif } TEST(eventd, proxy) From efdeec5d4cfafc20d23abf8ae8505110120ee020 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 00:46:35 +0000 Subject: [PATCH 020/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 13 +++++++++++++ src/sonic-eventd/src/eventd.h | 3 +++ src/sonic-eventd/src/main.cpp | 1 + 3 files changed, 17 insertions(+) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 98e2f16ef7eb..e0d6c5bc1b57 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -98,9 +98,12 @@ stats_collector::start() * A subscriber is required to set a subscription. Else all published * events will be dropped at the point of publishing itself. */ + SWSS_LOG_ERROR("DROP: Enter stats_collector::start()"); + m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); + SWSS_LOG_ERROR("DROP: Enter stats_collector::start()"); if (!s_unit_testing) { m_counters_db = make_shared("COUNTERS_DB", 0); RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); @@ -109,10 +112,12 @@ stats_collector::start() RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); m_thr_writer = thread(&stats_collector::run_writer, this); + SWSS_LOG_ERROR("DROP: stats_collector::start() started writer"); } m_thr_collector = thread(&stats_collector::run_collector, this); rc = 0; out: + SWSS_LOG_ERROR("DROP: Exiting stats_collector::start() rc=%d", rc); return rc; } @@ -121,6 +126,8 @@ stats_collector::run_writer() { while (true) { if (m_updated.exchange(false)) { + SWSS_LOG_ERROR("DROP: run_writer rc=%d", rc); + /* Update if there had been any update */ for (int i = 0; i < COUNTERS_EVENTS_TOTAL; ++i) { @@ -129,7 +136,9 @@ stats_collector::run_writer() fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); m_stats_table->set(counter_keys[i], fv); + SWSS_LOG_ERROR("DROP: run_writer i=%d cntr=%d", i, m_lst_counters[i]); } + SWSS_LOG_ERROR("DROP: run_writer rc=%d", rc); } if (m_shutdown) { break; @@ -140,8 +149,10 @@ stats_collector::run_writer() * shutdown flag, as any counters collected during sleep * needs to be updated. */ + SWSS_LOG_ERROR("DROP: run_writer after sleep"); } + SWSS_LOG_ERROR("DROP: run_writer exiting"); m_stats_table.reset(); m_counters_db.reset(); } @@ -179,6 +190,7 @@ stats_collector::run_collector() ss.str().c_str()); } + SWSS_LOG_ERROR("DROP: run_collector rc=%d", rc); if (rc == 0) { increment_published(1+op.missed_cnt); } @@ -196,6 +208,7 @@ stats_collector::run_collector() * hence losing few messages in flight is acceptable. Any more complex code * to handle is unwanted. */ + SWSS_LOG_ERROR("DROP: run_collector Exiting..."); return; } diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 0bb3223d4d7c..6f3e4322b1b5 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -70,6 +70,8 @@ class stats_collector int start(); void stop() { + + SWSS_LOG_ERROR("DROP: stopping stats_collector); m_shutdown = true; if (m_thr_collector.joinable()) { @@ -82,6 +84,7 @@ class stats_collector events_deinit_subscriber(m_subs_handle); m_subs_handle = NULL; + SWSS_LOG_ERROR("DROP: stopping DONE stats_collector); } void increment_published(counters_t val) { diff --git a/src/sonic-eventd/src/main.cpp b/src/sonic-eventd/src/main.cpp index ea058d5fac14..9e6cbaa202ee 100644 --- a/src/sonic-eventd/src/main.cpp +++ b/src/sonic-eventd/src/main.cpp @@ -5,6 +5,7 @@ void run_eventd_service(); int main() { + swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG); SWSS_LOG_INFO("The eventd service started"); run_eventd_service(); From 5ffe3f9fe357b156c1497590a9896889931048d8 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 18:54:34 +0000 Subject: [PATCH 021/137] debug --- src/sonic-eventd/src/eventd.cpp | 16 ++++++++++++++++ src/sonic-eventd/src/main.cpp | 1 + 2 files changed, 17 insertions(+) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index e0d6c5bc1b57..cdf5351f61ae 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -548,9 +548,13 @@ run_eventd_service() RET_ON_ERR(proxy->init() == 0, "Failed to init proxy"); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); + RET_ON_ERR(service.init_server(zctx) == 0, "Failed to init service"); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); RET_ON_ERR(stats_instance.start() == 0, "Failed to start stats collector"); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); /* * Start cache service, right upon eventd starts so as not to lose @@ -560,6 +564,7 @@ run_eventd_service() capture = new capture_service(zctx, cache_max); RET_ON_ERR(capture->set_control(INIT_CAPTURE) == 0, "Failed to init capture"); RET_ON_ERR(capture->set_control(START_CAPTURE) == 0, "Failed to start capture"); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); while(code != EVENT_EXIT) { int resp = -1; @@ -581,6 +586,7 @@ run_eventd_service() if (capture != NULL) { resp = capture->set_control(INIT_CAPTURE); } + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; @@ -591,6 +597,7 @@ run_eventd_service() break; } resp = capture->set_control(START_CAPTURE, &req_data); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; @@ -609,6 +616,7 @@ run_eventd_service() } delete capture; capture = NULL; + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; @@ -644,16 +652,19 @@ run_eventd_service() } } } + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; case EVENT_ECHO: resp = 0; resp_data.swap(req_data); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; case EVENT_EXIT: resp = 0; + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; default: @@ -663,20 +674,25 @@ run_eventd_service() } RET_ON_ERR(service.channel_write(resp, resp_data) == 0, "Failed to write response back"); + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); } out: + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); service.close_service(); stats_instance.stop(); if (proxy != NULL) { delete proxy; } + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); if (capture != NULL) { delete capture; } + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); if (thrCollector.joinable()) { thrCollector.join(); } + SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); if (zctx != NULL) { zmq_ctx_term(zctx); } diff --git a/src/sonic-eventd/src/main.cpp b/src/sonic-eventd/src/main.cpp index 9e6cbaa202ee..7a20497f0986 100644 --- a/src/sonic-eventd/src/main.cpp +++ b/src/sonic-eventd/src/main.cpp @@ -7,6 +7,7 @@ int main() { swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG); SWSS_LOG_INFO("The eventd service started"); + SWSS_LOG_ERROR("ERR:The eventd service started"); run_eventd_service(); From 3ee2d082af8cf2a5613e825b2d9018da3363ea9c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 18:59:01 +0000 Subject: [PATCH 022/137] compile fix --- rules/docker-eventd.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/docker-eventd.mk b/rules/docker-eventd.mk index 5a546aca1cb5..466cf684ca9e 100644 --- a/rules/docker-eventd.mk +++ b/rules/docker-eventd.mk @@ -43,4 +43,5 @@ $(DOCKER_EVENTD)_PLUGIN = rsyslog_plugin $($(DOCKER_EVENTD)_PLUGIN)_PATH = $($(DOCKER_EVENTD)_FILESPATH) SONIC_COPY_FILES += $($(DOCKER_EVENTD)_PLUGIN) +$(DOCKER_EVENTD)_FILES = $($(DOCKER_EVENTD)_PLUGIN) From 36d5ded169ab1f678095ca6f17ad2db5fa9dd361 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 19:08:46 +0000 Subject: [PATCH 023/137] compile fix --- src/sonic-eventd/src/eventd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 6f3e4322b1b5..0d06aac54b9f 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -71,7 +71,7 @@ class stats_collector void stop() { - SWSS_LOG_ERROR("DROP: stopping stats_collector); + SWSS_LOG_ERROR("DROP: stopping stats_collector"); m_shutdown = true; if (m_thr_collector.joinable()) { @@ -84,7 +84,7 @@ class stats_collector events_deinit_subscriber(m_subs_handle); m_subs_handle = NULL; - SWSS_LOG_ERROR("DROP: stopping DONE stats_collector); + SWSS_LOG_ERROR("DROP: stopping DONE stats_collector"); } void increment_published(counters_t val) { From 8c469a6d874477d03544c9e51a318ba70c49a7da Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 19:12:34 +0000 Subject: [PATCH 024/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index cdf5351f61ae..5dbab074a01f 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -126,7 +126,7 @@ stats_collector::run_writer() { while (true) { if (m_updated.exchange(false)) { - SWSS_LOG_ERROR("DROP: run_writer rc=%d", rc); + SWSS_LOG_ERROR("DROP: run_writer"); /* Update if there had been any update */ @@ -136,7 +136,7 @@ stats_collector::run_writer() fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); m_stats_table->set(counter_keys[i], fv); - SWSS_LOG_ERROR("DROP: run_writer i=%d cntr=%d", i, m_lst_counters[i]); + SWSS_LOG_ERROR("DROP: run_writer i=%d cntr=%d", i, (int)m_lst_counters[i]); } SWSS_LOG_ERROR("DROP: run_writer rc=%d", rc); } From 59f1f96f0405c7babcde40c3ef576782b2508ed2 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 19:15:45 +0000 Subject: [PATCH 025/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 5dbab074a01f..feb6f53e31ca 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -138,7 +138,7 @@ stats_collector::run_writer() m_stats_table->set(counter_keys[i], fv); SWSS_LOG_ERROR("DROP: run_writer i=%d cntr=%d", i, (int)m_lst_counters[i]); } - SWSS_LOG_ERROR("DROP: run_writer rc=%d", rc); + SWSS_LOG_ERROR("DROP: run_writer"); } if (m_shutdown) { break; From d315ae068b297fdeee992fac030715a53e438467 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 20:16:17 +0000 Subject: [PATCH 026/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index feb6f53e31ca..cd6f151ea825 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -98,12 +98,12 @@ stats_collector::start() * A subscriber is required to set a subscription. Else all published * events will be dropped at the point of publishing itself. */ - SWSS_LOG_ERROR("DROP: Enter stats_collector::start()"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: Enter", __FUNCTION__, __LINE__); m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); - SWSS_LOG_ERROR("DROP: Enter stats_collector::start()"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: Got subscriber", __FUNCTION__, __LINE__); if (!s_unit_testing) { m_counters_db = make_shared("COUNTERS_DB", 0); RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); @@ -112,12 +112,12 @@ stats_collector::start() RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); m_thr_writer = thread(&stats_collector::run_writer, this); - SWSS_LOG_ERROR("DROP: stats_collector::start() started writer"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: stats_collector::start() started writer", __FUNCTION__, __LINE__); } m_thr_collector = thread(&stats_collector::run_collector, this); rc = 0; out: - SWSS_LOG_ERROR("DROP: Exiting stats_collector::start() rc=%d", rc); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: Exiting stats_collector::start() rc=%d", __FUNCTION__, __LINE__, rc); return rc; } @@ -126,7 +126,7 @@ stats_collector::run_writer() { while (true) { if (m_updated.exchange(false)) { - SWSS_LOG_ERROR("DROP: run_writer"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); /* Update if there had been any update */ @@ -136,9 +136,9 @@ stats_collector::run_writer() fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); m_stats_table->set(counter_keys[i], fv); - SWSS_LOG_ERROR("DROP: run_writer i=%d cntr=%d", i, (int)m_lst_counters[i]); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer i=%d cntr=%d", __FUNCTION__, __LINE__, i, (int)m_lst_counters[i]); } - SWSS_LOG_ERROR("DROP: run_writer"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); } if (m_shutdown) { break; @@ -149,10 +149,10 @@ stats_collector::run_writer() * shutdown flag, as any counters collected during sleep * needs to be updated. */ - SWSS_LOG_ERROR("DROP: run_writer after sleep"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer after sleep", __FUNCTION__, __LINE__); } - SWSS_LOG_ERROR("DROP: run_writer exiting"); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer exiting", __FUNCTION__, __LINE__); m_stats_table.reset(); m_counters_db.reset(); } @@ -190,7 +190,7 @@ stats_collector::run_collector() ss.str().c_str()); } - SWSS_LOG_ERROR("DROP: run_collector rc=%d", rc); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector rc=%d", __FUNCTION__, __LINE__, rc); if (rc == 0) { increment_published(1+op.missed_cnt); } @@ -208,7 +208,7 @@ stats_collector::run_collector() * hence losing few messages in flight is acceptable. Any more complex code * to handle is unwanted. */ - SWSS_LOG_ERROR("DROP: run_collector Exiting..."); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector Exiting...", __FUNCTION__, __LINE__); return; } From cb9a29a6b0148baab1a1b8acef6e2fdcf61fed97 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 20:36:41 +0000 Subject: [PATCH 027/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index cd6f151ea825..cfad095f8a1e 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -190,7 +190,10 @@ stats_collector::run_collector() ss.str().c_str()); } - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector rc=%d", __FUNCTION__, __LINE__, rc); + if ((rc != 0) && (rc != 11)) { + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector rc=%d", __FUNCTION__, __LINE__, rc); + } + if (rc == 0) { increment_published(1+op.missed_cnt); } From bc576ebe9fa9730d37f201ac3168823d1b0c189e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 20:40:18 +0000 Subject: [PATCH 028/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index cfad095f8a1e..6072a379d74f 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -190,7 +190,7 @@ stats_collector::run_collector() ss.str().c_str()); } - if ((rc != 0) && (rc != 11)) { + if (rc != 11) { SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector rc=%d", __FUNCTION__, __LINE__, rc); } From 60b1242c2c9d53227f39cca05e973251cb661f91 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 20:59:26 +0000 Subject: [PATCH 029/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 6072a379d74f..d0988d898421 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -135,8 +135,9 @@ stats_collector::run_writer() fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); - m_stats_table->set(counter_keys[i], fv); - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer i=%d cntr=%d", __FUNCTION__, __LINE__, i, (int)m_lst_counters[i]); + bool bset = m_stats_table->set(counter_keys[i], fv); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer bset=%d i=%d cntr=%d", + __FUNCTION__, __LINE__, bset, i, (int)m_lst_counters[i]); } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); } @@ -149,7 +150,7 @@ stats_collector::run_writer() * shutdown flag, as any counters collected during sleep * needs to be updated. */ - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer after sleep", __FUNCTION__, __LINE__); + // SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer after sleep", __FUNCTION__, __LINE__); } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer exiting", __FUNCTION__, __LINE__); From 881f59a83fdf6cd1c8c4b78e26a34d8a6562018c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:02:21 +0000 Subject: [PATCH 030/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index d0988d898421..bc1f6a0ab577 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -135,9 +135,9 @@ stats_collector::run_writer() fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); - bool bset = m_stats_table->set(counter_keys[i], fv); - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer bset=%d i=%d cntr=%d", - __FUNCTION__, __LINE__, bset, i, (int)m_lst_counters[i]); + m_stats_table->set(counter_keys[i], fv); + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer i=%d cntr=%d", + __FUNCTION__, __LINE__, i, (int)m_lst_counters[i]); } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); } From c5d3503b049fc28857e3e8d4b1f64eb797bd4ca2 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:08:32 +0000 Subject: [PATCH 031/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index bc1f6a0ab577..6e42360f3e05 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -138,6 +138,12 @@ stats_collector::run_writer() m_stats_table->set(counter_keys[i], fv); SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer i=%d cntr=%d", __FUNCTION__, __LINE__, i, (int)m_lst_counters[i]); + { + stringstream ss; + + ss << fv; + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s val:%s\n", counter_keys[i].c_str(), ss.str().c_str()); + } } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); } From 8d89f85826aa889518b8a600aa4557749b7575fa Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:17:49 +0000 Subject: [PATCH 032/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 6e42360f3e05..987610a2f937 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -139,10 +139,14 @@ stats_collector::run_writer() SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer i=%d cntr=%d", __FUNCTION__, __LINE__, i, (int)m_lst_counters[i]); { + vector::const_iterator itc; stringstream ss; - ss << fv; - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s val:%s\n", counter_keys[i].c_str(), ss.str().c_str()); + for (itc = fv.begin(); itc != fv.end(); ++itc) { + ss << "key: " << itc->first << " val: " << itc->second << ";"; + } + SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s sz=%d val:%s\n", + counter_keys[i].c_str(), (int)fv.size(), ss.str().c_str()); } } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); From b0b24c68a448a087bf7f43b3eeeb949cdbc802e7 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:28:17 +0000 Subject: [PATCH 033/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 987610a2f937..71e19ec303e2 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -146,7 +146,8 @@ stats_collector::run_writer() ss << "key: " << itc->first << " val: " << itc->second << ";"; } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s sz=%d val:%s\n", - counter_keys[i].c_str(), (int)fv.size(), ss.str().c_str()); + __FUNCTION__, __LINE__, counter_keys[i].c_str(), + (int)fv.size(), ss.str().c_str()); } } SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); From 75a7bf7eef8e2ae38b92945cb489b797f2e45967 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:46:04 +0000 Subject: [PATCH 034/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 71e19ec303e2..358b63e5a5fc 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -38,9 +38,9 @@ using namespace swss; #define STATS_COLLECTOR_TIMEOUT 1000 -static string counter_keys[COUNTERS_EVENTS_TOTAL] = { - string(COUNTERS_EVENTS_TABLE) + ":" + COUNTERS_EVENTS_PUBLISHED, - string(COUNTERS_EVENTS_TABLE) + ":" + COUNTERS_EVENTS_MISSED_CACHE +static const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { + COUNTERS_EVENTS_PUBLISHED, + COUNTERS_EVENTS_MISSED_CACHE }; #define EVENTS_STATS_FIELD_NAME "value" @@ -142,9 +142,11 @@ stats_collector::run_writer() vector::const_iterator itc; stringstream ss; + ss << "{" for (itc = fv.begin(); itc != fv.end(); ++itc) { - ss << "key: " << itc->first << " val: " << itc->second << ";"; + ss << "{" << itc->first << "," << itc->second << "},"; } + ss << "}" SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s sz=%d val:%s\n", __FUNCTION__, __LINE__, counter_keys[i].c_str(), (int)fv.size(), ss.str().c_str()); From 0d8ba01e901dc459a35558c4bbd59536aa1be0e7 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:53:10 +0000 Subject: [PATCH 035/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 358b63e5a5fc..440ba1da4672 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -142,11 +142,11 @@ stats_collector::run_writer() vector::const_iterator itc; stringstream ss; - ss << "{" + ss << "{"; for (itc = fv.begin(); itc != fv.end(); ++itc) { ss << "{" << itc->first << "," << itc->second << "},"; } - ss << "}" + ss << "}"; SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s sz=%d val:%s\n", __FUNCTION__, __LINE__, counter_keys[i].c_str(), (int)fv.size(), ss.str().c_str()); From 8648f9b1e420b6f68f0f4b75e8cf976cbb0a3a80 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 30 Jul 2022 21:55:30 +0000 Subject: [PATCH 036/137] compile fix --- src/sonic-eventd/src/eventd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 440ba1da4672..be4fb10bd31c 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -148,7 +148,7 @@ stats_collector::run_writer() } ss << "}"; SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s sz=%d val:%s\n", - __FUNCTION__, __LINE__, counter_keys[i].c_str(), + __FUNCTION__, __LINE__, counter_keys[i], (int)fv.size(), ss.str().c_str()); } } From 05bf708ec585baa9ea70dd3894181b5566fa3d89 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 3 Aug 2022 16:32:24 +0000 Subject: [PATCH 037/137] drop rsyslog plugin copy temporarily --- files/build_templates/sonic_debian_extension.j2 | 4 ++-- rules/docker-eventd.mk | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index fb417c29dc66..6cef47a392a6 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -779,8 +779,8 @@ sudo bash -c "echo { > $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ctr_image_name sudo bash -c "echo } >> $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ctr_image_names.json" # copy rsyslog plugin binary for use by all dockers that use plugin to publish events. -sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS} -sudo cp ${files_path}/rsyslog_plugin ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/ +# sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS} +# sudo cp ${files_path}/rsyslog_plugin ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/ {% for script in installer_start_scripts.split(' ') -%} if [ -f $TARGET_MACHINE"_{{script}}" ]; then diff --git a/rules/docker-eventd.mk b/rules/docker-eventd.mk index 466cf684ca9e..af747bd231be 100644 --- a/rules/docker-eventd.mk +++ b/rules/docker-eventd.mk @@ -37,11 +37,10 @@ $(DOCKER_EVENTD)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro SONIC_BULLSEYE_DOCKERS += $(DOCKER_EVENTD) SONIC_BULLSEYE_DBG_DOCKERS += $(DOCKER_EVENTD_DBG) -$(DOCKER_EVENTD)_FILESPATH = $($(SONIC_EVENTD)_SRC_PATH)/rsyslog_plugin +# $(DOCKER_EVENTD)_FILESPATH = $($(SONIC_EVENTD)_SRC_PATH)/rsyslog_plugin -$(DOCKER_EVENTD)_PLUGIN = rsyslog_plugin -$($(DOCKER_EVENTD)_PLUGIN)_PATH = $($(DOCKER_EVENTD)_FILESPATH) +# $(DOCKER_EVENTD)_PLUGIN = rsyslog_plugin +# $($(DOCKER_EVENTD)_PLUGIN)_PATH = $($(DOCKER_EVENTD)_FILESPATH) -SONIC_COPY_FILES += $($(DOCKER_EVENTD)_PLUGIN) -$(DOCKER_EVENTD)_FILES = $($(DOCKER_EVENTD)_PLUGIN) +# $(DOCKER_EVENTD)_FILES = $($(DOCKER_EVENTD)_PLUGIN) From 1dad767620dd33b84028898b8caef44aeb0a71d9 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 3 Aug 2022 18:14:11 +0000 Subject: [PATCH 038/137] enable copy of rsyslog plugin --- files/build_templates/sonic_debian_extension.j2 | 4 ++-- rules/docker-eventd.mk | 9 +++++---- slave.mk | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 6cef47a392a6..fb417c29dc66 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -779,8 +779,8 @@ sudo bash -c "echo { > $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ctr_image_name sudo bash -c "echo } >> $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/ctr_image_names.json" # copy rsyslog plugin binary for use by all dockers that use plugin to publish events. -# sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS} -# sudo cp ${files_path}/rsyslog_plugin ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/ +sudo mkdir -p ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS} +sudo cp ${files_path}/rsyslog_plugin ${FILESYSTEM_ROOT_USR_SHARE_SONIC_SCRIPTS}/ {% for script in installer_start_scripts.split(' ') -%} if [ -f $TARGET_MACHINE"_{{script}}" ]; then diff --git a/rules/docker-eventd.mk b/rules/docker-eventd.mk index af747bd231be..c69fee09e569 100644 --- a/rules/docker-eventd.mk +++ b/rules/docker-eventd.mk @@ -37,10 +37,11 @@ $(DOCKER_EVENTD)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro SONIC_BULLSEYE_DOCKERS += $(DOCKER_EVENTD) SONIC_BULLSEYE_DBG_DOCKERS += $(DOCKER_EVENTD_DBG) -# $(DOCKER_EVENTD)_FILESPATH = $($(SONIC_EVENTD)_SRC_PATH)/rsyslog_plugin +$(DOCKER_EVENTD)_FILESPATH = $($(SONIC_EVENTD)_SRC_PATH)/rsyslog_plugin -# $(DOCKER_EVENTD)_PLUGIN = rsyslog_plugin -# $($(DOCKER_EVENTD)_PLUGIN)_PATH = $($(DOCKER_EVENTD)_FILESPATH) +$(DOCKER_EVENTD)_PLUGIN = rsyslog_plugin +$($(DOCKER_EVENTD)_PLUGIN)_PATH = $($(DOCKER_EVENTD)_FILESPATH) -# $(DOCKER_EVENTD)_FILES = $($(DOCKER_EVENTD)_PLUGIN) +SONIC_COPY_FILES += $($(DOCKER_EVENTD)_PLUGIN) +$(DOCKER_EVENTD)_SHARED_FILES = $($(DOCKER_EVENTD)_PLUGIN) diff --git a/slave.mk b/slave.mk index 8a400a8c88c4..9105c7c64c65 100644 --- a/slave.mk +++ b/slave.mk @@ -1225,6 +1225,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $(if $($(docker:-dbg.gz=.gz)_MACHINE),\ mv $($(docker:-dbg.gz=.gz)_CONTAINER_NAME).sh $($(docker:-dbg.gz=.gz)_MACHINE)_$($(docker:-dbg.gz=.gz)_CONTAINER_NAME).sh ) + $(foreach file, $($(docker)_SHARED_FILES), \ + { cp $($(file)_PATH)/$(file) $(FILES_PATH)/ $(LOG) || exit 1 ; } ; ) ) From 1f01b1d61b961393235e85d74ee207fb64c85fbc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 4 Aug 2022 00:11:56 +0000 Subject: [PATCH 039/137] submodule update to statistics branch. --- src/sonic-swss-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-swss-common b/src/sonic-swss-common index 2247dbea47f9..0f583976d1ee 160000 --- a/src/sonic-swss-common +++ b/src/sonic-swss-common @@ -1 +1 @@ -Subproject commit 2247dbea47f968411b28b5c04d4be89d72d08cbf +Subproject commit 0f583976d1eeb99ea12fe29e9a964174c6bd63e2 From 810407983e4d23c3e6cc2fc3bf1a39e8297b6228 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 4 Aug 2022 00:20:00 +0000 Subject: [PATCH 040/137] submod update sonic-gnmi --- src/sonic-gnmi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-gnmi b/src/sonic-gnmi index 92428dac99b2..b65f2e82e8e9 160000 --- a/src/sonic-gnmi +++ b/src/sonic-gnmi @@ -1 +1 @@ -Subproject commit 92428dac99b2d6d97b4c904cb83933cbc8f7e848 +Subproject commit b65f2e82e8e9fa5ad52512295cd965d806866891 From 1fdff7d6b669de02fcd51e335525e95bb3077caf Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 6 Aug 2022 00:54:53 +0000 Subject: [PATCH 041/137] Revert back to public master for gnmi. --- src/sonic-gnmi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-gnmi b/src/sonic-gnmi index b65f2e82e8e9..92428dac99b2 160000 --- a/src/sonic-gnmi +++ b/src/sonic-gnmi @@ -1 +1 @@ -Subproject commit b65f2e82e8e9fa5ad52512295cd965d806866891 +Subproject commit 92428dac99b2d6d97b4c904cb83933cbc8f7e848 From a0463150a80ef9a3978e347f56207a5fbf56aa94 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 6 Aug 2022 00:54:53 +0000 Subject: [PATCH 042/137] Revert back to public master for gnmi. --- src/sonic-gnmi | 2 +- src/sonic-swss-common | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 160000 src/sonic-swss-common diff --git a/src/sonic-gnmi b/src/sonic-gnmi index b65f2e82e8e9..92428dac99b2 160000 --- a/src/sonic-gnmi +++ b/src/sonic-gnmi @@ -1 +1 @@ -Subproject commit b65f2e82e8e9fa5ad52512295cd965d806866891 +Subproject commit 92428dac99b2d6d97b4c904cb83933cbc8f7e848 diff --git a/src/sonic-swss-common b/src/sonic-swss-common deleted file mode 160000 index 0f583976d1ee..000000000000 --- a/src/sonic-swss-common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0f583976d1eeb99ea12fe29e9a964174c6bd63e2 From 1bf94915d4ee37be267e748d3e0711205f938131 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Sat, 6 Aug 2022 01:38:17 +0000 Subject: [PATCH 043/137] remove debug messages --- src/sonic-eventd/src/eventd.cpp | 49 --------------------------------- src/sonic-eventd/src/eventd.h | 2 -- 2 files changed, 51 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index be4fb10bd31c..8ee4ae3ca106 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -98,12 +98,9 @@ stats_collector::start() * A subscriber is required to set a subscription. Else all published * events will be dropped at the point of publishing itself. */ - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: Enter", __FUNCTION__, __LINE__); - m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: Got subscriber", __FUNCTION__, __LINE__); if (!s_unit_testing) { m_counters_db = make_shared("COUNTERS_DB", 0); RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); @@ -112,12 +109,10 @@ stats_collector::start() RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); m_thr_writer = thread(&stats_collector::run_writer, this); - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: stats_collector::start() started writer", __FUNCTION__, __LINE__); } m_thr_collector = thread(&stats_collector::run_collector, this); rc = 0; out: - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: Exiting stats_collector::start() rc=%d", __FUNCTION__, __LINE__, rc); return rc; } @@ -126,8 +121,6 @@ stats_collector::run_writer() { while (true) { if (m_updated.exchange(false)) { - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); - /* Update if there had been any update */ for (int i = 0; i < COUNTERS_EVENTS_TOTAL; ++i) { @@ -136,23 +129,7 @@ stats_collector::run_writer() fv.emplace_back(EVENTS_STATS_FIELD_NAME, to_string(m_lst_counters[i])); m_stats_table->set(counter_keys[i], fv); - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer i=%d cntr=%d", - __FUNCTION__, __LINE__, i, (int)m_lst_counters[i]); - { - vector::const_iterator itc; - stringstream ss; - - ss << "{"; - for (itc = fv.begin(); itc != fv.end(); ++itc) { - ss << "{" << itc->first << "," << itc->second << "},"; - } - ss << "}"; - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: key:%s sz=%d val:%s\n", - __FUNCTION__, __LINE__, counter_keys[i], - (int)fv.size(), ss.str().c_str()); - } } - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer", __FUNCTION__, __LINE__); } if (m_shutdown) { break; @@ -163,10 +140,8 @@ stats_collector::run_writer() * shutdown flag, as any counters collected during sleep * needs to be updated. */ - // SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer after sleep", __FUNCTION__, __LINE__); } - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_writer exiting", __FUNCTION__, __LINE__); m_stats_table.reset(); m_counters_db.reset(); } @@ -204,10 +179,6 @@ stats_collector::run_collector() ss.str().c_str()); } - if (rc != 11) { - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector rc=%d", __FUNCTION__, __LINE__, rc); - } - if (rc == 0) { increment_published(1+op.missed_cnt); } @@ -225,7 +196,6 @@ stats_collector::run_collector() * hence losing few messages in flight is acceptable. Any more complex code * to handle is unwanted. */ - SWSS_LOG_ERROR("stats_collector::%s::%d DROP: run_collector Exiting...", __FUNCTION__, __LINE__); return; } @@ -291,9 +261,6 @@ capture_service::init_capture_cache(const event_serialized_lst_t &lst) m_events.push_back(*itc); } } - else { - SWSS_LOG_ERROR("failed to serialize cache message from subscriber; DROP"); - } } } @@ -565,13 +532,9 @@ run_eventd_service() RET_ON_ERR(proxy->init() == 0, "Failed to init proxy"); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); - RET_ON_ERR(service.init_server(zctx) == 0, "Failed to init service"); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); RET_ON_ERR(stats_instance.start() == 0, "Failed to start stats collector"); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); /* * Start cache service, right upon eventd starts so as not to lose @@ -581,7 +544,6 @@ run_eventd_service() capture = new capture_service(zctx, cache_max); RET_ON_ERR(capture->set_control(INIT_CAPTURE) == 0, "Failed to init capture"); RET_ON_ERR(capture->set_control(START_CAPTURE) == 0, "Failed to start capture"); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); while(code != EVENT_EXIT) { int resp = -1; @@ -603,7 +565,6 @@ run_eventd_service() if (capture != NULL) { resp = capture->set_control(INIT_CAPTURE); } - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; @@ -614,7 +575,6 @@ run_eventd_service() break; } resp = capture->set_control(START_CAPTURE, &req_data); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; @@ -633,7 +593,6 @@ run_eventd_service() } delete capture; capture = NULL; - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; @@ -669,19 +628,16 @@ run_eventd_service() } } } - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; case EVENT_ECHO: resp = 0; resp_data.swap(req_data); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; case EVENT_EXIT: resp = 0; - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); break; default: @@ -691,25 +647,20 @@ run_eventd_service() } RET_ON_ERR(service.channel_write(resp, resp_data) == 0, "Failed to write response back"); - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); } out: - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); service.close_service(); stats_instance.stop(); if (proxy != NULL) { delete proxy; } - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); if (capture != NULL) { delete capture; } - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); if (thrCollector.joinable()) { thrCollector.join(); } - SWSS_LOG_ERROR("DROP: reached here %s::%d\n", __FUNCTION__, __LINE__); if (zctx != NULL) { zmq_ctx_term(zctx); } diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 0d06aac54b9f..caad0ad9b838 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -71,7 +71,6 @@ class stats_collector void stop() { - SWSS_LOG_ERROR("DROP: stopping stats_collector"); m_shutdown = true; if (m_thr_collector.joinable()) { @@ -84,7 +83,6 @@ class stats_collector events_deinit_subscriber(m_subs_handle); m_subs_handle = NULL; - SWSS_LOG_ERROR("DROP: stopping DONE stats_collector"); } void increment_published(counters_t val) { From d9788b0717906cc8c7f56ee8041d0e6ebc6071ea Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 8 Aug 2022 21:46:14 +0000 Subject: [PATCH 044/137] eventd to send heartbeat messages --- src/sonic-eventd/src/eventd.cpp | 46 ++++++++++++++++++++++++++++----- src/sonic-eventd/src/eventd.h | 6 ++++- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 8ee4ae3ca106..436c35c0cc2f 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -14,7 +14,9 @@ * * (2) Main proxy service that runs XSUB/XPUB ends * - * (3) Get stats for total published counter in memory. + * (3) Get stats for total published counter in memory. This thread also sends + * heartbeat message. It accomplishes by counting upon receive missed due + * to event receive timeout. * * (4) Thread to update counters from memory to redis periodically. * @@ -35,7 +37,19 @@ using namespace swss; /* Sock read timeout in milliseconds, to enable look for control signals */ #define CAPTURE_SOCK_TIMEOUT 300 -#define STATS_COLLECTOR_TIMEOUT 1000 +#define STATS_COLLECTOR_TIMEOUT 300 + +/* + * Sets heartbeat interval little less than expected 2 secs, to ensure + * an heartbeat is sent within 2 seconds. Sending one extra is fine, but + * not sending one within 2 seconds is not acceptable. + */ +#define HEARBEAT_INTERVAL 1900 +#define HEARBEAT_CNT ((HEARBEAT_INTERVAL) / (STATS_COLLECTOR_TIMEOUT)) + +/* Source & tag for heartbeat events */ +#define EVENTD_PUBLISHER_SOURCE "eventd" +#define EVENTD_HEARTBEAT_TAG "heartbeat" static const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { @@ -98,6 +112,10 @@ stats_collector::start() * A subscriber is required to set a subscription. Else all published * events will be dropped at the point of publishing itself. */ + m_pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); + RET_ON_ERR(m_pub_handle != NULL, + "failed to create publisher handle for heartbeats"); + m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); @@ -105,7 +123,8 @@ stats_collector::start() m_counters_db = make_shared("COUNTERS_DB", 0); RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); - m_stats_table = make_shared(m_counters_db.get(), COUNTERS_EVENTS_TABLE); + m_stats_table = make_shared( + m_counters_db.get(), COUNTERS_EVENTS_TABLE); RET_ON_ERR(m_stats_table != NULL, "Failed to get events table"); m_thr_writer = thread(&stats_collector::run_writer, this); @@ -149,6 +168,7 @@ stats_collector::run_writer() void stats_collector::run_collector() { + int hb_cntr = 0; /* * Though we can count off of capture socket, then we need to duplicate * code in event_receive which has the logic to count all missed per @@ -181,11 +201,23 @@ stats_collector::run_collector() if (rc == 0) { increment_published(1+op.missed_cnt); + + /* reset counter on receive to restart. */ + hb_cntr = 0; } - else if (rc < 0) { - SWSS_LOG_ERROR( - "event_receive failed with rc=%d; stats:published(%lu)", rc, - m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); + else { + if (rc < 0) { + SWSS_LOG_ERROR( + "event_receive failed with rc=%d; stats:published(%lu)", rc, + m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); + } + if (++hb_cntr >= HEARBEAT_CNT) { + rc = event_publish(m_pub_handle, EVENTD_HEARTBEAT_TAG); + if (rc != 0) { + SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); + } + hb_cntr = 0; + } } } diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index caad0ad9b838..771e1aad5996 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -57,7 +57,8 @@ class eventd_proxy class stats_collector { public: - stats_collector() : m_shutdown(false), m_subs_handle(NULL) + stats_collector() : m_shutdown(false), + m_subs_handle(NULL), m_pub_handle(NULL) { for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { m_lst_counters[i] = 0; @@ -82,7 +83,9 @@ class stats_collector } events_deinit_subscriber(m_subs_handle); + events_deinit_publisher(m_pub_handle); m_subs_handle = NULL; + m_pub_handle = NULL; } void increment_published(counters_t val) { @@ -117,6 +120,7 @@ class stats_collector shared_ptr m_stats_table; event_handle_t m_subs_handle; + event_handle_t m_pub_handle; }; /* From 13494db554e8810e5bf7a5beea09c17dcfa0e3d4 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 9 Aug 2022 17:30:58 +0000 Subject: [PATCH 045/137] Added heartbeat pause during capture --- src/sonic-eventd/src/eventd.cpp | 10 ++++++++-- src/sonic-eventd/src/eventd.h | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 436c35c0cc2f..b8387920762d 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -48,7 +48,7 @@ using namespace swss; #define HEARBEAT_CNT ((HEARBEAT_INTERVAL) / (STATS_COLLECTOR_TIMEOUT)) /* Source & tag for heartbeat events */ -#define EVENTD_PUBLISHER_SOURCE "eventd" +#define EVENTD_PUBLISHER_SOURCE "sonic-events-eventd" #define EVENTD_HEARTBEAT_TAG "heartbeat" @@ -211,7 +211,7 @@ stats_collector::run_collector() "event_receive failed with rc=%d; stats:published(%lu)", rc, m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } - if (++hb_cntr >= HEARBEAT_CNT) { + if (!m_pause_heartbeat && ++hb_cntr >= HEARBEAT_CNT) { rc = event_publish(m_pub_handle, EVENTD_HEARTBEAT_TAG); if (rc != 0) { SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); @@ -606,7 +606,11 @@ run_eventd_service() resp = -1; break; } + /* Pause heartbeat during caching */ + stats_instance.hearbeat_ctrl(true) + resp = capture->set_control(START_CAPTURE, &req_data); + break; @@ -625,6 +629,8 @@ run_eventd_service() } delete capture; capture = NULL; + /* Unpause heartbeat upon stop caching */ + stats_instance.hearbeat_ctrl() break; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 771e1aad5996..9ecd601e3b9a 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -58,7 +58,8 @@ class stats_collector { public: stats_collector() : m_shutdown(false), - m_subs_handle(NULL), m_pub_handle(NULL) + m_subs_handle(NULL), m_pub_handle(NULL), + m_pause_heartbeat(false) { for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { m_lst_counters[i] = 0; @@ -96,6 +97,11 @@ class stats_collector _update_stats(INDEX_COUNTERS_EVENTS_MISSED_CACHE, val); } + /* A way to pause heartbeat */ + void hearbeat_ctrl(bool pause = false) { + m_pause_heartbeat = pause; + } + private: void _update_stats(int index, counters_t val) { m_lst_counters[index] += val; @@ -121,6 +127,8 @@ class stats_collector event_handle_t m_subs_handle; event_handle_t m_pub_handle; + + bool m_pause_heartbeat; }; /* From 38039bc59b2a2c5e8c62e1bd5fc832fa3b5c7c21 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 9 Aug 2022 17:47:37 +0000 Subject: [PATCH 046/137] Ignore heartbeat message --- src/sonic-eventd/tests/eventd_ut.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index a64206fca3d2..8d25d44ce5e4 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -641,6 +641,7 @@ TEST(eventd, service) /* Test normal cache op; init, start & stop via event_service APIs */ int init_cache = 4; /* provided along with start capture */ event_serialized_lst_t evts_start, evts_read; + vector evts_start_int; EXPECT_TRUE(init_cache > 1); @@ -650,6 +651,7 @@ TEST(eventd, service) string evt_str; serialize(ev, evt_str); evts_start.push_back(evt_str); + evts_start_int.push_back(ev); } @@ -664,7 +666,19 @@ TEST(eventd, service) /* Read the cache */ EXPECT_EQ(0, service.cache_read(evts_read)); - EXPECT_EQ(evts_read, evts_start); + if (evts_read != evts_start) { + vector evts_read_int; + + for (event_serialized_lst_t::const_iterator itc = evts_read.begin(); + itc != evts_read.end(); ++itc) { + internal_event_t event; + + if (deserialize(*itc, event) == 0) { + evts_read_int.push_back(event); + } + } + EXPECT_EQ(evts_read_int, evts_start_int); + } } EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); From 4e95b54374a501048e64861b7f7eff068a83f4ba Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 9 Aug 2022 21:10:32 +0000 Subject: [PATCH 047/137] syntax --- src/sonic-eventd/src/eventd.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index b8387920762d..e826a13d89c7 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -607,10 +607,9 @@ run_eventd_service() break; } /* Pause heartbeat during caching */ - stats_instance.hearbeat_ctrl(true) + stats_instance.hearbeat_ctrl(true); resp = capture->set_control(START_CAPTURE, &req_data); - break; @@ -629,8 +628,9 @@ run_eventd_service() } delete capture; capture = NULL; + /* Unpause heartbeat upon stop caching */ - stats_instance.hearbeat_ctrl() + stats_instance.hearbeat_ctrl(); break; From 5fab4104abf1b367973e6d45cd30627e4d54fc7f Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 9 Aug 2022 21:50:02 +0000 Subject: [PATCH 048/137] minor --- src/sonic-eventd/src/eventd.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index e826a13d89c7..139b3b03f999 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -219,6 +219,14 @@ stats_collector::run_collector() hb_cntr = 0; } } + { + static int cnt = 0; + + if ((cnt++%10) == 0) { + SWSS_LOG_ERROR("DROP: m_pause_heartbeat=%d hb_cntr=%d", + m_pause_heartbeat, hb_cntr); + } + } } /* @@ -607,7 +615,7 @@ run_eventd_service() break; } /* Pause heartbeat during caching */ - stats_instance.hearbeat_ctrl(true); + stats_instance.heartbeat_ctrl(true); resp = capture->set_control(START_CAPTURE, &req_data); break; @@ -630,7 +638,7 @@ run_eventd_service() capture = NULL; /* Unpause heartbeat upon stop caching */ - stats_instance.hearbeat_ctrl(); + stats_instance.heartbeat_ctrl(); break; From 876e2ac89957bab37ff5625a0add162ab1689363 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 9 Aug 2022 22:10:15 +0000 Subject: [PATCH 049/137] heartbeat control on cache start at init --- src/sonic-eventd/src/eventd.cpp | 11 +++-------- src/sonic-eventd/src/eventd.h | 3 ++- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 139b3b03f999..1838af58d5b5 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -219,14 +219,6 @@ stats_collector::run_collector() hb_cntr = 0; } } - { - static int cnt = 0; - - if ((cnt++%10) == 0) { - SWSS_LOG_ERROR("DROP: m_pause_heartbeat=%d hb_cntr=%d", - m_pause_heartbeat, hb_cntr); - } - } } /* @@ -576,6 +568,9 @@ run_eventd_service() RET_ON_ERR(stats_instance.start() == 0, "Failed to start stats collector"); + /* Pause heartbeat during caching */ + stats_instance.heartbeat_ctrl(true); + /* * Start cache service, right upon eventd starts so as not to lose * events until telemetry starts. diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 9ecd601e3b9a..702df25dcb5a 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -98,8 +98,9 @@ class stats_collector } /* A way to pause heartbeat */ - void hearbeat_ctrl(bool pause = false) { + void heartbeat_ctrl(bool pause = false) { m_pause_heartbeat = pause; + SWSS_LOG_INFO("Set heartbeat_ctrl pause=%d", pause); } private: From 3d1a01233922fe54d6aeb3025c26a3010519e129 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 15:18:48 +0000 Subject: [PATCH 050/137] test update --- src/sonic-eventd/tests/eventd_ut.cpp | 29 +++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 8d25d44ce5e4..16c0f50c9a4e 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -593,7 +593,7 @@ TEST(eventd, service) * It starts to capture too. */ - set_unit_testing(true); + // set_unit_testing(true); thread thread_service(&run_eventd_service); /* Need client side service to interact with server side */ @@ -681,6 +681,33 @@ TEST(eventd, service) } } + { + // Test heartbeat + event_receive_op_t op; + + /* Have a 3 second timeout for receive */ + subs_handle = events_init_subscriber(false, 3 * 1000); + EXPECT_TRUE(subs_handle != NULL); + + rc = event_receive(subs_handle, op); + EXPECT_EQ(rc, 0); + + EXPECT_EQ(op.key, "sonic-events-eventd:heartbeat"); + + EXPECT_EQ(1, (int) op.params.size()); + + EXPECT_EQ(op.begin()->first, "timestamp") + + /* The content of timestamp is validated by swsscommon */ + + events_deinit_subscriber(subs_handle); + + } + + { + // Test stats + } + EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); service.close_service(); From f1d458e420524c4a54e3df6e4b4229e24be5df8a Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 15:40:34 +0000 Subject: [PATCH 051/137] syntax --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 16c0f50c9a4e..a77e233b81ce 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -696,7 +696,7 @@ TEST(eventd, service) EXPECT_EQ(1, (int) op.params.size()); - EXPECT_EQ(op.begin()->first, "timestamp") + EXPECT_EQ(op.params.begin()->first, "timestamp"); /* The content of timestamp is validated by swsscommon */ From 152225f242262958b8dc9c73784a2eee7c6445e8 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 15:47:40 +0000 Subject: [PATCH 052/137] syntax --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index a77e233b81ce..3e0891cfcd63 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -686,10 +686,10 @@ TEST(eventd, service) event_receive_op_t op; /* Have a 3 second timeout for receive */ - subs_handle = events_init_subscriber(false, 3 * 1000); + event_handle_t subs_handle = events_init_subscriber(false, 3 * 1000); EXPECT_TRUE(subs_handle != NULL); - rc = event_receive(subs_handle, op); + int rc = event_receive(subs_handle, op); EXPECT_EQ(rc, 0); EXPECT_EQ(op.key, "sonic-events-eventd:heartbeat"); From df86e65e0db4a0ec2eff3ff37f3bc05954e175cc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 15:54:07 +0000 Subject: [PATCH 053/137] syntax --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 3e0891cfcd63..8aadc09388b4 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -593,7 +593,7 @@ TEST(eventd, service) * It starts to capture too. */ - // set_unit_testing(true); + set_unit_testing(true); thread thread_service(&run_eventd_service); /* Need client side service to interact with server side */ From 2e25cac3f0285c92f06407e7cca70f604eac85c4 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 18:38:09 +0000 Subject: [PATCH 054/137] Adding redis env to test --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- src/sonic-eventd/tests/main.cpp | 76 ++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 8aadc09388b4..3e0891cfcd63 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -593,7 +593,7 @@ TEST(eventd, service) * It starts to capture too. */ - set_unit_testing(true); + // set_unit_testing(true); thread thread_service(&run_eventd_service); /* Need client side service to interact with server side */ diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index f803fbc39d5a..b23025729ef3 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -1,10 +1,86 @@ #include "gtest/gtest.h" +#include "common/dbconnector.h" #include using namespace std; +using namespace swss; + +string existing_file = "./tests/redis_multi_db_ut_config/database_config.json"; +string nonexisting_file = "./tests/redis_multi_db_ut_config/database_config_nonexisting.json"; +// string global_existing_file = "./tests/redis_multi_db_ut_config/database_global.json"; + +#define TEST_DB "APPL_DB" +#define TEST_NAMESPACE "asic0" +#define INVALID_NAMESPACE "invalid" + +class SwsscommonEnvironment : public ::testing::Environment { +public: + // Override this to define how to set up the environment. + void SetUp() override { + // by default , init should be false + cout<<"Default : isInit = "< Date: Wed, 10 Aug 2022 20:40:28 +0000 Subject: [PATCH 055/137] Adding redis env to test --- src/sonic-eventd/tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index b23025729ef3..548de768381e 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -1,5 +1,5 @@ #include "gtest/gtest.h" -#include "common/dbconnector.h" +#include "dbconnector.h" #include using namespace std; From 6814b11dc87d2f4d6515d39a440eac4925ad7b84 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 20:46:28 +0000 Subject: [PATCH 056/137] Adding redis env to test --- .../database_config.json | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/sonic-eventd/tests/redis_multi_db_ut_config/database_config.json diff --git a/src/sonic-eventd/tests/redis_multi_db_ut_config/database_config.json b/src/sonic-eventd/tests/redis_multi_db_ut_config/database_config.json new file mode 100644 index 000000000000..141bb65f0f48 --- /dev/null +++ b/src/sonic-eventd/tests/redis_multi_db_ut_config/database_config.json @@ -0,0 +1,112 @@ +{ + "INSTANCES": { + "redis":{ + "hostname" : "127.0.0.1", + "port": 6379, + "unix_socket_path": "/var/run/redis/redis.sock" + }, + "redis1":{ + "hostname" : "127.0.0.1", + "port": 6380, + "unix_socket_path": "/var/run/redis/redis1.sock" + }, + "redis2":{ + "hostname" : "127.0.0.1", + "port": 6381, + "unix_socket_path": "/var/run/redis/redis2.sock" + }, + "redis3":{ + "hostname" : "127.0.0.1", + "port": 6382, + "unix_socket_path": "/var/run/redis/redis3.sock" + }, + "redis4":{ + "hostname" : "127.0.0.1", + "port": 6383, + "unix_socket_path": "/var/run/redis/redis4.sock" + } + }, + "DATABASES" : { + "APPL_DB" : { + "id" : 0, + "separator": ":", + "instance" : "redis" + }, + "ASIC_DB" : { + "id" : 1, + "separator": ":", + "instance" : "redis" + }, + "COUNTERS_DB" : { + "id" : 2, + "separator": ":", + "instance" : "redis" + }, + "LOGLEVEL_DB" : { + "id" : 3, + "separator": ":", + "instance" : "redis" + }, + "CONFIG_DB" : { + "id" : 4, + "separator": "|", + "instance" : "redis" + }, + "PFC_WD_DB" : { + "id" : 5, + "separator": ":", + "instance" : "redis" + }, + "FLEX_COUNTER_DB" : { + "id" : 5, + "separator": ":", + "instance" : "redis" + }, + "STATE_DB" : { + "id" : 6, + "separator": "|", + "instance" : "redis" + }, + "SNMP_OVERLAY_DB" : { + "id" : 7, + "separator": "|", + "instance" : "redis" + }, + "RESTAPI_DB": { + "id": 8, + "separator": "|", + "instance": "redis" + }, + "GB_ASIC_DB": { + "id": 9, + "separator": ":", + "instance": "redis" + }, + "GB_COUNTERS_DB": { + "id": 10, + "separator": ":", + "instance": "redis" + }, + "GB_FLEX_COUNTER_DB": { + "id": 11, + "separator": ":", + "instance": "redis" + }, + "STATE_DB2" : { + "id" : 13, + "separator": "|", + "instance" : "redis" + }, + "APPL_STATE_DB" : { + "id" : 14, + "separator": ":", + "instance" : "redis" + }, + "TEST_DB" : { + "id" : 15, + "separator": ":", + "instance" : "redis" + } + }, + "VERSION" : "1.0" +} From 4326bd41891f4fa5903b19b4c3f7793bbd2e4702 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 21:44:47 +0000 Subject: [PATCH 057/137] Adding redis env to test --- src/sonic-eventd/tests/eventd_ut.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 3e0891cfcd63..a88190bf2691 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -593,9 +593,13 @@ TEST(eventd, service) * It starts to capture too. */ - // set_unit_testing(true); + set_unit_testing(true); thread thread_service(&run_eventd_service); + printf("Calling DBConnector\n"); + DBConnector db("TEST_DB", 0, true); + printf("Created DBConnector\n"); + /* Need client side service to interact with server side */ EXPECT_EQ(0, service.init_client(zctx)); From 3d77276de149950e84019b7095912ba24b52537c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 21:48:17 +0000 Subject: [PATCH 058/137] Adding redis env to test --- src/sonic-eventd/tests/eventd_ut.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index a88190bf2691..ff90739badd6 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -11,6 +11,7 @@ #include "../src/eventd.h" using namespace std; +using namespace swss; typedef struct { int id; From 08f52489050edb8d82884e99a72803f51342324e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 21:55:12 +0000 Subject: [PATCH 059/137] Adding redis env to test --- src/sonic-eventd/Makefile | 5 +- src/sonic-eventd/tests/main.cpp | 2 - .../database_config0.json | 92 +++++++++++++++++++ .../database_config1.json | 92 +++++++++++++++++++ .../database_global.json | 16 ++++ 5 files changed, 203 insertions(+), 4 deletions(-) create mode 100644 src/sonic-eventd/tests/redis_multi_db_ut_config/database_config0.json create mode 100644 src/sonic-eventd/tests/redis_multi_db_ut_config/database_config1.json create mode 100644 src/sonic-eventd/tests/redis_multi_db_ut_config/database_global.json diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index 6493a732312a..e6fb6505d4d0 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -25,7 +25,8 @@ endif -include rsyslog_plugin/subdir.mk -include rsyslog_plugin_tests/subdir.mk -all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests +# all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests +all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin sonic-eventd: $(OBJS) @echo 'Building target: $@' @@ -57,7 +58,7 @@ eventd-tests: $(TEST_OBJS) @echo 'Finished running tests' @echo ' ' -rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS) +xxrsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS) @echo 'BUILDING target: $@' @echo 'Invoking G++ Linker' $(CC) $(LDFLAGS) -o $(RSYSLOG-PLUGIN_TEST) $(RSYSLOG-PLUGIN-TEST_OBJS) $(LIBS) $(TEST_LIBS) diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 548de768381e..87936b11ed03 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -38,7 +38,6 @@ class SwsscommonEnvironment : public ::testing::Environment { cout<<"INIT: load local db config file, isInit = "< Date: Wed, 10 Aug 2022 21:57:34 +0000 Subject: [PATCH 060/137] Adding redis env to test --- src/sonic-eventd/tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 87936b11ed03..0472d4c92f5f 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -7,7 +7,7 @@ using namespace swss; string existing_file = "./tests/redis_multi_db_ut_config/database_config.json"; string nonexisting_file = "./tests/redis_multi_db_ut_config/database_config_nonexisting.json"; -// string global_existing_file = "./tests/redis_multi_db_ut_config/database_global.json"; +string global_existing_file = "./tests/redis_multi_db_ut_config/database_global.json"; #define TEST_DB "APPL_DB" #define TEST_NAMESPACE "asic0" From 4e5758df662e02a435b1f365cd51c5f4e62f426d Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 22:55:28 +0000 Subject: [PATCH 061/137] Adding redis env to test --- src/sonic-eventd/tests/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 0472d4c92f5f..8dd0ccaeb617 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -69,6 +69,14 @@ class SwsscommonEnvironment : public ::testing::Environment { { EXPECT_TRUE(strstr(e.what(), "Namespace invalid is not a valid namespace name in config file")); } + try + { + DBConnector db("TEST_DB", 0, true); + } + catch (exception &e) + { + EXPECT_TRUE(strstr(e.what(), "Unable to get DB Connector")); + } } }; From a5f8c2dc4c59e50f5a365d461c9ee8153a0600a2 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 10 Aug 2022 22:58:43 +0000 Subject: [PATCH 062/137] Adding redis env to test --- src/sonic-eventd/tests/eventd_ut.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index ff90739badd6..b0539602ca88 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -597,9 +597,16 @@ TEST(eventd, service) set_unit_testing(true); thread thread_service(&run_eventd_service); - printf("Calling DBConnector\n"); - DBConnector db("TEST_DB", 0, true); - printf("Created DBConnector\n"); + try + { + printf("Calling DBConnector\n"); + DBConnector db("TEST_DB", 0, true); + printf("Created DBConnector\n"); + } + catch (exception &e) + { + EXPECT_TRUE(strstr(e.what(), "eventd_ut: Unable to get DB Connector")); + } /* Need client side service to interact with server side */ EXPECT_EQ(0, service.init_client(zctx)); @@ -691,7 +698,7 @@ TEST(eventd, service) event_receive_op_t op; /* Have a 3 second timeout for receive */ - event_handle_t subs_handle = events_init_subscriber(false, 3 * 1000); + event_handle_t subs_handle = events_init_subscriber(false, 5 * 1000); EXPECT_TRUE(subs_handle != NULL); int rc = event_receive(subs_handle, op); From e084c5bca4164a5fd50d17d459a1e7528c42aee4 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:05:44 +0000 Subject: [PATCH 063/137] testing --- src/sonic-eventd/src/eventd.cpp | 5 ++++- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 1838af58d5b5..7640d6d56272 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -169,6 +169,8 @@ void stats_collector::run_collector() { int hb_cntr = 0; + string hb_key = string(EVENTD_PUBLISHER_SOURCE) + ":" + EVENTD_HEARTBEAT_TAG; + /* * Though we can count off of capture socket, then we need to duplicate * code in event_receive which has the logic to count all missed per @@ -199,7 +201,7 @@ stats_collector::run_collector() ss.str().c_str()); } - if (rc == 0) { + if ((rc == 0) && (op.key != hb_key)) { increment_published(1+op.missed_cnt); /* reset counter on receive to restart. */ @@ -216,6 +218,7 @@ stats_collector::run_collector() if (rc != 0) { SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); } + SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; } } diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index b0539602ca88..3a5df89ac89f 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -220,12 +220,12 @@ void run_pub(void *mock_pub, const string wr_source, internal_events_lst_t &lst) void debug_on() { /* compile with -D DEBUG_TEST or add "#define DEBUG_TEST" to include. */ -#ifdef DEBUG_TEST +// #ifdef DEBUG_TEST /* Direct log messages to stdout */ string dummy, op("STDOUT"); swss::Logger::swssOutputNotify(dummy, op); swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG); -#endif +// #endif } TEST(eventd, proxy) From 240258730711ef020dfd0258577a22fbe4dcc142 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:10:19 +0000 Subject: [PATCH 064/137] testing --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 3a5df89ac89f..297b2a856ba2 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -605,7 +605,7 @@ TEST(eventd, service) } catch (exception &e) { - EXPECT_TRUE(strstr(e.what(), "eventd_ut: Unable to get DB Connector")); + printf("e=(%s) eventd_ut: Unable to get DB Connector", strstr(e.what())); } /* Need client side service to interact with server side */ From 0e5be2ee12c428fb45e762f03b2c50b33f003e0b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:13:45 +0000 Subject: [PATCH 065/137] testing --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 297b2a856ba2..632fe6118e67 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -605,7 +605,7 @@ TEST(eventd, service) } catch (exception &e) { - printf("e=(%s) eventd_ut: Unable to get DB Connector", strstr(e.what())); + printf("e=(%s) eventd_ut: Unable to get DB Connector", e.what()); } /* Need client side service to interact with server side */ From aaccf2579975df28b6f1f325fac4e3b5b9e1eb70 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:17:41 +0000 Subject: [PATCH 066/137] testing --- src/sonic-eventd/tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 8dd0ccaeb617..86a08c335b8f 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -75,7 +75,7 @@ class SwsscommonEnvironment : public ::testing::Environment { } catch (exception &e) { - EXPECT_TRUE(strstr(e.what(), "Unable to get DB Connector")); + printf("Unable to get DB Connector, e=(%s)\n", e.what()); } } From c7d5dc758e7f41d69e59e5d137ab89211bb83b18 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:25:55 +0000 Subject: [PATCH 067/137] testing --- src/sonic-eventd/src/eventd.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 7640d6d56272..9989d5de69a8 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -185,6 +185,7 @@ stats_collector::run_collector() * The write of these counters into redis is done by another thread. */ + printf("DROP: heartbeat: stats_collector started\n"); while(!m_shutdown) { event_receive_op_t op; int rc = 0; @@ -200,6 +201,7 @@ stats_collector::run_collector() SWSS_LOG_ERROR("Cache save event failed with %s", ss.str().c_str()); } + printf("DROP: heartbeat: event_receive rc=%d\n", rc); if ((rc == 0) && (op.key != hb_key)) { increment_published(1+op.missed_cnt); @@ -221,9 +223,14 @@ stats_collector::run_collector() SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; } + else { + printf("DROP: heartbeat: hb_cntr=%d m_pause_heartbeat=%d\n", + hb_cntr, m_pause_heartbeat); + } } } + printf("DROP: heartbeat: stats_collector stopped\n"); /* * NOTE: A shutdown could lose messages in cache. * But consider, that eventd shutdown is a critical shutdown as it would From b6c43b883235792e31e979677c08ccbe1dc9b00c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:40:04 +0000 Subject: [PATCH 068/137] testing --- src/sonic-eventd/src/eventd.cpp | 10 ++++++---- src/sonic-eventd/tests/eventd_ut.cpp | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 9989d5de69a8..fc4b4dc3777c 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -185,7 +185,7 @@ stats_collector::run_collector() * The write of these counters into redis is done by another thread. */ - printf("DROP: heartbeat: stats_collector started\n"); + printf("DROP: heartbeat: stats_collector started HEARBEAT_CNT=%d\n", HEARBEAT_CNT); while(!m_shutdown) { event_receive_op_t op; int rc = 0; @@ -201,7 +201,7 @@ stats_collector::run_collector() SWSS_LOG_ERROR("Cache save event failed with %s", ss.str().c_str()); } - printf("DROP: heartbeat: event_receive rc=%d\n", rc); + printf("DROP: heartbeat: event_receive rc=%d key=%s\n", rc, op.key.c_str()); if ((rc == 0) && (op.key != hb_key)) { increment_published(1+op.missed_cnt); @@ -224,8 +224,10 @@ stats_collector::run_collector() hb_cntr = 0; } else { - printf("DROP: heartbeat: hb_cntr=%d m_pause_heartbeat=%d\n", - hb_cntr, m_pause_heartbeat); + stringstream ss; + ss << duration_cast(system_clock::now().time_since_epoch()).count(); + printf("DROP: heartbeat: tnow=%s hb_cntr=%d m_pause_heartbeat=%d\n", + ss.str().c_str(), hb_cntr, m_pause_heartbeat); } } } diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 632fe6118e67..94d5284213ad 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -698,10 +698,23 @@ TEST(eventd, service) event_receive_op_t op; /* Have a 3 second timeout for receive */ - event_handle_t subs_handle = events_init_subscriber(false, 5 * 1000); + event_handle_t subs_handle = events_init_subscriber(false, 5000); EXPECT_TRUE(subs_handle != NULL); + auto st = duration_cast(system_clock::now().time_since_epoch()).count(); + { + stringstream ss; + ss << st; + printf("start heartbeat receive: tstart:%s\n", ss.str().c_st()); + } int rc = event_receive(subs_handle, op); + auto en = duration_cast(system_clock::now().time_since_epoch()).count(); + { + stringstream ss; + ss << en << "diff: " << (en -st); + printf("start heartbeat receive: tstart:%s\n", ss.str().c_st()); + } + EXPECT_EQ(rc, 0); EXPECT_EQ(op.key, "sonic-events-eventd:heartbeat"); From cd009cb3da1a56d1a2300d8ebacf874520bc11a5 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:41:28 +0000 Subject: [PATCH 069/137] testing --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 94d5284213ad..7a2cad707513 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -705,14 +705,14 @@ TEST(eventd, service) { stringstream ss; ss << st; - printf("start heartbeat receive: tstart:%s\n", ss.str().c_st()); + printf("start heartbeat receive: tstart:%s\n", ss.str().c_str()); } int rc = event_receive(subs_handle, op); auto en = duration_cast(system_clock::now().time_since_epoch()).count(); { stringstream ss; ss << en << "diff: " << (en -st); - printf("start heartbeat receive: tstart:%s\n", ss.str().c_st()); + printf("start heartbeat receive: tstart:%s\n", ss.str().c_str()); } EXPECT_EQ(rc, 0); From 64d91bbbdcdd5e28e73fa485dd3ab57aac1724af Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 00:46:15 +0000 Subject: [PATCH 070/137] testing --- src/sonic-eventd/src/eventd.cpp | 2 +- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index fc4b4dc3777c..111739fbfb06 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -36,7 +36,7 @@ using namespace swss; #define VEC_SIZE(p) ((int)p.size()) /* Sock read timeout in milliseconds, to enable look for control signals */ -#define CAPTURE_SOCK_TIMEOUT 300 +#define CAPTURE_SOCK_TIMEOUT 500 #define STATS_COLLECTOR_TIMEOUT 300 /* diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 7a2cad707513..e2380dcaeccb 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -711,8 +711,8 @@ TEST(eventd, service) auto en = duration_cast(system_clock::now().time_since_epoch()).count(); { stringstream ss; - ss << en << "diff: " << (en -st); - printf("start heartbeat receive: tstart:%s\n", ss.str().c_str()); + ss << en << " diff: " << (en -st); + printf("start heartbeat receive: tend :%s\n", ss.str().c_str()); } EXPECT_EQ(rc, 0); From fbf0828e3531b985d1ae095514f99f43b218dd3c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 02:05:52 +0000 Subject: [PATCH 071/137] testing --- src/sonic-eventd/src/eventd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 111739fbfb06..54c86e3c192e 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -36,8 +36,8 @@ using namespace swss; #define VEC_SIZE(p) ((int)p.size()) /* Sock read timeout in milliseconds, to enable look for control signals */ -#define CAPTURE_SOCK_TIMEOUT 500 -#define STATS_COLLECTOR_TIMEOUT 300 +#define CAPTURE_SOCK_TIMEOUT 800 +#define STATS_COLLECTOR_TIMEOUT 500 /* * Sets heartbeat interval little less than expected 2 secs, to ensure From 605ca5cd37a3efb3b27b9c17b9a72ec65e5ac9b9 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 02:08:18 +0000 Subject: [PATCH 072/137] testing --- src/sonic-eventd/src/eventd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 54c86e3c192e..f0fdf84abed6 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -189,6 +189,7 @@ stats_collector::run_collector() while(!m_shutdown) { event_receive_op_t op; int rc = 0; + auto ts = duration_cast(system_clock::now().time_since_epoch()).count(); try { rc = event_receive(m_subs_handle, op); @@ -225,9 +226,11 @@ stats_collector::run_collector() } else { stringstream ss; - ss << duration_cast(system_clock::now().time_since_epoch()).count(); + auto tn = duration_cast(system_clock::now().time_since_epoch()).count(); + ss << tn << " diff: " << (tn -ts); printf("DROP: heartbeat: tnow=%s hb_cntr=%d m_pause_heartbeat=%d\n", ss.str().c_str(), hb_cntr, m_pause_heartbeat); + ts = tn; } } } From 990d42975a0f2673f2526c2fbac777a73a28573a Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 02:13:32 +0000 Subject: [PATCH 073/137] testing --- src/sonic-eventd/src/eventd.cpp | 1 + src/sonic-eventd/tests/eventd_ut.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index f0fdf84abed6..f8f44db83256 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -118,6 +118,7 @@ stats_collector::start() m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); + printf("m_subs_handle=%p\n", m_subs_handle); if (!s_unit_testing) { m_counters_db = make_shared("COUNTERS_DB", 0); diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index e2380dcaeccb..c7d14b0c9335 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -700,6 +700,8 @@ TEST(eventd, service) /* Have a 3 second timeout for receive */ event_handle_t subs_handle = events_init_subscriber(false, 5000); EXPECT_TRUE(subs_handle != NULL); + printf("UT: subs_handle=%p\n", subs_handle); + auto st = duration_cast(system_clock::now().time_since_epoch()).count(); { From e6e766f65690d9631f42287fad1f0887ee4d0335 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 14:48:35 +0000 Subject: [PATCH 074/137] static link --- src/sonic-eventd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index e6fb6505d4d0..6db2c032fdc4 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -52,7 +52,7 @@ rsyslog-plugin: $(RSYSLOG-PLUGIN_OBJS) eventd-tests: $(TEST_OBJS) @echo 'Building target: $@' @echo 'Invoking: G++ Linker' - $(CC) $(LDFLAGS) -o $(EVENTD_TEST) $(TEST_OBJS) $(LIBS) $(TEST_LIBS) + $(CC) $(LDFLAGS) -o $(EVENTD_TEST) $(TEST_OBJS) $(LIBS) $(TEST_LIBS) -static @echo 'Finished building target: $@' $(EVENTD_TEST) @echo 'Finished running tests' From 4aa4ba1563b23bd1554d8e2c5925bdfe23b7c7f1 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 15:16:11 +0000 Subject: [PATCH 075/137] revert static --- src/sonic-eventd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index 6db2c032fdc4..e6fb6505d4d0 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -52,7 +52,7 @@ rsyslog-plugin: $(RSYSLOG-PLUGIN_OBJS) eventd-tests: $(TEST_OBJS) @echo 'Building target: $@' @echo 'Invoking: G++ Linker' - $(CC) $(LDFLAGS) -o $(EVENTD_TEST) $(TEST_OBJS) $(LIBS) $(TEST_LIBS) -static + $(CC) $(LDFLAGS) -o $(EVENTD_TEST) $(TEST_OBJS) $(LIBS) $(TEST_LIBS) @echo 'Finished building target: $@' $(EVENTD_TEST) @echo 'Finished running tests' From 399745147662ee2c0481dfc0528e6ae38e1ab951 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 16:16:46 +0000 Subject: [PATCH 076/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 37 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index c7d14b0c9335..887d3ef7b833 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -704,26 +704,35 @@ TEST(eventd, service) auto st = duration_cast(system_clock::now().time_since_epoch()).count(); + while (true) { - stringstream ss; - ss << st; - printf("start heartbeat receive: tstart:%s\n", ss.str().c_str()); - } - int rc = event_receive(subs_handle, op); - auto en = duration_cast(system_clock::now().time_since_epoch()).count(); - { - stringstream ss; - ss << en << " diff: " << (en -st); - printf("start heartbeat receive: tend :%s\n", ss.str().c_str()); + int rc = event_receive(subs_handle, op); + if (rc == 0) { + break; + } + auto en = duration_cast(system_clock::now().time_since_epoch()).count(); + if ((en -st) > 3000) { + EXPECT_LE((en -st), 3000); + break; + } + else { + stringstream ss; + ss << (en -st); + printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str()); + } } EXPECT_EQ(rc, 0); - EXPECT_EQ(op.key, "sonic-events-eventd:heartbeat"); - - EXPECT_EQ(1, (int) op.params.size()); + if (rc == 0) { + EXPECT_EQ(op.key, "sonic-events-eventd:heartbeat"); + + EXPECT_EQ(1, (int) op.params.size()); - EXPECT_EQ(op.params.begin()->first, "timestamp"); + if (!op.params.empty()) { + EXPECT_EQ(op.params.begin()->first, "timestamp"); + } + } /* The content of timestamp is validated by swsscommon */ From 0c6ff11b6e2270387062c0323dda2b41631342b3 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 16:20:05 +0000 Subject: [PATCH 077/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 887d3ef7b833..cbf8fef4dea4 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -696,6 +696,7 @@ TEST(eventd, service) { // Test heartbeat event_receive_op_t op; + int rc = -1; /* Have a 3 second timeout for receive */ event_handle_t subs_handle = events_init_subscriber(false, 5000); @@ -706,7 +707,7 @@ TEST(eventd, service) auto st = duration_cast(system_clock::now().time_since_epoch()).count(); while (true) { - int rc = event_receive(subs_handle, op); + rc = event_receive(subs_handle, op); if (rc == 0) { break; } From a5287f58ff00dd621026be221fb7c8f96d351023 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 17:00:13 +0000 Subject: [PATCH 078/137] test fix --- src/sonic-eventd/src/eventd.cpp | 3 +- src/sonic-eventd/src/eventd.h | 9 ++- src/sonic-eventd/tests/eventd_ut.cpp | 107 +++++++++++++++------------ 3 files changed, 68 insertions(+), 51 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index f8f44db83256..fdc91d5d946c 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -37,7 +37,7 @@ using namespace swss; /* Sock read timeout in milliseconds, to enable look for control signals */ #define CAPTURE_SOCK_TIMEOUT 800 -#define STATS_COLLECTOR_TIMEOUT 500 +#define STATS_COLLECTOR_TIMEOUT 300 /* * Sets heartbeat interval little less than expected 2 secs, to ensure @@ -224,6 +224,7 @@ stats_collector::run_collector() } SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; + ++m_heartbeats_cnt; } else { stringstream ss; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 702df25dcb5a..3b1da2411609 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -59,7 +59,8 @@ class stats_collector public: stats_collector() : m_shutdown(false), m_subs_handle(NULL), m_pub_handle(NULL), - m_pause_heartbeat(false) + m_pause_heartbeat(false), + m_heartbeats_cnt(0) { for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { m_lst_counters[i] = 0; @@ -103,6 +104,10 @@ class stats_collector SWSS_LOG_INFO("Set heartbeat_ctrl pause=%d", pause); } + uint64_t heartbeats_cnt() const { + return m_heartbeats_cnt; + } + private: void _update_stats(int index, counters_t val) { m_lst_counters[index] += val; @@ -130,6 +135,8 @@ class stats_collector event_handle_t m_pub_handle; bool m_pause_heartbeat; + + uint64_t m_heartbeats_cnt; }; /* diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index cbf8fef4dea4..1c1a63b4d6da 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -693,66 +693,75 @@ TEST(eventd, service) } } - { - // Test heartbeat - event_receive_op_t op; - int rc = -1; - - /* Have a 3 second timeout for receive */ - event_handle_t subs_handle = events_init_subscriber(false, 5000); - EXPECT_TRUE(subs_handle != NULL); - printf("UT: subs_handle=%p\n", subs_handle); - - - auto st = duration_cast(system_clock::now().time_since_epoch()).count(); - while (true) - { - rc = event_receive(subs_handle, op); - if (rc == 0) { - break; - } - auto en = duration_cast(system_clock::now().time_since_epoch()).count(); - if ((en -st) > 3000) { - EXPECT_LE((en -st), 3000); - break; - } - else { - stringstream ss; - ss << (en -st); - printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str()); - } - } - - EXPECT_EQ(rc, 0); + EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); - if (rc == 0) { - EXPECT_EQ(op.key, "sonic-events-eventd:heartbeat"); - - EXPECT_EQ(1, (int) op.params.size()); + service.close_service(); - if (!op.params.empty()) { - EXPECT_EQ(op.params.begin()->first, "timestamp"); - } - } + thread_service.join(); - /* The content of timestamp is validated by swsscommon */ + zmq_ctx_term(zctx); + printf("Service TEST completed\n"); +} - events_deinit_subscriber(subs_handle); - } +TEST(eventd, heartbeat) +{ + printf("heartbeat TEST started\n"); - { - // Test stats + int rc, cnt; + stats_collector stats_instance; + + debug_on(); + + rc = stats_instance.start(); + EXPECT_EQ(rc, 0); + + auto st = duration_cast(system_clock::now().time_since_epoch()).count(); + while (stats_instance.heartbeats_cnt() != 0) { + auto en = duration_cast(system_clock::now().time_since_epoch()).count(); + if ((en -st) > 3000) { + EXPECT_LE((en -st), 3000); + break; + } + else { + stringstream ss; + ss << (en -st); + printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str()); + } } - EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); + stats_instance.heartbeat_ctrl(true); + + /* Sleep to ensure the other thread noticed the update. */ + this_thread::sleep_for(chrono::milliseconds(200)); - service.close_service(); + /* Get current count */ + cnt = stats_instance.heartbeats_cnt(); - thread_service.join(); + /* Wait for 3 seconds with no new neartbeat */ + this_thread::sleep_for(chrono::seconds(3)); - zmq_ctx_term(zctx); - printf("Service TEST completed\n"); + EXPECT_EQ(stats_instance.heartbeats_cnt(), cnt); + + /* Turn on heartbeat + stats_instance.heartbeat_ctrl(true); + + st = duration_cast(system_clock::now().time_since_epoch()).count(); + /* Wait for a heartbeat */ + while (stats_instance.heartbeats_cnt() == cnt) { + auto en = duration_cast(system_clock::now().time_since_epoch()).count(); + if ((en -st) > 3000) { + EXPECT_LE((en -st), 3000); + break; + } + else { + stringstream ss; + ss << (en -st); + printf("DROP:Waiting for NO heartbeat for 3secs. duration:%s ms", ss.str().c_str()); + } + } + stats_instance.stop(); + printf("heartbeat TEST completed\n"); } From 6c1c90f23d7aa53a282d088035973b2c3f57f682 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 17:07:36 +0000 Subject: [PATCH 079/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 1c1a63b4d6da..13f8e9104696 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -744,8 +744,8 @@ TEST(eventd, heartbeat) EXPECT_EQ(stats_instance.heartbeats_cnt(), cnt); /* Turn on heartbeat - stats_instance.heartbeat_ctrl(true); - + stats_instance.heartbeat_ctrl(); + st = duration_cast(system_clock::now().time_since_epoch()).count(); /* Wait for a heartbeat */ while (stats_instance.heartbeats_cnt() == cnt) { From d16cc76a92b2ded83106d809d34e49836d45a73e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 17:34:15 +0000 Subject: [PATCH 080/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 53 +++++++++++++--------------- src/sonic-eventd/tests/main.cpp | 4 ++- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 13f8e9104696..db7543f552b5 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -703,24 +703,15 @@ TEST(eventd, service) printf("Service TEST completed\n"); } - -TEST(eventd, heartbeat) +void +wait_for_heartbeat(stats_collector &stats_instance, int cnt) { - printf("heartbeat TEST started\n"); - - int rc, cnt; - stats_collector stats_instance; - - debug_on(); - - rc = stats_instance.start(); - EXPECT_EQ(rc, 0); - auto st = duration_cast(system_clock::now().time_since_epoch()).count(); - while (stats_instance.heartbeats_cnt() != 0) { + while (stats_instance.heartbeats_cnt() != cnt) { auto en = duration_cast(system_clock::now().time_since_epoch()).count(); if ((en -st) > 3000) { EXPECT_LE((en -st), 3000); + EXPECT_EQ(cnt, stats_instance.heartbeats_cnt()); break; } else { @@ -729,10 +720,27 @@ TEST(eventd, heartbeat) printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str()); } } +} +TEST(eventd, heartbeat) +{ + printf("heartbeat TEST started\n"); + + int rc, cnt; + stats_collector stats_instance; + + debug_on(); + + rc = stats_instance.start(); + EXPECT_EQ(rc, 0); + + /* Wait for any non-zero heartbeat */ + wait_for_heartbeat(stats_instance, 0); + + /* Pause heartbeat */ stats_instance.heartbeat_ctrl(true); - /* Sleep to ensure the other thread noticed the update. */ + /* Sleep to ensure the other thread noticed the pause request. */ this_thread::sleep_for(chrono::milliseconds(200)); /* Get current count */ @@ -746,20 +754,9 @@ TEST(eventd, heartbeat) /* Turn on heartbeat stats_instance.heartbeat_ctrl(); - st = duration_cast(system_clock::now().time_since_epoch()).count(); - /* Wait for a heartbeat */ - while (stats_instance.heartbeats_cnt() == cnt) { - auto en = duration_cast(system_clock::now().time_since_epoch()).count(); - if ((en -st) > 3000) { - EXPECT_LE((en -st), 3000); - break; - } - else { - stringstream ss; - ss << (en -st); - printf("DROP:Waiting for NO heartbeat for 3secs. duration:%s ms", ss.str().c_str()); - } - } + /* Wait for heartbeat count to change from last count */ + wait_for_heartbeat(stats_instance, cnt); + stats_instance.stop(); printf("heartbeat TEST completed\n"); } diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 86a08c335b8f..0095f819d869 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -13,6 +13,8 @@ string global_existing_file = "./tests/redis_multi_db_ut_config/database_global. #define TEST_NAMESPACE "asic0" #define INVALID_NAMESPACE "invalid" +SwsscommonEnvironment* const env = NULL; + class SwsscommonEnvironment : public ::testing::Environment { public: // Override this to define how to set up the environment. @@ -86,7 +88,7 @@ int main(int argc, char* argv[]) testing::InitGoogleTest(&argc, argv); // Registers a global test environment, and verifies that the // registration function returns its argument. - SwsscommonEnvironment* const env = new SwsscommonEnvironment; + env = new SwsscommonEnvironment; testing::AddGlobalTestEnvironment(env); return RUN_ALL_TESTS(); } From 764b70972cc28fec66cbffcad821b42b18805d23 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 17:39:53 +0000 Subject: [PATCH 081/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 5 +++-- src/sonic-eventd/tests/main.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index db7543f552b5..1c908cae72cb 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -704,7 +704,7 @@ TEST(eventd, service) } void -wait_for_heartbeat(stats_collector &stats_instance, int cnt) +wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) { auto st = duration_cast(system_clock::now().time_since_epoch()).count(); while (stats_instance.heartbeats_cnt() != cnt) { @@ -726,7 +726,8 @@ TEST(eventd, heartbeat) { printf("heartbeat TEST started\n"); - int rc, cnt; + int rc; + long unsigned int cnt; stats_collector stats_instance; debug_on(); diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 0095f819d869..0e2e174b6af4 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -13,8 +13,6 @@ string global_existing_file = "./tests/redis_multi_db_ut_config/database_global. #define TEST_NAMESPACE "asic0" #define INVALID_NAMESPACE "invalid" -SwsscommonEnvironment* const env = NULL; - class SwsscommonEnvironment : public ::testing::Environment { public: // Override this to define how to set up the environment. @@ -83,6 +81,8 @@ class SwsscommonEnvironment : public ::testing::Environment { } }; +SwsscommonEnvironment* const env = NULL; + int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); From a6263d3868066f23b77f7ea719d0b10832884c51 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 17:41:36 +0000 Subject: [PATCH 082/137] test fix --- src/sonic-eventd/tests/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 0e2e174b6af4..076b9878d628 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -81,7 +81,7 @@ class SwsscommonEnvironment : public ::testing::Environment { } }; -SwsscommonEnvironment* const env = NULL; +SwsscommonEnvironment* env = NULL; int main(int argc, char* argv[]) { From 59b64c786747da04512a7de8397791a022a830f0 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 17:58:38 +0000 Subject: [PATCH 083/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 22 ++++++++++++++++++++-- src/sonic-eventd/tests/main.cpp | 23 +++++++++++++++++++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 1c908cae72cb..0db2ec97ee5f 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -13,6 +13,8 @@ using namespace std; using namespace swss; +extern SwsscommonEnvironment* swss_env; + typedef struct { int id; string source; @@ -594,7 +596,14 @@ TEST(eventd, service) * It starts to capture too. */ - set_unit_testing(true); + if (!swss_env->is_redis_available()) { + set_unit_testing(true); + printf("DROP: redis not available\n"); + } + else { + printf("DROP: redis NOT available\n"); + } + thread thread_service(&run_eventd_service); try @@ -707,7 +716,7 @@ void wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) { auto st = duration_cast(system_clock::now().time_since_epoch()).count(); - while (stats_instance.heartbeats_cnt() != cnt) { + while (stats_instance.heartbeats_cnt() == cnt) { auto en = duration_cast(system_clock::now().time_since_epoch()).count(); if ((en -st) > 3000) { EXPECT_LE((en -st), 3000); @@ -732,6 +741,15 @@ TEST(eventd, heartbeat) debug_on(); + if (!swss_env->is_redis_available()) { + set_unit_testing(true); + printf("DROP: redis not available\n"); + } + else { + printf("DROP: redis NOT available\n"); + } + + rc = stats_instance.start(); EXPECT_EQ(rc, 0); diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 076b9878d628..991077ac1c60 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -69,26 +69,41 @@ class SwsscommonEnvironment : public ::testing::Environment { { EXPECT_TRUE(strstr(e.what(), "Namespace invalid is not a valid namespace name in config file")); } + + // Get this info handy + is_redis_available(); + } + + bool is_redis_available() const + { + static bool ret = test_redis(); + return ret; + } + +private: + bool test_redis() const + { try { DBConnector db("TEST_DB", 0, true); + return true; } catch (exception &e) { printf("Unable to get DB Connector, e=(%s)\n", e.what()); + return false; } - } }; -SwsscommonEnvironment* env = NULL; +SwsscommonEnvironment* swss_env = NULL; int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); // Registers a global test environment, and verifies that the // registration function returns its argument. - env = new SwsscommonEnvironment; - testing::AddGlobalTestEnvironment(env); + swss_env = new SwsscommonEnvironment; + testing::AddGlobalTestEnvironment(swss_env); return RUN_ALL_TESTS(); } From 3d1da3957caeb7b9e7ccf80a48bb455f26348b03 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 18:05:48 +0000 Subject: [PATCH 084/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 0db2ec97ee5f..5fc4014ef4e5 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -601,7 +601,7 @@ TEST(eventd, service) printf("DROP: redis not available\n"); } else { - printf("DROP: redis NOT available\n"); + printf("DROP: redis available\n"); } thread thread_service(&run_eventd_service); @@ -743,10 +743,10 @@ TEST(eventd, heartbeat) if (!swss_env->is_redis_available()) { set_unit_testing(true); - printf("DROP: redis not available\n"); + printf("DROP: redis NOT available\n"); } else { - printf("DROP: redis NOT available\n"); + printf("DROP: redis available\n"); } From 70b7aa33ffba2ca26f5003e7f03f9c78ca864915 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 18:15:14 +0000 Subject: [PATCH 085/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 6 +++--- src/sonic-eventd/tests/main.cpp | 22 +++++----------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 5fc4014ef4e5..bb457e06b815 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -13,7 +13,7 @@ using namespace std; using namespace swss; -extern SwsscommonEnvironment* swss_env; +extern bool g_is_redis_available; typedef struct { int id; @@ -596,7 +596,7 @@ TEST(eventd, service) * It starts to capture too. */ - if (!swss_env->is_redis_available()) { + if (!g_is_redis_available) { set_unit_testing(true); printf("DROP: redis not available\n"); } @@ -741,7 +741,7 @@ TEST(eventd, heartbeat) debug_on(); - if (!swss_env->is_redis_available()) { + if (!g_is_redis_available) { set_unit_testing(true); printf("DROP: redis NOT available\n"); } diff --git a/src/sonic-eventd/tests/main.cpp b/src/sonic-eventd/tests/main.cpp index 991077ac1c60..2858e13f8d67 100644 --- a/src/sonic-eventd/tests/main.cpp +++ b/src/sonic-eventd/tests/main.cpp @@ -13,6 +13,8 @@ string global_existing_file = "./tests/redis_multi_db_ut_config/database_global. #define TEST_NAMESPACE "asic0" #define INVALID_NAMESPACE "invalid" +bool g_is_redis_available = false; + class SwsscommonEnvironment : public ::testing::Environment { public: // Override this to define how to set up the environment. @@ -71,39 +73,25 @@ class SwsscommonEnvironment : public ::testing::Environment { } // Get this info handy - is_redis_available(); - } - - bool is_redis_available() const - { - static bool ret = test_redis(); - return ret; - } - -private: - bool test_redis() const - { try { DBConnector db("TEST_DB", 0, true); - return true; + g_is_redis_available = true; } catch (exception &e) { printf("Unable to get DB Connector, e=(%s)\n", e.what()); - return false; } } }; -SwsscommonEnvironment* swss_env = NULL; int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); // Registers a global test environment, and verifies that the // registration function returns its argument. - swss_env = new SwsscommonEnvironment; - testing::AddGlobalTestEnvironment(swss_env); + SwsscommonEnvironment* const env = new SwsscommonEnvironment; + testing::AddGlobalTestEnvironment(env); return RUN_ALL_TESTS(); } From 28857fb2a82d9d57ef801a91a42df75ad66a6549 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 18:21:41 +0000 Subject: [PATCH 086/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index bb457e06b815..945cbf8fdd61 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -715,6 +715,8 @@ TEST(eventd, service) void wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) { + printf("wait_for_heartbeat START cnt=%d\n", (int)cnt); + auto st = duration_cast(system_clock::now().time_since_epoch()).count(); while (stats_instance.heartbeats_cnt() == cnt) { auto en = duration_cast(system_clock::now().time_since_epoch()).count(); @@ -728,7 +730,9 @@ wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) ss << (en -st); printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str()); } + this_thread::sleep_for(chrono::milliseconds(200)); } + printf("wait_for_heartbeat DONE cnt=%d\n", (int)cnt); } TEST(eventd, heartbeat) From 9f762aca259c4459ccea45763ffe75e1aa7c9bb8 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 18:22:50 +0000 Subject: [PATCH 087/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 945cbf8fdd61..5400f71e17e2 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -728,9 +728,9 @@ wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) else { stringstream ss; ss << (en -st); - printf("DROP:Waiting for heartbeat. duration:%s ms", ss.str().c_str()); + printf("DROP:Waiting for heartbeat. duration:%s ms\n", ss.str().c_str()); } - this_thread::sleep_for(chrono::milliseconds(200)); + this_thread::sleep_for(chrono::milliseconds(300)); } printf("wait_for_heartbeat DONE cnt=%d\n", (int)cnt); } From 5c478bf8e248fc5c1cc111a14e76922d09613e1b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 18:30:20 +0000 Subject: [PATCH 088/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 5400f71e17e2..9b090bc9909b 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -732,7 +732,8 @@ wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) } this_thread::sleep_for(chrono::milliseconds(300)); } - printf("wait_for_heartbeat DONE cnt=%d\n", (int)cnt); + printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", + (int)cnt, (int)stats_instance.heartbeats_cnt()); } TEST(eventd, heartbeat) @@ -774,7 +775,7 @@ TEST(eventd, heartbeat) EXPECT_EQ(stats_instance.heartbeats_cnt(), cnt); - /* Turn on heartbeat + /* Turn on heartbeat */ stats_instance.heartbeat_ctrl(); /* Wait for heartbeat count to change from last count */ From b6e7cda30c86c2edd4da17ab19ea1cd9114660e5 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 19:58:14 +0000 Subject: [PATCH 089/137] test fix --- src/sonic-eventd/src/eventd.cpp | 32 ++++++++++++++++++-------------- src/sonic-eventd/src/eventd.h | 9 --------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index fdc91d5d946c..3049fdaf6f07 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -108,18 +108,6 @@ stats_collector::start() { int rc = -1; - /* - * A subscriber is required to set a subscription. Else all published - * events will be dropped at the point of publishing itself. - */ - m_pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); - RET_ON_ERR(m_pub_handle != NULL, - "failed to create publisher handle for heartbeats"); - - m_subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); - RET_ON_ERR(m_subs_handle != NULL, "failed to subscribe to all"); - printf("m_subs_handle=%p\n", m_subs_handle); - if (!s_unit_testing) { m_counters_db = make_shared("COUNTERS_DB", 0); RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); @@ -171,6 +159,19 @@ stats_collector::run_collector() { int hb_cntr = 0; string hb_key = string(EVENTD_PUBLISHER_SOURCE) + ":" + EVENTD_HEARTBEAT_TAG; + event_handle_t pub_handle = NULL; + event_handle_t subs_handle = NULL; + + /* + * A subscriber is required to set a subscription. Else all published + * events will be dropped at the point of publishing itself. + */ + pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); + RET_ON_ERR(pub_handle != NULL, + "failed to create publisher handle for heartbeats"); + + subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); + RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); /* * Though we can count off of capture socket, then we need to duplicate @@ -193,7 +194,7 @@ stats_collector::run_collector() auto ts = duration_cast(system_clock::now().time_since_epoch()).count(); try { - rc = event_receive(m_subs_handle, op); + rc = event_receive(subs_handle, op); } catch (exception& e) { @@ -218,7 +219,7 @@ stats_collector::run_collector() m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } if (!m_pause_heartbeat && ++hb_cntr >= HEARBEAT_CNT) { - rc = event_publish(m_pub_handle, EVENTD_HEARTBEAT_TAG); + rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); if (rc != 0) { SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); } @@ -245,6 +246,9 @@ stats_collector::run_collector() * hence losing few messages in flight is acceptable. Any more complex code * to handle is unwanted. */ + + events_deinit_subscriber(subs_handle); + events_deinit_publisher(pub_handle); return; } diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 3b1da2411609..c616ef000856 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -58,7 +58,6 @@ class stats_collector { public: stats_collector() : m_shutdown(false), - m_subs_handle(NULL), m_pub_handle(NULL), m_pause_heartbeat(false), m_heartbeats_cnt(0) { @@ -83,11 +82,6 @@ class stats_collector if (m_thr_writer.joinable()) { m_thr_writer.join(); } - - events_deinit_subscriber(m_subs_handle); - events_deinit_publisher(m_pub_handle); - m_subs_handle = NULL; - m_pub_handle = NULL; } void increment_published(counters_t val) { @@ -131,9 +125,6 @@ class stats_collector shared_ptr m_counters_db; shared_ptr m_stats_table; - event_handle_t m_subs_handle; - event_handle_t m_pub_handle; - bool m_pause_heartbeat; uint64_t m_heartbeats_cnt; From abc54ee59d4f2efaf8ad9775e9265339e0494d24 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 20:35:48 +0000 Subject: [PATCH 090/137] test fix --- src/sonic-eventd/src/eventd.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 3049fdaf6f07..4681f3014499 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -567,7 +567,6 @@ run_eventd_service() stats_collector stats_instance; eventd_proxy *proxy = NULL; capture_service *capture = NULL; - thread thrCollector; event_serialized_lst_t capture_fifo_events; last_events_t capture_last_events; @@ -720,9 +719,6 @@ run_eventd_service() if (capture != NULL) { delete capture; } - if (thrCollector.joinable()) { - thrCollector.join(); - } if (zctx != NULL) { zmq_ctx_term(zctx); } From 4960cea5318ebd6ea188e6d5eff4115501693c5c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 20:54:43 +0000 Subject: [PATCH 091/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 9b090bc9909b..6ce1dea48845 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -754,6 +754,14 @@ TEST(eventd, heartbeat) printf("DROP: redis available\n"); } + void *zctx = zmq_ctx_new(); + EXPECT_TRUE(NULL != zctx); + + eventd_proxy *pxy = new eventd_proxy(zctx); + EXPECT_TRUE(NULL != pxy); + + /* Starting proxy */ + EXPECT_EQ(0, pxy->init()); rc = stats_instance.start(); EXPECT_EQ(rc, 0); @@ -782,6 +790,11 @@ TEST(eventd, heartbeat) wait_for_heartbeat(stats_instance, cnt); stats_instance.stop(); + + delete pxy; + + zmq_ctx_term(zctx); + printf("heartbeat TEST completed\n"); } From c91c944a338fd4b5f758b1cf989a7606b010beb5 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 20:57:37 +0000 Subject: [PATCH 092/137] test fix --- src/sonic-eventd/src/eventd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 4681f3014499..e9bf2095d67c 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -238,6 +238,7 @@ stats_collector::run_collector() } } +out: printf("DROP: heartbeat: stats_collector stopped\n"); /* * NOTE: A shutdown could lose messages in cache. From abc2de36e2b86f9d067045e229dc59f31d70461e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 21:16:09 +0000 Subject: [PATCH 093/137] test fix --- src/sonic-eventd/src/eventd.cpp | 10 ---------- src/sonic-eventd/tests/eventd_ut.cpp | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index e9bf2095d67c..e22191ffc4a9 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -191,7 +191,6 @@ stats_collector::run_collector() while(!m_shutdown) { event_receive_op_t op; int rc = 0; - auto ts = duration_cast(system_clock::now().time_since_epoch()).count(); try { rc = event_receive(subs_handle, op); @@ -204,7 +203,6 @@ stats_collector::run_collector() SWSS_LOG_ERROR("Cache save event failed with %s", ss.str().c_str()); } - printf("DROP: heartbeat: event_receive rc=%d key=%s\n", rc, op.key.c_str()); if ((rc == 0) && (op.key != hb_key)) { increment_published(1+op.missed_cnt); @@ -227,14 +225,6 @@ stats_collector::run_collector() hb_cntr = 0; ++m_heartbeats_cnt; } - else { - stringstream ss; - auto tn = duration_cast(system_clock::now().time_since_epoch()).count(); - ss << tn << " diff: " << (tn -ts); - printf("DROP: heartbeat: tnow=%s hb_cntr=%d m_pause_heartbeat=%d\n", - ss.str().c_str(), hb_cntr, m_pause_heartbeat); - ts = tn; - } } } diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 6ce1dea48845..17198c8b1f74 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -789,10 +789,13 @@ TEST(eventd, heartbeat) /* Wait for heartbeat count to change from last count */ wait_for_heartbeat(stats_instance, cnt); + printf("Stopping stats_instance\n"); stats_instance.stop(); + printf("Deleting proxy\n"); delete pxy; + printf("Terminating ctx\n"); zmq_ctx_term(zctx); printf("heartbeat TEST completed\n"); From 84c119737de47445e5f283c97c9bd877ff503293 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Thu, 11 Aug 2022 21:20:14 +0000 Subject: [PATCH 094/137] test fix --- src/sonic-eventd/tests/eventd_ut.cpp | 180 +++++++++++++-------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 17198c8b1f74..59296b3aa59d 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -570,6 +570,96 @@ TEST(eventd, captureCacheMax) } +void +wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) +{ + printf("wait_for_heartbeat START cnt=%d\n", (int)cnt); + + auto st = duration_cast(system_clock::now().time_since_epoch()).count(); + while (stats_instance.heartbeats_cnt() == cnt) { + auto en = duration_cast(system_clock::now().time_since_epoch()).count(); + if ((en -st) > 3000) { + EXPECT_LE((en -st), 3000); + EXPECT_EQ(cnt, stats_instance.heartbeats_cnt()); + break; + } + else { + stringstream ss; + ss << (en -st); + printf("DROP:Waiting for heartbeat. duration:%s ms\n", ss.str().c_str()); + } + this_thread::sleep_for(chrono::milliseconds(300)); + } + printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", + (int)cnt, (int)stats_instance.heartbeats_cnt()); +} + +TEST(eventd, heartbeat) +{ + printf("heartbeat TEST started\n"); + + int rc; + long unsigned int cnt; + stats_collector stats_instance; + + debug_on(); + + if (!g_is_redis_available) { + set_unit_testing(true); + printf("DROP: redis NOT available\n"); + } + else { + printf("DROP: redis available\n"); + } + + void *zctx = zmq_ctx_new(); + EXPECT_TRUE(NULL != zctx); + + eventd_proxy *pxy = new eventd_proxy(zctx); + EXPECT_TRUE(NULL != pxy); + + /* Starting proxy */ + EXPECT_EQ(0, pxy->init()); + + rc = stats_instance.start(); + EXPECT_EQ(rc, 0); + + /* Wait for any non-zero heartbeat */ + wait_for_heartbeat(stats_instance, 0); + + /* Pause heartbeat */ + stats_instance.heartbeat_ctrl(true); + + /* Sleep to ensure the other thread noticed the pause request. */ + this_thread::sleep_for(chrono::milliseconds(200)); + + /* Get current count */ + cnt = stats_instance.heartbeats_cnt(); + + /* Wait for 3 seconds with no new neartbeat */ + this_thread::sleep_for(chrono::seconds(3)); + + EXPECT_EQ(stats_instance.heartbeats_cnt(), cnt); + + /* Turn on heartbeat */ + stats_instance.heartbeat_ctrl(); + + /* Wait for heartbeat count to change from last count */ + wait_for_heartbeat(stats_instance, cnt); + + printf("Stopping stats_instance\n"); + stats_instance.stop(); + + printf("Deleting proxy\n"); + delete pxy; + + printf("Terminating ctx\n"); + zmq_ctx_term(zctx); + + printf("heartbeat TEST completed\n"); +} + + TEST(eventd, service) { /* @@ -712,94 +802,4 @@ TEST(eventd, service) printf("Service TEST completed\n"); } -void -wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) -{ - printf("wait_for_heartbeat START cnt=%d\n", (int)cnt); - - auto st = duration_cast(system_clock::now().time_since_epoch()).count(); - while (stats_instance.heartbeats_cnt() == cnt) { - auto en = duration_cast(system_clock::now().time_since_epoch()).count(); - if ((en -st) > 3000) { - EXPECT_LE((en -st), 3000); - EXPECT_EQ(cnt, stats_instance.heartbeats_cnt()); - break; - } - else { - stringstream ss; - ss << (en -st); - printf("DROP:Waiting for heartbeat. duration:%s ms\n", ss.str().c_str()); - } - this_thread::sleep_for(chrono::milliseconds(300)); - } - printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", - (int)cnt, (int)stats_instance.heartbeats_cnt()); -} - -TEST(eventd, heartbeat) -{ - printf("heartbeat TEST started\n"); - - int rc; - long unsigned int cnt; - stats_collector stats_instance; - - debug_on(); - - if (!g_is_redis_available) { - set_unit_testing(true); - printf("DROP: redis NOT available\n"); - } - else { - printf("DROP: redis available\n"); - } - - void *zctx = zmq_ctx_new(); - EXPECT_TRUE(NULL != zctx); - - eventd_proxy *pxy = new eventd_proxy(zctx); - EXPECT_TRUE(NULL != pxy); - - /* Starting proxy */ - EXPECT_EQ(0, pxy->init()); - - rc = stats_instance.start(); - EXPECT_EQ(rc, 0); - - /* Wait for any non-zero heartbeat */ - wait_for_heartbeat(stats_instance, 0); - - /* Pause heartbeat */ - stats_instance.heartbeat_ctrl(true); - - /* Sleep to ensure the other thread noticed the pause request. */ - this_thread::sleep_for(chrono::milliseconds(200)); - - /* Get current count */ - cnt = stats_instance.heartbeats_cnt(); - - /* Wait for 3 seconds with no new neartbeat */ - this_thread::sleep_for(chrono::seconds(3)); - - EXPECT_EQ(stats_instance.heartbeats_cnt(), cnt); - - /* Turn on heartbeat */ - stats_instance.heartbeat_ctrl(); - - /* Wait for heartbeat count to change from last count */ - wait_for_heartbeat(stats_instance, cnt); - - printf("Stopping stats_instance\n"); - stats_instance.stop(); - - printf("Deleting proxy\n"); - delete pxy; - - printf("Terminating ctx\n"); - zmq_ctx_term(zctx); - - printf("heartbeat TEST completed\n"); -} - - // TODO -- Add unit tests for stats From cb9a2d2a2d4d1a1916767468483ab421e76454cc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 15:13:09 +0000 Subject: [PATCH 095/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 36 +++-- src/sonic-eventd/src/eventd.h | 27 ++-- src/sonic-eventd/tests/eventd_ut.cpp | 193 ++++++++++++++------------- 3 files changed, 142 insertions(+), 114 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index e22191ffc4a9..31b841f2eabf 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -39,14 +39,6 @@ using namespace swss; #define CAPTURE_SOCK_TIMEOUT 800 #define STATS_COLLECTOR_TIMEOUT 300 -/* - * Sets heartbeat interval little less than expected 2 secs, to ensure - * an heartbeat is sent within 2 seconds. Sending one extra is fine, but - * not sending one within 2 seconds is not acceptable. - */ -#define HEARBEAT_INTERVAL 1900 -#define HEARBEAT_CNT ((HEARBEAT_INTERVAL) / (STATS_COLLECTOR_TIMEOUT)) - /* Source & tag for heartbeat events */ #define EVENTD_PUBLISHER_SOURCE "sonic-events-eventd" #define EVENTD_HEARTBEAT_TAG "heartbeat" @@ -103,6 +95,24 @@ eventd_proxy::run() } +stats_collector::stats_collector() : + m_shutdown(false), m_pause_heartbeat(false), m_heartbeats_published(0), + m_heartbeats_interval_cnt(HEARTBEAT_INTERVAL/STATS_COLLECTOR_TIMEOUT) +{ + for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { + m_lst_counters[i] = 0; + } + m_updated = false; +} + +void +stats_collector::set_heartbeat_interval(int val) +{ + if (val > 0) { + m_heartbeats_interval_cnt = (val / STATS_COLLECTOR_TIMEOUT); + } +} + int stats_collector::start() { @@ -187,7 +197,7 @@ stats_collector::run_collector() * The write of these counters into redis is done by another thread. */ - printf("DROP: heartbeat: stats_collector started HEARBEAT_CNT=%d\n", HEARBEAT_CNT); + printf("DROP: heartbeat: stats_collector started HEARTBEAT_CNT=%d\n", m_heartbeats_interval_cnt); while(!m_shutdown) { event_receive_op_t op; int rc = 0; @@ -216,14 +226,14 @@ stats_collector::run_collector() "event_receive failed with rc=%d; stats:published(%lu)", rc, m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } - if (!m_pause_heartbeat && ++hb_cntr >= HEARBEAT_CNT) { + if (!m_pause_heartbeat && ++hb_cntr >= m_heartbeats_interval_cnt) { rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); if (rc != 0) { SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); } SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; - ++m_heartbeats_cnt; + ++m_heartbeats_published; } } } @@ -240,6 +250,7 @@ stats_collector::run_collector() events_deinit_subscriber(subs_handle); events_deinit_publisher(pub_handle); + m_shutdown = true; return; } @@ -591,6 +602,9 @@ run_eventd_service() RET_ON_ERR(capture->set_control(INIT_CAPTURE) == 0, "Failed to init capture"); RET_ON_ERR(capture->set_control(START_CAPTURE) == 0, "Failed to start capture"); + this_thread::sleep_for(chrono::milliseconds(200)); + RET_ON_ERR(!stats_instance.is_running(), "Failed to start stats instance"); + while(code != EVENT_EXIT) { int resp = -1; event_serialized_lst_t req_data, resp_data; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index c616ef000856..96f850eefd8d 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -18,6 +18,8 @@ enum { COUNTERS_EVENTS_TOTAL }; +#define HEARBEAT_INTERVAL 2000 /* Default: 2 seconds */ + /* * Started by eventd_service. * Creates XPUB & XSUB end points. @@ -57,15 +59,7 @@ class eventd_proxy class stats_collector { public: - stats_collector() : m_shutdown(false), - m_pause_heartbeat(false), - m_heartbeats_cnt(0) - { - for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { - m_lst_counters[i] = 0; - } - m_updated = false; - } + stats_collector(); ~stats_collector() { stop(); } @@ -92,14 +86,21 @@ class stats_collector _update_stats(INDEX_COUNTERS_EVENTS_MISSED_CACHE, val); } + void set_heartbeat_interval(int val); + /* A way to pause heartbeat */ void heartbeat_ctrl(bool pause = false) { m_pause_heartbeat = pause; SWSS_LOG_INFO("Set heartbeat_ctrl pause=%d", pause); } - uint64_t heartbeats_cnt() const { - return m_heartbeats_cnt; + uint64_t heartbeats_published() const { + return m_heartbeats_published; + } + + bool is_running() + { + return !m_shutdown; } private: @@ -127,7 +128,9 @@ class stats_collector bool m_pause_heartbeat; - uint64_t m_heartbeats_cnt; + uint64_t m_heartbeats_published; + + int m_heartbeats_interval_cnt; }; /* diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 59296b3aa59d..9c6caddec58f 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -569,97 +569,6 @@ TEST(eventd, captureCacheMax) printf("Capture TEST with matchinhg cache-max completed\n"); } - -void -wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt) -{ - printf("wait_for_heartbeat START cnt=%d\n", (int)cnt); - - auto st = duration_cast(system_clock::now().time_since_epoch()).count(); - while (stats_instance.heartbeats_cnt() == cnt) { - auto en = duration_cast(system_clock::now().time_since_epoch()).count(); - if ((en -st) > 3000) { - EXPECT_LE((en -st), 3000); - EXPECT_EQ(cnt, stats_instance.heartbeats_cnt()); - break; - } - else { - stringstream ss; - ss << (en -st); - printf("DROP:Waiting for heartbeat. duration:%s ms\n", ss.str().c_str()); - } - this_thread::sleep_for(chrono::milliseconds(300)); - } - printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", - (int)cnt, (int)stats_instance.heartbeats_cnt()); -} - -TEST(eventd, heartbeat) -{ - printf("heartbeat TEST started\n"); - - int rc; - long unsigned int cnt; - stats_collector stats_instance; - - debug_on(); - - if (!g_is_redis_available) { - set_unit_testing(true); - printf("DROP: redis NOT available\n"); - } - else { - printf("DROP: redis available\n"); - } - - void *zctx = zmq_ctx_new(); - EXPECT_TRUE(NULL != zctx); - - eventd_proxy *pxy = new eventd_proxy(zctx); - EXPECT_TRUE(NULL != pxy); - - /* Starting proxy */ - EXPECT_EQ(0, pxy->init()); - - rc = stats_instance.start(); - EXPECT_EQ(rc, 0); - - /* Wait for any non-zero heartbeat */ - wait_for_heartbeat(stats_instance, 0); - - /* Pause heartbeat */ - stats_instance.heartbeat_ctrl(true); - - /* Sleep to ensure the other thread noticed the pause request. */ - this_thread::sleep_for(chrono::milliseconds(200)); - - /* Get current count */ - cnt = stats_instance.heartbeats_cnt(); - - /* Wait for 3 seconds with no new neartbeat */ - this_thread::sleep_for(chrono::seconds(3)); - - EXPECT_EQ(stats_instance.heartbeats_cnt(), cnt); - - /* Turn on heartbeat */ - stats_instance.heartbeat_ctrl(); - - /* Wait for heartbeat count to change from last count */ - wait_for_heartbeat(stats_instance, cnt); - - printf("Stopping stats_instance\n"); - stats_instance.stop(); - - printf("Deleting proxy\n"); - delete pxy; - - printf("Terminating ctx\n"); - zmq_ctx_term(zctx); - - printf("heartbeat TEST completed\n"); -} - - TEST(eventd, service) { /* @@ -802,4 +711,106 @@ TEST(eventd, service) printf("Service TEST completed\n"); } + +void +wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt, + int wait_ms = 3000) +{ + int diff = 0; + printf("wait_for_heartbeat START cnt=%d\n", (int)cnt); + + auto st = duration_cast(system_clock::now().time_since_epoch()).count(); + while (stats_instance.heartbeats_published() == cnt) { + auto en = duration_cast(system_clock::now().time_since_epoch()).count(); + diff = en - st; + if (diff > wait_ms) { + EXPECT_LE(diff, wait_ms); + EXPECT_EQ(cnt, stats_instance.heartbeats_published()); + break; + } + else { + stringstream ss; + ss << (en -st); + printf("DROP:Waiting for heartbeat. duration:%s ms\n", ss.str().c_str()); + } + this_thread::sleep_for(chrono::milliseconds(300)); + } + printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", + (int)cnt, (int)stats_instance.heartbeats_published()); + return diff; +} + +TEST(eventd, heartbeat) +{ + printf("heartbeat TEST started\n"); + + int rc; + long unsigned int cnt; + stats_collector stats_instance; + + debug_on(); + + if (!g_is_redis_available) { + set_unit_testing(true); + printf("DROP: redis NOT available\n"); + } + else { + printf("DROP: redis available\n"); + DBConnector db("COUNTERS_DB", 0, true); + printf("DROP: Created COUNTERS_DB\n"); + } + + void *zctx = zmq_ctx_new(); + EXPECT_TRUE(NULL != zctx); + + eventd_proxy *pxy = new eventd_proxy(zctx); + EXPECT_TRUE(NULL != pxy); + + /* Starting proxy */ + EXPECT_EQ(0, pxy->init()); + + rc = stats_instance.start(); + EXPECT_EQ(rc, 0); + + /* Wait for any non-zero heartbeat */ + wait_for_heartbeat(stats_instance, 0); + + /* Pause heartbeat */ + stats_instance.heartbeat_ctrl(true); + + /* Sleep to ensure the other thread noticed the pause request. */ + this_thread::sleep_for(chrono::milliseconds(200)); + + /* Get current count */ + cnt = stats_instance.heartbeats_published(); + + /* Wait for 3 seconds with no new neartbeat */ + this_thread::sleep_for(chrono::seconds(3)); + + EXPECT_EQ(stats_instance.heartbeats_published(), cnt); + + /* Set interval as 1 second */ + stats_instance.set_heartbeat_interval(1); + + /* Turn on heartbeat */ + stats_instance.heartbeat_ctrl(); + + /* Wait for heartbeat count to change from last count */ + wait_for_heartbeat(stats_instance, cnt, 2000); + + printf("Stopping stats_instance\n"); + stats_instance.stop(); + + printf("Deleting proxy\n"); + delete pxy; + + printf("Terminating ctx\n"); + zmq_ctx_term(zctx); + + printf("heartbeat TEST completed\n"); +} + +xx + + // TODO -- Add unit tests for stats From 81375e5e20c24166c67afdd5e6d420315488c832 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 15:19:23 +0000 Subject: [PATCH 096/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 2 ++ src/sonic-eventd/src/eventd.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 31b841f2eabf..88e26d366c77 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -39,6 +39,8 @@ using namespace swss; #define CAPTURE_SOCK_TIMEOUT 800 #define STATS_COLLECTOR_TIMEOUT 300 +#define HEARTBEAT_INTERVAL 2000 /* Default: 2 seconds */ + /* Source & tag for heartbeat events */ #define EVENTD_PUBLISHER_SOURCE "sonic-events-eventd" #define EVENTD_HEARTBEAT_TAG "heartbeat" diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 96f850eefd8d..dce5fa2e4246 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -18,7 +18,6 @@ enum { COUNTERS_EVENTS_TOTAL }; -#define HEARBEAT_INTERVAL 2000 /* Default: 2 seconds */ /* * Started by eventd_service. From 2d9dd0e5e37ed6fcf36e2869993fff9ab0d93823 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 15:21:02 +0000 Subject: [PATCH 097/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 9c6caddec58f..fab6c44bd4bd 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -737,7 +737,6 @@ wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt, } printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", (int)cnt, (int)stats_instance.heartbeats_published()); - return diff; } TEST(eventd, heartbeat) @@ -810,7 +809,5 @@ TEST(eventd, heartbeat) printf("heartbeat TEST completed\n"); } -xx - // TODO -- Add unit tests for stats From 19e72384751e3e260327e6dc8cba1395f83c4afc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 20:48:42 +0000 Subject: [PATCH 098/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 20 ++++-- src/sonic-eventd/src/eventd.h | 23 ++++-- src/sonic-eventd/tests/eventd_ut.cpp | 101 +++++++++++++++++++++++---- 3 files changed, 118 insertions(+), 26 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 88e26d366c77..4be4b91f187f 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -121,7 +121,13 @@ stats_collector::start() int rc = -1; if (!s_unit_testing) { - m_counters_db = make_shared("COUNTERS_DB", 0); + try { + m_counters_db = make_shared("COUNTERS_DB", 0, true); + } + catch (exception &e) + { + SWSS_LOG_ERROR("Unable to get DB Connector, e=(%s)\n", e.what()); + } RET_ON_ERR(m_counters_db != NULL, "Failed to get COUNTERS_DB"); m_stats_table = make_shared( @@ -470,7 +476,10 @@ capture_service::do_capture() case CAP_STATE_LAST: total_overflow++; m_last_events[rid] = evt_str; - m_total_missed_cache = total_overflow - m_last_events.size(); + if (total_overflow > m_last_events.size()) { + m_total_missed_cache++; + m_stats_instance->increment_missed_cache(1); + } break; } } @@ -600,12 +609,12 @@ run_eventd_service() * events until telemetry starts. * Telemetry will send a stop & collect cache upon startup */ - capture = new capture_service(zctx, cache_max); + capture = new capture_service(zctx, cache_max, &stats_instance); RET_ON_ERR(capture->set_control(INIT_CAPTURE) == 0, "Failed to init capture"); RET_ON_ERR(capture->set_control(START_CAPTURE) == 0, "Failed to start capture"); this_thread::sleep_for(chrono::milliseconds(200)); - RET_ON_ERR(!stats_instance.is_running(), "Failed to start stats instance"); + RET_ON_ERR(stats_instance.is_running(), "Failed to start stats instance"); while(code != EVENT_EXIT) { int resp = -1; @@ -623,7 +632,7 @@ run_eventd_service() event_serialized_lst_t().swap(capture_fifo_events); last_events_t().swap(capture_last_events); - capture = new capture_service(zctx, cache_max); + capture = new capture_service(zctx, cache_max, &stats_instance); if (capture != NULL) { resp = capture->set_control(INIT_CAPTURE); } @@ -654,7 +663,6 @@ run_eventd_service() counters_t overflow; resp = capture->read_cache(capture_fifo_events, capture_last_events, overflow); - stats_instance.increment_missed_cache(overflow); } delete capture; capture = NULL; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index dce5fa2e4246..dd110b9f0579 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -16,7 +16,7 @@ enum { INDEX_COUNTERS_EVENTS_PUBLISHED, INDEX_COUNTERS_EVENTS_MISSED_CACHE, COUNTERS_EVENTS_TOTAL -}; +} stats_counter_index_t; /* @@ -85,7 +85,17 @@ class stats_collector _update_stats(INDEX_COUNTERS_EVENTS_MISSED_CACHE, val); } - void set_heartbeat_interval(int val); + counters_t read_counter(stats_counter_index_t index) { + if (index != COUNTERS_EVENTS_TOTAL) { + return m_lst_counters[index]; + } + else { + return 0; + } + } + + /* Sets heartbeat interval in milliseconds */ + void set_heartbeat_interval(int val_in_ms); /* A way to pause heartbeat */ void heartbeat_ctrl(bool pause = false) { @@ -184,9 +194,10 @@ typedef enum { class capture_service { public: - capture_service(void *ctx, int cache_max) : m_ctx(ctx), m_cap_run(false), - m_ctrl(NEED_INIT), m_cache_max(cache_max), m_last_events_init(false), - m_total_missed_cache(0) + capture_service(void *ctx, int cache_max, stats_collector *stats) : + m_ctx(ctx), m_stats_instance(stats), m_cap_run(false), + m_ctrl(NEED_INIT), m_cache_max(cache_max), + m_last_events_init(false), m_total_missed_cache(0) {} ~capture_service(); @@ -203,6 +214,8 @@ class capture_service void stop_capture(); void *m_ctx; + stats_collector *m_stats_instance; + bool m_cap_run; capture_control_t m_ctrl; thread m_thr; diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index fab6c44bd4bd..35a755771fab 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -14,6 +14,7 @@ using namespace std; using namespace swss; extern bool g_is_redis_available; +extern const char *counter_keys[]; typedef struct { int id; @@ -309,6 +310,7 @@ TEST(eventd, capture) string sub_source; int sub_evts_sz = 0; internal_events_lst_t sub_evts; + stats_collector stats_instance; /* run_pub details */ string wr_source("hello"); @@ -337,7 +339,7 @@ TEST(eventd, capture) thread thr_sub(&run_sub, zctx, ref(term_sub), ref(sub_source), ref(sub_evts), ref(sub_evts_sz)); /* Create capture service */ - capture_service *pcap = new capture_service(zctx, cache_max); + capture_service *pcap = new capture_service(zctx, cache_max, &stats_instance); /* Expect START_CAPTURE */ EXPECT_EQ(-1, pcap->set_control(STOP_CAPTURE)); @@ -453,6 +455,7 @@ TEST(eventd, captureCacheMax) string sub_source; int sub_evts_sz = 0; internal_events_lst_t sub_evts; + stats_collector stats_instance; /* run_pub details */ string wr_source("hello"); @@ -481,7 +484,7 @@ TEST(eventd, captureCacheMax) thread thr_sub(&run_sub, zctx, ref(term_sub), ref(sub_source), ref(sub_evts), ref(sub_evts_sz)); /* Create capture service */ - capture_service *pcap = new capture_service(zctx, cache_max); + capture_service *pcap = new capture_service(zctx, cache_max, &stats_instance); /* Expect START_CAPTURE */ EXPECT_EQ(-1, pcap->set_control(STOP_CAPTURE)); @@ -605,17 +608,6 @@ TEST(eventd, service) thread thread_service(&run_eventd_service); - try - { - printf("Calling DBConnector\n"); - DBConnector db("TEST_DB", 0, true); - printf("Created DBConnector\n"); - } - catch (exception &e) - { - printf("e=(%s) eventd_ut: Unable to get DB Connector", e.what()); - } - /* Need client side service to interact with server side */ EXPECT_EQ(0, service.init_client(zctx)); @@ -755,8 +747,6 @@ TEST(eventd, heartbeat) } else { printf("DROP: redis available\n"); - DBConnector db("COUNTERS_DB", 0, true); - printf("DROP: Created COUNTERS_DB\n"); } void *zctx = zmq_ctx_new(); @@ -810,4 +800,85 @@ TEST(eventd, heartbeat) } +TEST(eventd, testDB) +{ + printf("DB TEST started\n"); + debug_on(); + + /* consts used */ + const int pub_count = 5; + const int cache_max = 3; + const int overflow = pub_count - cache_max; + + int rc = 0; + stats_collector stats_instance; + string wr_source("hello"); + internal_events_lst_t wr_evts; + event_handle_t pub_handle; + vector db_val; + + if (!g_is_redis_available) { + printf("DROP: redis not available. DONE\n"); + printf("DB TEST skipped\n"); + return; + } + + DBConnector db("COUNTERS_DB", 0, true); + + + /* Not testing heartbeat; Hence set high val as 10 seconds */ + stats_instance.set_heartbeat_interval(10000); + + /* Start instance to capture published count & as well writes to DB */ + EXPECT_EQ(0, stats_instance.start()); + + void *zctx = zmq_ctx_new(); + EXPECT_TRUE(NULL != zctx); + + /* Run proxy to enable receive as capture test needs to receive */ + eventd_proxy *pxy = new eventd_proxy(zctx); + EXPECT_TRUE(NULL != pxy); + + /* Starting proxy */ + EXPECT_EQ(0, pxy->init()); + + /* Create capture service */ + capture_service *pcap = new capture_service(zctx, cache_max, &stats_instance); + + pub_handle = events_init_publisher("test_db"); + + for(int i=0; i < pub_count; ++i) { + string tag = string("test_db_tag_") + to_string(i); + event_publish(pub_handle, tag); + } + + EXPECT_EQ(pub_count, stats_instance.read_counter(INDEX_COUNTERS_EVENTS_PUBLISHED)); + + + for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { + string key = string("COUNTERS_DB:") + counter_keys[i]; + + EXPECT_TRUE(db.exists(key)); + try { + string s = *db.get(key); + printf("db[%s] = (%s)\n", key.c_str(), s.c_str()); + } + catch (exception &e) + { + EXPECT_TRUE(false, "Failed to get key=(%s) err=(%s)", + key.c_str(), e.what()); + } + } + + events_deinit_publisher(pub_handle); + + stats_instance.stop(); + + delete pxy; + zmq_ctx_term(zctx); + + printf("DB TEST completed\n"); +} + + // TODO -- Add unit tests for stats From 35cda960e6d442a51e2b7a2985c9fb4fe23350ab Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:12:45 +0000 Subject: [PATCH 099/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 56 +++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 35a755771fab..fb24039123ff 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -808,14 +808,15 @@ TEST(eventd, testDB) /* consts used */ const int pub_count = 5; const int cache_max = 3; - const int overflow = pub_count - cache_max; + const int overflow_exp = 3; int rc = 0; stats_collector stats_instance; - string wr_source("hello"); - internal_events_lst_t wr_evts; event_handle_t pub_handle; - vector db_val; + event_serialized_lst_t evts_read; + last_events_t last_evts_read; + counters_t overflow; + string tag; if (!g_is_redis_available) { printf("DROP: redis not available. DONE\n"); @@ -823,6 +824,7 @@ TEST(eventd, testDB) return; } + EXPECT_LT(cache_max, pub_count); DBConnector db("COUNTERS_DB", 0, true); @@ -845,14 +847,54 @@ TEST(eventd, testDB) /* Create capture service */ capture_service *pcap = new capture_service(zctx, cache_max, &stats_instance); + /* Initialize the capture */ + EXPECT_EQ(0, pcap->set_control(INIT_CAPTURE)); + + /* Kick off capture */ + EXPECT_EQ(0, pcap->set_control(START_CAPTURE)); + pub_handle = events_init_publisher("test_db"); for(int i=0; i < pub_count; ++i) { - string tag = string("test_db_tag_") + to_string(i); + tag = string("test_db_tag_") + to_string(i); event_publish(pub_handle, tag); } - EXPECT_EQ(pub_count, stats_instance.read_counter(INDEX_COUNTERS_EVENTS_PUBLISHED)); + for(int i=0; i < overflow_exp; ++i) { + /* + * Send the same tag. so it will overflow, as this tag is + * already sent past cache-max. + */ + event_publish(pub_handle, tag); + } + + /* Pause to ensure all publisghed events did reach capture service */ + this_thread::sleep_for(chrono::milliseconds(200)); + + EXPECT_EQ(0, pcap->set_control(STOP_CAPTURE)); + + /* + * Sent pub_count messages of different tags. + * Followed by overflow_exp count of events with same tag as already sent. + * + * Total published = pub_count + overflow_exp + * The cache_max count of events are read properly by cache service + * pub_count - cache_max is captured in last_evts_read as tags are different. + * overflow_exp count is not captured in last events as duplicate tags, + * hence overflow. + */ + + /* Read the cache */ + EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read, overflow)); + + EXPECT_EQ(cache_max, (int)evts_read.size()); + EXPECT_EQ((pub_count - cache_max), (int)last_evts_read.size()); + EXPECT_EQ(overflow_exp, overflow); + + EXPECT_EQ(pub_count, stats_instance.read_counter( + INDEX_COUNTERS_EVENTS_PUBLISHED)); + EXPECT_EQ(overflow, stats_instance.read_counter( + INDEX_COUNTERS_EVENTS_MISSED_CACHE)); for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { @@ -875,6 +917,8 @@ TEST(eventd, testDB) stats_instance.stop(); delete pxy; + delete pcap; + zmq_ctx_term(zctx); printf("DB TEST completed\n"); From c576d05af53f3b44bb37f72a2b0f2f4b4dbc2716 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:19:39 +0000 Subject: [PATCH 100/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 2 +- src/sonic-eventd/src/eventd.h | 2 +- src/sonic-eventd/tests/eventd_ut.cpp | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 4be4b91f187f..5dd11e2148c6 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -46,7 +46,7 @@ using namespace swss; #define EVENTD_HEARTBEAT_TAG "heartbeat" -static const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { +const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { COUNTERS_EVENTS_PUBLISHED, COUNTERS_EVENTS_MISSED_CACHE }; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index dd110b9f0579..ae97e4dd47ee 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -12,7 +12,7 @@ typedef map last_events_t; /* stat counters */ typedef uint64_t counters_t; -enum { +typedef enum { INDEX_COUNTERS_EVENTS_PUBLISHED, INDEX_COUNTERS_EVENTS_MISSED_CACHE, COUNTERS_EVENTS_TOTAL diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index fb24039123ff..1a4b54393f9d 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -810,7 +810,6 @@ TEST(eventd, testDB) const int cache_max = 3; const int overflow_exp = 3; - int rc = 0; stats_collector stats_instance; event_handle_t pub_handle; event_serialized_lst_t evts_read; @@ -907,8 +906,8 @@ TEST(eventd, testDB) } catch (exception &e) { - EXPECT_TRUE(false, "Failed to get key=(%s) err=(%s)", - key.c_str(), e.what()); + SWSS_LOG_ERROR("Failed to get key=(%s) err=(%s)", key.c_str(), e.what()); + EXPECT_TRUE(false); } } From e131a44870ce7ce42200fe832c3ee6e88fbd0a8e Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:21:38 +0000 Subject: [PATCH 101/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 1a4b54393f9d..2dd8cd9d64aa 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -231,6 +231,7 @@ void debug_on() // #endif } +#if 0 TEST(eventd, proxy) { debug_on(); @@ -798,6 +799,7 @@ TEST(eventd, heartbeat) printf("heartbeat TEST completed\n"); } +#endif TEST(eventd, testDB) From 6014b960f08f876181b0442e5425bbd9448141db Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:31:46 +0000 Subject: [PATCH 102/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 42 +++++++++++----------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 2dd8cd9d64aa..9001b8c97a52 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -808,9 +808,8 @@ TEST(eventd, testDB) debug_on(); /* consts used */ - const int pub_count = 5; + const int pub_count = 7; const int cache_max = 3; - const int overflow_exp = 3; stats_collector stats_instance; event_handle_t pub_handle; @@ -861,40 +860,28 @@ TEST(eventd, testDB) event_publish(pub_handle, tag); } - for(int i=0; i < overflow_exp; ++i) { - /* - * Send the same tag. so it will overflow, as this tag is - * already sent past cache-max. - */ - event_publish(pub_handle, tag); - } - /* Pause to ensure all publisghed events did reach capture service */ this_thread::sleep_for(chrono::milliseconds(200)); EXPECT_EQ(0, pcap->set_control(STOP_CAPTURE)); + /* Read the cache */ + EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read, overflow)); + /* * Sent pub_count messages of different tags. - * Followed by overflow_exp count of events with same tag as already sent. - * - * Total published = pub_count + overflow_exp - * The cache_max count of events are read properly by cache service - * pub_count - cache_max is captured in last_evts_read as tags are different. - * overflow_exp count is not captured in last events as duplicate tags, - * hence overflow. + * Upon cache max, only event per sender/runtime-id is saved. Hence + * expected last_evts_read is one. + * expected overflow = pub_count - cache_max - 1 */ - /* Read the cache */ - EXPECT_EQ(0, pcap->read_cache(evts_read, last_evts_read, overflow)); - EXPECT_EQ(cache_max, (int)evts_read.size()); - EXPECT_EQ((pub_count - cache_max), (int)last_evts_read.size()); - EXPECT_EQ(overflow_exp, overflow); + EXPECT_EQ(1, (int)last_evts_read.size()); + EXPECT_EQ((pub_count - cache_max - 1), overflow); EXPECT_EQ(pub_count, stats_instance.read_counter( INDEX_COUNTERS_EVENTS_PUBLISHED)); - EXPECT_EQ(overflow, stats_instance.read_counter( + EXPECT_EQ((pub_count - cache_max - 1), stats_instance.read_counter( INDEX_COUNTERS_EVENTS_MISSED_CACHE)); @@ -903,8 +890,13 @@ TEST(eventd, testDB) EXPECT_TRUE(db.exists(key)); try { - string s = *db.get(key); - printf("db[%s] = (%s)\n", key.c_str(), s.c_str()); + shared_ptr s = db.get(key); + if (s != NULL) { + printf("db[%s] = (%s)\n", key.c_str(), ccs.c_str()); + } + else { + printf("db[%s] = \n", key.c_str()); + } } catch (exception &e) { From 9f3f0b489efd53be723c84e1bdae48a974285298 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:32:43 +0000 Subject: [PATCH 103/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 9001b8c97a52..2db0f4d7e41a 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -892,7 +892,7 @@ TEST(eventd, testDB) try { shared_ptr s = db.get(key); if (s != NULL) { - printf("db[%s] = (%s)\n", key.c_str(), ccs.c_str()); + printf("db[%s] = (%s)\n", key.c_str(), s.get()->c_str()); } else { printf("db[%s] = \n", key.c_str()); From d5c32fb8011d531c91fe8a4ded39fea183ad7bd8 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:39:27 +0000 Subject: [PATCH 104/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 2db0f4d7e41a..88d6b3ddf7af 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -884,9 +884,13 @@ TEST(eventd, testDB) EXPECT_EQ((pub_count - cache_max - 1), stats_instance.read_counter( INDEX_COUNTERS_EVENTS_MISSED_CACHE)); + printf("deinit publisher\n"); + events_deinit_publisher(pub_handle); + printf("deinit publisher DONE\n"); + for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { - string key = string("COUNTERS_DB:") + counter_keys[i]; + string key = string("COUNTERS_EVENTS:") + counter_keys[i]; EXPECT_TRUE(db.exists(key)); try { @@ -905,8 +909,6 @@ TEST(eventd, testDB) } } - events_deinit_publisher(pub_handle); - stats_instance.stop(); delete pxy; From dab5d7b14c92058f43641bd656ff44541c850980 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 21:49:06 +0000 Subject: [PATCH 105/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 5dd11e2148c6..c6a146000350 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -177,16 +177,16 @@ stats_collector::run_collector() { int hb_cntr = 0; string hb_key = string(EVENTD_PUBLISHER_SOURCE) + ":" + EVENTD_HEARTBEAT_TAG; - event_handle_t pub_handle = NULL; + // event_handle_t pub_handle = NULL; event_handle_t subs_handle = NULL; /* * A subscriber is required to set a subscription. Else all published * events will be dropped at the point of publishing itself. */ - pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); - RET_ON_ERR(pub_handle != NULL, - "failed to create publisher handle for heartbeats"); + // pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); + // RET_ON_ERR(pub_handle != NULL, + // "failed to create publisher handle for heartbeats"); subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); @@ -235,10 +235,10 @@ stats_collector::run_collector() m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } if (!m_pause_heartbeat && ++hb_cntr >= m_heartbeats_interval_cnt) { - rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); - if (rc != 0) { - SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); - } + // rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); + // if (rc != 0) { + // SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); + // } SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; ++m_heartbeats_published; @@ -257,7 +257,7 @@ stats_collector::run_collector() */ events_deinit_subscriber(subs_handle); - events_deinit_publisher(pub_handle); + // events_deinit_publisher(pub_handle); m_shutdown = true; return; } From 844a220297d983e22fd5d057a84ca79909de4c0c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Mon, 15 Aug 2022 23:09:16 +0000 Subject: [PATCH 106/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 1 + src/sonic-eventd/tests/eventd_ut.cpp | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index c6a146000350..95f56e777e01 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -223,6 +223,7 @@ stats_collector::run_collector() } if ((rc == 0) && (op.key != hb_key)) { + /* TODO: Discount EVENT_STR_CTRL_DEINIT messages too */ increment_published(1+op.missed_cnt); /* reset counter on receive to restart. */ diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 88d6b3ddf7af..46b111f8b192 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -892,19 +892,24 @@ TEST(eventd, testDB) for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { string key = string("COUNTERS_EVENTS:") + counter_keys[i]; - EXPECT_TRUE(db.exists(key)); - try { - shared_ptr s = db.get(key); - if (s != NULL) { - printf("db[%s] = (%s)\n", key.c_str(), s.get()->c_str()); + if (db.exists(key)) { + try { + unordered_map m = db.hgetall(key); + printf("hgetall BEGIN key=%s\n", key.c_str()); + for(unordered_map::const_iterator itc = m.begin(); + itc != m.end(); ++itc) { + printf("val[%s] = (%s)\n", itc->first.c_str(), itc->second.c_str()); + } + printf("hgetall END\n"); } - else { - printf("db[%s] = \n", key.c_str()); + catch (exception &e) + { + SWSS_LOG_ERROR("Failed to get key=(%s) err=(%s)", key.c_str(), e.what()); + EXPECT_TRUE(false); } } - catch (exception &e) - { - SWSS_LOG_ERROR("Failed to get key=(%s) err=(%s)", key.c_str(), e.what()); + else { + SWSS_LOG_ERROR("Failed to test key(%s) exists", key.c_str()); EXPECT_TRUE(false); } } From 94070e2ace92f5e9bdb72bf31977d8756aa48f61 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:02:46 +0000 Subject: [PATCH 107/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 2 -- src/sonic-eventd/src/eventd.h | 3 ++- src/sonic-eventd/tests/eventd_ut.cpp | 33 ++++++++++++++++++---------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 95f56e777e01..7e81869de5cc 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -51,8 +51,6 @@ const char *counter_keys[COUNTERS_EVENTS_TOTAL] = { COUNTERS_EVENTS_MISSED_CACHE }; -#define EVENTS_STATS_FIELD_NAME "value" - static bool s_unit_testing = false; int diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index ae97e4dd47ee..be6266383f23 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -18,11 +18,12 @@ typedef enum { COUNTERS_EVENTS_TOTAL } stats_counter_index_t; +#define EVENTS_STATS_FIELD_NAME "value" /* * Started by eventd_service. * Creates XPUB & XSUB end points. - onicanalytics.azurecr.io Bind the same + * Bind the same * Create a PUB socket end point for capture and bind. * Call run_proxy method with sockets in a dedicated thread. * Thread runs forever until the zmq context is terminated. diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 46b111f8b192..f57d310cd4e8 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -884,32 +884,43 @@ TEST(eventd, testDB) EXPECT_EQ((pub_count - cache_max - 1), stats_instance.read_counter( INDEX_COUNTERS_EVENTS_MISSED_CACHE)); - printf("deinit publisher\n"); events_deinit_publisher(pub_handle); - printf("deinit publisher DONE\n"); - for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { string key = string("COUNTERS_EVENTS:") + counter_keys[i]; + unordered_map m; + bool key_found = false, val_found=false, val_match=false; if (db.exists(key)) { try { - unordered_map m = db.hgetall(key); - printf("hgetall BEGIN key=%s\n", key.c_str()); - for(unordered_map::const_iterator itc = m.begin(); - itc != m.end(); ++itc) { - printf("val[%s] = (%s)\n", itc->first.c_str(), itc->second.c_str()); + m = db.hgetall(key); + unordered_map::const_iterator itc = + m.find(EVENTS_STATS_FIELD_NAME); + if (itc != m.end()) { + int expect = (key == COUNTERS_EVENTS_PUBLISHED ? pub_count : + (pub_count - cache_max - 1)); + val_match = (exist == stoi(itc->second) ? true : false); + val_found = true; } - printf("hgetall END\n"); } catch (exception &e) { SWSS_LOG_ERROR("Failed to get key=(%s) err=(%s)", key.c_str(), e.what()); EXPECT_TRUE(false); } + key_found = true; } - else { - SWSS_LOG_ERROR("Failed to test key(%s) exists", key.c_str()); + + if (!val_match) { + SWSS_LOG_ERROR("key=%s key_found=%d val_found=%d fields=%d", + key.c_str(), key_found, val_found, (int)m.size()); + + SWSS_LOG_ERROR("hgetall BEGIN key=%s", key.c_str()); + for(unordered_map::const_iterator itc = m.begin(); + itc != m.end(); ++itc) { + SWSS_LOG_ERROR("val[%s] = (%s)", itc->first.c_str(), itc->second.c_str()); + } + SWSS_LOG_ERROR("hgetall END\n"); EXPECT_TRUE(false); } } From 7dfa72872c68d8f0edb0dfd39a19b38f10005e7c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:04:37 +0000 Subject: [PATCH 108/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index f57d310cd4e8..e2d7ec0ec44a 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -899,7 +899,7 @@ TEST(eventd, testDB) if (itc != m.end()) { int expect = (key == COUNTERS_EVENTS_PUBLISHED ? pub_count : (pub_count - cache_max - 1)); - val_match = (exist == stoi(itc->second) ? true : false); + val_match = (expect == stoi(itc->second) ? true : false); val_found = true; } } From c40e80b120438ac324b9bcbb8e0467402924f442 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:07:12 +0000 Subject: [PATCH 109/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index e2d7ec0ec44a..98842e3a1121 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -895,13 +895,16 @@ TEST(eventd, testDB) try { m = db.hgetall(key); unordered_map::const_iterator itc = - m.find(EVENTS_STATS_FIELD_NAME); + m.find(string(EVENTS_STATS_FIELD_NAME)); if (itc != m.end()) { int expect = (key == COUNTERS_EVENTS_PUBLISHED ? pub_count : (pub_count - cache_max - 1)); val_match = (expect == stoi(itc->second) ? true : false); val_found = true; } + else { + printf("Failed to find %s\n", EVENTS_STATS_FIELD_NAME); + } } catch (exception &e) { From 5fb93f98a989719a6fed1998d621b34eb759c5ec Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:11:33 +0000 Subject: [PATCH 110/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 98842e3a1121..a7cba1980917 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -900,6 +900,7 @@ TEST(eventd, testDB) int expect = (key == COUNTERS_EVENTS_PUBLISHED ? pub_count : (pub_count - cache_max - 1)); val_match = (expect == stoi(itc->second) ? true : false); + printf("key=%s expect=%d val=%d\n", key.c_str(), expect, stoi(itc->second)); val_found = true; } else { From a64ace9fd0d6b438067965a1fe24817eb54328b8 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:13:00 +0000 Subject: [PATCH 111/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index a7cba1980917..53277b7e1135 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -897,8 +897,8 @@ TEST(eventd, testDB) unordered_map::const_iterator itc = m.find(string(EVENTS_STATS_FIELD_NAME)); if (itc != m.end()) { - int expect = (key == COUNTERS_EVENTS_PUBLISHED ? pub_count : - (pub_count - cache_max - 1)); + int expect = (counter_keys[i] == COUNTERS_EVENTS_PUBLISHED ? + pub_count : (pub_count - cache_max - 1)); val_match = (expect == stoi(itc->second) ? true : false); printf("key=%s expect=%d val=%d\n", key.c_str(), expect, stoi(itc->second)); val_found = true; From 16a9a8bfeef47c5e85b8542e709620aa9c1cf6fc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:14:36 +0000 Subject: [PATCH 112/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 53277b7e1135..0b791b3a06ba 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -897,7 +897,7 @@ TEST(eventd, testDB) unordered_map::const_iterator itc = m.find(string(EVENTS_STATS_FIELD_NAME)); if (itc != m.end()) { - int expect = (counter_keys[i] == COUNTERS_EVENTS_PUBLISHED ? + int expect = (counter_keys[i] == string(COUNTERS_EVENTS_PUBLISHED) ? pub_count : (pub_count - cache_max - 1)); val_match = (expect == stoi(itc->second) ? true : false); printf("key=%s expect=%d val=%d\n", key.c_str(), expect, stoi(itc->second)); From 69345a1086c6a96e75de5db1dfe0f41a8d83b6b0 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:16:47 +0000 Subject: [PATCH 113/137] testing ... --- src/sonic-eventd/tests/eventd_ut.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 0b791b3a06ba..49892c708e33 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -231,7 +231,6 @@ void debug_on() // #endif } -#if 0 TEST(eventd, proxy) { debug_on(); @@ -799,7 +798,6 @@ TEST(eventd, heartbeat) printf("heartbeat TEST completed\n"); } -#endif TEST(eventd, testDB) From a981c0eb00f0ed17e47c28b9a33ca28fae9bb550 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:23:47 +0000 Subject: [PATCH 114/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 19 +++++++++---------- src/sonic-eventd/tests/eventd_ut.cpp | 22 +--------------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 7e81869de5cc..f22a1bc075aa 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -175,16 +175,16 @@ stats_collector::run_collector() { int hb_cntr = 0; string hb_key = string(EVENTD_PUBLISHER_SOURCE) + ":" + EVENTD_HEARTBEAT_TAG; - // event_handle_t pub_handle = NULL; + event_handle_t pub_handle = NULL; event_handle_t subs_handle = NULL; /* * A subscriber is required to set a subscription. Else all published * events will be dropped at the point of publishing itself. */ - // pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); - // RET_ON_ERR(pub_handle != NULL, - // "failed to create publisher handle for heartbeats"); + pub_handle = events_init_publisher(EVENTD_PUBLISHER_SOURCE); + RET_ON_ERR(pub_handle != NULL, + "failed to create publisher handle for heartbeats"); subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); @@ -203,7 +203,6 @@ stats_collector::run_collector() * The write of these counters into redis is done by another thread. */ - printf("DROP: heartbeat: stats_collector started HEARTBEAT_CNT=%d\n", m_heartbeats_interval_cnt); while(!m_shutdown) { event_receive_op_t op; int rc = 0; @@ -234,10 +233,10 @@ stats_collector::run_collector() m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } if (!m_pause_heartbeat && ++hb_cntr >= m_heartbeats_interval_cnt) { - // rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); - // if (rc != 0) { - // SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); - // } + rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); + if (rc != 0) { + SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); + } SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; ++m_heartbeats_published; @@ -256,7 +255,7 @@ stats_collector::run_collector() */ events_deinit_subscriber(subs_handle); - // events_deinit_publisher(pub_handle); + events_deinit_publisher(pub_handle); m_shutdown = true; return; } diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 49892c708e33..550fc7b17272 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -600,10 +600,6 @@ TEST(eventd, service) if (!g_is_redis_available) { set_unit_testing(true); - printf("DROP: redis not available\n"); - } - else { - printf("DROP: redis available\n"); } thread thread_service(&run_eventd_service); @@ -709,7 +705,6 @@ wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt, int wait_ms = 3000) { int diff = 0; - printf("wait_for_heartbeat START cnt=%d\n", (int)cnt); auto st = duration_cast(system_clock::now().time_since_epoch()).count(); while (stats_instance.heartbeats_published() == cnt) { @@ -723,12 +718,9 @@ wait_for_heartbeat(stats_collector &stats_instance, long unsigned int cnt, else { stringstream ss; ss << (en -st); - printf("DROP:Waiting for heartbeat. duration:%s ms\n", ss.str().c_str()); } this_thread::sleep_for(chrono::milliseconds(300)); } - printf("wait_for_heartbeat DONE cnt=%d ct=%d\n", - (int)cnt, (int)stats_instance.heartbeats_published()); } TEST(eventd, heartbeat) @@ -743,10 +735,6 @@ TEST(eventd, heartbeat) if (!g_is_redis_available) { set_unit_testing(true); - printf("DROP: redis NOT available\n"); - } - else { - printf("DROP: redis available\n"); } void *zctx = zmq_ctx_new(); @@ -787,13 +775,10 @@ TEST(eventd, heartbeat) /* Wait for heartbeat count to change from last count */ wait_for_heartbeat(stats_instance, cnt, 2000); - printf("Stopping stats_instance\n"); stats_instance.stop(); - printf("Deleting proxy\n"); delete pxy; - printf("Terminating ctx\n"); zmq_ctx_term(zctx); printf("heartbeat TEST completed\n"); @@ -817,8 +802,7 @@ TEST(eventd, testDB) string tag; if (!g_is_redis_available) { - printf("DROP: redis not available. DONE\n"); - printf("DB TEST skipped\n"); + printf("redis not available; Hence DB TEST skipped\n"); return; } @@ -898,12 +882,8 @@ TEST(eventd, testDB) int expect = (counter_keys[i] == string(COUNTERS_EVENTS_PUBLISHED) ? pub_count : (pub_count - cache_max - 1)); val_match = (expect == stoi(itc->second) ? true : false); - printf("key=%s expect=%d val=%d\n", key.c_str(), expect, stoi(itc->second)); val_found = true; } - else { - printf("Failed to find %s\n", EVENTS_STATS_FIELD_NAME); - } } catch (exception &e) { From c79aa57aae0f13ff32e3b2953df2e3e1e92c83cf Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 00:26:33 +0000 Subject: [PATCH 115/137] testing ... --- src/sonic-eventd/src/eventd.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index f22a1bc075aa..dc54ee0c18c5 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -237,7 +237,6 @@ stats_collector::run_collector() if (rc != 0) { SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); } - SWSS_LOG_ERROR("DROP: published heartbeat rc=%d", rc); hb_cntr = 0; ++m_heartbeats_published; } @@ -245,7 +244,6 @@ stats_collector::run_collector() } out: - printf("DROP: heartbeat: stats_collector stopped\n"); /* * NOTE: A shutdown could lose messages in cache. * But consider, that eventd shutdown is a critical shutdown as it would From 9994547c13e42d7a79e452dfc6a9c840c809da4a Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 03:08:37 +0000 Subject: [PATCH 116/137] revert submodule --- src/sonic-swss-common | 1 + 1 file changed, 1 insertion(+) create mode 160000 src/sonic-swss-common diff --git a/src/sonic-swss-common b/src/sonic-swss-common new file mode 160000 index 000000000000..ecc13b26f70c --- /dev/null +++ b/src/sonic-swss-common @@ -0,0 +1 @@ +Subproject commit ecc13b26f70c22812eda4c03ddcc063ed800d8b7 From cbd932018ae61aefd323ba13e901ca85cfa1bff0 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 03:13:49 +0000 Subject: [PATCH 117/137] ignore submod --- src/wpasupplicant/sonic-wpa-supplicant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wpasupplicant/sonic-wpa-supplicant b/src/wpasupplicant/sonic-wpa-supplicant index 24f505148191..88d1eaea944c 160000 --- a/src/wpasupplicant/sonic-wpa-supplicant +++ b/src/wpasupplicant/sonic-wpa-supplicant @@ -1 +1 @@ -Subproject commit 24f5051481910677b9e5937c01b8b941185086d3 +Subproject commit 88d1eaea944c5ea90d9d7796dc10abc80823ed93 From 27a762d8b2d3640019c304daac94afccd5e6c988 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 21:48:34 +0000 Subject: [PATCH 118/137] update & review updates --- src/sonic-eventd/Makefile | 3 +- src/sonic-eventd/src/eventd.cpp | 46 +++++++++++++++++++++++++--- src/sonic-eventd/src/eventd.h | 20 +++++++++--- src/sonic-eventd/tests/eventd_ut.cpp | 42 +++++++++++-------------- 4 files changed, 76 insertions(+), 35 deletions(-) diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index e6fb6505d4d0..c6559d926792 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -25,8 +25,7 @@ endif -include rsyslog_plugin/subdir.mk -include rsyslog_plugin_tests/subdir.mk -# all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests -all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin +all: sonic-eventd eventd-tests eventd-tool rsyslog-plugin rsyslog-plugin-tests sonic-eventd: $(OBJS) @echo 'Building target: $@' diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index dc54ee0c18c5..a45b2c25e8b5 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -37,7 +37,6 @@ using namespace swss; /* Sock read timeout in milliseconds, to enable look for control signals */ #define CAPTURE_SOCK_TIMEOUT 800 -#define STATS_COLLECTOR_TIMEOUT 300 #define HEARTBEAT_INTERVAL 2000 /* Default: 2 seconds */ @@ -97,7 +96,7 @@ eventd_proxy::run() stats_collector::stats_collector() : m_shutdown(false), m_pause_heartbeat(false), m_heartbeats_published(0), - m_heartbeats_interval_cnt(HEARTBEAT_INTERVAL/STATS_COLLECTOR_TIMEOUT) + m_heartbeats_interval_cnt(HEARTBEAT_INTERVAL/STATS_HEARTBEAT_MIN) { for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { m_lst_counters[i] = 0; @@ -105,14 +104,22 @@ stats_collector::stats_collector() : m_updated = false; } + void stats_collector::set_heartbeat_interval(int val) { if (val > 0) { - m_heartbeats_interval_cnt = (val / STATS_COLLECTOR_TIMEOUT); + m_heartbeats_interval_cnt = (val / STATS_HEARTBEAT_MIN); } } + +int +stats_collector::get_heartbeat_interval() +{ + return m_heartbeats_interval_cnt * STATS_HEARTBEAT_MIN; +} + int stats_collector::start() { @@ -186,7 +193,7 @@ stats_collector::run_collector() RET_ON_ERR(pub_handle != NULL, "failed to create publisher handle for heartbeats"); - subs_handle = events_init_subscriber(false, STATS_COLLECTOR_TIMEOUT); + subs_handle = events_init_subscriber(false, STATS_HEARTBEAT_MIN); RET_ON_ERR(subs_handle != NULL, "failed to subscribe to all"); /* @@ -255,7 +262,6 @@ stats_collector::run_collector() events_deinit_subscriber(subs_handle); events_deinit_publisher(pub_handle); m_shutdown = true; - return; } capture_service::~capture_service() @@ -566,6 +572,32 @@ capture_service::read_cache(event_serialized_lst_t &lst_fifo, return 0; } +static int +process_options(stats_collector *stats, const event_serialized_lst_t &req_data, + event_serialized_lst_t &resp_data) +{ + int ret = -1; + if (!req_data.empty()) { + RET_ON_ERR(req.data.size() == 1, "Expect only one options string %d", + (int)req.data.size()); + const auto &data = nlohmann::json::parse(*(req.begin())); + RET_ON_ERR(data.size() != 1, "Only one supported option. Expect 1. size=%d", + (int)data.size()); + const auto it = data.find(GLOBAL_OPTION_HEARTBEAT); + RET_ON_ERR(it != data.end(), "Expect HEARTBEAT_INTERVAL; got %s", + data.begin()->first.c_str()); + stats->set_heartbeat_interval(it->second); + ret = 0; + } + else { + nlohmann::json msg = nlohmann::json::object(); + msg[GLOBAL_OPTION_HEARTBEAT] = stats->get_heartbeat_interval(); + resp_data.push_back(msg.dump()); + ret = 0; + } + return ret; +} + void run_eventd_service() @@ -708,6 +740,10 @@ run_eventd_service() resp_data.swap(req_data); break; + case EVENT_OPTIONS: + resp = process_options(&stats_instance, req_data, resp_data); + break; + case EVENT_EXIT: resp = 0; break; diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index be6266383f23..b8ffca4ca3e6 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -19,6 +19,7 @@ typedef enum { } stats_counter_index_t; #define EVENTS_STATS_FIELD_NAME "value" +#define STATS_HEARTBEAT_MIN 300 /* * Started by eventd_service. @@ -98,6 +99,13 @@ class stats_collector /* Sets heartbeat interval in milliseconds */ void set_heartbeat_interval(int val_in_ms); + /* + * Get heartbeat interval in milliseconds + * NOTE: Set & get value may not match as the value is rounded + * to a multiple of smallest possible interval. + */ + void get_heartbeat_interval(int val_in_ms); + /* A way to pause heartbeat */ void heartbeat_ctrl(bool pause = false) { m_pause_heartbeat = pause; @@ -114,16 +122,20 @@ class stats_collector } private: - void _update_stats(int index, counters_t val) { - m_lst_counters[index] += val; - m_updated = true; + void _update_stats(stats_counter_index_t index, counters_t val) { + if (index != COUNTERS_EVENTS_TOTAL) { + m_lst_counters[index] += val; + m_updated = true; + } + else { + SWSS_LOG_ERROR("Internal code error. Invalid index=%d", index); + } } void run_collector(); void run_writer(); - atomic m_updated; counters_t m_lst_counters[COUNTERS_EVENTS_TOTAL]; diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 550fc7b17272..c4de07add779 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -220,21 +220,8 @@ void run_pub(void *mock_pub, const string wr_source, internal_events_lst_t &lst) } -void debug_on() -{ - /* compile with -D DEBUG_TEST or add "#define DEBUG_TEST" to include. */ -// #ifdef DEBUG_TEST - /* Direct log messages to stdout */ - string dummy, op("STDOUT"); - swss::Logger::swssOutputNotify(dummy, op); - swss::Logger::setMinPrio(swss::Logger::SWSS_DEBUG); -// #endif -} - TEST(eventd, proxy) { - debug_on(); - printf("Proxy TEST started\n"); bool term_sub = false; bool term_cap = false; @@ -304,7 +291,6 @@ TEST(eventd, proxy) TEST(eventd, capture) { printf("Capture TEST started\n"); - debug_on(); bool term_sub = false; string sub_source; @@ -445,7 +431,6 @@ TEST(eventd, capture) TEST(eventd, captureCacheMax) { printf("Capture TEST with matchinhg cache-max started\n"); - debug_on(); /* * Need to run subscriber; Else publisher would skip publishing @@ -583,7 +568,6 @@ TEST(eventd, service) * TEST(eventd, capture) has already tested caching. */ printf("Service TEST started\n"); - debug_on(); /* startup strings; expected list & read list from capture */ event_service service; @@ -689,6 +673,19 @@ TEST(eventd, service) } } + { + string set_opt_bad("{\"HEARTBEAT_INTERVAL\": 2000, \"OFFLINE_CACHE_SIZE\": 500}"); + /* NOTE: 1800 is multiple of STATS_HEARTBEAT_MIN */ + string set_opt_good("{\"HEARTBEAT_INTERVAL\": 1800 }"); + char buff[100]; + + EXPECT_EQ(-1, service.global_options_set(set_opt_bad.c_str())); + EXPECT_EQ(0, service.global_options_set(set_opt_good.c_str())); + EXPECT_EQ(0, service.global_options_get(buff, sizeof(buff))); + + EXPECT_EQ(1800, stoi(buff)); + } + EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); service.close_service(); @@ -731,8 +728,6 @@ TEST(eventd, heartbeat) long unsigned int cnt; stats_collector stats_instance; - debug_on(); - if (!g_is_redis_available) { set_unit_testing(true); } @@ -788,7 +783,6 @@ TEST(eventd, heartbeat) TEST(eventd, testDB) { printf("DB TEST started\n"); - debug_on(); /* consts used */ const int pub_count = 7; @@ -887,22 +881,22 @@ TEST(eventd, testDB) } catch (exception &e) { - SWSS_LOG_ERROR("Failed to get key=(%s) err=(%s)", key.c_str(), e.what()); + printf("Failed to get key=(%s) err=(%s)", key.c_str(), e.what()); EXPECT_TRUE(false); } key_found = true; } if (!val_match) { - SWSS_LOG_ERROR("key=%s key_found=%d val_found=%d fields=%d", + printf("key=%s key_found=%d val_found=%d fields=%d", key.c_str(), key_found, val_found, (int)m.size()); - SWSS_LOG_ERROR("hgetall BEGIN key=%s", key.c_str()); + printf("hgetall BEGIN key=%s", key.c_str()); for(unordered_map::const_iterator itc = m.begin(); itc != m.end(); ++itc) { - SWSS_LOG_ERROR("val[%s] = (%s)", itc->first.c_str(), itc->second.c_str()); + printf("val[%s] = (%s)", itc->first.c_str(), itc->second.c_str()); } - SWSS_LOG_ERROR("hgetall END\n"); + printf("hgetall END\n"); EXPECT_TRUE(false); } } From f2175a183950607c0fde1d808334a7435bb4aa71 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 21:53:46 +0000 Subject: [PATCH 119/137] update & review updates --- src/sonic-eventd/src/eventd.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index a45b2c25e8b5..e0e4c0218ec1 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -578,9 +578,9 @@ process_options(stats_collector *stats, const event_serialized_lst_t &req_data, { int ret = -1; if (!req_data.empty()) { - RET_ON_ERR(req.data.size() == 1, "Expect only one options string %d", - (int)req.data.size()); - const auto &data = nlohmann::json::parse(*(req.begin())); + RET_ON_ERR(req_data.size() == 1, "Expect only one options string %d", + (int)req_data.size()); + const auto &data = nlohmann::json::parse(*(req_data.begin())); RET_ON_ERR(data.size() != 1, "Only one supported option. Expect 1. size=%d", (int)data.size()); const auto it = data.find(GLOBAL_OPTION_HEARTBEAT); @@ -595,6 +595,7 @@ process_options(stats_collector *stats, const event_serialized_lst_t &req_data, resp_data.push_back(msg.dump()); ret = 0; } +out: return ret; } From c530a048903df86fa06be885a86d6ca2eaa07414 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 21:54:24 +0000 Subject: [PATCH 120/137] update & review updates --- src/sonic-eventd/src/eventd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index b8ffca4ca3e6..679b64d3371d 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -104,7 +104,7 @@ class stats_collector * NOTE: Set & get value may not match as the value is rounded * to a multiple of smallest possible interval. */ - void get_heartbeat_interval(int val_in_ms); + int get_heartbeat_interval(int val_in_ms); /* A way to pause heartbeat */ void heartbeat_ctrl(bool pause = false) { From 0a159097ad693d8c54385acfb46a4a1552c21025 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 21:55:20 +0000 Subject: [PATCH 121/137] update & review updates --- src/sonic-eventd/src/eventd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 679b64d3371d..597ab24a2622 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -104,7 +104,7 @@ class stats_collector * NOTE: Set & get value may not match as the value is rounded * to a multiple of smallest possible interval. */ - int get_heartbeat_interval(int val_in_ms); + int get_heartbeat_interval(); /* A way to pause heartbeat */ void heartbeat_ctrl(bool pause = false) { From 6bf37784fa01f1080a0544beeb0fa2b6b5c85ac2 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:00:43 +0000 Subject: [PATCH 122/137] update & review updates --- src/sonic-eventd/src/eventd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index e0e4c0218ec1..8193fdd0aee8 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -585,8 +585,8 @@ process_options(stats_collector *stats, const event_serialized_lst_t &req_data, (int)data.size()); const auto it = data.find(GLOBAL_OPTION_HEARTBEAT); RET_ON_ERR(it != data.end(), "Expect HEARTBEAT_INTERVAL; got %s", - data.begin()->first.c_str()); - stats->set_heartbeat_interval(it->second); + data.begin().key()); + stats->set_heartbeat_interval(it.value()); ret = 0; } else { From ec2185bb6ffe13f990a224dc88a3b38ba4bbc09b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:01:41 +0000 Subject: [PATCH 123/137] update & review updates --- src/sonic-eventd/src/eventd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 8193fdd0aee8..cea6fd6138c5 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -585,7 +585,7 @@ process_options(stats_collector *stats, const event_serialized_lst_t &req_data, (int)data.size()); const auto it = data.find(GLOBAL_OPTION_HEARTBEAT); RET_ON_ERR(it != data.end(), "Expect HEARTBEAT_INTERVAL; got %s", - data.begin().key()); + data.begin().key().c_str()); stats->set_heartbeat_interval(it.value()); ret = 0; } From cbe864f025319f744376df0544ec4d81dfe80399 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:11:05 +0000 Subject: [PATCH 124/137] update & review updates --- src/sonic-eventd/src/eventd.cpp | 2 +- src/sonic-eventd/tests/eventd_ut.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index cea6fd6138c5..0a5f129b4663 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -581,7 +581,7 @@ process_options(stats_collector *stats, const event_serialized_lst_t &req_data, RET_ON_ERR(req_data.size() == 1, "Expect only one options string %d", (int)req_data.size()); const auto &data = nlohmann::json::parse(*(req_data.begin())); - RET_ON_ERR(data.size() != 1, "Only one supported option. Expect 1. size=%d", + RET_ON_ERR(data.size() == 1, "Only one supported option. Expect 1. size=%d", (int)data.size()); const auto it = data.find(GLOBAL_OPTION_HEARTBEAT); RET_ON_ERR(it != data.end(), "Expect HEARTBEAT_INTERVAL; got %s", diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index c4de07add779..32b763d9a60c 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -678,10 +678,11 @@ TEST(eventd, service) /* NOTE: 1800 is multiple of STATS_HEARTBEAT_MIN */ string set_opt_good("{\"HEARTBEAT_INTERVAL\": 1800 }"); char buff[100]; + buff[0] = 0; EXPECT_EQ(-1, service.global_options_set(set_opt_bad.c_str())); EXPECT_EQ(0, service.global_options_set(set_opt_good.c_str())); - EXPECT_EQ(0, service.global_options_get(buff, sizeof(buff))); + EXPECT_LT(0, service.global_options_get(buff, sizeof(buff))); EXPECT_EQ(1800, stoi(buff)); } From cadaab31d3b3281ad590260045adb7a75742e5dc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:19:34 +0000 Subject: [PATCH 125/137] update & review updates --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 32b763d9a60c..85859f159833 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -682,12 +682,16 @@ TEST(eventd, service) EXPECT_EQ(-1, service.global_options_set(set_opt_bad.c_str())); EXPECT_EQ(0, service.global_options_set(set_opt_good.c_str())); + printf("Here %s:%d\n", __FUNCTION__, __LINE__); EXPECT_LT(0, service.global_options_get(buff, sizeof(buff))); + printf("Here %s:%d\n", __FUNCTION__, __LINE__); EXPECT_EQ(1800, stoi(buff)); + printf("Here %s:%d\n", __FUNCTION__, __LINE__); } EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); + printf("Here %s:%d\n", __FUNCTION__, __LINE__); service.close_service(); From cbff7630c9bb38f7ca6367e765a8204fa5c45e6c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:21:48 +0000 Subject: [PATCH 126/137] update & review updates --- src/sonic-eventd/tests/eventd_ut.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 85859f159833..c70d3c9c8af9 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -685,6 +685,7 @@ TEST(eventd, service) printf("Here %s:%d\n", __FUNCTION__, __LINE__); EXPECT_LT(0, service.global_options_get(buff, sizeof(buff))); printf("Here %s:%d\n", __FUNCTION__, __LINE__); + printf("%s\n", buff); EXPECT_EQ(1800, stoi(buff)); printf("Here %s:%d\n", __FUNCTION__, __LINE__); From 1309608cb45672246cf801899f2d7bcc5b095138 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:24:13 +0000 Subject: [PATCH 127/137] update & review updates --- src/sonic-eventd/tests/eventd_ut.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index c70d3c9c8af9..f6e3cdd18b2b 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -676,7 +676,7 @@ TEST(eventd, service) { string set_opt_bad("{\"HEARTBEAT_INTERVAL\": 2000, \"OFFLINE_CACHE_SIZE\": 500}"); /* NOTE: 1800 is multiple of STATS_HEARTBEAT_MIN */ - string set_opt_good("{\"HEARTBEAT_INTERVAL\": 1800 }"); + string set_opt_good("{\"HEARTBEAT_INTERVAL\":1800}"); char buff[100]; buff[0] = 0; @@ -685,9 +685,8 @@ TEST(eventd, service) printf("Here %s:%d\n", __FUNCTION__, __LINE__); EXPECT_LT(0, service.global_options_get(buff, sizeof(buff))); printf("Here %s:%d\n", __FUNCTION__, __LINE__); - printf("%s\n", buff); - EXPECT_EQ(1800, stoi(buff)); + EXPECT_EQ(set_opt_good, string(buff)); printf("Here %s:%d\n", __FUNCTION__, __LINE__); } From 5fca96ca0a0ec5ea675711e4835293c90429335b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:25:36 +0000 Subject: [PATCH 128/137] update & review updates --- src/sonic-eventd/tests/eventd_ut.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index f6e3cdd18b2b..8dbcfc3f748c 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -682,16 +682,12 @@ TEST(eventd, service) EXPECT_EQ(-1, service.global_options_set(set_opt_bad.c_str())); EXPECT_EQ(0, service.global_options_set(set_opt_good.c_str())); - printf("Here %s:%d\n", __FUNCTION__, __LINE__); EXPECT_LT(0, service.global_options_get(buff, sizeof(buff))); - printf("Here %s:%d\n", __FUNCTION__, __LINE__); EXPECT_EQ(set_opt_good, string(buff)); - printf("Here %s:%d\n", __FUNCTION__, __LINE__); } EXPECT_EQ(0, service.send_recv(EVENT_EXIT)); - printf("Here %s:%d\n", __FUNCTION__, __LINE__); service.close_service(); From 2820bcfcefc64146b4997968114f968895bba05b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 16 Aug 2022 22:48:07 +0000 Subject: [PATCH 129/137] update & review updates --- src/sonic-eventd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/Makefile b/src/sonic-eventd/Makefile index c6559d926792..6493a732312a 100644 --- a/src/sonic-eventd/Makefile +++ b/src/sonic-eventd/Makefile @@ -57,7 +57,7 @@ eventd-tests: $(TEST_OBJS) @echo 'Finished running tests' @echo ' ' -xxrsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS) +rsyslog-plugin-tests: $(RSYSLOG-PLUGIN-TEST_OBJS) @echo 'BUILDING target: $@' @echo 'Invoking G++ Linker' $(CC) $(LDFLAGS) -o $(RSYSLOG-PLUGIN_TEST) $(RSYSLOG-PLUGIN-TEST_OBJS) $(LIBS) $(TEST_LIBS) From 4e93440c1e8642ff137e933955e896499085895c Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 17:07:00 +0000 Subject: [PATCH 130/137] udpate heartbeat handling --- src/sonic-eventd/src/eventd.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 0a5f129b4663..f27f0eb00128 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -109,8 +109,24 @@ void stats_collector::set_heartbeat_interval(int val) { if (val > 0) { - m_heartbeats_interval_cnt = (val / STATS_HEARTBEAT_MIN); + /* Round to highest possible multiples of MIN */ + m_heartbeats_interval_cnt = + (((val * 1000) + STATS_HEARTBEAT_MIN - 1) / STATS_HEARTBEAT_MIN); } + else if (val == 0) { + /* Least possible */ + m_heartbeats_interval_cnt = 1; + } + else if (val == -1) { + /* Turn off heartbeat */ + m_heartbeats_interval_cnt = 0; + SWSS_LOG_INFO("Heartbeat turned OFF"); + } + /* Any other value is ignored as invalid */ + + SWSS_LOG_INFO("Set heartbeat: val=%d secs cnt=%d min=%d ms final=%d secs", + val, m_heartbeats_interval_cnt, STATS_HEARTBEAT_MIN, + (m_heartbeats_interval_cnt * STATS_HEARTBEAT_MIN / 1000)); } @@ -239,7 +255,8 @@ stats_collector::run_collector() "event_receive failed with rc=%d; stats:published(%lu)", rc, m_lst_counters[INDEX_COUNTERS_EVENTS_PUBLISHED]); } - if (!m_pause_heartbeat && ++hb_cntr >= m_heartbeats_interval_cnt) { + if (!m_pause_heartbeat && (m_heartbeats_interval_cnt > 0) && + ++hb_cntr >= m_heartbeats_interval_cnt) { rc = event_publish(pub_handle, EVENTD_HEARTBEAT_TAG); if (rc != 0) { SWSS_LOG_ERROR("Failed to publish heartbeat rc=%d", rc); From f5f496bf0c1d4f7c54f85f2ce07a5406451fcc5a Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 17:13:40 +0000 Subject: [PATCH 131/137] syntax --- src/sonic-eventd/src/eventd.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sonic-eventd/src/eventd.h b/src/sonic-eventd/src/eventd.h index 597ab24a2622..8411223b35be 100644 --- a/src/sonic-eventd/src/eventd.h +++ b/src/sonic-eventd/src/eventd.h @@ -4,6 +4,7 @@ #include "table.h" #include "events_service.h" #include "events.h" +#include "events_wrap.h" #define ARRAY_SIZE(l) (sizeof(l)/sizeof((l)[0])) From 3c4f35bfbb692849e89e834c530e20bf09d314dc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 17:19:35 +0000 Subject: [PATCH 132/137] syntax --- src/sonic-eventd/src/eventd.cpp | 2 +- src/sonic-eventd/tests/eventd_ut.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index f27f0eb00128..6f88726e30e6 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -133,7 +133,7 @@ stats_collector::set_heartbeat_interval(int val) int stats_collector::get_heartbeat_interval() { - return m_heartbeats_interval_cnt * STATS_HEARTBEAT_MIN; + return m_heartbeats_interval_cnt * STATS_HEARTBEAT_MIN / 1000; } int diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 8dbcfc3f748c..6a8e62f2e879 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -675,8 +675,7 @@ TEST(eventd, service) { string set_opt_bad("{\"HEARTBEAT_INTERVAL\": 2000, \"OFFLINE_CACHE_SIZE\": 500}"); - /* NOTE: 1800 is multiple of STATS_HEARTBEAT_MIN */ - string set_opt_good("{\"HEARTBEAT_INTERVAL\":1800}"); + string set_opt_good("{\"HEARTBEAT_INTERVAL\":3}"); char buff[100]; buff[0] = 0; From 633d7fe86451bfae50a5989a48175c14136453eb Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 17:22:54 +0000 Subject: [PATCH 133/137] syntax --- src/sonic-eventd/tests/eventd_ut.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-eventd/tests/eventd_ut.cpp b/src/sonic-eventd/tests/eventd_ut.cpp index 6a8e62f2e879..399255edb2b8 100644 --- a/src/sonic-eventd/tests/eventd_ut.cpp +++ b/src/sonic-eventd/tests/eventd_ut.cpp @@ -675,7 +675,7 @@ TEST(eventd, service) { string set_opt_bad("{\"HEARTBEAT_INTERVAL\": 2000, \"OFFLINE_CACHE_SIZE\": 500}"); - string set_opt_good("{\"HEARTBEAT_INTERVAL\":3}"); + string set_opt_good("{\"HEARTBEAT_INTERVAL\":5}"); char buff[100]; buff[0] = 0; From a411ed9a0e6b67eba6aca2680b94122773b108bc Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 17:37:57 +0000 Subject: [PATCH 134/137] syntax --- src/sonic-eventd/src/eventd.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 6f88726e30e6..714196533047 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -38,7 +38,7 @@ using namespace swss; /* Sock read timeout in milliseconds, to enable look for control signals */ #define CAPTURE_SOCK_TIMEOUT 800 -#define HEARTBEAT_INTERVAL 2000 /* Default: 2 seconds */ +#define HEARTBEAT_INTERVAL_SECS 2 /* Default: 2 seconds */ /* Source & tag for heartbeat events */ #define EVENTD_PUBLISHER_SOURCE "sonic-events-eventd" @@ -96,8 +96,9 @@ eventd_proxy::run() stats_collector::stats_collector() : m_shutdown(false), m_pause_heartbeat(false), m_heartbeats_published(0), - m_heartbeats_interval_cnt(HEARTBEAT_INTERVAL/STATS_HEARTBEAT_MIN) + m_heartbeats_interval_cnt(0) { + set_heartbeat_interval(HEARTBEAT_INTERVAL_SECS); for (int i=0; i < COUNTERS_EVENTS_TOTAL; ++i) { m_lst_counters[i] = 0; } From efececb4c7d56c5aa77e3a2d240cfb32b3d1718b Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 17:45:59 +0000 Subject: [PATCH 135/137] syntax --- src/sonic-eventd/src/eventd.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sonic-eventd/src/eventd.cpp b/src/sonic-eventd/src/eventd.cpp index 714196533047..1ff9dd8be20b 100644 --- a/src/sonic-eventd/src/eventd.cpp +++ b/src/sonic-eventd/src/eventd.cpp @@ -239,8 +239,7 @@ stats_collector::run_collector() rc = -1; stringstream ss; ss << e.what(); - SWSS_LOG_ERROR("Cache save event failed with %s", - ss.str().c_str()); + SWSS_LOG_ERROR("Receive event failed with %s", ss.str().c_str()); } if ((rc == 0) && (op.key != hb_key)) { From 1c5f5c1246fc9b24ede6ef27d21f1a94c964b265 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Wed, 17 Aug 2022 19:55:08 +0000 Subject: [PATCH 136/137] reset submod --- src/sonic-swss-common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sonic-swss-common b/src/sonic-swss-common index ecc13b26f70c..7e8d47cd635c 160000 --- a/src/sonic-swss-common +++ b/src/sonic-swss-common @@ -1 +1 @@ -Subproject commit ecc13b26f70c22812eda4c03ddcc063ed800d8b7 +Subproject commit 7e8d47cd635c4da3533d4dd3aee64f485fe91e62 From 6ee154905960859515524c782b506317dbe8acc4 Mon Sep 17 00:00:00 2001 From: Renuka Manavalan Date: Tue, 30 Aug 2022 23:15:32 +0000 Subject: [PATCH 137/137] Added to sonic.target --- files/build_templates/eventd.service.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/eventd.service.j2 b/files/build_templates/eventd.service.j2 index 1aaedefd1227..0ad7f52ee83d 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=multi-user.target +WantedBy=sonic.target