Skip to content

Commit 870a1bf

Browse files
committed
in_tail: add flb_encoding support to in_tail-plugin
* Adds new option: "encoding" to in_tail. * If encoding fails. message is skipped. Signed-off-by: Jukka Pihl <[email protected]>
1 parent f4ca012 commit 870a1bf

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

plugins/in_tail/tail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ static struct flb_config_map config_map[] = {
640640
"Replacement in case of decoding error (default: unicode replacement char)",
641641
},
642642
#endif
643-
643+
644644
/* Multiline Options */
645645
#ifdef FLB_HAVE_PARSER
646646
{

plugins/in_tail/tail_config.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ struct flb_tail_config *flb_tail_config_create(struct flb_input_instance *ins,
9898
#ifdef FLB_HAVE_SQLDB
9999
ctx->db_sync = 1; /* sqlite sync 'normal' */
100100
#endif
101+
#ifdef FLB_HAVE_UTF8_ENCODER
102+
ctx->encoding = NULL;
103+
#endif
101104

102105
/* Load the config map */
103106
ret = flb_input_config_map_set(ins, (void *) ctx);
@@ -460,6 +463,12 @@ int flb_tail_config_destroy(struct flb_tail_config *config)
460463
}
461464
#endif
462465

466+
#ifdef FLB_HAVE_UTF8_ENCODER
467+
if(config->encoding) {
468+
flb_encoding_close(config->encoding);
469+
}
470+
#endif
471+
463472
flb_free(config);
464473
return 0;
465474
}

plugins/in_tail/tail_config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#ifdef FLB_HAVE_PARSER
3434
#include <fluent-bit/multiline/flb_ml.h>
3535
#endif
36+
#ifdef FLB_HAVE_UTF8_ENCODER
37+
#include <fluent-bit/flb_encoding.h>
38+
#endif
3639

3740

3841
/* Metrics */
@@ -104,6 +107,10 @@ struct flb_tail_config {
104107
sqlite3_stmt *stmt_offset;
105108
#endif
106109

110+
#ifdef FLB_HAVE_UTF8_ENCODER
111+
struct flb_encoding *encoding;
112+
#endif
113+
107114
/* Parser / Format */
108115
struct flb_parser *parser;
109116

plugins/in_tail/tail_file.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
307307
msgpack_sbuffer *out_sbuf;
308308
msgpack_packer *out_pck;
309309
struct flb_tail_config *ctx = file->config;
310+
#ifdef FLB_HAVE_UTF8_ENCODER
311+
char *decoded;
312+
size_t decoded_len;
313+
#endif
310314

311315
/* Create a temporary msgpack buffer */
312316
msgpack_sbuffer_init(&mp_sbuf);
@@ -371,6 +375,18 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
371375
line_len = len - crlf;
372376
repl_line = NULL;
373377

378+
#ifdef FLB_HAVE_UTF8_ENCODER
379+
decoded = NULL;
380+
if(ctx->encoding) {
381+
ret = flb_encoding_decode(ctx->encoding, line, line_len, &decoded, &decoded_len);
382+
if (ret != FLB_ENCODING_SUCCESS) {
383+
flb_plg_error(ctx->ins, "encoding failed '%.*s'", line_len, line);
384+
goto go_next;
385+
}
386+
line = decoded;
387+
line_len = decoded_len;
388+
}
389+
#endif
374390
if (ctx->ml_ctx) {
375391
ret = flb_ml_append(ctx->ml_ctx, file->ml_stream_id,
376392
FLB_ML_TYPE_TEXT,
@@ -421,7 +437,7 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
421437
/* Parser failed, pack raw text */
422438
flb_time_get(&out_time);
423439
flb_tail_file_pack_line(out_sbuf, out_pck, &out_time,
424-
data, len, file, processed_bytes);
440+
line, len, file, processed_bytes);
425441
}
426442
}
427443
else if (ctx->multiline == FLB_TRUE) {
@@ -465,6 +481,12 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
465481
processed_bytes += len + 1;
466482
file->parsed = 0;
467483
lines++;
484+
#ifdef FLB_HAVE_UTF8_ENCODER
485+
if(decoded) {
486+
flb_free(decoded);
487+
decoded = NULL;
488+
}
489+
#endif
468490
}
469491
file->parsed = file->buf_len;
470492

@@ -519,6 +541,7 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
519541
}
520542

521543
msgpack_sbuffer_destroy(out_sbuf);
544+
522545
return lines;
523546
}
524547

0 commit comments

Comments
 (0)