@@ -182,8 +182,9 @@ static int in_kafka_collect(struct flb_input_instance *ins,
182
182
183
183
184
184
if (!ctx -> enable_auto_commit ) {
185
- /* TO-DO: commit the record based on `ret` */
186
- rd_kafka_commit (ctx -> kafka .rk , NULL , 0 );
185
+ if (ret == FLB_EVENT_ENCODER_SUCCESS ) {
186
+ rd_kafka_commit (ctx -> kafka .rk , NULL , 0 );
187
+ }
187
188
}
188
189
189
190
/* Break from the loop when reaching the limit of polling if available */
@@ -225,6 +226,7 @@ static int in_kafka_init(struct flb_input_instance *ins,
225
226
char errstr [512 ];
226
227
(void ) data ;
227
228
char conf_val [16 ];
229
+ size_t dsize ;
228
230
229
231
/* Allocate space for the configuration context */
230
232
ctx = flb_malloc (sizeof (struct flb_in_kafka_config ));
@@ -252,13 +254,20 @@ static int in_kafka_init(struct flb_input_instance *ins,
252
254
* -> minimize the delay we might create
253
255
* b) run in our own thread:
254
256
* -> optimize for throuput and relay on 'fetch.wait.max.ms'
255
- * which is set to 500 by default default. lets set it to
256
- * twice that so that increasing fetch.wait.max.ms still
257
- * has an effect.
257
+ * which is set to 500 by default default. wa algin our
258
+ * timeout with what is set for 'fetch.wait.max.ms'
258
259
*/
259
260
ctx -> poll_timeount_ms = 1 ;
260
- if (ins -> is_threaded ) {
261
- ctx -> poll_timeount_ms = 1000 ;
261
+ if (ins -> is_threaded ) {
262
+ ctx -> poll_timeount_ms = 550 ; // ensure kafa triggers timeout
263
+
264
+ // align our timeout with what was configured for fetch.wait.max.ms
265
+ dsize = sizeof (conf_val );
266
+ res = rd_kafka_conf_get (kafka_conf , "fetch.wait.max.ms" , conf_val , & dsize );
267
+ if (res == RD_KAFKA_CONF_OK && dsize <= sizeof (conf_val )) {
268
+ // add 50ms so kafa triggers timout
269
+ ctx -> poll_timeount_ms = atoi (conf_val ) + 50 ;
270
+ }
262
271
}
263
272
264
273
if (ctx -> buffer_max_size > 0 ) {
@@ -451,7 +460,6 @@ static struct flb_config_map config_map[] = {
451
460
0 , FLB_TRUE , offsetof(struct flb_in_kafka_config , enable_auto_commit ),
452
461
"Rely on kafka auto-commit and commit messages in batches"
453
462
},
454
- /* EOF */
455
463
{0 }
456
464
};
457
465
0 commit comments