Skip to content

Commit 7f76856

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 ebcee93 commit 7f76856

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
@@ -639,7 +639,7 @@ static struct flb_config_map config_map[] = {
639639
"specify the charset encoder to decode message",
640640
},
641641
#endif
642-
642+
643643
/* Multiline Options */
644644
#ifdef FLB_HAVE_PARSER
645645
{

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);
@@ -441,6 +444,12 @@ int flb_tail_config_destroy(struct flb_tail_config *config)
441444
}
442445
#endif
443446

447+
#ifdef FLB_HAVE_UTF8_ENCODER
448+
if(config->encoding) {
449+
flb_encoding_close(config->encoding);
450+
}
451+
#endif
452+
444453
flb_free(config);
445454
return 0;
446455
}

plugins/in_tail/tail_config.h

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

3639
/* Metrics */
3740
#ifdef FLB_HAVE_METRICS
@@ -102,6 +105,10 @@ struct flb_tail_config {
102105
sqlite3_stmt *stmt_offset;
103106
#endif
104107

108+
#ifdef FLB_HAVE_UTF8_ENCODER
109+
struct flb_encoding *encoding;
110+
#endif
111+
105112
/* Parser / Format */
106113
struct flb_parser *parser;
107114

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);
@@ -370,6 +374,18 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
370374
line_len = len - crlf;
371375
repl_line = NULL;
372376

377+
#ifdef FLB_HAVE_UTF8_ENCODER
378+
decoded = NULL;
379+
if(ctx->encoding) {
380+
ret = flb_encoding_decode(ctx->encoding, line, line_len, &decoded, &decoded_len);
381+
if (ret != FLB_ENCODING_SUCCESS) {
382+
flb_plg_error(ctx->ins, "encoding failed '%.*s'", line_len, line);
383+
goto go_next;
384+
}
385+
line = decoded;
386+
line_len = decoded_len;
387+
}
388+
#endif
373389
if (ctx->ml_ctx) {
374390
ret = flb_ml_append(ctx->ml_ctx, file->ml_stream_id,
375391
FLB_ML_TYPE_TEXT,
@@ -420,7 +436,7 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
420436
/* Parser failed, pack raw text */
421437
flb_time_get(&out_time);
422438
flb_tail_file_pack_line(out_sbuf, out_pck, &out_time,
423-
data, len, file, processed_bytes);
439+
line, len, file, processed_bytes);
424440
}
425441
}
426442
else if (ctx->multiline == FLB_TRUE) {
@@ -464,6 +480,12 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
464480
processed_bytes += len + 1;
465481
file->parsed = 0;
466482
lines++;
483+
#ifdef FLB_HAVE_UTF8_ENCODER
484+
if(decoded) {
485+
flb_free(decoded);
486+
decoded = NULL;
487+
}
488+
#endif
467489
}
468490
file->parsed = file->buf_len;
469491

@@ -518,6 +540,7 @@ static int process_content(struct flb_tail_file *file, size_t *bytes)
518540
}
519541

520542
msgpack_sbuffer_destroy(out_sbuf);
543+
521544
return lines;
522545
}
523546

0 commit comments

Comments
 (0)