Skip to content

Commit 827dc18

Browse files
committed
in_winevtlog: use 'storage_max_chunk_size' to determine reading size threshold
Used configurable parameter 'storage.max_chunk_size' to calculate reading size threshold instead of fixed FLB_INPUT_CHUNK_FS_MAX_SIZE. Unnecessary type conversions were removed (all related variables are `size_t`). Introduced MAXIMUM_THRESHOLD_PERCENT to replace MAXIMUM_THRESHOLD_SIZE for calculation of threshold as percentage of user configured parameter. Signed-off-by: Castor Sky <csky57@gmail.com>
1 parent 4778796 commit 827dc18

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

plugins/in_winevtlog/in_winevtlog.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
#include <fluent-bit/flb_pack.h>
2424
#include <fluent-bit/flb_utils.h>
2525
#include <fluent-bit/flb_sqldb.h>
26+
#include <fluent-bit/flb_input_chunk.h>
2627
#include "winevtlog.h"
2728

2829
#define DEFAULT_INTERVAL_SEC 1
2930
#define DEFAULT_INTERVAL_NSEC 0
3031
#define DEFAULT_THRESHOLD_SIZE 0x7ffff /* Default reading buffer size */
3132
/* (512kib = 524287bytes) */
3233
#define MINIMUM_THRESHOLD_SIZE 0x0400 /* 1024 bytes */
33-
#define MAXIMUM_THRESHOLD_SIZE (FLB_INPUT_CHUNK_FS_MAX_SIZE - (1024 * 200))
34+
#define MAXIMUM_THRESHOLD_PERCENT 90
3435

3536
static int in_winevtlog_collect(struct flb_input_instance *ins,
3637
struct flb_config *config, void *in_context);
@@ -163,6 +164,7 @@ static int in_winevtlog_init(struct flb_input_instance *in,
163164
int status = WINEVTLOG_SESSION_CREATE_OK;
164165
double mult = 2.0;
165166
DWORD tmp_ms = 0;
167+
size_t maximum_threshold_size;
166168

167169
/* Initialize context */
168170
ctx = flb_calloc(1, sizeof(struct winevtlog_config));
@@ -273,32 +275,33 @@ static int in_winevtlog_init(struct flb_input_instance *in,
273275
ctx->session = session;
274276

275277
/* Set up total reading size threshold */
278+
maximum_threshold_size = flb_input_chunk_get_max_size(config) / 100 * MAXIMUM_THRESHOLD_PERCENT;
276279
if (ctx->total_size_threshold >= MINIMUM_THRESHOLD_SIZE &&
277-
ctx->total_size_threshold <= MAXIMUM_THRESHOLD_SIZE) {
278-
flb_utils_bytes_to_human_readable_size((size_t) ctx->total_size_threshold,
280+
ctx->total_size_threshold <= maximum_threshold_size) {
281+
flb_utils_bytes_to_human_readable_size(ctx->total_size_threshold,
279282
human_readable_size,
280283
sizeof(human_readable_size) - 1);
281284
flb_plg_debug(ctx->ins,
282285
"read limit per cycle is set up as %s",
283286
human_readable_size);
284287
}
285-
else if (ctx->total_size_threshold > MAXIMUM_THRESHOLD_SIZE) {
286-
flb_utils_bytes_to_human_readable_size((size_t) MAXIMUM_THRESHOLD_SIZE,
288+
else if (ctx->total_size_threshold > maximum_threshold_size) {
289+
flb_utils_bytes_to_human_readable_size(maximum_threshold_size,
287290
human_readable_size,
288291
sizeof(human_readable_size) - 1);
289292
flb_plg_warn(ctx->ins,
290293
"read limit per cycle cannot exceed %s. Set up to %s",
291294
human_readable_size, human_readable_size);
292-
ctx->total_size_threshold = (unsigned int) MAXIMUM_THRESHOLD_SIZE;
295+
ctx->total_size_threshold = maximum_threshold_size;
293296
}
294297
else if (ctx->total_size_threshold < MINIMUM_THRESHOLD_SIZE){
295-
flb_utils_bytes_to_human_readable_size((size_t) MINIMUM_THRESHOLD_SIZE,
298+
flb_utils_bytes_to_human_readable_size(MINIMUM_THRESHOLD_SIZE,
296299
human_readable_size,
297300
sizeof(human_readable_size) - 1);
298301
flb_plg_warn(ctx->ins,
299302
"read limit per cycle cannot under 1KiB. Set up to %s",
300303
human_readable_size);
301-
ctx->total_size_threshold = (unsigned int) MINIMUM_THRESHOLD_SIZE;
304+
ctx->total_size_threshold = MINIMUM_THRESHOLD_SIZE;
302305
}
303306

304307
/* Open channels */

0 commit comments

Comments
 (0)