Skip to content

Commit

Permalink
lib: cmetrics: upgrade to v0.9.7
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <eduardo@calyptia.com>
  • Loading branch information
edsiper committed Oct 10, 2024
1 parent 352c5f2 commit d7d0938
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 44 deletions.
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 9)
set(CMT_VERSION_PATCH 6)
set(CMT_VERSION_PATCH 7)
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down
73 changes: 30 additions & 43 deletions lib/cmetrics/src/cmt_encode_opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ static Opentelemetry__Proto__Metrics__V1__ScopeMetrics **
static void destroy_scope_metric_list(
Opentelemetry__Proto__Metrics__V1__ScopeMetrics **metric_list);

struct cfl_kvlist *fetch_metadata_kvlist_key(
struct cfl_kvlist *kvlist, char *key)
struct cfl_kvlist *fetch_metadata_kvlist_key(struct cfl_kvlist *kvlist, char *key)
{
struct cfl_variant *entry_variant;
struct cfl_kvlist *entry_kvlist;
Expand Down Expand Up @@ -1015,16 +1014,6 @@ static Opentelemetry__Proto__Metrics__V1__ResourceMetrics **
return metric_list;
}

static void destroy_scope_metrics(
Opentelemetry__Proto__Metrics__V1__ScopeMetrics *metric)
{
if (metric != NULL) {
destroy_metric_list(metric->metrics);

free(metric);
}
}

void destroy_instrumentation_scope(Opentelemetry__Proto__Common__V1__InstrumentationScope *scope)
{
if (scope->name != NULL) {
Expand All @@ -1042,6 +1031,21 @@ void destroy_instrumentation_scope(Opentelemetry__Proto__Common__V1__Instrumenta
free(scope);
}

static void destroy_scope_metrics(Opentelemetry__Proto__Metrics__V1__ScopeMetrics *metric)
{
if (metric != NULL) {
if (is_string_releaseable(metric->schema_url)) {
cfl_sds_destroy(metric->schema_url);
metric->schema_url = NULL;
}
if (metric->scope != NULL) {
destroy_instrumentation_scope(metric->scope);
}
destroy_metric_list(metric->metrics);
free(metric);
}
}

static Opentelemetry__Proto__Common__V1__InstrumentationScope *
initialize_instrumentation_scope(
struct cfl_kvlist *scope_root,
Expand All @@ -1065,9 +1069,7 @@ static Opentelemetry__Proto__Common__V1__InstrumentationScope *
return NULL;
}

scope = \
calloc(1, sizeof(Opentelemetry__Proto__Common__V1__InstrumentationScope));

scope = calloc(1, sizeof(Opentelemetry__Proto__Common__V1__InstrumentationScope));
if (scope == NULL) {
*error_detection_flag = CMT_TRUE;

Expand Down Expand Up @@ -1109,20 +1111,17 @@ static Opentelemetry__Proto__Common__V1__InstrumentationScope *
return scope;
}

static Opentelemetry__Proto__Metrics__V1__ScopeMetrics *
initialize_scope_metrics(
struct cfl_kvlist *scope_metrics_root,
size_t metric_element_count)
static Opentelemetry__Proto__Metrics__V1__ScopeMetrics *initialize_scope_metrics(
struct cfl_kvlist *scope_metrics_root,
size_t metric_element_count)
{
int error_detection_flag;
Opentelemetry__Proto__Metrics__V1__ScopeMetrics *scope_metrics;
struct cfl_kvlist *metadata;

metadata = fetch_metadata_kvlist_key(scope_metrics_root, "metadata");

scope_metrics = \
calloc(1, sizeof(Opentelemetry__Proto__Metrics__V1__ScopeMetrics));

scope_metrics = calloc(1, sizeof(Opentelemetry__Proto__Metrics__V1__ScopeMetrics));
if (scope_metrics == NULL) {
return NULL;
}
Expand All @@ -1132,9 +1131,7 @@ static Opentelemetry__Proto__Metrics__V1__ScopeMetrics *
error_detection_flag = CMT_FALSE;

if (metric_element_count > 0) {
scope_metrics->metrics = \
initialize_metric_list(metric_element_count);

scope_metrics->metrics = initialize_metric_list(metric_element_count);
if (scope_metrics->metrics == NULL) {
error_detection_flag = CMT_TRUE;
}
Expand All @@ -1145,12 +1142,11 @@ static Opentelemetry__Proto__Metrics__V1__ScopeMetrics *

if (!error_detection_flag && metadata != NULL) {
scope_metrics->schema_url = fetch_metadata_string_key(metadata, "schema_url", &error_detection_flag);

}

if (error_detection_flag &&
scope_metrics != NULL) {
if (error_detection_flag && scope_metrics != NULL) {
destroy_scope_metrics(scope_metrics);

scope_metrics = NULL;
}

Expand Down Expand Up @@ -1195,9 +1191,7 @@ static void destroy_scope_metric_list(
}
}

static Opentelemetry__Proto__Metrics__V1__ScopeMetrics **
initialize_scope_metrics_list(
size_t element_count)
static Opentelemetry__Proto__Metrics__V1__ScopeMetrics **initialize_scope_metrics_list(size_t element_count)
{
Opentelemetry__Proto__Metrics__V1__ScopeMetrics **metric_list;

Expand All @@ -1207,8 +1201,7 @@ static Opentelemetry__Proto__Metrics__V1__ScopeMetrics **
return metric_list;
}

static void destroy_attribute(
Opentelemetry__Proto__Common__V1__KeyValue *attribute)
static void destroy_attribute(Opentelemetry__Proto__Common__V1__KeyValue *attribute)
{
if (attribute != NULL) {
if (attribute->value != NULL) {
Expand Down Expand Up @@ -2078,10 +2071,8 @@ static void destroy_opentelemetry_context(
}
}

static Opentelemetry__Proto__Resource__V1__Resource *
initialize_resource(
struct cfl_kvlist *resource_root,
int *error_detection_flag)
static Opentelemetry__Proto__Resource__V1__Resource *initialize_resource(struct cfl_kvlist *resource_root,
int *error_detection_flag)
{
struct cfl_kvlist *attributes;
struct cfl_kvlist *metadata;
Expand All @@ -2096,17 +2087,13 @@ static Opentelemetry__Proto__Resource__V1__Resource *
attributes = fetch_metadata_kvlist_key(resource_root, "attributes");
metadata = fetch_metadata_kvlist_key(resource_root, "metadata");

if (cfl_kvlist_count(attributes) == 0 &&
cfl_kvlist_count(metadata) == 0) {
if (cfl_kvlist_count(attributes) == 0 && cfl_kvlist_count(metadata) == 0) {
return NULL;
}

resource = \
calloc(1, sizeof(Opentelemetry__Proto__Resource__V1__Resource));

resource = calloc(1, sizeof(Opentelemetry__Proto__Resource__V1__Resource));
if (resource == NULL) {
*error_detection_flag = CMT_TRUE;

return NULL;
}

Expand Down

0 comments on commit d7d0938

Please sign in to comment.