Skip to content

Commit

Permalink
cat: added histogram and summary copying (#195)
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Alminana <leonardo@calyptia.com>
  • Loading branch information
leonardo-albertovich committed Apr 9, 2024
1 parent de2f6fb commit 19632e0
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/cmt_cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 19632e0

Please sign in to comment.