Skip to content

Commit 4e94184

Browse files
committed
flb_encode: Log warning when UTF8 encoding fails
Signed-off-by: Nigel Stewart <[email protected]>
1 parent 54b8d48 commit 4e94184

File tree

7 files changed

+20
-12
lines changed

7 files changed

+20
-12
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ option(FLB_SMALL "Optimise for small size" No)
5050
option(FLB_COVERAGE "Build with code-coverage" No)
5151
option(FLB_JEMALLOC "Build with Jemalloc support" No)
5252
option(FLB_REGEX "Build with Regex support" Yes)
53-
option(FLB_ENCODE "Build with encoding support" Yes)
53+
option(FLB_ENCODE "Build with UTF8 encoding support" Yes)
5454
option(FLB_PARSER "Build with Parser support" Yes)
5555
option(FLB_TLS "Build with SSL/TLS support" No)
5656
option(FLB_BINARY "Build executable binary" Yes)

cmake/headers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include_directories(
1515
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_SQLITE}
1616
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MPACK}/src
1717
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_MINIZ}/
18-
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}
18+
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_ONIGMO}
1919
${CMAKE_CURRENT_BINARY_DIR}/include
2020
)
2121

include/fluent-bit/flb_encode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ typedef void *flb_encoder;
2727

2828
#ifdef FLB_HAVE_ENCODE
2929
flb_encoder flb_get_encoder(const char *encoding);
30-
void flb_msgpack_encode_utf8(flb_encoder enc, msgpack_packer* pk, const void* b, size_t l);
30+
void flb_msgpack_encode_utf8(flb_encoder encoder, const char *module, msgpack_packer *pk, const void *b, size_t l);
3131
#else
3232
static inline flb_encoder flb_get_encoder(const char *encoding)
3333
{
3434
return NULL;
3535
}
3636

37-
static inline void flb_msgpack_encode_utf8(flb_encoder enc, msgpack_packer* pk, const void* b, size_t l)
37+
static inline void flb_msgpack_encode_utf8(flb_encoder encoder, const char *module, msgpack_packer *pk, const void *b, size_t l)
3838
{
3939
msgpack_pack_str(pk, l);
4040
msgpack_pack_str_body(pk, b, l);

plugins/in_syslog/syslog_prot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static inline int pack_line(struct flb_syslog *ctx,
4545

4646
msgpack_pack_array(&mp_pck, 2);
4747
flb_time_append_to_msgpack(time, &mp_pck, 0);
48-
flb_msgpack_encode_utf8(ctx->encoding, &mp_pck, data, data_size);
48+
flb_msgpack_encode_utf8(ctx->encoding, "in_syslog", &mp_pck, data, data_size);
4949

5050
flb_input_chunk_append_raw(ctx->i_ins, NULL, 0, mp_sbuf.data, mp_sbuf.size);
5151
msgpack_sbuffer_destroy(&mp_sbuf);

plugins/in_tail/tail_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ int flb_tail_file_pack_line(msgpack_sbuffer *mp_sbuf, msgpack_packer *mp_pck,
208208

209209
msgpack_pack_str(mp_pck, ctx->key_len);
210210
msgpack_pack_str_body(mp_pck, ctx->key, ctx->key_len);
211-
flb_msgpack_encode_utf8(ctx->encoding, mp_pck, data, data_size);
211+
flb_msgpack_encode_utf8(ctx->encoding, "in_tail", mp_pck, data, data_size);
212212

213213
return 0;
214214
}

plugins/in_tail/tail_multiline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static inline void flb_tail_mult_append_raw(char *buf, int size,
239239
struct flb_tail_config *config)
240240
{
241241
/* Append the raw string */
242-
flb_msgpack_encode_utf8(config->encoding, &file->mult_pck, buf, size);
242+
flb_msgpack_encode_utf8(config->encoding, "in_tail", &file->mult_pck, buf, size);
243243
}
244244

245245
/* Check if the last key value type of a map is string or not */

src/flb_encode.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#include <fluent-bit/flb_encode.h>
22+
#include <fluent-bit/flb_log.h>
2223
#include <fluent-bit/flb_mem.h>
2324

2425
#ifdef FLB_HAVE_ENCODE
@@ -31,35 +32,42 @@ flb_encoder flb_get_encoder(const char *encoding)
3132
return tutf8e_encoder(encoding);
3233
}
3334

34-
void flb_msgpack_encode_utf8(flb_encoder enc, msgpack_packer* pk, const void* b, size_t l)
35+
void flb_msgpack_encode_utf8(flb_encoder encoder, const char *module, msgpack_packer *pk, const void *b, size_t l)
3536
{
36-
if (enc) {
37+
if (encoder) {
3738
size_t size = 0;
38-
if (!tutf8e_encoder_buffer_length(enc, b, l, &size) && size) {
39+
if (!tutf8e_encoder_buffer_length(encoder, b, l, &size) && size) {
3940
/* Already UTF8 encoded? */
4041
if (size == l) {
4142
}
4243
/* Small enough for encoding to stack? */
4344
else if (size<=TUTF8_BUFFER_SIZE) {
4445
char buffer[TUTF8_BUFFER_SIZE];
45-
if (!tutf8e_encoder_buffer_encode(enc, b, l, buffer, &size) && size) {
46+
if (!tutf8e_encoder_buffer_encode(encoder, b, l, buffer, &size) && size) {
4647
msgpack_pack_str(pk, size);
4748
msgpack_pack_str_body(pk, buffer, size);
4849
return;
4950
}
51+
/* Not expecting to get here ordinarily */
52+
flb_warn("[%s] failed to encode to UTF8", module);
5053
}
5154
/* malloc/free the encoded copy */
5255
else {
5356
char *buffer = (char *) flb_malloc(size);
54-
if (buffer && !tutf8e_encoder_buffer_encode(enc, b, l, buffer, &size) && size) {
57+
if (buffer && !tutf8e_encoder_buffer_encode(encoder, b, l, buffer, &size) && size) {
5558
msgpack_pack_str(pk, size);
5659
msgpack_pack_str_body(pk, buffer, size);
5760
free(buffer);
5861
return;
5962
}
63+
/* Not expecting to get here ordinarily */
6064
free(buffer);
65+
flb_warn("[%s] failed to encode to UTF8", module);
6166
}
6267
}
68+
else {
69+
flb_warn("[%s] failed to encode to UTF8", module);
70+
}
6371
}
6472

6573
/* Could not or need not encode to UTF8 */

0 commit comments

Comments
 (0)