@@ -1466,24 +1466,63 @@ static void test_buffer_limit_truncation()
1466
1466
uint64_t stream_id ;
1467
1467
struct flb_config * config ;
1468
1468
struct flb_ml * ml ;
1469
+ struct flb_ml_parser * mlp ;
1469
1470
struct flb_ml_parser_ins * mlp_i ;
1471
+ struct flb_parser * p ;
1470
1472
struct flb_time tm ;
1471
1473
1474
+ /*
1475
+ * A realistic Docker log where the content of the "log" field will be
1476
+ * concatenated, and that concatenated buffer is what should be truncated.
1477
+ */
1478
+ char * line1 = "{\"log\": \"12345678901234567890\", \"stream\": \"stdout\"}" ;
1479
+ char * line2 = "{\"log\": \"abcdefghijklmnopqrstuvwxyz\", \"stream\": \"stdout\"}" ;
1480
+
1472
1481
config = flb_config_init ();
1473
- config -> multiline_buffer_limit = 32 ;
1482
+ /* The buffer limit is for the concatenated 'log' content, not the full JSON */
1483
+ config -> multiline_buffer_limit = 80 ;
1484
+
1485
+ /* Use the dummy 'docker' parser for JSON extraction */
1486
+ p = flb_parser_get ("docker" , config );
1474
1487
1488
+ /* This parser will trigger on any content, ensuring concatenation. */
1475
1489
ml = flb_ml_create (config , "limit-test" );
1476
1490
TEST_CHECK (ml != NULL );
1477
1491
1478
- mlp_i = flb_ml_parser_instance_create (ml , "docker" );
1492
+ mlp = flb_ml_parser_create (config , "test-concat" , FLB_ML_REGEX ,
1493
+ NULL , FLB_FALSE , 1000 ,
1494
+ "log" , NULL , NULL ,
1495
+ p , "docker" );
1496
+ TEST_CHECK (mlp != NULL );
1497
+
1498
+ /* Define rules that will always match the test data */
1499
+ ret = flb_ml_rule_create (mlp , "start_state" , "/./" , "cont" , NULL );
1500
+ TEST_CHECK (ret == 0 );
1501
+ ret = flb_ml_rule_create (mlp , "cont" , "/./" , "cont" , NULL );
1502
+ TEST_CHECK (ret == 0 );
1503
+
1504
+ /* Finalize parser initialization */
1505
+ ret = flb_ml_parser_init (mlp );
1506
+ TEST_CHECK (ret == 0 );
1507
+
1508
+ mlp_i = flb_ml_parser_instance_create (ml , "test-concat" );
1479
1509
TEST_CHECK (mlp_i != NULL );
1480
1510
1481
1511
ret = flb_ml_stream_create (ml , "test" , -1 , flush_callback , NULL , & stream_id );
1482
1512
TEST_CHECK (ret == 0 );
1483
1513
1484
1514
flb_time_get (& tm );
1485
- ret = flb_ml_append_text (ml , stream_id , & tm ,
1486
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" , 36 );
1515
+
1516
+ /* Append the first line. It will match the 'start_state' and start a block. */
1517
+ ret = flb_ml_append_text (ml , stream_id , & tm , line1 , strlen (line1 ));
1518
+ TEST_CHECK (ret == FLB_MULTILINE_OK );
1519
+
1520
+ /*
1521
+ * Append the second line. This will match the 'cont' state and concatenate.
1522
+ * The concatenation will exceed the limit
1523
+ * and correctly trigger the truncation logic.
1524
+ */
1525
+ ret = flb_ml_append_text (ml , stream_id , & tm , line2 , strlen (line2 ));
1487
1526
TEST_CHECK (ret == FLB_MULTILINE_TRUNCATED );
1488
1527
1489
1528
flb_ml_destroy (ml );
0 commit comments