]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
redis: ensure a dump per second
authorEric Leblond <eric@regit.org>
Thu, 23 Jan 2020 12:30:29 +0000 (13:30 +0100)
committerVictor Julien <victor@inliniac.net>
Sat, 6 Jun 2020 12:32:02 +0000 (14:32 +0200)
In sync mode, Suricata was waiting to have batch size alerts before
logging them. This was introducing delay in some configuration with
low traffic.

src/util-log-redis.c
src/util-log-redis.h

index 4c4d37f2e9177e2cbbed735489bc555e1c137a7e..a145e4f564bfb3447399ce227b1fc2fb73e1e5c2 100644 (file)
@@ -67,6 +67,7 @@ static SCLogRedisContext *SCLogRedisContextAlloc(void)
     ctx->async   = NULL;
 #endif
     ctx->batch_count = 0;
+    ctx->last_push = 0;
     ctx->tried = 0;
 
     return ctx;
@@ -92,6 +93,7 @@ static SCLogRedisContext *SCLogRedisContextAsyncAlloc(void)
     ctx->ev_base = NULL;
     ctx->connected = 0;
     ctx->batch_count = 0;
+    ctx->last_push = 0;
     ctx->tried = 0;
 
     return ctx;
@@ -347,11 +349,14 @@ static int SCLogRedisWriteSync(LogFileCtx *file_ctx, const char *string)
                 file_ctx->redis_setup.command,
                 file_ctx->redis_setup.key,
                 string);
-        if (ctx->batch_count == file_ctx->redis_setup.batch_size) {
+        time_t now = time(NULL);
+        if ((ctx->batch_count == file_ctx->redis_setup.batch_size) || (ctx->last_push < now)) {
             redisReply *reply;
             int i;
+            int batch_size = ctx->batch_count;
             ctx->batch_count = 0;
-            for (i = 0; i <= file_ctx->redis_setup.batch_size; i++) {
+            ctx->last_push = now;
+            for (i = 0; i <= batch_size; i++) {
                 if (redisGetReply(redis, (void **)&reply) == REDIS_OK) {
                     freeReplyObject(reply);
                     ret = 0;
index 0153151ebaa1412ed1034f271aea85a3b978b406..ec4a4aff73c5ef6d54ad5a19ec2cb06c45277093 100644 (file)
@@ -55,6 +55,7 @@ typedef struct SCLogRedisContext_ {
 #endif /* HAVE_LIBEVENT */
     time_t tried;
     int  batch_count;
+    time_t last_push;
 } SCLogRedisContext;
 
 void SCLogRedisInit(void);