@@ -1299,6 +1299,83 @@ void flb_test_filter_parser_reserve_on_preserve_on()
12991299 test_ctx_destroy (ctx );
13001300}
13011301
1302+ void flb_test_filter_parser_nest_under_on ()
1303+ {
1304+ int ret ;
1305+ int bytes ;
1306+ char * p , * output , * expected ;
1307+ flb_ctx_t * ctx ;
1308+ int in_ffd ;
1309+ int out_ffd ;
1310+ int filter_ffd ;
1311+ struct flb_parser * parser ;
1312+
1313+ struct flb_lib_out_cb cb ;
1314+ cb .cb = callback_test ;
1315+ cb .data = NULL ;
1316+
1317+ clear_output ();
1318+
1319+ ctx = flb_create ();
1320+
1321+ /* Configure service */
1322+ flb_service_set (ctx , "Flush" , FLUSH_INTERVAL , "Grace" "1" , "Log_Level" , "debug" , NULL );
1323+
1324+ /* Input */
1325+ in_ffd = flb_input (ctx , (char * ) "lib" , NULL );
1326+ TEST_CHECK (in_ffd >= 0 );
1327+ flb_input_set (ctx , in_ffd ,
1328+ "Tag" , "test" ,
1329+ NULL );
1330+
1331+ /* Parser */
1332+ parser = flb_parser_create ("json" , "json" , NULL ,
1333+ FLB_FALSE ,
1334+ NULL , NULL , NULL , MK_FALSE , MK_TRUE , FLB_FALSE , FLB_FALSE ,
1335+ NULL , 0 , NULL , ctx -> config );
1336+ TEST_CHECK (parser != NULL );
1337+
1338+ /* Filter */
1339+ filter_ffd = flb_filter (ctx , (char * ) "parser" , NULL );
1340+ TEST_CHECK (filter_ffd >= 0 );
1341+ ret = flb_filter_set (ctx , filter_ffd ,
1342+ "Match" , "test" ,
1343+ "Key_Name" , "to_parse" ,
1344+ "Nest_Under" , "nest_key" ,
1345+ "Parser" , "json" ,
1346+ NULL );
1347+ TEST_CHECK (ret == 0 );
1348+
1349+ /* Output */
1350+ out_ffd = flb_output (ctx , (char * ) "lib" , & cb );
1351+ TEST_CHECK (out_ffd >= 0 );
1352+ flb_output_set (ctx , out_ffd ,
1353+ "Match" , "*" ,
1354+ "format" , "json" ,
1355+ NULL );
1356+
1357+ /* Start the engine */
1358+ ret = flb_start (ctx );
1359+ TEST_CHECK (ret == 0 );
1360+
1361+ /* Ingest data */
1362+ p = "[1,{\"hello\":\"world\",\"some_object\":{\"foo\":\"bar\"},\"to_parse\":\"{\\\"key\\\":\\\"value\\\",\\\"object\\\":{\\\"a\\\":\\\"b\\\"}}\"}]" ;
1363+ bytes = flb_lib_push (ctx , in_ffd , p , strlen (p ));
1364+ TEST_CHECK (bytes == strlen (p ));
1365+
1366+ wait_with_timeout (1500 , & output ); /* waiting flush and ensuring data flush */
1367+ TEST_CHECK_ (output != NULL , "Expected output to not be NULL" );
1368+ if (output != NULL ) {
1369+ /* check extra data was not preserved */
1370+ expected = "{\"nest_key\":{\"key\":\"value\",\"object\":{\"a\":\"b\"}}}" ;
1371+ TEST_CHECK_ (strstr (output , expected ) != NULL , "Expected output to contain key one , got '%s'" , output );
1372+ free (output );
1373+ }
1374+
1375+ flb_stop (ctx );
1376+ flb_destroy (ctx );
1377+ }
1378+
13021379TEST_LIST = {
13031380 {"filter_parser_extract_fields" , flb_test_filter_parser_extract_fields },
13041381 {"filter_parser_reserve_data_off" , flb_test_filter_parser_reserve_data_off },
@@ -1313,6 +1390,7 @@ TEST_LIST = {
13131390 {"filter_parser_reserve_off_preserve_on" , flb_test_filter_parser_reserve_off_preserve_on },
13141391 {"filter_parser_reserve_on_preserve_off" , flb_test_filter_parser_reserve_on_preserve_off },
13151392 {"filter_parser_reserve_on_preserve_on" , flb_test_filter_parser_reserve_on_preserve_on },
1393+ {"filter_parser_nest_under_on" , flb_test_filter_parser_nest_under_on },
13161394 {NULL , NULL }
13171395};
13181396
0 commit comments