Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1: backport fixes 2024-09-26 #9433

Merged
merged 8 commits into from
Sep 27, 2024
2 changes: 1 addition & 1 deletion lib/ctraces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif()
# CTraces Version
set(CTR_VERSION_MAJOR 0)
set(CTR_VERSION_MINOR 5)
set(CTR_VERSION_PATCH 5)
set(CTR_VERSION_PATCH 6)
set(CTR_VERSION_STR "${CTR_VERSION_MAJOR}.${CTR_VERSION_MINOR}.${CTR_VERSION_PATCH}")

# Define __FILENAME__ consistently across Operating Systems
Expand Down
29 changes: 25 additions & 4 deletions lib/ctraces/src/ctr_encode_opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <ctraces/ctraces.h>
#include <fluent-otel-proto/fluent-otel.h>

static void destroy_scope_spans(Opentelemetry__Proto__Trace__V1__ScopeSpans **scope_spans,
size_t count);

static inline Opentelemetry__Proto__Common__V1__AnyValue *ctr_variant_to_otlp_any_value(struct cfl_variant *value);
static inline Opentelemetry__Proto__Common__V1__KeyValue *ctr_variant_kvpair_to_otlp_kvpair(struct cfl_kvpair *input_pair);
static inline Opentelemetry__Proto__Common__V1__AnyValue *ctr_variant_kvlist_to_otlp_any_value(struct cfl_variant *value);
Expand Down Expand Up @@ -914,11 +917,21 @@ static Opentelemetry__Proto__Common__V1__InstrumentationScope *set_instrumentati
return NULL;
}

otel_scope->name = instrumentation_scope->name;
otel_scope->version = instrumentation_scope->version;
if (instrumentation_scope->name) {
otel_scope->name = instrumentation_scope->name;
}
else {
otel_scope->name = "";
}
if (instrumentation_scope->version) {
otel_scope->version = instrumentation_scope->version;
}
else {
otel_scope->version = "";
}
otel_scope->n_attributes = get_attributes_count(instrumentation_scope->attr);
otel_scope->dropped_attributes_count = instrumentation_scope->dropped_attr_count;
otel_scope->attributes = set_attributes_from_ctr(instrumentation_scope->attr);;
otel_scope->attributes = set_attributes_from_ctr(instrumentation_scope->attr);

return otel_scope;
}
Expand Down Expand Up @@ -976,11 +989,19 @@ static Opentelemetry__Proto__Trace__V1__ScopeSpans **set_scope_spans(struct ctra

otel_scope_span = initialize_scope_span();
if (!otel_scope_span) {
if (scope_span_index > 0) {
destroy_scope_spans(scope_spans, scope_span_index - 1);
}

free(scope_spans);

return NULL;
}

otel_scope_span->schema_url = scope_span->schema_url;
otel_scope_span->scope = set_instrumentation_scope(scope_span->instrumentation_scope);
if (scope_span->instrumentation_scope != NULL) {
otel_scope_span->scope = set_instrumentation_scope(scope_span->instrumentation_scope);
}

span_count = cfl_list_size(&scope_span->spans);
otel_scope_span->n_spans = span_count;
Expand Down
94 changes: 94 additions & 0 deletions lib/ctraces/tests/decoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,81 @@ static struct ctrace *generate_encoder_test_data()
return context;
}

static int generate_sample_resource_minimal_attributes(struct ctrace_resource *resource)
{
struct ctrace_attributes *attributes;
int result;

attributes = ctr_attributes_create();

if (attributes == NULL) {
return -1;
}

result = ctr_attributes_set_string(attributes, "receiver.tool", "ctraces");

if (result != 0) {
ctr_attributes_destroy(attributes);

return -2;
}

result = ctr_resource_set_attributes(resource, attributes);

if (result != 0) {
ctr_attributes_destroy(attributes);

return -3;
}

return 0;
}

static struct ctrace *generate_encoder_test_data_with_empty_spans()
{
struct ctrace_resource_span *resource_span;
struct ctrace_scope_span *scope_span;
struct ctrace *context;
int result;

context = ctr_create(NULL);

if (context == NULL) {
return NULL;
}

resource_span = ctr_resource_span_create(context);

if (resource_span == NULL) {
ctr_destroy(context);

return NULL;
}

ctr_resource_span_set_schema_url(resource_span, "");
ctr_resource_set_dropped_attr_count(resource_span->resource, 0);

result = generate_sample_resource_minimal_attributes(resource_span->resource);

if (result != 0) {
ctr_destroy(context);

return NULL;
}

scope_span = ctr_scope_span_create(resource_span);

if (scope_span == NULL) {
ctr_destroy(context);

return NULL;
}

ctr_scope_span_set_schema_url(scope_span, "");

return context;
}

/*
* perform the following and then compare text buffers
*
Expand Down Expand Up @@ -483,6 +558,24 @@ void test_msgpack_to_cmt()
ctr_destroy(context);
}

void test_msgpack_to_ctr_with_empty_spans()
{
struct ctrace *context;
char *referece_text_buffer;

context = generate_encoder_test_data_with_empty_spans();
TEST_ASSERT(context != NULL);

referece_text_buffer = ctr_encode_text_create(context);
TEST_ASSERT(referece_text_buffer != NULL);

printf("%s\n", referece_text_buffer);
msgpack_encode_decode_and_compare(context);

ctr_encode_text_destroy(referece_text_buffer);
ctr_destroy(context);
}

void test_simple_to_msgpack_and_back()
{
struct ctrace *ctx;
Expand Down Expand Up @@ -640,5 +733,6 @@ void test_simple_to_msgpack_and_back()
TEST_LIST = {
{"cmt_simple_to_msgpack_and_back", test_simple_to_msgpack_and_back},
{"cmt_msgpack", test_msgpack_to_cmt},
{"empty_spans", test_msgpack_to_ctr_with_empty_spans},
{ 0 }
};
6 changes: 5 additions & 1 deletion plugins/in_calyptia_fleet/in_calyptia_fleet.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,10 @@ static msgpack_object *msgpack_lookup_map_key(msgpack_object *obj, const char *k

key = &cur->key.via.str;

if (key->size != strlen(keyname)) {
continue;
}

if (strncmp(key->ptr, keyname, key->size) == 0) {
return &cur->val;
}
Expand Down Expand Up @@ -799,7 +803,7 @@ static ssize_t parse_fleet_search_json(struct flb_in_calyptia_fleet_config *ctx,
break;
}

fleet = msgpack_lookup_map_key(map, "ID");
fleet = msgpack_lookup_map_key(map, "id");
if (fleet == NULL) {
flb_plg_error(ctx->ins, "unable to find fleet by name");
break;
Expand Down
46 changes: 46 additions & 0 deletions plugins/out_calyptia/calyptia.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,52 @@ static flb_sds_t get_agent_metadata(struct flb_calyptia *ctx)
msgpack_pack_str(&mp_pck, 9);
msgpack_pack_str_body(&mp_pck, "community", 9);

flb_mp_map_header_append(&mh);
msgpack_pack_str(&mp_pck, 2);
msgpack_pack_str_body(&mp_pck, "os", 2);
#ifdef FLB_SYSTEM_WINDOWS
len = strlen("windows");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "windows", len);
#elif FLB_SYSTEM_MACOS
len = strlen("macos");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "macos", len);
#elif __linux__
len = strlen("linux");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "linux", len);
#else
len = strlen("unknown");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "unknown", len);
#endif

flb_mp_map_header_append(&mh);
msgpack_pack_str(&mp_pck, 4);
msgpack_pack_str_body(&mp_pck, "arch", 4);
#if defined(__arm__) || defined(_M_ARM)
len = strlen("arm");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "arm", len);
#elif defined(__aarch64__)
len = strlen("arm64");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "arm64", len);
#elif defined(__amd64__) || defined(_M_AMD64)
len = strlen("x86_64");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "x86_64", len);
#elif defined(__i686__) || defined(_M_I86)
len = strlen("x86");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "x86", len);
#else
len = strlen("unknown");
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, "unknown", len);
#endif

/* machineID */
flb_mp_map_header_append(&mh);
msgpack_pack_str(&mp_pck, 9);
Expand Down
20 changes: 18 additions & 2 deletions src/config_format/flb_cf_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ static int state_create_group(struct flb_cf *conf, struct parser_state *state, c
return YAML_SUCCESS;
}

static struct parser_state *state_pop(struct local_ctx *ctx)
static struct parser_state *state_pop_with_cleanup(struct local_ctx *ctx, int destroy_variants)
{
struct parser_state *last;

Expand All @@ -2083,6 +2083,17 @@ static struct parser_state *state_pop(struct local_ctx *ctx)
cfl_kvlist_destroy(last->keyvals);
}

if (destroy_variants == FLB_TRUE) {
/* Teardown associated variant stuffs */
if (last->variant_kvlist_key != NULL) {
cfl_sds_destroy(last->variant_kvlist_key);
}

if (last->variant != NULL) {
cfl_variant_destroy(last->variant);
}
}

state_destroy(last);

if (cfl_list_size(&ctx->states) <= 0) {
Expand All @@ -2092,6 +2103,11 @@ static struct parser_state *state_pop(struct local_ctx *ctx)
return cfl_list_entry_last(&ctx->states, struct parser_state, _head);
}

static struct parser_state *state_pop(struct local_ctx *ctx)
{
return state_pop_with_cleanup(ctx, FLB_FALSE);
}

static void state_destroy(struct parser_state *s)
{
flb_free(s);
Expand Down Expand Up @@ -2264,7 +2280,7 @@ static int read_config(struct flb_cf *conf, struct local_ctx *ctx,

/* free all remaining states */
if (code == -1) {
while ((state = state_pop(ctx)));
while ((state = state_pop_with_cleanup(ctx, FLB_TRUE)));
}
else {
state = state_pop(ctx);
Expand Down
1 change: 1 addition & 0 deletions src/multiline/flb_ml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,7 @@ int flb_ml_flush_stream_group(struct flb_ml_parser *ml_parser,
}
msgpack_unpacked_destroy(&result);
group->mp_sbuf.size = 0;
group->mp_md_sbuf.size = 0;
}
else if (len > 0) {
/* Pack raw content as Fluent Bit record */
Expand Down
16 changes: 16 additions & 0 deletions tests/internal/config_format_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define FLB_001 FLB_TESTS_CONF_PATH "/issue_7559.yaml"
#define FLB_002 FLB_TESTS_CONF_PATH "/processors.yaml"
#define FLB_000_WIN FLB_TESTS_CONF_PATH "\\fluent-bit-windows.yaml"
#define FLB_BROKEN_PLUGIN_VARIANT FLB_TESTS_CONF_PATH "/broken_plugin_variant.yaml"

#ifdef _WIN32
#define FLB_BASIC FLB_000_WIN
Expand Down Expand Up @@ -180,6 +181,20 @@ static void test_customs_section()
flb_cf_destroy(cf);
}

static void test_broken_plugin_variant_yaml()
{
struct flb_cf *cf;

cf = flb_cf_yaml_create(NULL, FLB_BROKEN_PLUGIN_VARIANT, NULL, 0);
TEST_CHECK(cf == NULL);

if (cf != NULL) {
TEST_CHECK_(cf != NULL, "somewhat config_format is created wrongly");
flb_cf_dump(cf);
flb_cf_destroy(cf);
}
}

static void test_slist_even()
{
struct flb_cf *cf;
Expand Down Expand Up @@ -443,6 +458,7 @@ static void test_processors()
TEST_LIST = {
{ "basic" , test_basic},
{ "customs section", test_customs_section},
{ "broken_plugin_variant_yaml", test_broken_plugin_variant_yaml},
{ "slist odd", test_slist_odd},
{ "slist even", test_slist_even},
{ "parsers file conf", test_parser_conf},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
env:
flush_interval: 1

service:
http_server: "on"
Health_Check: "on"
log_level: info

pipeline:
inputs:
- name: event_type
tag: event
type: logs
processors:
logs:
- name: log_replacer
replacement:
some_extra_data:
unsupported:
hi: * # this character should be quoted
some_string: "hello world"
unquoted_literals:
- some_int: 4
- some_float: 3.1
- some_bool: true
quoted_literals:
- some_quoted_int: "4"
- some_quoted_float: '3.1'
- some_quoted_bool: "true"

outputs:
- name: stdout
format: json
match: event
Loading