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

lib: upgrade core libraries #8310

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cfl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# C Floppy Version
set(CFL_VERSION_MAJOR 0)
set(CFL_VERSION_MINOR 2)
set(CFL_VERSION_PATCH 2)
set(CFL_VERSION_MINOR 3)
set(CFL_VERSION_PATCH 0)
set(CFL_VERSION_STR "${CFL_VERSION_MAJOR}.${CFL_VERSION_MINOR}.${CFL_VERSION_PATCH}")

# Configuration options
Expand Down
1 change: 1 addition & 0 deletions lib/cfl/include/cfl/cfl_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int cfl_array_append_bytes(struct cfl_array *array, char *value, size_t length);
int cfl_array_append_reference(struct cfl_array *array, void *value);
int cfl_array_append_bool(struct cfl_array *array, int value);
int cfl_array_append_int64(struct cfl_array *array, int64_t value);
int cfl_array_append_uint64(struct cfl_array *array, uint64_t value);
int cfl_array_append_double(struct cfl_array *array, double value);
int cfl_array_append_array(struct cfl_array *array, struct cfl_array *value);
int cfl_array_append_new_array(struct cfl_array *array, size_t size);
Expand Down
3 changes: 3 additions & 0 deletions lib/cfl/include/cfl/cfl_kvlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ int cfl_kvlist_insert_bool(struct cfl_kvlist *list,
int cfl_kvlist_insert_int64(struct cfl_kvlist *list,
char *key, int64_t value);

int cfl_kvlist_insert_uint64(struct cfl_kvlist *list,
char *key, uint64_t value);

int cfl_kvlist_insert_double(struct cfl_kvlist *list,
char *key, double value);

Expand Down
3 changes: 3 additions & 0 deletions lib/cfl/include/cfl/cfl_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define CFL_VARIANT_KVLIST 6
#define CFL_VARIANT_BYTES 7
#define CFL_VARIANT_REFERENCE 8
#define CFL_VARIANT_UINT 9

struct cfl_array;
struct cfl_kvlist;
Expand All @@ -43,6 +44,7 @@ struct cfl_variant {
cfl_sds_t as_bytes;
unsigned int as_bool;
int64_t as_int64;
uint64_t as_uint64;
double as_double;
void *as_reference;
struct cfl_array *as_array;
Expand All @@ -54,6 +56,7 @@ struct cfl_variant *cfl_variant_create_from_string(char *value);
struct cfl_variant *cfl_variant_create_from_bytes(char *value, size_t length);
struct cfl_variant *cfl_variant_create_from_bool(int value);
struct cfl_variant *cfl_variant_create_from_int64(int64_t value);
struct cfl_variant *cfl_variant_create_from_uint64(uint64_t value);
struct cfl_variant *cfl_variant_create_from_double(double value);
struct cfl_variant *cfl_variant_create_from_array(struct cfl_array *value);
struct cfl_variant *cfl_variant_create_from_kvlist(struct cfl_kvlist *value);
Expand Down
21 changes: 21 additions & 0 deletions lib/cfl/src/cfl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ int cfl_array_append_int64(struct cfl_array *array, int64_t value)
return 0;
}

int cfl_array_append_uint64(struct cfl_array *array, uint64_t value)
{
struct cfl_variant *value_instance;
int result;

value_instance = cfl_variant_create_from_uint64(value);

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

result = cfl_array_append(array, value_instance);

if (result) {
cfl_variant_destroy(value_instance);
return -2;
}

return 0;
}


int cfl_array_append_double(struct cfl_array *array, double value)
{
Expand Down
23 changes: 23 additions & 0 deletions lib/cfl/src/cfl_kvlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,29 @@ int cfl_kvlist_insert_int64(struct cfl_kvlist *list,
return 0;
}

int cfl_kvlist_insert_uint64(struct cfl_kvlist *list,
char *key, uint64_t value)
{
struct cfl_variant *value_instance;
int result;

value_instance = cfl_variant_create_from_uint64(value);

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

result = cfl_kvlist_insert(list, key, value_instance);

if (result) {
cfl_variant_destroy(value_instance);

return -2;
}

return 0;
}

int cfl_kvlist_insert_double(struct cfl_kvlist *list,
char *key, double value)
{
Expand Down
16 changes: 16 additions & 0 deletions lib/cfl/src/cfl_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ int cfl_variant_print(FILE *fp, struct cfl_variant *val)
case CFL_VARIANT_INT:
ret = fprintf(fp, "%" PRId64, val->data.as_int64);
break;
case CFL_VARIANT_UINT:
ret = fprintf(fp, "%" PRIu64, val->data.as_uint64);
break;
case CFL_VARIANT_DOUBLE:
ret = fprintf(fp, "%lf", val->data.as_double);
break;
Expand Down Expand Up @@ -146,6 +149,19 @@ struct cfl_variant *cfl_variant_create_from_int64(int64_t value)
return instance;
}

struct cfl_variant *cfl_variant_create_from_uint64(uint64_t value)
{
struct cfl_variant *instance;

instance = cfl_variant_create();
if (instance != NULL) {
instance->data.as_uint64 = value;
instance->type = CFL_VARIANT_UINT;
}

return instance;
}

struct cfl_variant *cfl_variant_create_from_double(double value)
{
struct cfl_variant *instance;
Expand Down
40 changes: 40 additions & 0 deletions lib/cfl/tests/variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,45 @@ static void test_variant_print_int64()
}
}

static void test_variant_print_uint64()
{
int ret;
int i;
uint64_t inputs[] = {1, 0, 18446744073709551615ULL};
char *expects[] = {"1", "0", "18446744073709551615" /*UINT64_MAX*/};

FILE *fp = NULL;
struct cfl_variant *val = NULL;

for (i=0; i<sizeof(inputs)/sizeof(uint64_t); i++) {
fp = tmpfile();
if (!TEST_CHECK(fp != NULL)) {
TEST_MSG("%d: fp is NULL", i);
continue;
}
val = cfl_variant_create_from_uint64(inputs[i]);
if (!TEST_CHECK(val != NULL)) {
TEST_MSG("%d: cfl_variant_create_from_uint64 failed", i);
fclose(fp);
continue;
}

ret = cfl_variant_print(fp, val);
if (!TEST_CHECK(ret > 0)) {
TEST_MSG("%d:cfl_variant_print failed", i);
cfl_variant_destroy(val);
fclose(fp);
continue;
}
ret = compare(fp, expects[i], 0);
if (!TEST_CHECK(ret == 0)) {
TEST_MSG("%d:compare failed", i);
}
cfl_variant_destroy(val);
fclose(fp);
}
}

static void test_variant_print_array()
{
int ret;
Expand Down Expand Up @@ -459,6 +498,7 @@ static void test_variant_print_unknown()
TEST_LIST = {
{"variant_print_bool", test_variant_print_bool},
{"variant_print_int64", test_variant_print_int64},
{"variant_print_uint64", test_variant_print_uint64},
{"variant_print_double", test_variant_print_double},
{"variant_print_string", test_variant_print_string},
{"variant_print_bytes", test_variant_print_bytes},
Expand Down
2 changes: 1 addition & 1 deletion lib/cmetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMetrics Version
set(CMT_VERSION_MAJOR 0)
set(CMT_VERSION_MINOR 6)
set(CMT_VERSION_PATCH 5)
set(CMT_VERSION_PATCH 6)
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down
4 changes: 2 additions & 2 deletions lib/ctraces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ endif()

# CTraces Version
set(CTR_VERSION_MAJOR 0)
set(CTR_VERSION_MINOR 3)
set(CTR_VERSION_PATCH 1)
set(CTR_VERSION_MINOR 4)
set(CTR_VERSION_PATCH 0)
set(CTR_VERSION_STR "${CTR_VERSION_MAJOR}.${CTR_VERSION_MINOR}.${CTR_VERSION_PATCH}")

# Define __FILENAME__ consistently across Operating Systems
Expand Down
2 changes: 1 addition & 1 deletion lib/ctraces/examples/otlp-encoder/otlp-encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int main()
ctr_span_event_set_attribute_string(event, "syscall 3", "write()");

/* add a key/value pair list */
kv = cfl_kvlist_create(1);
kv = cfl_kvlist_create();
cfl_kvlist_insert_string(kv, "language", "c");

ctr_span_set_attribute_kvlist(span_root, "my-list", kv);
Expand Down
2 changes: 1 addition & 1 deletion lib/ctraces/examples/simple-c-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int main()
ctr_span_event_set_attribute_string(event, "syscall 3", "write()");

/* add a key/value pair list */
kv = cfl_kvlist_create(1);
kv = cfl_kvlist_create();
cfl_kvlist_insert_string(kv, "language", "c");

ctr_span_set_attribute_kvlist(span_root, "my-list", kv);
Expand Down
19 changes: 18 additions & 1 deletion lib/ctraces/include/ctraces/ctr_variant_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#include <mpack/mpack.h>

#define CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE 100
#define CFL_VARIANT_UTILS_INITIAL_ARRAY_SIZE 100
#define CFL_VARIANT_UTILS_SERIALIZED_ARRAY_SIZE_LIMIT 100000

/* These are the only functions meant for general use,
* the reason why the kvlist packing and unpacking
* functions are exposed is the internal and external
Expand Down Expand Up @@ -226,12 +230,25 @@ static inline int unpack_cfl_array(mpack_reader_t *reader,

entry_count = mpack_tag_array_count(&tag);

internal_array = cfl_array_create(entry_count);
if (entry_count >= CFL_VARIANT_UTILS_SERIALIZED_ARRAY_SIZE_LIMIT) {
return -2;
}

if (entry_count >= CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE) {
internal_array = cfl_array_create(CFL_VARIANT_UTILS_INITIAL_ARRAY_SIZE);
}
else {
internal_array = cfl_array_create(entry_count);
}

if (internal_array == NULL) {
return -3;
}

if (entry_count >= CFL_VARIANT_UTILS_MAXIMUM_FIXED_ARRAY_SIZE) {
cfl_array_resizable(internal_array, CFL_TRUE);
}

for (index = 0 ; index < entry_count ; index++) {
result = unpack_cfl_variant(reader, &entry_value);

Expand Down
2 changes: 1 addition & 1 deletion lib/ctraces/src/ctr_attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ctrace_attributes *ctr_attributes_create()
return NULL;
}

attr->kv = cfl_kvlist_create(128);
attr->kv = cfl_kvlist_create();
if (!attr->kv) {
free(attr);
return NULL;
Expand Down
30 changes: 27 additions & 3 deletions lib/ctraces/src/ctr_decode_msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ static int unpack_instrumentation_scope_attributes(mpack_reader_t *reader, size_
return CTR_DECODE_MSGPACK_VARIANT_DECODE_ERROR;
}

if (context->scope_span->instrumentation_scope->attr != NULL) {
ctr_attributes_destroy(context->scope_span->instrumentation_scope->attr);
context->scope_span->instrumentation_scope->attr = NULL;
}

context->scope_span->instrumentation_scope->attr = attributes;
}

Expand All @@ -132,6 +137,7 @@ static int unpack_instrumentation_scope_attributes(mpack_reader_t *reader, size_

static int unpack_scope_span_instrumentation_scope(mpack_reader_t *reader, size_t index, void *ctx)
{
int result;
struct ctrace_instrumentation_scope *instrumentation_scope;
struct ctr_msgpack_decode_context *context = ctx;
struct ctr_mpack_map_entry_callback_t callbacks[] = \
Expand All @@ -151,7 +157,12 @@ static int unpack_scope_span_instrumentation_scope(mpack_reader_t *reader, size_

ctr_scope_span_set_instrumentation_scope(context->scope_span, instrumentation_scope);

return ctr_mpack_unpack_map(reader, callbacks, ctx);
result = ctr_mpack_unpack_map(reader, callbacks, ctx);
if (result != CTR_DECODE_MSGPACK_SUCCESS) {
ctr_instrumentation_scope_destroy(context->scope_span->instrumentation_scope);
context->scope_span->instrumentation_scope = NULL;
}
return result;
}

/* Event callbacks */
Expand Down Expand Up @@ -541,6 +552,7 @@ static int unpack_span_status(mpack_reader_t *reader, size_t index, void *ctx)

static int unpack_span(mpack_reader_t *reader, size_t index, void *ctx)
{
int result;
struct ctr_msgpack_decode_context *context = ctx;
struct ctr_mpack_map_entry_callback_t callbacks[] = \
{
Expand All @@ -565,8 +577,14 @@ static int unpack_span(mpack_reader_t *reader, size_t index, void *ctx)
if (context->span == NULL) {
return CTR_DECODE_MSGPACK_ALLOCATION_ERROR;
}
result = ctr_mpack_unpack_map(reader, callbacks, ctx);

return ctr_mpack_unpack_map(reader, callbacks, ctx);
if (result != CTR_DECODE_MSGPACK_SUCCESS) {
ctr_span_destroy(context->span);
context->span = NULL;
}

return result;
}

/* Scope span callbacks */
Expand All @@ -591,6 +609,7 @@ static int unpack_scope_span_schema_url(mpack_reader_t *reader, size_t index, vo

static int unpack_scope_span(mpack_reader_t *reader, size_t index, void *ctx)
{
int result;
struct ctr_msgpack_decode_context *context = ctx;
struct ctr_mpack_map_entry_callback_t callbacks[] = \
{
Expand All @@ -606,7 +625,12 @@ static int unpack_scope_span(mpack_reader_t *reader, size_t index, void *ctx)
return CTR_DECODE_MSGPACK_ALLOCATION_ERROR;
}

return ctr_mpack_unpack_map(reader, callbacks, ctx);
result = ctr_mpack_unpack_map(reader, callbacks, ctx);
if (result != CTR_DECODE_MSGPACK_SUCCESS) {
ctr_scope_span_destroy(context->scope_span);
context->scope_span = NULL;
}
return result;
}

/* Resource span callbacks */
Expand Down
4 changes: 3 additions & 1 deletion lib/ctraces/src/ctr_decode_opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ int ctr_decode_opentelemetry_create(struct ctrace **out_ctr,
ctr_span_kind_set(span, otel_span->kind);
ctr_span_start_ts(ctr, span, otel_span->start_time_unix_nano);
ctr_span_end_ts(ctr, span, otel_span->end_time_unix_nano);
ctr_span_set_status(span, otel_span->status->code, otel_span->status->message);
if (otel_span->status) {
ctr_span_set_status(span, otel_span->status->code, otel_span->status->message);
}
ctr_span_set_attributes(span, otel_span->n_attributes, otel_span->attributes);
ctr_span_set_events(span, otel_span->n_events, otel_span->events);
ctr_span_set_dropped_attributes_count(span, otel_span->dropped_attributes_count);
Expand Down
Loading
Loading