@@ -163,6 +163,93 @@ void flb_test_filter_parser_extract_fields()
163
163
flb_destroy (ctx );
164
164
}
165
165
166
+ void flb_test_filter_parser_record_accessor ()
167
+ {
168
+ int ret ;
169
+ int bytes ;
170
+ char * p , * output , * expected ;
171
+ flb_ctx_t * ctx ;
172
+ int in_ffd ;
173
+ int out_ffd ;
174
+ int filter_ffd ;
175
+ struct flb_parser * parser ;
176
+
177
+ struct flb_lib_out_cb cb ;
178
+ cb .cb = callback_test ;
179
+ cb .data = NULL ;
180
+
181
+ clear_output ();
182
+
183
+ ctx = flb_create ();
184
+
185
+ /* Configure service */
186
+ flb_service_set (ctx , "Flush" , FLUSH_INTERVAL , "Grace" "1" , "Log_Level" , "debug" , NULL );
187
+
188
+ /* Input */
189
+ in_ffd = flb_input (ctx , (char * ) "lib" , NULL );
190
+ TEST_CHECK (in_ffd >= 0 );
191
+ flb_input_set (ctx , in_ffd ,
192
+ "Tag" , "test" ,
193
+ NULL );
194
+
195
+ /* Parser */
196
+ parser = flb_parser_create ("dummy_test" , "regex" , "^(?<INT>[^ ]+) (?<FLOAT>[^ ]+) (?<BOOL>[^ ]+) (?<STRING>.+)$" ,
197
+ FLB_TRUE ,
198
+ NULL , NULL , NULL , MK_FALSE , MK_TRUE , FLB_FALSE , FLB_FALSE , NULL , 0 ,
199
+ NULL , ctx -> config );
200
+ TEST_CHECK (parser != NULL );
201
+
202
+ /* Filter */
203
+ filter_ffd = flb_filter (ctx , (char * ) "parser" , NULL );
204
+ TEST_CHECK (filter_ffd >= 0 );
205
+ ret = flb_filter_set (ctx , filter_ffd ,
206
+ "Match" , "test" ,
207
+ "Key_Name" , "$log['data']" ,
208
+ "Parser" , "dummy_test" ,
209
+ "Reserve_Data" , "On" ,
210
+ "Preserve_Key" , "Off" ,
211
+ NULL );
212
+ TEST_CHECK (ret == 0 );
213
+
214
+ /* Output */
215
+ out_ffd = flb_output (ctx , (char * ) "lib" , & cb );
216
+ TEST_CHECK (out_ffd >= 0 );
217
+ flb_output_set (ctx , out_ffd ,
218
+ "Match" , "*" ,
219
+ "format" , "json" ,
220
+ NULL );
221
+
222
+ /* Start the engine */
223
+ ret = flb_start (ctx );
224
+ TEST_CHECK (ret == 0 );
225
+
226
+ /* Ingest data */
227
+ p = "[1448403340,{\"log\":{\"data\":\"100 0.5 true This is an example\"},\"extra\":\"Some more data\"}]" ;
228
+ bytes = flb_lib_push (ctx , in_ffd , p , strlen (p ));
229
+ TEST_CHECK (bytes == strlen (p ));
230
+
231
+ wait_with_timeout (2000 , & output ); /* waiting flush and ensuring data flush */
232
+ TEST_CHECK_ (output != NULL , "Expected output to not be NULL" );
233
+ if (output != NULL ) {
234
+ /* check timestamp */
235
+ expected = "[1448403340.000000,{" ;
236
+ TEST_CHECK_ (strstr (output , expected ) != NULL , "Expected output to contain '%s', got '%s'" , expected , output );
237
+ /* check fields were extracted */
238
+ expected = "\"INT\":\"100\",\"FLOAT\":\"0.5\",\"BOOL\":\"true\",\"STRING\":\"This is an example\"" ;
239
+ TEST_CHECK_ (strstr (output , expected ) != NULL , "Expected output to contain '%s', got '%s'" , expected , output );
240
+ /* check original nested key */
241
+ expected = "\"log\":{\"data\":\"100 0.5 true This is an example\"}" ;
242
+ TEST_CHECK_ (strstr (output , expected ) != NULL , "Expected output to contain '%s', got '%s'" , expected , output );
243
+ /* check extra data preserved */
244
+ expected = "\"extra\":\"Some more data\"" ;
245
+ TEST_CHECK_ (strstr (output , expected ) != NULL , "Expected output to preserve extra field, got '%s'" , output );
246
+ free (output );
247
+ }
248
+
249
+ flb_stop (ctx );
250
+ flb_destroy (ctx );
251
+ }
252
+
166
253
void flb_test_filter_parser_reserve_data_off ()
167
254
{
168
255
int ret ;
@@ -1301,6 +1388,7 @@ void flb_test_filter_parser_reserve_on_preserve_on()
1301
1388
1302
1389
TEST_LIST = {
1303
1390
{"filter_parser_extract_fields" , flb_test_filter_parser_extract_fields },
1391
+ {"filter_parser_record_accessor" , flb_test_filter_parser_record_accessor },
1304
1392
{"filter_parser_reserve_data_off" , flb_test_filter_parser_reserve_data_off },
1305
1393
{"filter_parser_handle_time_key" , flb_test_filter_parser_handle_time_key },
1306
1394
{"filter_parser_handle_time_key_with_time_zone" , flb_test_filter_parser_handle_time_key_with_time_zone },
0 commit comments