@@ -1466,24 +1466,65 @@ static void test_buffer_limit_truncation()
14661466 uint64_t stream_id ;
14671467 struct flb_config * config ;
14681468 struct flb_ml * ml ;
1469+ struct flb_ml_parser * mlp ;
14691470 struct flb_ml_parser_ins * mlp_i ;
1471+ struct flb_parser * p ;
14701472 struct flb_time tm ;
14711473
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+
14721481 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 );
14741487
1488+ /* This parser will trigger on any content, ensuring concatenation. */
14751489 ml = flb_ml_create (config , "limit-test" );
14761490 TEST_CHECK (ml != NULL );
14771491
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" );
14791509 TEST_CHECK (mlp_i != NULL );
14801510
14811511 ret = flb_ml_stream_create (ml , "test" , -1 , flush_callback , NULL , & stream_id );
14821512 TEST_CHECK (ret == 0 );
14831513
14841514 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+ printf ("ret (line 1) = %d\n" , ret );
1519+ TEST_CHECK (ret == FLB_MULTILINE_OK );
1520+
1521+ /*
1522+ * Append the second line. This will match the 'cont' state and concatenate.
1523+ * The concatenation (20 + 1 + 26 bytes) will exceed the 32-byte limit
1524+ * and correctly trigger the truncation logic.
1525+ */
1526+ ret = flb_ml_append_text (ml , stream_id , & tm , line2 , strlen (line2 ));
1527+ printf ("ret (line 2) = %d\n" , ret );
14871528 TEST_CHECK (ret == FLB_MULTILINE_TRUNCATED );
14881529
14891530 flb_ml_destroy (ml );
0 commit comments