summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-06-17 13:34:17 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-06-17 13:34:17 +0200
commit4357348b96e801bad73e83bc7891cd4d08b18b24 (patch)
tree0ae64f857f5248cc354d901acf866d92e7f2e15e
parent9ac7e207705a585bb4d11f4058ff7f640158c8d3 (diff)
downloadrsyslog-4357348b96e801bad73e83bc7891cd4d08b18b24.tar.gz
rsyslog-4357348b96e801bad73e83bc7891cd4d08b18b24.tar.bz2
rsyslog-4357348b96e801bad73e83bc7891cd4d08b18b24.zip
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 ;)
-rwxr-xr-xplugins/imjournal/imjournal.c3
-rw-r--r--runtime/ratelimit.c16
-rw-r--r--runtime/ratelimit.h2
3 files changed, 20 insertions, 1 deletions
diff --git a/plugins/imjournal/imjournal.c b/plugins/imjournal/imjournal.c
index 7f6c31d6..dcae5354 100755
--- a/plugins/imjournal/imjournal.c
+++ b/plugins/imjournal/imjournal.c
@@ -515,7 +515,10 @@ finalize_it:
BEGINrunInput
CODESTARTrunInput
CHKiRet(ratelimitNew(&ratelimiter, "imjournal", NULL));
+ dbgprintf("imjournal: ratelimiting burst %d, interval %d\n", cs.ratelimitBurst,
+ cs.ratelimitInterval);
ratelimitSetLinuxLike(ratelimiter, cs.ratelimitInterval, cs.ratelimitBurst);
+ ratelimitSetNoTimeCache(ratelimiter);
if (cs.stateFile) {
CHKiRet(loadJournalState());
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;
}
-
diff --git a/runtime/ratelimit.h b/runtime/ratelimit.h
index a058b069..563777fd 100644
--- a/runtime/ratelimit.h
+++ b/runtime/ratelimit.h
@@ -35,6 +35,7 @@ struct ratelimit_s {
unsigned nsupp; /**< nbr of msgs suppressed */
msg_t *pMsg;
sbool bThreadSafe; /**< do we need to operate in Thread-Safe mode? */
+ sbool bNoTimeCache; /**< if we shall not used cached reception time */
pthread_mutex_t mut; /**< mutex if thread-safe operation desired */
};
@@ -42,6 +43,7 @@ struct ratelimit_s {
rsRetVal ratelimitNew(ratelimit_t **ppThis, char *modname, char *dynname);
void ratelimitSetThreadSafe(ratelimit_t *ratelimit);
void ratelimitSetLinuxLike(ratelimit_t *ratelimit, unsigned short interval, unsigned short burst);
+void ratelimitSetNoTimeCache(ratelimit_t *ratelimit);
void ratelimitSetSeverity(ratelimit_t *ratelimit, intTiny severity);
rsRetVal ratelimitMsg(ratelimit_t *ratelimit, msg_t *pMsg, msg_t **ppRep);
rsRetVal ratelimitAddMsg(ratelimit_t *ratelimit, multi_submit_t *pMultiSub, msg_t *pMsg);