@@ -1390,6 +1390,91 @@ void flb_test_offset_key()
1390
1390
test_tail_ctx_destroy (ctx );
1391
1391
}
1392
1392
1393
+ void flb_test_multiline_offset_key ()
1394
+ {
1395
+ struct flb_lib_out_cb cb_data ;
1396
+ struct test_tail_ctx * ctx ;
1397
+ char * file [] = {"multiline_offset.log" };
1398
+ char * offset_key = "OffsetKey" ;
1399
+ char * msg_before_tail = "[2025-06-16 20:42:22,291] INFO - aaaaaaaaaaa" ;
1400
+ char * msg_before_tail2 = "[2025-06-16 20:42:22,500] Error" ;
1401
+ char * msg_final = "[2025-06-16 20:45:29,234] Fatal" ;
1402
+ char expected_msg [1024 ] = {0 };
1403
+ int ret ;
1404
+ int num ;
1405
+
1406
+ char * expected_strs [] = {msg_final , & expected_msg [0 ]};
1407
+ struct str_list expected = {
1408
+ .size = sizeof (expected_strs )/sizeof (char * ),
1409
+ .lists = & expected_strs [0 ],
1410
+ };
1411
+
1412
+ clear_output_num ();
1413
+
1414
+ cb_data .cb = cb_check_json_str_list ;
1415
+ cb_data .data = & expected ;
1416
+
1417
+ // multiline offset is at the end of the message
1418
+ ret = snprintf (& expected_msg [0 ], sizeof (expected_msg ), "\"%s\":%ld" , offset_key , strlen (msg_before_tail )+ strlen (NEW_LINE )+ strlen (msg_before_tail2 )+ strlen (NEW_LINE )+ strlen (msg_final )+ strlen (NEW_LINE ));
1419
+ if (!TEST_CHECK (ret >= 0 )) {
1420
+ TEST_MSG ("snprintf failed" );
1421
+ exit (EXIT_FAILURE );
1422
+ }
1423
+
1424
+ ctx = test_tail_ctx_create (& cb_data , & file [0 ], sizeof (file )/sizeof (char * ), FLB_TRUE );
1425
+ if (!TEST_CHECK (ctx != NULL )) {
1426
+ TEST_MSG ("test_ctx_create failed" );
1427
+ exit (EXIT_FAILURE );
1428
+ }
1429
+
1430
+ ret = flb_service_set (ctx -> flb , "Parsers_File" , DPATH "/parsers_multiline.conf" , NULL );
1431
+ TEST_CHECK (ret == 0 );
1432
+
1433
+ ret = flb_input_set (ctx -> flb , ctx -> o_ffd ,
1434
+ "path" , file [0 ],
1435
+ "offset_key" , offset_key ,
1436
+ "multiline.parser" , "multiline-regex" ,
1437
+ NULL );
1438
+ TEST_CHECK (ret == 0 );
1439
+
1440
+ ret = flb_output_set (ctx -> flb , ctx -> o_ffd ,
1441
+ "format" , "json" ,
1442
+ NULL );
1443
+ TEST_CHECK (ret == 0 );
1444
+
1445
+ ret = write_msg (ctx , msg_before_tail , strlen (msg_before_tail ));
1446
+ if (!TEST_CHECK (ret > 0 )) {
1447
+ test_tail_ctx_destroy (ctx );
1448
+ exit (EXIT_FAILURE );
1449
+ }
1450
+
1451
+ ret = write_msg (ctx , msg_before_tail2 , strlen (msg_before_tail2 ));
1452
+ if (!TEST_CHECK (ret > 0 )) {
1453
+ test_tail_ctx_destroy (ctx );
1454
+ exit (EXIT_FAILURE );
1455
+ }
1456
+
1457
+ /* Start the engine */
1458
+ ret = flb_start (ctx -> flb );
1459
+ TEST_CHECK (ret == 0 );
1460
+
1461
+ ret = write_msg (ctx , msg_final , strlen (msg_final ));
1462
+ if (!TEST_CHECK (ret > 0 )) {
1463
+ test_tail_ctx_destroy (ctx );
1464
+ exit (EXIT_FAILURE );
1465
+ }
1466
+
1467
+ /* waiting to flush */
1468
+ flb_time_msleep (2000 );
1469
+
1470
+ num = get_output_num ();
1471
+ if (!TEST_CHECK (num > 0 )) {
1472
+ TEST_MSG ("no outputs" );
1473
+ }
1474
+
1475
+ test_tail_ctx_destroy (ctx );
1476
+ }
1477
+
1393
1478
void flb_test_skip_empty_lines ()
1394
1479
{
1395
1480
struct flb_lib_out_cb cb_data ;
@@ -2345,6 +2430,7 @@ TEST_LIST = {
2345
2430
{"path_key" , flb_test_path_key },
2346
2431
{"exclude_path" , flb_test_exclude_path },
2347
2432
{"offset_key" , flb_test_offset_key },
2433
+ {"multiline_offset_key" , flb_test_multiline_offset_key },
2348
2434
{"skip_empty_lines" , flb_test_skip_empty_lines },
2349
2435
{"skip_empty_lines_crlf" , flb_test_skip_empty_lines_crlf },
2350
2436
{"ignore_older" , flb_test_ignore_older },
0 commit comments