Merge pull request #4743 from Cropi/ratelimit-fix

Avoid use of loadConf in favor of runConf in ratelimiting during runtime
This commit is contained in:
Rainer Gerhards 2021-12-14 13:25:12 +01:00 committed by GitHub
commit 4fea318bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 11 deletions

View File

@ -773,6 +773,7 @@ act_obj_add(fs_edge_t *const edge, const char *const name, const int is_file,
act->file_id[0] = '\0'; act->file_id[0] = '\0';
act->file_id_prev[0] = '\0'; act->file_id_prev[0] = '\0';
act->is_symlink = is_symlink; act->is_symlink = is_symlink;
act->ratelimiter = NULL;
if (source) { /* we are target of symlink */ if (source) { /* we are target of symlink */
CHKmalloc(act->source_name = strdup(source)); CHKmalloc(act->source_name = strdup(source));
} else { } else {
@ -800,6 +801,8 @@ act_obj_add(fs_edge_t *const edge, const char *const name, const int is_file,
finalize_it: finalize_it:
if(iRet != RS_RET_OK) { if(iRet != RS_RET_OK) {
if(act != NULL) { if(act != NULL) {
if (act->ratelimiter != NULL)
ratelimitDestruct(act->ratelimiter);
free(act->name); free(act->name);
free(act); free(act);
} }

View File

@ -343,6 +343,7 @@ CODESTARTbeginCnfLoad
pModConf->bKeepKernelStamp = 0; pModConf->bKeepKernelStamp = 0;
pModConf->iFacilIntMsg = klogFacilIntMsg(); pModConf->iFacilIntMsg = klogFacilIntMsg();
loadModConf->configSetViaV2Method = 0; loadModConf->configSetViaV2Method = 0;
pModConf->ratelimiter = NULL;
pModConf->ratelimitBurst = 10000; /* arbitrary high limit */ pModConf->ratelimitBurst = 10000; /* arbitrary high limit */
pModConf->ratelimitInterval = 0; /* off */ pModConf->ratelimitInterval = 0; /* off */
bLegacyCnfModGlobalsPermitted = 1; bLegacyCnfModGlobalsPermitted = 1;

View File

@ -1744,6 +1744,7 @@ addListner(modConfData_t __attribute__((unused)) *modConf, instanceConf_t *inst)
CHKmalloc(pSrv = calloc(1, sizeof(ptcpsrv_t))); CHKmalloc(pSrv = calloc(1, sizeof(ptcpsrv_t)));
pthread_mutex_init(&pSrv->mutSessLst, NULL); pthread_mutex_init(&pSrv->mutSessLst, NULL);
pSrv->ratelimiter = NULL;
pSrv->pSess = NULL; pSrv->pSess = NULL;
pSrv->pLstn = NULL; pSrv->pLstn = NULL;
pSrv->inst = inst; pSrv->inst = inst;

View File

@ -316,6 +316,7 @@ addListner(instanceConf_t *inst)
newlcnfinfo->sock = newSocks[iSrc]; newlcnfinfo->sock = newSocks[iSrc];
newlcnfinfo->pRuleset = inst->pBindRuleset; newlcnfinfo->pRuleset = inst->pBindRuleset;
newlcnfinfo->dfltTZ = inst->dfltTZ; newlcnfinfo->dfltTZ = inst->dfltTZ;
newlcnfinfo->ratelimiter = NULL;
/* query socket IPv4 vs IPv6 */ /* query socket IPv4 vs IPv6 */
sa.sin_family = 0; /* just to keep CLANG static analyzer happy! */ sa.sin_family = 0; /* just to keep CLANG static analyzer happy! */
if(getsockname(newlcnfinfo->sock, (struct sockaddr*) &sa, &salen) != 0) { if(getsockname(newlcnfinfo->sock, (struct sockaddr*) &sa, &salen) != 0) {
@ -338,6 +339,9 @@ addListner(instanceConf_t *inst)
inputname, bindName, port, suffix); inputname, bindName, port, suffix);
dispname[sizeof(dispname)-1] = '\0'; /* just to be on the save side... */ dispname[sizeof(dispname)-1] = '\0'; /* just to be on the save side... */
CHKiRet(ratelimitNew(&newlcnfinfo->ratelimiter, (char*)dispname, NULL)); CHKiRet(ratelimitNew(&newlcnfinfo->ratelimiter, (char*)dispname, NULL));
ratelimitSetLinuxLike(newlcnfinfo->ratelimiter, inst->ratelimitInterval,
inst->ratelimitBurst);
ratelimitSetThreadSafe(newlcnfinfo->ratelimiter);
if(inst->bAppendPortToInpname) { if(inst->bAppendPortToInpname) {
snprintf((char*)inpnameBuf, sizeof(inpnameBuf), "%s%s", snprintf((char*)inpnameBuf, sizeof(inpnameBuf), "%s%s",
inputname, port); inputname, port);
@ -348,9 +352,6 @@ addListner(instanceConf_t *inst)
CHKiRet(prop.SetString(newlcnfinfo->pInputName, CHKiRet(prop.SetString(newlcnfinfo->pInputName,
inputname, ustrlen(inputname))); inputname, ustrlen(inputname)));
CHKiRet(prop.ConstructFinalize(newlcnfinfo->pInputName)); CHKiRet(prop.ConstructFinalize(newlcnfinfo->pInputName));
ratelimitSetLinuxLike(newlcnfinfo->ratelimiter, inst->ratelimitInterval,
inst->ratelimitBurst);
ratelimitSetThreadSafe(newlcnfinfo->ratelimiter);
/* support statistics gathering */ /* support statistics gathering */
CHKiRet(statsobj.Construct(&(newlcnfinfo->stats))); CHKiRet(statsobj.Construct(&(newlcnfinfo->stats)));
CHKiRet(statsobj.SetName(newlcnfinfo->stats, dispname)); CHKiRet(statsobj.SetName(newlcnfinfo->stats, dispname));

View File

@ -239,7 +239,7 @@ ratelimitMsg(ratelimit_t *__restrict__ const ratelimit, smsg_t *pMsg, smsg_t **p
*ppRepMsg = NULL; *ppRepMsg = NULL;
if(ratelimit->bReduceRepeatMsgs || ratelimit->severity > 0) { if(runConf->globals.bReduceRepeatMsgs || ratelimit->severity > 0) {
/* consider early parsing only if really needed */ /* consider early parsing only if really needed */
if((pMsg->msgFlags & NEEDS_PARSING) != 0) { if((pMsg->msgFlags & NEEDS_PARSING) != 0) {
if((localRet = parser.ParseMsg(pMsg)) != RS_RET_OK) { if((localRet = parser.ParseMsg(pMsg)) != RS_RET_OK) {
@ -261,7 +261,7 @@ ratelimitMsg(ratelimit_t *__restrict__ const ratelimit, smsg_t *pMsg, smsg_t **p
ABORT_FINALIZE(RS_RET_DISCARDMSG); ABORT_FINALIZE(RS_RET_DISCARDMSG);
} }
} }
if(ratelimit->bReduceRepeatMsgs) { if(runConf->globals.bReduceRepeatMsgs) {
CHKiRet(doLastMessageRepeatedNTimes(ratelimit, pMsg, ppRepMsg)); CHKiRet(doLastMessageRepeatedNTimes(ratelimit, pMsg, ppRepMsg));
} }
finalize_it: finalize_it:
@ -276,7 +276,7 @@ finalize_it:
int int
ratelimitChecked(ratelimit_t *ratelimit) ratelimitChecked(ratelimit_t *ratelimit)
{ {
return ratelimit->interval || ratelimit->bReduceRepeatMsgs; return ratelimit->interval || runConf->globals.bReduceRepeatMsgs;
} }
@ -349,10 +349,7 @@ ratelimitNew(ratelimit_t **ppThis, const char *modname, const char *dynname)
namebuf[sizeof(namebuf)-1] = '\0'; /* to be on safe side */ namebuf[sizeof(namebuf)-1] = '\0'; /* to be on safe side */
pThis->name = strdup(namebuf); pThis->name = strdup(namebuf);
} }
/* pThis->severity == 0 - all messages are ratelimited */ DBGPRINTF("ratelimit:%s:new ratelimiter\n", pThis->name);
pThis->bReduceRepeatMsgs = loadConf->globals.bReduceRepeatMsgs;
DBGPRINTF("ratelimit:%s:new ratelimiter:bReduceRepeatMsgs %d\n",
pThis->name, pThis->bReduceRepeatMsgs);
*ppThis = pThis; *ppThis = pThis;
finalize_it: finalize_it:
RETiRet; RETiRet;

View File

@ -31,7 +31,6 @@ struct ratelimit_s {
unsigned missed; unsigned missed;
time_t begin; time_t begin;
/* support for "last message repeated n times */ /* support for "last message repeated n times */
int bReduceRepeatMsgs; /**< shall we do "last message repeated n times" processing? */
unsigned nsupp; /**< nbr of msgs suppressed */ unsigned nsupp; /**< nbr of msgs suppressed */
smsg_t *pMsg; smsg_t *pMsg;
sbool bThreadSafe; /**< do we need to operate in Thread-Safe mode? */ sbool bThreadSafe; /**< do we need to operate in Thread-Safe mode? */

View File

@ -3,6 +3,7 @@
# This file is part of the rsyslog project, released under ASL 2.0 # This file is part of the rsyslog project, released under ASL 2.0
. ${srcdir:=.}/diag.sh init . ${srcdir:=.}/diag.sh init
export NUMMESSAGES=50000 export NUMMESSAGES=50000
export TB_TEST_MAX_RUNTIME=1500
export QUEUE_EMPTY_CHECK_FUNC=wait_seq_check export QUEUE_EMPTY_CHECK_FUNC=wait_seq_check
generate_conf generate_conf
add_conf ' add_conf '

View File

@ -1,5 +1,6 @@
#!/bin/bash #!/bin/bash
# This file is part of the rsyslog project, released under ASL 2.0 # This file is part of the rsyslog project, released under ASL 2.0
export USE_VALGRIND="YES" export USE_VALGRIND="YES"
export TB_TEST_MAX_RUNTIME=1500
export NUMMESSAGES=10000 # reduce for slower valgrind run export NUMMESSAGES=10000 # reduce for slower valgrind run
source ${srcdir:-.}/imtcp_conndrop_tls.sh source ${srcdir:-.}/imtcp_conndrop_tls.sh

View File

@ -1,3 +1,4 @@
#!/bin/bash #!/bin/bash
export USE_VALGRIND="YES" export USE_VALGRIND="YES"
export TB_TEST_MAX_RUNTIME=1500
source ${srcdir:-.}/rscript_http_request.sh source ${srcdir:-.}/rscript_http_request.sh