From 953f0856ee36d96ce39e1a3a853b25386bfb1a42 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Tue, 5 Nov 2024 14:54:37 -0600 Subject: [PATCH] lib: cmetrics: upgrade to v0.9.9 Signed-off-by: Eduardo Silva --- lib/cmetrics/CMakeLists.txt | 2 +- lib/cmetrics/src/cmt_encode_opentelemetry.c | 69 +++++++++------------ 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/lib/cmetrics/CMakeLists.txt b/lib/cmetrics/CMakeLists.txt index 55d02dc8619..18582997d61 100644 --- a/lib/cmetrics/CMakeLists.txt +++ b/lib/cmetrics/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # CMetrics Version set(CMT_VERSION_MAJOR 0) set(CMT_VERSION_MINOR 9) -set(CMT_VERSION_PATCH 8) +set(CMT_VERSION_PATCH 9) set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}") # Include helpers diff --git a/lib/cmetrics/src/cmt_encode_opentelemetry.c b/lib/cmetrics/src/cmt_encode_opentelemetry.c index af7605f7e73..8f961aa7625 100644 --- a/lib/cmetrics/src/cmt_encode_opentelemetry.c +++ b/lib/cmetrics/src/cmt_encode_opentelemetry.c @@ -273,7 +273,7 @@ static inline void otlp_kvpair_destroy(Opentelemetry__Proto__Common__V1__KeyValu { if (kvpair != NULL) { if (kvpair->key != NULL) { - free(kvpair->key); + cfl_sds_destroy(kvpair->key); } if (kvpair->value != NULL) { @@ -323,7 +323,7 @@ static inline void otlp_any_value_destroy(Opentelemetry__Proto__Common__V1__AnyV if (value != NULL) { if (value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) { if (value->string_value != NULL) { - free(value->string_value); + cfl_sds_destroy(value->string_value); } } else if (value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_ARRAY_VALUE) { @@ -494,21 +494,19 @@ static inline Opentelemetry__Proto__Common__V1__KeyValue *cfl_variant_kvpair_to_ pair = otlp_kvpair_value_initialize(); if (pair != NULL) { - pair->key = strdup(input_pair->key); + pair->key = cfl_sds_create(input_pair->key); if (pair->key != NULL) { pair->value = cfl_variant_to_otlp_any_value(input_pair->val); if (pair->value == NULL) { - free(pair->key); - + cfl_sds_destroy(pair->key); pair->key = NULL; } } if (pair->key == NULL) { free(pair); - pair = NULL; } } @@ -649,11 +647,9 @@ static inline Opentelemetry__Proto__Common__V1__AnyValue *cfl_variant_string_to_ result = otlp_any_value_initialize(CFL_VARIANT_STRING, 0); if (result != NULL) { - result->string_value = strdup(value->data.as_string); - + result->string_value = cfl_sds_create(value->data.as_string); if (result->string_value == NULL) { otlp_any_value_destroy(result); - result = NULL; } } @@ -1061,50 +1057,49 @@ static Opentelemetry__Proto__Common__V1__InstrumentationScope * return NULL; } + /* cmetrics: retrieve attributes and metadata fields */ attributes = fetch_metadata_kvlist_key(scope_root, "attributes"); metadata = fetch_metadata_kvlist_key(scope_root, "metadata"); - if (cfl_kvlist_count(attributes) == 0 && - cfl_kvlist_count(metadata) == 0) { - return NULL; - } - + /* create scope */ scope = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__InstrumentationScope)); if (scope == NULL) { *error_detection_flag = CMT_TRUE; - return NULL; } - opentelemetry__proto__common__v1__instrumentation_scope__init(scope); - scope->attributes = cfl_kvlist_to_otlp_kvpair_list(attributes); + /* attributes */ + if (attributes && cfl_kvlist_count(attributes) > 0) { + scope->attributes = cfl_kvlist_to_otlp_kvpair_list(attributes); - if (scope->attributes == NULL) { - *error_detection_flag = CMT_TRUE; - } - - scope->n_attributes = cfl_kvlist_count(attributes); + if (scope->attributes == NULL) { + *error_detection_flag = CMT_TRUE; + } - if (!(*error_detection_flag)) { - scope->dropped_attributes_count = (uint32_t) fetch_metadata_int64_key( - metadata, - "dropped_attributes_count", - error_detection_flag); + scope->n_attributes = cfl_kvlist_count(attributes); } - if (!(*error_detection_flag)) { - scope->name = fetch_metadata_string_key(metadata, "name", error_detection_flag); - } + /* scope metadata */ + if (metadata) { + if (!(*error_detection_flag)) { + scope->dropped_attributes_count = (uint32_t) fetch_metadata_int64_key( + metadata, + "dropped_attributes_count", + error_detection_flag); + } - if (!(*error_detection_flag)) { - scope->version = fetch_metadata_string_key(metadata, "version", error_detection_flag); + if (!(*error_detection_flag)) { + scope->name = fetch_metadata_string_key(metadata, "name", error_detection_flag); + } + + if (!(*error_detection_flag)) { + scope->version = fetch_metadata_string_key(metadata, "version", error_detection_flag); + } } - if (*error_detection_flag && - scope != NULL) { + if (*error_detection_flag && scope != NULL) { destroy_instrumentation_scope(scope); - scope = NULL; } @@ -1205,13 +1200,11 @@ static void destroy_attribute(Opentelemetry__Proto__Common__V1__KeyValue *attrib { if (attribute != NULL) { if (attribute->value != NULL) { - if (attribute->value->value_case == \ - OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) { + if (attribute->value->value_case == OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE) { if (is_string_releaseable(attribute->value->string_value)) { cfl_sds_destroy(attribute->value->string_value); } } - free(attribute->value); }