Skip to content

Commit 5c70876

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 ae0c77c commit 5c70876

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));
@@ -255,32 +257,33 @@ static int in_winevtlog_init(struct flb_input_instance *in,
255257
ctx->session = session;
256258

257259
/* Set up total reading size threshold */
260+
maximum_threshold_size = flb_input_chunk_get_max_size(config) / 100 * MAXIMUM_THRESHOLD_PERCENT;
258261
if (ctx->total_size_threshold >= MINIMUM_THRESHOLD_SIZE &&
259-
ctx->total_size_threshold <= MAXIMUM_THRESHOLD_SIZE) {
260-
flb_utils_bytes_to_human_readable_size((size_t) ctx->total_size_threshold,
262+
ctx->total_size_threshold <= maximum_threshold_size) {
263+
flb_utils_bytes_to_human_readable_size(ctx->total_size_threshold,
261264
human_readable_size,
262265
sizeof(human_readable_size) - 1);
263266
flb_plg_debug(ctx->ins,
264267
"read limit per cycle is set up as %s",
265268
human_readable_size);
266269
}
267-
else if (ctx->total_size_threshold > MAXIMUM_THRESHOLD_SIZE) {
268-
flb_utils_bytes_to_human_readable_size((size_t) MAXIMUM_THRESHOLD_SIZE,
270+
else if (ctx->total_size_threshold > maximum_threshold_size) {
271+
flb_utils_bytes_to_human_readable_size(maximum_threshold_size,
269272
human_readable_size,
270273
sizeof(human_readable_size) - 1);
271274
flb_plg_warn(ctx->ins,
272275
"read limit per cycle cannot exceed %s. Set up to %s",
273276
human_readable_size, human_readable_size);
274-
ctx->total_size_threshold = (unsigned int) MAXIMUM_THRESHOLD_SIZE;
277+
ctx->total_size_threshold = maximum_threshold_size;
275278
}
276279
else if (ctx->total_size_threshold < MINIMUM_THRESHOLD_SIZE){
277-
flb_utils_bytes_to_human_readable_size((size_t) MINIMUM_THRESHOLD_SIZE,
280+
flb_utils_bytes_to_human_readable_size(MINIMUM_THRESHOLD_SIZE,
278281
human_readable_size,
279282
sizeof(human_readable_size) - 1);
280283
flb_plg_warn(ctx->ins,
281284
"read limit per cycle cannot under 1KiB. Set up to %s",
282285
human_readable_size);
283-
ctx->total_size_threshold = (unsigned int) MINIMUM_THRESHOLD_SIZE;
286+
ctx->total_size_threshold = MINIMUM_THRESHOLD_SIZE;
284287
}
285288

286289
/* Open channels */

0 commit comments

Comments
 (0)