Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lib: cmetrics: upgrade to v2.0.1
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
  • Loading branch information
edsiper committed Feb 12, 2026
commit 74e570d6017e3256e16190e8b5d41fd1ea62a053
4 changes: 3 additions & 1 deletion lib/cmetrics/src/cmt_encode_prometheus_remote_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,9 @@ int pack_complex_metric_sample(struct cmt_prometheus_remote_write_context *conte
context->sequence_number -= SYNTHETIC_METRIC_HISTOGRAM_COUNT_SEQUENCE_DELTA;
}

if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS &&
(map->type == CMT_HISTOGRAM ||
(map->type == CMT_EXP_HISTOGRAM && metric->exp_hist_sum_set == CMT_TRUE))) {
context->sequence_number += SYNTHETIC_METRIC_HISTOGRAM_SUM_SEQUENCE_DELTA;

cfl_sds_len_set(synthetized_metric_name,
Expand Down
70 changes: 70 additions & 0 deletions lib/cmetrics/tests/exp_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,34 @@ static int get_prometheus_bucket_value(cfl_sds_t encoded_prometheus,
return 0;
}

static int remote_write_contains_metric_name(Prometheus__WriteRequest *request,
const char *metric_name)
{
size_t index;
size_t label_index;

for (index = 0; index < request->n_timeseries; index++) {
if (request->timeseries[index] == NULL) {
continue;
}

for (label_index = 0; label_index < request->timeseries[index]->n_labels; label_index++) {
if (request->timeseries[index]->labels[label_index] == NULL) {
continue;
}

if (request->timeseries[index]->labels[label_index]->name != NULL &&
request->timeseries[index]->labels[label_index]->value != NULL &&
strcmp(request->timeseries[index]->labels[label_index]->name, "__name__") == 0 &&
strcmp(request->timeseries[index]->labels[label_index]->value, metric_name) == 0) {
return CMT_TRUE;
}
}
}

return CMT_FALSE;
}

static int assert_prometheus_bucket_monotonicity(cfl_sds_t encoded_prometheus,
double *out_last_finite,
double *out_plus_inf)
Expand Down Expand Up @@ -714,12 +742,54 @@ void test_exp_histogram_prometheus_no_sum()
cmt_destroy(context);
}

void test_exp_histogram_remote_write_no_sum()
{
uint64_t positive[3] = {3, 5, 7};
uint64_t negative[2] = {2, 1};
cfl_sds_t encoded_remote_write;
struct cmt *context;
Prometheus__WriteRequest *request;

cmt_initialize();

context = cmt_create();
TEST_CHECK(context != NULL);
if (context == NULL) {
return;
}

TEST_CHECK(create_test_metric_custom(context, cfl_time_now(),
2, 11, 0.0,
-2, 3, positive,
-1, 2, negative,
CMT_FALSE, 123.75, 29) != NULL);

encoded_remote_write = cmt_encode_prometheus_remote_write_create(context);
TEST_CHECK(encoded_remote_write != NULL);
if (encoded_remote_write != NULL) {
request = prometheus__write_request__unpack(NULL,
cfl_sds_len(encoded_remote_write),
(uint8_t *) encoded_remote_write);
TEST_CHECK(request != NULL);
if (request != NULL) {
TEST_CHECK(remote_write_contains_metric_name(request, "cm_native_exp_hist_count") == CMT_TRUE);
TEST_CHECK(remote_write_contains_metric_name(request, "cm_native_exp_hist_sum") == CMT_FALSE);
TEST_CHECK(remote_write_contains_metric_name(request, "cm_native_exp_hist_bucket") == CMT_TRUE);
prometheus__write_request__free_unpacked(request, NULL);
}
}

cmt_encode_prometheus_remote_write_destroy(encoded_remote_write);
cmt_destroy(context);
}

TEST_LIST = {
{"exp_histogram_msgpack_roundtrip", test_exp_histogram_msgpack_roundtrip},
{"exp_histogram_encoder_smoke", test_exp_histogram_encoder_smoke},
{"exp_histogram_nonzero_zero_threshold", test_exp_histogram_nonzero_zero_threshold},
{"exp_histogram_cat_filter_smoke", test_exp_histogram_cat_filter_smoke},
{"exp_histogram_cat_sparse_merge", test_exp_histogram_cat_sparse_merge},
{"exp_histogram_prometheus_no_sum", test_exp_histogram_prometheus_no_sum},
{"exp_histogram_remote_write_no_sum", test_exp_histogram_remote_write_no_sum},
{ 0 }
};
Loading