From b9b61bc037aed4d3d0fac6b0b4d88bc78b7b485d Mon Sep 17 00:00:00 2001 From: Neil McKee Date: Sat, 3 Jun 2023 15:29:49 -0700 Subject: [PATCH] mod_sonic wait for SYSTEM_READY with timeout (default=180S) --- hsflowd.spec | 2 +- src/Linux/hsflowconfig.c | 4 ++++ src/Linux/hsflowd.c | 1 + src/Linux/hsflowd.h | 2 ++ src/Linux/hsflowtokens.h | 1 + src/Linux/mod_sonic.c | 23 +++++++++++++++++++---- 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/hsflowd.spec b/hsflowd.spec index c1c28cf..5c5634c 100644 --- a/hsflowd.spec +++ b/hsflowd.spec @@ -1,7 +1,7 @@ Summary: host sFlow daemon Name: hsflowd Version: 2.0.51 -Release: 25 +Release: 26 License: http://sflow.net/license.html Group: Applications/Internet URL: http://sflow.net diff --git a/src/Linux/hsflowconfig.c b/src/Linux/hsflowconfig.c index a51d1f7..187fc3e 100644 --- a/src/Linux/hsflowconfig.c +++ b/src/Linux/hsflowconfig.c @@ -1431,6 +1431,7 @@ extern "C" { if((tok = expectToken(sp, tok, HSPTOKEN_STARTOBJ)) == NULL) return NO; sp->sonic.sonic = YES; sp->sonic.unixsock = YES; + sp->sonic.waitReady = HSP_SONIC_DEFAULT_WAITREADY_SECS; level[++depth] = HSPOBJ_SONIC; break; case HSPTOKEN_DBUS: @@ -1931,6 +1932,9 @@ extern "C" { case HSPTOKEN_DBCONFIG: if((tok = expectString(sp, tok, &sp->sonic.dbconfig, "path")) == NULL) return NO; break; + case HSPTOKEN_WAITREADY: + if((tok = expectInteger32(sp, tok, &sp->sonic.waitReady, 0, 0xFFFFFFFF)) == NULL) return NO; + break; default: unexpectedToken(sp, tok, level[depth]); return NO; diff --git a/src/Linux/hsflowd.c b/src/Linux/hsflowd.c index 5404903..f7bd9a0 100644 --- a/src/Linux/hsflowd.c +++ b/src/Linux/hsflowd.c @@ -2069,6 +2069,7 @@ extern "C" { sp->sonic.unixsock = YES; sp->sonic.setIfAlias = YES; sp->sonic.setIfName = YES; + sp->sonic.waitReady = HSP_SONIC_DEFAULT_WAITREADY_SECS; sp->psample.psample = YES; sp->psample.ingress = YES; sp->psample.egress = YES; diff --git a/src/Linux/hsflowd.h b/src/Linux/hsflowd.h index 4c3773c..255e9dd 100644 --- a/src/Linux/hsflowd.h +++ b/src/Linux/hsflowd.h @@ -607,6 +607,8 @@ extern "C" { bool setIfAlias; bool setIfName; char *dbconfig; + uint32_t waitReady; // seconds +#define HSP_SONIC_DEFAULT_WAITREADY_SECS 180 } sonic; struct { bool nvml; diff --git a/src/Linux/hsflowtokens.h b/src/Linux/hsflowtokens.h index 2ddcade..892ea90 100644 --- a/src/Linux/hsflowtokens.h +++ b/src/Linux/hsflowtokens.h @@ -89,3 +89,4 @@ HSPTOKEN_DATA( HSPTOKEN_UNIXSOCK, "unixsock", HSPTOKENTYPE_ATTRIB, NULL) HSPTOKEN_DATA( HSPTOKEN_INGRESS, "ingress", HSPTOKENTYPE_ATTRIB, NULL) HSPTOKEN_DATA( HSPTOKEN_EGRESS, "egress", HSPTOKENTYPE_ATTRIB, NULL) HSPTOKEN_DATA( HSPTOKEN_K8S, "k8s", HSPTOKENTYPE_OBJ, NULL) +HSPTOKEN_DATA( HSPTOKEN_WAITREADY, "waitReady", HSPTOKENTYPE_ATTRIB, NULL) diff --git a/src/Linux/mod_sonic.c b/src/Linux/mod_sonic.c index 517a60b..a1e3694 100644 --- a/src/Linux/mod_sonic.c +++ b/src/Linux/mod_sonic.c @@ -139,6 +139,7 @@ extern "C" { bool changedPortPriority:1; u_char actorSystemMAC[8]; uint32_t localAS; + time_t waitReadyStart; bool system_ready; bool sflow_enable; uint32_t sflow_polling; @@ -673,8 +674,10 @@ extern "C" { myDebug(1, "sonic db_connectCB: status= %d", status); if(status == REDIS_OK) { db->connected = YES; - if(db_allConnected(db->mod)) + if(db_allConnected(db->mod)) { mdata->state = HSP_SONIC_STATE_WAIT_READY; + mdata->waitReadyStart = mdata->pollBus->now.tv_sec; + } } } @@ -1234,6 +1237,7 @@ extern "C" { HSPSonicDBClient *db = (HSPSonicDBClient *)ctx->ev.data; EVMod *mod = db->mod; HSP *sp = (HSP *)EVROOTDATA(mod); + HSP_mod_SONIC *mdata = (HSP_mod_SONIC *)mod->data; redisReply *reply = (redisReply *)magic; HSPSonicPort *prt = (HSPSonicPort *)req_magic; @@ -1299,7 +1303,7 @@ extern "C" { | HSP_ETCTR_OPER | HSP_ETCTR_ADMIN; accumulateNioCounters(sp, adaptor, &prt->ctrs, &prt->et_ctrs); - nio->last_update = sp->pollBus->now.tv_sec; + nio->last_update = mdata->pollBus->now.tv_sec; } } } @@ -1862,6 +1866,7 @@ extern "C" { */ static void evt_tick(EVMod *mod, EVEvent *evt, void *data, size_t dataLen) { + HSP *sp = (HSP *)EVROOTDATA(mod); HSP_mod_SONIC *mdata = (HSP_mod_SONIC *)mod->data; switch(mdata->state) { @@ -1879,10 +1884,20 @@ extern "C" { db_connect(mod); break; case HSP_SONIC_STATE_WAIT_READY: - db_getSystemReady(mod); + // all dbs connected - wait for SYSTEM_READY + { + time_t waiting = mdata->pollBus->now.tv_sec - mdata->waitReadyStart; + if(waiting < sp->sonic.waitReady) { + db_getSystemReady(mod); + } + else { + myDebug(1, "sonic: waitReady timeout after %u seconds", waiting); + mdata->state = HSP_SONIC_STATE_CONNECTED; + } + } break; case HSP_SONIC_STATE_CONNECTED: - // connected - learn config + // connected and ready - learn config db_getMeta(mod); dbEvt_subscribe(mod); // the next step is to read the starting agent/polling/collector