Skip to content

Commit 96b4589

Browse files
Made the param configurable
Signed-off-by: Athish Pranav D <[email protected]>
1 parent 6114210 commit 96b4589

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
ctx->key_name = NULL;
106107
ctx->reserve_data = FLB_FALSE;
@@ -352,16 +353,14 @@ static int cb_parser_filter(const void *data, size_t bytes,
352353
out_buf = strdup(parsed_buf);
353354
out_size = parsed_size;
354355
}
355-
if (ctx->hash_value_field) {
356+
if (ctx->hash_value_field!=NULL) {
356357
char *new_buf = NULL;
357358
size_t new_size;
358359
int ret;
359-
flb_sds_t hash_key = flb_sds_create("parsed");
360360
ret = flb_msgpack_append_map_to_record(&new_buf, &new_size,
361-
hash_key,
361+
ctx->hash_value_field,
362362
out_buf, out_size,
363363
parsed_buf,parsed_size);
364-
flb_sds_destroy(hash_key);
365364
if ( ret != FLB_MAP_EXPAND_SUCCESS){
366365
flb_plg_error(ctx->ins, "cannot append parsed entry to record");
367366

@@ -470,9 +469,9 @@ static struct flb_config_map config_map[] = {
470469
"If false, all other original fields will be removed."
471470
},
472471
{
473-
FLB_CONFIG_MAP_BOOL, "Hash_Value_Field", "false",
472+
FLB_CONFIG_MAP_STR, "Hash_Value_Field", NULL,
474473
0, FLB_TRUE, offsetof(struct filter_parser_ctx, hash_value_field),
475-
"Stores the parsed values as a hash value in a field with key `parsed`. "
474+
"Stores the parsed values as a hash value in a field with key given. "
476475
},
477476
{
478477
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)