diff --git a/orchagent/main.cpp b/orchagent/main.cpp index d50508f6ce..5dfc124d5d 100644 --- a/orchagent/main.cpp +++ b/orchagent/main.cpp @@ -73,7 +73,7 @@ uint32_t create_switch_timeout = 0; void usage() { - cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size] [-q zmq_server_address] [-c mode] [-t create_switch_timeout] [-v VRF]" << endl; + cout << "usage: orchagent [-h] [-r record_type] [-d record_location] [-f swss_rec_filename] [-j sairedis_rec_filename] [-b batch_size] [-m MAC] [-i INST_ID] [-s] [-z mode] [-k bulk_size] [-q zmq_server_address] [-c mode] [-t create_switch_timeout] [-v VRF] [-I heart_beat_interval]" << endl; cout << " -h: display this message" << endl; cout << " -r record_type: record orchagent logs with type (default 3)" << endl; cout << " Bit 0: sairedis.rec, Bit 1: swss.rec, Bit 2: responsepublisher.rec. For example:" << endl; @@ -95,6 +95,7 @@ void usage() cout << " -c counter mode (traditional|asic_db), default: asic_db" << endl; cout << " -t Override create switch timeout, in sec" << endl; cout << " -v vrf: VRF name (default empty)" << endl; + cout << " -I heart_beat_interval: Heart beat interval in millisecond (default 10)" << endl; } void sighup_handler(int signo) @@ -350,7 +351,7 @@ int main(int argc, char **argv) string responsepublisher_rec_filename = Recorder::RESPPUB_FNAME; int record_type = 3; // Only swss and sairedis recordings enabled by default. - while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:q:c:t:v:")) != -1) + while ((opt = getopt(argc, argv, "b:m:r:f:j:d:i:hsz:k:q:c:t:v:I:")) != -1) { switch (opt) { @@ -450,6 +451,12 @@ int main(int argc, char **argv) vrf = optarg; } break; + case 'I': + if (optarg) + { + g_heart_beat_interval = atoi(optarg); + } + break; default: /* '?' */ exit(EXIT_FAILURE); } diff --git a/orchagent/orchdaemon.cpp b/orchagent/orchdaemon.cpp index 13ef89c487..1a43f21187 100644 --- a/orchagent/orchdaemon.cpp +++ b/orchagent/orchdaemon.cpp @@ -24,7 +24,8 @@ using namespace swss; #define APP_FABRIC_MONITOR_DATA_TABLE_NAME "FABRIC_MONITOR_TABLE" /* orchagent heart beat message interval */ -#define HEART_BEAT_INTERVAL_MSECS 10 * 1000 +#define HEART_BEAT_INTERVAL_MSECS_DEFAULT 10 * 1000 +long int g_heart_beat_interval = HEART_BEAT_INTERVAL_MSECS_DEFAULT; extern sai_switch_api_t* sai_switch_api; extern sai_object_id_t gSwitchId; @@ -1091,9 +1092,15 @@ void OrchDaemon::addOrchList(Orch *o) void OrchDaemon::heartBeat(std::chrono::time_point tcurrent) { + if (g_heart_beat_interval <= 0) + { + // disable heart beat feature when interval is 0 + return; + } + // output heart beat message to SYSLOG auto diff = std::chrono::duration_cast(tcurrent - m_lastHeartBeat); - if (diff.count() >= HEART_BEAT_INTERVAL_MSECS) + if (diff.count() >= g_heart_beat_interval) { m_lastHeartBeat = tcurrent; // output heart beat message to supervisord with 'PROCESS_COMMUNICATION_STDOUT' event: http://supervisord.org/events.html diff --git a/orchagent/orchdaemon.h b/orchagent/orchdaemon.h index 6a1c0b999a..63db44460b 100644 --- a/orchagent/orchdaemon.h +++ b/orchagent/orchdaemon.h @@ -56,6 +56,8 @@ using namespace swss; +extern long int g_heart_beat_interval; + class OrchDaemon { public: diff --git a/tests/test_zmq.py b/tests/test_zmq.py index 0f7e5359f3..6312c443d2 100644 --- a/tests/test_zmq.py +++ b/tests/test_zmq.py @@ -120,3 +120,37 @@ def test_vrf(self, dvs): dvs.runcmd("cp /usr/bin/orchagent.sh_vrf_ut_backup /usr/bin/orchagent.sh") dvs.stop_swss() dvs.start_swss() + + def test_heartbeat(self, dvs): + # Improve test code coverage, change orchagent to disable heartbeat + dvs.runcmd("cp /usr/bin/orchagent.sh /usr/bin/orchagent.sh_hb_ut_backup") + dvs.runcmd("sed -i.bak 's/\/usr\/bin\/orchagent /\/usr\/bin\/orchagent -I 0 /g' /usr/bin/orchagent.sh") + dvs.stop_swss() + dvs.start_swss() + + # wait orchagent start + time.sleep(3) + process_statue = dvs.runcmd("ps -ef") + zmq_logger.debug("Process status: {}".format(process_statue)) + + # revert change + dvs.runcmd("cp /usr/bin/orchagent.sh_hb_ut_backup /usr/bin/orchagent.sh") + dvs.stop_swss() + dvs.start_swss() + + def test_usage(self, dvs): + # Improve test code coverage, change orchagent to display usage + dvs.runcmd("cp /usr/bin/orchagent.sh /usr/bin/orchagent.sh_usage_ut_backup") + dvs.runcmd("sed -i.bak 's/\/usr\/bin\/orchagent /\/usr\/bin\/orchagent -h /g' /usr/bin/orchagent.sh") + dvs.stop_swss() + dvs.start_swss() + + # wait orchagent start + time.sleep(3) + process_statue = dvs.runcmd("ps -ef") + zmq_logger.debug("Process status: {}".format(process_statue)) + + # revert change + dvs.runcmd("cp /usr/bin/orchagent.sh_usage_ut_backup /usr/bin/orchagent.sh") + dvs.stop_swss() + dvs.start_swss()