@@ -297,7 +297,7 @@ static int cb_lua_init(struct flb_filter_instance *f_ins,
297
297
return 0 ;
298
298
}
299
299
300
- static int pack_result (double ts , msgpack_packer * pck , msgpack_sbuffer * sbuf ,
300
+ static int pack_result (struct flb_time * ts , msgpack_packer * pck , msgpack_sbuffer * sbuf ,
301
301
char * data , size_t bytes )
302
302
{
303
303
int ret ;
@@ -306,7 +306,6 @@ static int pack_result (double ts, msgpack_packer *pck, msgpack_sbuffer *sbuf,
306
306
size_t off = 0 ;
307
307
msgpack_object root ;
308
308
msgpack_unpacked result ;
309
- struct flb_time t ;
310
309
311
310
msgpack_unpacked_init (& result );
312
311
ret = msgpack_unpack_next (& result , data , bytes , & off );
@@ -334,8 +333,7 @@ static int pack_result (double ts, msgpack_packer *pck, msgpack_sbuffer *sbuf,
334
333
msgpack_pack_array (pck , 2 );
335
334
336
335
/* timestamp: convert from double to Fluent Bit format */
337
- flb_time_from_double (& t , ts );
338
- flb_time_append_to_msgpack (& t , pck , 0 );
336
+ flb_time_append_to_msgpack (ts , pck , 0 );
339
337
340
338
/* Pack lua table */
341
339
msgpack_pack_object (pck , * (map + i ));
@@ -363,9 +361,7 @@ static int pack_result (double ts, msgpack_packer *pck, msgpack_sbuffer *sbuf,
363
361
/* main array */
364
362
msgpack_pack_array (pck , 2 );
365
363
366
- /* timestamp: convert from double to Fluent Bit format */
367
- flb_time_from_double (& t , ts );
368
- flb_time_append_to_msgpack (& t , pck , 0 );
364
+ flb_time_append_to_msgpack (ts , pck , 0 );
369
365
370
366
/* Pack lua table */
371
367
msgpack_sbuffer_write (sbuf , data , bytes );
@@ -391,6 +387,7 @@ static int cb_lua_filter(const void *data, size_t bytes,
391
387
msgpack_unpacked result ;
392
388
msgpack_sbuffer tmp_sbuf ;
393
389
msgpack_packer tmp_pck ;
390
+ struct flb_time t_orig ;
394
391
struct flb_time t ;
395
392
struct lua_filter * ctx = filter_context ;
396
393
/* Lua return values */
@@ -413,6 +410,7 @@ static int cb_lua_filter(const void *data, size_t bytes,
413
410
414
411
/* Get timestamp */
415
412
flb_time_pop_from_msgpack (& t , & result , & p );
413
+ t_orig = t ;
416
414
ts = flb_time_to_double (& t );
417
415
418
416
/* Prepare function call, pass 3 arguments, expect 3 return values */
@@ -442,8 +440,15 @@ static int cb_lua_filter(const void *data, size_t bytes,
442
440
else if (l_code == 0 ) { /* Keep record, repack */
443
441
msgpack_pack_object (& tmp_pck , root );
444
442
}
445
- else if (l_code == 1 ) { /* Modified, pack new data */
446
- ret = pack_result (l_timestamp , & tmp_pck , & tmp_sbuf ,
443
+ else if (l_code == 1 || l_code == 2 ) { /* Modified, pack new data */
444
+ if (l_code == 1 ) {
445
+ flb_time_from_double (& t , l_timestamp );
446
+ }
447
+ else if (l_code == 2 ) {
448
+ /* Keep the timestamp */
449
+ t = t_orig ;
450
+ }
451
+ ret = pack_result (& t , & tmp_pck , & tmp_sbuf ,
447
452
data_sbuf .data , data_sbuf .size );
448
453
if (ret == FLB_FALSE ) {
449
454
flb_plg_error (ctx -> ins , "invalid table returned at %s(), %s" ,
0 commit comments