From 4357348b96e801bad73e83bc7891cd4d08b18b24 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 17 Jun 2013 13:34:17 +0200 Subject: implement new ratelimiting mode for imjournal and make imjournal use it. The new mode is needed, as imjournal uses journal's timestamp as message generation time (which otherwise is when the message entered the system, and the ratelimiter uses this as current timestamp in order to save performance). It is debatable if imjournal is doing the right thing here. But it doesn't feel totally wrong. So let's safe that debate for later ;) --- runtime/ratelimit.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'runtime/ratelimit.c') diff --git a/runtime/ratelimit.c b/runtime/ratelimit.c index 6e1df3e2..f5c75c53 100644 --- a/runtime/ratelimit.c +++ b/runtime/ratelimit.c @@ -150,6 +150,15 @@ withinRatelimit(ratelimit_t *ratelimit, time_t tt) goto finalize_it; } + /* we primarily need "NoTimeCache" mode for imjournal, as it + * sets the message generation time to the journal timestamp. + * As such, we do not get a proper indication of the actual + * message rate. To prevent this, we need to query local + * system time ourselvs. + */ + if(ratelimit->bNoTimeCache) + tt = time(NULL); + assert(ratelimit->burst != 0); if(ratelimit->begin == 0) @@ -318,6 +327,12 @@ ratelimitSetThreadSafe(ratelimit_t *ratelimit) ratelimit->bThreadSafe = 1; pthread_mutex_init(&ratelimit->mut, NULL); } +void +ratelimitSetNoTimeCache(ratelimit_t *ratelimit) +{ + ratelimit->bNoTimeCache = 1; + pthread_mutex_init(&ratelimit->mut, NULL); +} /* Severity level determines which messages are subject to * ratelimiting. Default (no value set) is all messages. @@ -368,4 +383,3 @@ ratelimitModInit(void) finalize_it: RETiRet; } - -- cgit v1.2.3 From 1f6d402d50501bc612eb5041ed0674eb23432166 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 17 Jun 2013 14:18:23 +0200 Subject: imjournal fix: put ratelimiter destruction in wrong entry point No regression, this was in recently written, never-released code. --- runtime/ratelimit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/ratelimit.c') diff --git a/runtime/ratelimit.c b/runtime/ratelimit.c index f5c75c53..a808e04a 100644 --- a/runtime/ratelimit.c +++ b/runtime/ratelimit.c @@ -164,7 +164,7 @@ withinRatelimit(ratelimit_t *ratelimit, time_t tt) if(ratelimit->begin == 0) ratelimit->begin = tt; - /* resume if we go out of out time window */ + /* resume if we go out of time window */ if(tt > ratelimit->begin + ratelimit->interval) { ratelimit->begin = 0; ratelimit->done = 0; -- cgit v1.2.3