From ed943185720df586e924d97a31b3df2914d431bb Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Tue, 15 Oct 2024 15:19:37 +0900 Subject: [PATCH] encode_opentelemetry: Encode otel payloads if valid contexts are existing Signed-off-by: Hiroshi Hatake --- src/cmt_encode_opentelemetry.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cmt_encode_opentelemetry.c b/src/cmt_encode_opentelemetry.c index 80b988d..0035220 100644 --- a/src/cmt_encode_opentelemetry.c +++ b/src/cmt_encode_opentelemetry.c @@ -2396,6 +2396,7 @@ int pack_basic_type(struct cmt_opentelemetry_context *context, int result; struct cfl_list *head; uint64_t now; + int cutoff = CMT_FALSE; sample_count = 0; now = cfl_time_now(); @@ -2471,10 +2472,10 @@ int pack_basic_type(struct cmt_opentelemetry_context *context, if (context->use_cutoff == CMT_TRUE && check_staled_timestamp(&map->metric, now, context->cutoff_threshold)) { - destroy_metric(metric); /* Skip processing metrics which are staled over the threshold */ - return CMT_ENCODE_OPENTELEMETRY_CUTOFF_ERROR; + cutoff = CMT_TRUE; + continue; } result = append_sample_to_metric(context, @@ -2506,6 +2507,10 @@ int pack_basic_type(struct cmt_opentelemetry_context *context, (*metric_index)++; + if (cutoff == CMT_TRUE) { + return CMT_ENCODE_OPENTELEMETRY_CUTOFF_ERROR; + } + return result; } @@ -2631,10 +2636,9 @@ cfl_sds_t cmt_encode_opentelemetry_create_with_cutoff_opts(struct cmt *cmt, } } - if (result == CMT_ENCODE_OPENTELEMETRY_SUCCESS) { + if (metric_index > 0) { buf = render_opentelemetry_context_to_sds(context); - } - else if (result == CMT_ENCODE_OPENTELEMETRY_CUTOFF_ERROR) { + } else { buf = NULL; }