Skip to content

Commit e7b111b

Browse files
Made the param configurable
Signed-off-by: Athish Pranav D <[email protected]>
1 parent 7fdf7fe commit e7b111b

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

plugins/filter_parser/filter_parser.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static int configure(struct filter_parser_ctx *ctx,
101101
int ret;
102102
struct mk_list *head;
103103
struct flb_kv *kv;
104+
ctx->hash_value_field = NULL;
104105

105106
mk_list_init(&ctx->parsers);
106107

@@ -349,16 +350,14 @@ static int cb_parser_filter(const void *data, size_t bytes,
349350
out_buf = strdup(parsed_buf);
350351
out_size = parsed_size;
351352
}
352-
if (ctx->hash_value_field) {
353+
if (ctx->hash_value_field!=NULL) {
353354
char *new_buf = NULL;
354355
size_t new_size;
355356
int ret;
356-
flb_sds_t hash_key = flb_sds_create("parsed");
357357
ret = flb_msgpack_append_map_to_record(&new_buf, &new_size,
358-
hash_key,
358+
ctx->hash_value_field,
359359
out_buf, out_size,
360360
parsed_buf,parsed_size);
361-
flb_sds_destroy(hash_key);
362361
if ( ret != FLB_MAP_EXPAND_SUCCESS){
363362
flb_plg_error(ctx->ins, "cannot append parsed entry to record");
364363

@@ -467,9 +466,9 @@ static struct flb_config_map config_map[] = {
467466
"If false, all other original fields will be removed."
468467
},
469468
{
470-
FLB_CONFIG_MAP_BOOL, "Hash_Value_Field", "false",
469+
FLB_CONFIG_MAP_STR, "Hash_Value_Field", NULL,
471470
0, FLB_TRUE, offsetof(struct filter_parser_ctx, hash_value_field),
472-
"Stores the parsed values as a hash value in a field with key `parsed`. "
471+
"Stores the parsed values as a hash value in a field with key given. "
473472
},
474473
{
475474
FLB_CONFIG_MAP_DEPRECATED, "Unescape_key", NULL,

plugins/filter_parser/filter_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct filter_parser_ctx {
3535
int key_name_len;
3636
int reserve_data;
3737
int preserve_key;
38-
int hash_value_field;
38+
flb_sds_t hash_value_field;
3939
struct mk_list parsers;
4040
struct flb_filter_instance *ins;
4141
};

tests/runtime/filter_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ void flb_test_filter_parser_hash_value_field()
855855
"Match", "test",
856856
"Key_Name", "data",
857857
"Parser", "dummy_test",
858-
"Hash_Value_Field", "On",
858+
"Hash_Value_Field", "parsed",
859859
NULL);
860860
TEST_CHECK(ret == 0);
861861

0 commit comments

Comments
 (0)