From e2f7177bc0eec11e88c92322545dacb541d7cd31 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Tue, 9 Apr 2024 10:11:23 -0600 Subject: [PATCH] lib: cmetrics: upgrade to v0.7.3 Signed-off-by: Eduardo Silva --- lib/cmetrics/CMakeLists.txt | 2 +- lib/cmetrics/src/cmt_cat.c | 47 ++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/cmetrics/CMakeLists.txt b/lib/cmetrics/CMakeLists.txt index 0297a5658b2..6012d290169 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 7) -set(CMT_VERSION_PATCH 1) +set(CMT_VERSION_PATCH 3) set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}") # Include helpers diff --git a/lib/cmetrics/src/cmt_cat.c b/lib/cmetrics/src/cmt_cat.c index d93e5415f3a..5bb09cb2d75 100644 --- a/lib/cmetrics/src/cmt_cat.c +++ b/lib/cmetrics/src/cmt_cat.c @@ -107,6 +107,7 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map * struct cfl_list *head; struct cmt_metric *metric_dst; struct cmt_metric *metric_src; + struct cmt_histogram *histogram; /* Handle static metric (no labels case) */ if (src->metric_static_set) { @@ -116,6 +117,37 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map * metric_dst = &dst->metric; metric_src = &src->metric; + if (src->type == CMT_HISTOGRAM) { + histogram = (struct cmt_histogram *) src->parent; + + if (!metric_dst->hist_buckets) { + metric_dst->hist_buckets = calloc(1, sizeof(uint64_t) * (histogram->buckets->count + 1)); + if (!metric_dst->hist_buckets) { + return -1; + } + } + for (i = 0; i < histogram->buckets->count; i++) { + metric_dst->hist_buckets[i] = metric_src->hist_buckets[i]; + } + metric_dst->hist_count = metric_src->hist_count; + metric_dst->hist_sum = metric_src->hist_sum; + } + else if (src->type == CMT_SUMMARY) { + metric_dst->sum_quantiles_count = metric_src->sum_quantiles_count; + metric_dst->sum_quantiles_set = metric_src->sum_quantiles_set; + if (!metric_dst->sum_quantiles) { + metric_dst->sum_quantiles = calloc(1, sizeof(uint64_t) * (metric_src->sum_quantiles_count)); + if (!metric_dst->sum_quantiles) { + return -1; + } + } + for (i = 0; i < metric_src->sum_quantiles_count; i++) { + metric_dst->sum_quantiles[i] = metric_src->sum_quantiles[i]; + } + metric_dst->sum_count = metric_src->sum_count; + metric_dst->sum_sum = metric_src->sum_sum; + } + ts = cmt_metric_get_timestamp(metric_src); val = cmt_metric_get_value(metric_src); @@ -140,13 +172,16 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map * } if (src->type == CMT_HISTOGRAM) { + histogram = (struct cmt_histogram *) src->parent; + if (!metric_dst->hist_buckets) { - metric_dst->hist_buckets = calloc(1, sizeof(uint64_t) * (metric_src->hist_count + 1)); + metric_dst->hist_buckets = calloc(1, sizeof(uint64_t) * (histogram->buckets->count + 1)); if (!metric_dst->hist_buckets) { return -1; } } - for (i = 0; i < metric_src->hist_count; i++) { + + for (i = 0; i < histogram->buckets->count; i++) { metric_dst->hist_buckets[i] = metric_src->hist_buckets[i]; } metric_dst->hist_count = metric_src->hist_count; @@ -313,16 +348,12 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram) opts->name, opts->description, buckets, map->label_count, labels); + free(labels); + if (!hist) { return -1; } - for (i = 0; i < buckets_count; i++) { - val = histogram->buckets->upper_bounds[i]; - cmt_histogram_observe(hist, timestamp, val, map->label_count, labels); - } - free(labels); - ret = copy_map(&hist->opts, hist->map, map); if (ret == -1) { return -1;