Skip to content

Commit 5f3e4b3

Browse files
Merge branch 'fluent:master' into master
2 parents 9e20c7e + f1bea81 commit 5f3e4b3

File tree

137 files changed

+20765
-1063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+20765
-1063
lines changed

.github/workflows/cron-trivy.yaml

Lines changed: 0 additions & 91 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(fluent-bit C)
33

4+
include(CheckCCompilerFlag)
5+
46
# CMP0069 ensures that LTO is enabled for all compilers
57
cmake_policy(SET CMP0069 NEW)
68
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
@@ -207,7 +209,8 @@ option(FLB_SIGNV4 "Enable AWS Signv4 support" Yes)
207209
option(FLB_AWS "Enable AWS support" Yes)
208210
option(FLB_STATIC_CONF "Build binary using static configuration")
209211
option(FLB_STREAM_PROCESSOR "Enable Stream Processor" Yes)
210-
option(FLB_SIMD "Enable SIMD support" No)
212+
set(FLB_SIMD "Auto" CACHE STRING "Enable SIMD support (On, Off, Auto)")
213+
set_property(CACHE FLB_SIMD PROPERTY STRINGS "On;Off;Auto")
211214
option(FLB_CORO_STACK_SIZE "Set coroutine stack size")
212215
option(FLB_AVRO_ENCODER "Build with Avro encoding support" No)
213216
option(FLB_AWS_ERROR_REPORTER "Build with aws error reporting support" No)
@@ -258,7 +261,64 @@ option(FLB_EVENT_LOOP_SELECT "Enable select(2) event loop backend" No)
258261
option(FLB_EVENT_LOOP_LIBEVENT "Enable libevent event loop backend" No)
259262

260263
# SIMD support
261-
if(FLB_SIMD)
264+
# ------------
265+
# FLB_SIMD is a tri-state cache variable:
266+
# Auto : enable SIMD only when the target architecture/toolchain is known-good
267+
# On : require SIMD support and fail during configure otherwise
268+
# Off : disable SIMD explicitly
269+
string(TOUPPER "${FLB_SIMD}" FLB_SIMD_MODE)
270+
271+
if(FLB_SIMD_MODE MATCHES "^(ON|YES|TRUE|1)$")
272+
set(FLB_SIMD_MODE "ON")
273+
elseif(FLB_SIMD_MODE MATCHES "^(OFF|NO|FALSE|0)$")
274+
set(FLB_SIMD_MODE "OFF")
275+
elseif(NOT FLB_SIMD_MODE STREQUAL "AUTO")
276+
message(FATAL_ERROR "FLB_SIMD must be one of: On, Off, Auto")
277+
endif()
278+
279+
set(FLB_SIMD_ENABLED No)
280+
set(FLB_SIMD_RISCV_C_FLAGS "")
281+
282+
if(NOT FLB_SIMD_MODE STREQUAL "OFF")
283+
set(FLB_SIMD_SUPPORTED_ARCH No)
284+
285+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$" AND (CMAKE_SIZEOF_VOID_P GREATER 4))
286+
set(FLB_SIMD_SUPPORTED_ARCH Yes)
287+
set(FLB_SIMD_ENABLED Yes)
288+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64|ARM64|AARCH64)$")
289+
set(FLB_SIMD_SUPPORTED_ARCH Yes)
290+
set(FLB_SIMD_ENABLED Yes)
291+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv64)")
292+
set(FLB_SIMD_SUPPORTED_ARCH Yes)
293+
check_c_compiler_flag("-march=rv64gcv_zba" FLB_SIMD_RISCV_COMPILER_FLAG)
294+
295+
if(FLB_SIMD_RISCV_COMPILER_FLAG)
296+
set(FLB_SIMD_ENABLED Yes)
297+
set(FLB_SIMD_RISCV_C_FLAGS "-march=rv64gcv_zba")
298+
elseif(FLB_SIMD_MODE STREQUAL "ON")
299+
message(FATAL_ERROR
300+
"FLB_SIMD=On requires compiler support for -march=rv64gcv_zba on riscv64")
301+
else()
302+
message(WARNING
303+
"FLB_SIMD=Auto disabled SIMD on riscv64 because the compiler does not "
304+
"support -march=rv64gcv_zba")
305+
endif()
306+
endif()
307+
308+
if(NOT FLB_SIMD_SUPPORTED_ARCH)
309+
if(FLB_SIMD_MODE STREQUAL "ON")
310+
message(FATAL_ERROR
311+
"FLB_SIMD=On is only supported on x86_64, aarch64/arm64, and "
312+
"riscv64 with RVV compiler support")
313+
else()
314+
message(STATUS
315+
"FLB_SIMD=Auto disabled SIMD on unsupported architecture: "
316+
"${CMAKE_SYSTEM_PROCESSOR}")
317+
endif()
318+
endif()
319+
endif()
320+
321+
if(FLB_SIMD_ENABLED)
262322
FLB_DEFINITION(FLB_HAVE_SIMD)
263323
endif()
264324

@@ -665,6 +725,14 @@ add_subdirectory(${FLB_PATH_LIB_RING_BUFFER} EXCLUDE_FROM_ALL)
665725

666726
# yyson
667727
add_subdirectory(${FLB_PATH_LIB_YYJSON} EXCLUDE_FROM_ALL)
728+
if (TARGET yyjson AND NOT FLB_COVERAGE AND
729+
CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang|Intel")
730+
# yyjson's O0 reader can exceed the default coroutine stack budget.
731+
# Keep debug symbols, but force enough optimization to shrink the frame.
732+
target_compile_options(yyjson PRIVATE
733+
$<$<AND:$<COMPILE_LANGUAGE:C>,$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>:-Og>
734+
)
735+
endif()
668736

669737
# Avro
670738
if(FLB_AVRO_ENCODER)

cmake/riscv64.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(riscv64)")
22
message(STATUS "Forcing characters to be signed, as on x86_64.")
33
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char")
4+
45
if(FLB_LUAJIT)
56
message(WARNING "LuaJIT is disabled, this platform does not support built-in LuaJIT and system provided one neither.")
67
set(FLB_LUAJIT OFF)
78
endif()
8-
if(FLB_SIMD)
9-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=rv64gcv_zba")
9+
10+
if(FLB_SIMD_ENABLED AND NOT "${FLB_SIMD_RISCV_C_FLAGS}" STREQUAL "")
11+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLB_SIMD_RISCV_C_FLAGS}")
1012
endif()
1113
endif ()

include/fluent-bit/aws/flb_aws_compress.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define FLB_AWS_COMPRESS_ARROW 2
2727
#define FLB_AWS_COMPRESS_PARQUET 3
2828
#define FLB_AWS_COMPRESS_ZSTD 4
29+
#define FLB_AWS_COMPRESS_SNAPPY 5
2930

3031
/*
3132
* Get compression type from compression keyword. The return value is used to identify

include/fluent-bit/flb_compat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static inline char* basename(const char *path)
109109
char dir[_MAX_DIR];
110110
char fname[_MAX_FNAME];
111111
char ext[_MAX_EXT];
112-
static char buf[_MAX_PATH];
112+
static __declspec(thread) char buf[_MAX_PATH];
113113

114114
_splitpath_s(path, drive, _MAX_DRIVE, dir, _MAX_DIR,
115115
fname, _MAX_FNAME, ext, _MAX_EXT);

include/fluent-bit/flb_input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ struct flb_input_instance {
450450
/* TLS settings */
451451
int use_tls; /* bool, try to use TLS for I/O */
452452
int tls_verify; /* Verify certs (default: true) */
453+
int tls_verify_client; /* Verify client certs (default: false) */
453454
int tls_verify_hostname; /* Verify hostname (default: false) */
454455
int tls_debug; /* mbedtls debug level */
455456
char *tls_vhost; /* Virtual hostname for SNI */

include/fluent-bit/flb_mp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#define FLB_MP_ARRAY MSGPACK_OBJECT_ARRAY
2828

2929
int flb_mp_count(const void *data, size_t bytes);
30+
int flb_mp_count_log_records(const void *data, size_t bytes);
31+
int flb_mp_normalize_log_buffer_groups_msgpack(const void *in_buf, size_t in_size,
32+
char **out_buf, size_t *out_size);
33+
int flb_mp_normalize_log_buffer_groups(const void *in_buf, size_t in_size,
34+
char **out_buf, size_t *out_size);
3035
int flb_mp_count_remaining(const void *data, size_t bytes, size_t *remaining_bytes);
3136
int flb_mp_validate_log_chunk(const void *data, size_t bytes,
3237
int *out_records, size_t *processed_bytes);

include/fluent-bit/flb_mp_chunk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ struct flb_mp_chunk_cobj *flb_mp_chunk_cobj_create(struct flb_log_event_encoder
7171
int flb_mp_chunk_cobj_destroy(struct flb_mp_chunk_cobj *chunk_cobj);
7272

7373
int flb_mp_chunk_cobj_encode(struct flb_mp_chunk_cobj *chunk_cobj, char **out_buf, size_t *out_size);
74+
int flb_mp_chunk_cobj_count_log_records(struct flb_mp_chunk_cobj *chunk_cobj);
75+
int flb_mp_chunk_cobj_normalize_groups(struct flb_mp_chunk_cobj *chunk_cobj);
7476

7577

7678

include/fluent-bit/flb_output.h

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <fluent-bit/flb_upstream_ha.h>
4949
#include <fluent-bit/flb_event.h>
5050
#include <fluent-bit/flb_processor.h>
51+
#include <fluent-bit/flb_mp.h>
5152

5253
#include <cfl/cfl.h>
5354
#include <cmetrics/cmetrics.h>
@@ -468,6 +469,8 @@ struct flb_output_instance {
468469
struct cmt_gauge *cmt_chunk_available_capacity_percent;
469470
/* m: output_latency_seconds */
470471
struct cmt_histogram *cmt_latency;
472+
/* m: output_backpressure_wait_seconds */
473+
struct cmt_histogram *cmt_backpressure_wait;
471474

472475
/* OLD Metrics API */
473476
#ifdef FLB_HAVE_METRICS
@@ -783,6 +786,9 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task,
783786

784787
if (flb_processor_is_active(o_ins->processor)) {
785788
if (evc->type == FLB_EVENT_TYPE_LOGS) {
789+
char *normalized_buf;
790+
size_t normalized_size;
791+
786792
/* run the processor */
787793
ret = flb_processor_run(o_ins->processor,
788794
0,
@@ -796,7 +802,22 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task,
796802
return NULL;
797803
}
798804

799-
records = flb_mp_count(p_buf, p_size);
805+
normalized_buf = NULL;
806+
normalized_size = 0;
807+
808+
ret = flb_mp_normalize_log_buffer_groups_msgpack(p_buf, p_size,
809+
&normalized_buf,
810+
&normalized_size);
811+
if (ret == 0) {
812+
if (p_buf != evc->data) {
813+
flb_free(p_buf);
814+
}
815+
816+
p_buf = normalized_buf;
817+
p_size = normalized_size;
818+
}
819+
820+
records = flb_mp_count_log_records(p_buf, p_size);
800821
tmp = flb_event_chunk_create(evc->type, records, evc->tag, flb_sds_len(evc->tag), p_buf, p_size);
801822
if (!tmp) {
802823
flb_coro_destroy(coro);
@@ -1196,10 +1217,13 @@ struct flb_output_flush *flb_output_flush_create(struct flb_task *task,
11961217
*/
11971218
static inline void flb_output_return(int ret, struct flb_coro *co) {
11981219
int n;
1220+
int records;
11991221
int pipe_fd;
12001222
uint32_t set;
12011223
uint64_t val;
1224+
size_t bytes;
12021225
struct flb_task *task;
1226+
struct flb_event_chunk *counted_event_chunk;
12031227
struct flb_output_flush *out_flush;
12041228
struct flb_output_instance *o_ins;
12051229
struct flb_out_thread_instance *th_ins = NULL;
@@ -1208,10 +1232,22 @@ static inline void flb_output_return(int ret, struct flb_coro *co) {
12081232
o_ins = out_flush->o_ins;
12091233
task = out_flush->task;
12101234

1211-
flb_task_acquire_lock(task);
1235+
if (out_flush->processed_event_chunk) {
1236+
counted_event_chunk = out_flush->processed_event_chunk;
1237+
}
1238+
else {
1239+
counted_event_chunk = task->event_chunk;
1240+
}
12121241

1213-
flb_task_deactivate_route(task, o_ins);
1242+
records = task->event_chunk->total_events;
1243+
if (counted_event_chunk->type == FLB_EVENT_TYPE_LOGS) {
1244+
records = counted_event_chunk->total_events;
1245+
}
1246+
bytes = counted_event_chunk->size;
12141247

1248+
flb_task_acquire_lock(task);
1249+
flb_task_set_route_data(task, o_ins, records, bytes);
1250+
flb_task_deactivate_route(task, o_ins);
12151251
flb_task_release_lock(task);
12161252

12171253
#ifdef FLB_HAVE_CHUNK_TRACE

include/fluent-bit/flb_pack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ flb_sds_t flb_msgpack_raw_to_json_sds(const void *in_buf, size_t in_size, int es
111111

112112
int flb_pack_time_now(msgpack_packer *pck);
113113
int flb_msgpack_expand_map(char *map_data, size_t map_size,
114-
msgpack_object_kv **obj_arr, int obj_arr_len,
115-
char** out_buf, int* out_size);
114+
msgpack_object_kv **obj_arr, size_t obj_arr_len,
115+
char** out_buf, size_t *out_size);
116116

117117
struct flb_gelf_fields {
118118
flb_sds_t timestamp_key;

0 commit comments

Comments
 (0)