Skip to content

Commit c54abf0

Browse files
cosmo0920edsiper
authored andcommitted
out_chronicle: Fix log_key detection mechanism
The previous detection mechanism is too tight to handle missing log_key. Instead, we loosen the mechanism that permits to traverse entrie the record. And failing for just missing of anhy of the keys in a record map. Signed-off-by: Hiroshi Hatake <[email protected]>
1 parent f056222 commit c54abf0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

plugins/out_chronicle/chronicle.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static flb_sds_t flb_pack_msgpack_extract_log_key(void *out_context, uint64_t by
518518
int i;
519519
int map_size;
520520
int check = FLB_FALSE;
521-
int log_key_missing = 0;
521+
int log_key_found = FLB_FALSE;
522522
int ret;
523523
struct flb_chronicle *ctx = out_context;
524524
char *val_buf;
@@ -544,6 +544,7 @@ static flb_sds_t flb_pack_msgpack_extract_log_key(void *out_context, uint64_t by
544544
map = *log_event.body;
545545

546546
if (map.type != MSGPACK_OBJECT_MAP) {
547+
flb_free(val_buf);
547548
return NULL;
548549
}
549550

@@ -567,6 +568,7 @@ static flb_sds_t flb_pack_msgpack_extract_log_key(void *out_context, uint64_t by
567568

568569
if (check == FLB_TRUE) {
569570
if (strncmp(ctx->log_key, key_str, key_str_size) == 0) {
571+
log_key_found = FLB_TRUE;
570572

571573
/*
572574
* Copy contents of value into buffer. Necessary to copy
@@ -599,14 +601,12 @@ static flb_sds_t flb_pack_msgpack_extract_log_key(void *out_context, uint64_t by
599601
break;
600602
}
601603
}
602-
603-
/* If log_key was not found in the current record, mark log key as missing */
604-
log_key_missing++;
605604
}
606605

607-
if (log_key_missing > 0) {
608-
flb_plg_error(ctx->ins, "Could not find log_key '%s' in %d records",
609-
ctx->log_key, log_key_missing);
606+
/* Check the flag *after* the loop. If it's still false, the key was never found. */
607+
if (log_key_found == FLB_FALSE) {
608+
flb_plg_error(ctx->ins, "Could not find log_key '%s' in record",
609+
ctx->log_key);
610610
}
611611

612612
/* If nothing was read, destroy buffer */

0 commit comments

Comments
 (0)