@@ -72,6 +72,11 @@ void flb_log_event_decoder_reset(struct flb_log_event_decoder *context,
72
72
context -> buffer = input_buffer ;
73
73
context -> length = input_length ;
74
74
context -> last_result = FLB_EVENT_DECODER_ERROR_INSUFFICIENT_DATA ;
75
+ context -> current_group_metadata = NULL ;
76
+ context -> current_group_attributes = NULL ;
77
+
78
+ msgpack_unpacked_destroy (& context -> unpacked_group_record );
79
+ msgpack_unpacked_init (& context -> unpacked_group_record );
75
80
76
81
msgpack_unpacked_destroy (& context -> unpacked_event );
77
82
msgpack_unpacked_init (& context -> unpacked_event );
@@ -103,7 +108,7 @@ int flb_log_event_decoder_init(struct flb_log_event_decoder *context,
103
108
104
109
context -> dynamically_allocated = FLB_FALSE ;
105
110
context -> initialized = FLB_TRUE ;
106
- context -> read_groups = FLB_TRUE ;
111
+ context -> read_groups = FLB_FALSE ;
107
112
108
113
flb_log_event_decoder_reset (context , input_buffer , input_length );
109
114
@@ -141,6 +146,7 @@ void flb_log_event_decoder_destroy(struct flb_log_event_decoder *context)
141
146
142
147
if (context != NULL ) {
143
148
if (context -> initialized ) {
149
+ msgpack_unpacked_destroy (& context -> unpacked_group_record );
144
150
msgpack_unpacked_destroy (& context -> unpacked_empty_map );
145
151
msgpack_unpacked_destroy (& context -> unpacked_event );
146
152
}
@@ -180,12 +186,12 @@ int flb_log_event_decoder_decode_timestamp(msgpack_object *input,
180
186
return FLB_EVENT_DECODER_ERROR_WRONG_TIMESTAMP_TYPE ;
181
187
}
182
188
183
- output -> tm .tv_sec =
189
+ output -> tm .tv_sec =
184
190
(int32_t ) FLB_UINT32_TO_HOST_BYTE_ORDER (
185
191
FLB_ALIGNED_DWORD_READ (
186
192
(unsigned char * ) & input -> via .ext .ptr [0 ]));
187
193
188
- output -> tm .tv_nsec =
194
+ output -> tm .tv_nsec =
189
195
(int32_t ) FLB_UINT32_TO_HOST_BYTE_ORDER (
190
196
FLB_ALIGNED_DWORD_READ (
191
197
(unsigned char * ) & input -> via .ext .ptr [4 ]));
@@ -340,16 +346,49 @@ int flb_log_event_decoder_next(struct flb_log_event_decoder *context,
340
346
/* get log event type */
341
347
ret = flb_log_event_decoder_get_record_type (event , & record_type );
342
348
if (ret != 0 ) {
349
+ context -> current_group_metadata = NULL ;
350
+ context -> current_group_attributes = NULL ;
351
+
343
352
context -> last_result = FLB_EVENT_DECODER_ERROR_DESERIALIZATION_FAILURE ;
344
353
return context -> last_result ;
345
354
}
346
355
347
- /*
348
- * if we hava a group type record and the caller don't want groups, just
349
- * skip this record and move to the next one.
356
+ /* Meta records such as the group opener and closer are identified by negative
357
+ * timestamp values. In these cases we track the current group metadata and
358
+ * attributes in order to transparently provide them through the log_event
359
+ * structure but we also want to allow the client code raw access to such
360
+ * records which is why the read_groups decoder context property is used
361
+ * to determine the behavior.
350
362
*/
351
- if (record_type != FLB_LOG_EVENT_NORMAL && !context -> read_groups ) {
352
- return flb_log_event_decoder_next (context , event );
363
+ if (record_type != FLB_LOG_EVENT_NORMAL ) {
364
+ if (context -> read_groups != FLB_TRUE ) {
365
+ msgpack_unpacked_destroy (& context -> unpacked_group_record );
366
+
367
+ if (record_type == FLB_LOG_EVENT_GROUP_START ) {
368
+ memcpy (& context -> unpacked_group_record ,
369
+ & context -> unpacked_event ,
370
+ sizeof (msgpack_unpacked ));
371
+
372
+ context -> current_group_metadata = event -> metadata ;
373
+ context -> current_group_attributes = event -> body ;
374
+ }
375
+ else {
376
+ msgpack_unpacked_destroy (& context -> unpacked_event );
377
+
378
+ context -> current_group_metadata = NULL ;
379
+ context -> current_group_attributes = NULL ;
380
+ }
381
+
382
+ msgpack_unpacked_init (& context -> unpacked_event );
383
+
384
+ memset (event , 0 , sizeof (struct flb_log_event ));
385
+
386
+ return flb_log_event_decoder_next (context , event );
387
+ }
388
+ }
389
+ else {
390
+ event -> group_metadata = context -> current_group_metadata ;
391
+ event -> group_attributes = context -> current_group_attributes ;
353
392
}
354
393
}
355
394
0 commit comments