mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-15 10:30:40 +01:00
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:
commit
4fea318bcd
@ -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_prev[0] = '\0';
|
||||
act->is_symlink = is_symlink;
|
||||
act->ratelimiter = NULL;
|
||||
if (source) { /* we are target of symlink */
|
||||
CHKmalloc(act->source_name = strdup(source));
|
||||
} else {
|
||||
@ -800,6 +801,8 @@ act_obj_add(fs_edge_t *const edge, const char *const name, const int is_file,
|
||||
finalize_it:
|
||||
if(iRet != RS_RET_OK) {
|
||||
if(act != NULL) {
|
||||
if (act->ratelimiter != NULL)
|
||||
ratelimitDestruct(act->ratelimiter);
|
||||
free(act->name);
|
||||
free(act);
|
||||
}
|
||||
|
||||
@ -343,6 +343,7 @@ CODESTARTbeginCnfLoad
|
||||
pModConf->bKeepKernelStamp = 0;
|
||||
pModConf->iFacilIntMsg = klogFacilIntMsg();
|
||||
loadModConf->configSetViaV2Method = 0;
|
||||
pModConf->ratelimiter = NULL;
|
||||
pModConf->ratelimitBurst = 10000; /* arbitrary high limit */
|
||||
pModConf->ratelimitInterval = 0; /* off */
|
||||
bLegacyCnfModGlobalsPermitted = 1;
|
||||
|
||||
@ -1744,6 +1744,7 @@ addListner(modConfData_t __attribute__((unused)) *modConf, instanceConf_t *inst)
|
||||
|
||||
CHKmalloc(pSrv = calloc(1, sizeof(ptcpsrv_t)));
|
||||
pthread_mutex_init(&pSrv->mutSessLst, NULL);
|
||||
pSrv->ratelimiter = NULL;
|
||||
pSrv->pSess = NULL;
|
||||
pSrv->pLstn = NULL;
|
||||
pSrv->inst = inst;
|
||||
|
||||
@ -316,6 +316,7 @@ addListner(instanceConf_t *inst)
|
||||
newlcnfinfo->sock = newSocks[iSrc];
|
||||
newlcnfinfo->pRuleset = inst->pBindRuleset;
|
||||
newlcnfinfo->dfltTZ = inst->dfltTZ;
|
||||
newlcnfinfo->ratelimiter = NULL;
|
||||
/* query socket IPv4 vs IPv6 */
|
||||
sa.sin_family = 0; /* just to keep CLANG static analyzer happy! */
|
||||
if(getsockname(newlcnfinfo->sock, (struct sockaddr*) &sa, &salen) != 0) {
|
||||
@ -338,6 +339,9 @@ addListner(instanceConf_t *inst)
|
||||
inputname, bindName, port, suffix);
|
||||
dispname[sizeof(dispname)-1] = '\0'; /* just to be on the save side... */
|
||||
CHKiRet(ratelimitNew(&newlcnfinfo->ratelimiter, (char*)dispname, NULL));
|
||||
ratelimitSetLinuxLike(newlcnfinfo->ratelimiter, inst->ratelimitInterval,
|
||||
inst->ratelimitBurst);
|
||||
ratelimitSetThreadSafe(newlcnfinfo->ratelimiter);
|
||||
if(inst->bAppendPortToInpname) {
|
||||
snprintf((char*)inpnameBuf, sizeof(inpnameBuf), "%s%s",
|
||||
inputname, port);
|
||||
@ -348,9 +352,6 @@ addListner(instanceConf_t *inst)
|
||||
CHKiRet(prop.SetString(newlcnfinfo->pInputName,
|
||||
inputname, ustrlen(inputname)));
|
||||
CHKiRet(prop.ConstructFinalize(newlcnfinfo->pInputName));
|
||||
ratelimitSetLinuxLike(newlcnfinfo->ratelimiter, inst->ratelimitInterval,
|
||||
inst->ratelimitBurst);
|
||||
ratelimitSetThreadSafe(newlcnfinfo->ratelimiter);
|
||||
/* support statistics gathering */
|
||||
CHKiRet(statsobj.Construct(&(newlcnfinfo->stats)));
|
||||
CHKiRet(statsobj.SetName(newlcnfinfo->stats, dispname));
|
||||
|
||||
@ -239,7 +239,7 @@ ratelimitMsg(ratelimit_t *__restrict__ const ratelimit, smsg_t *pMsg, smsg_t **p
|
||||
|
||||
*ppRepMsg = NULL;
|
||||
|
||||
if(ratelimit->bReduceRepeatMsgs || ratelimit->severity > 0) {
|
||||
if(runConf->globals.bReduceRepeatMsgs || ratelimit->severity > 0) {
|
||||
/* consider early parsing only if really needed */
|
||||
if((pMsg->msgFlags & NEEDS_PARSING) != 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if(ratelimit->bReduceRepeatMsgs) {
|
||||
if(runConf->globals.bReduceRepeatMsgs) {
|
||||
CHKiRet(doLastMessageRepeatedNTimes(ratelimit, pMsg, ppRepMsg));
|
||||
}
|
||||
finalize_it:
|
||||
@ -276,7 +276,7 @@ finalize_it:
|
||||
int
|
||||
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 */
|
||||
pThis->name = strdup(namebuf);
|
||||
}
|
||||
/* pThis->severity == 0 - all messages are ratelimited */
|
||||
pThis->bReduceRepeatMsgs = loadConf->globals.bReduceRepeatMsgs;
|
||||
DBGPRINTF("ratelimit:%s:new ratelimiter:bReduceRepeatMsgs %d\n",
|
||||
pThis->name, pThis->bReduceRepeatMsgs);
|
||||
DBGPRINTF("ratelimit:%s:new ratelimiter\n", pThis->name);
|
||||
*ppThis = pThis;
|
||||
finalize_it:
|
||||
RETiRet;
|
||||
|
||||
@ -31,7 +31,6 @@ struct ratelimit_s {
|
||||
unsigned missed;
|
||||
time_t begin;
|
||||
/* support for "last message repeated n times */
|
||||
int bReduceRepeatMsgs; /**< shall we do "last message repeated n times" processing? */
|
||||
unsigned nsupp; /**< nbr of msgs suppressed */
|
||||
smsg_t *pMsg;
|
||||
sbool bThreadSafe; /**< do we need to operate in Thread-Safe mode? */
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
# This file is part of the rsyslog project, released under ASL 2.0
|
||||
. ${srcdir:=.}/diag.sh init
|
||||
export NUMMESSAGES=50000
|
||||
export TB_TEST_MAX_RUNTIME=1500
|
||||
export QUEUE_EMPTY_CHECK_FUNC=wait_seq_check
|
||||
generate_conf
|
||||
add_conf '
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#!/bin/bash
|
||||
# This file is part of the rsyslog project, released under ASL 2.0
|
||||
export USE_VALGRIND="YES"
|
||||
export TB_TEST_MAX_RUNTIME=1500
|
||||
export NUMMESSAGES=10000 # reduce for slower valgrind run
|
||||
source ${srcdir:-.}/imtcp_conndrop_tls.sh
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
export USE_VALGRIND="YES"
|
||||
export TB_TEST_MAX_RUNTIME=1500
|
||||
source ${srcdir:-.}/rscript_http_request.sh
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user