Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add heartbeat interval parameter. #3458

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions orchagent/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 9 additions & 2 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1091,9 +1092,15 @@ void OrchDaemon::addOrchList(Orch *o)

void OrchDaemon::heartBeat(std::chrono::time_point<std::chrono::high_resolution_clock> 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<std::chrono::milliseconds>(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
Expand Down
2 changes: 2 additions & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

using namespace swss;

extern long int g_heart_beat_interval;

class OrchDaemon
{
public:
Expand Down
34 changes: 34 additions & 0 deletions tests/test_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading