Skip to content

Commit 40a6d4a

Browse files
committed
lib: cmetrics: upgrade to v2.1.2
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 7d5942b commit 40a6d4a

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

lib/cmetrics/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
66
# CMetrics Version
77
set(CMT_VERSION_MAJOR 2)
88
set(CMT_VERSION_MINOR 1)
9-
set(CMT_VERSION_PATCH 1)
9+
set(CMT_VERSION_PATCH 2)
1010
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")
1111

1212
# Include helpers

lib/cmetrics/src/cmt_decode_prometheus.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,10 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
441441
{
442442
int ret = 0;
443443
int i;
444+
int has_le = CMT_FALSE;
444445
size_t bucket_count;
445446
size_t bucket_index;
447+
size_t label_count = 0;
446448
double *buckets = NULL;
447449
uint64_t *bucket_defaults = NULL;
448450
double sum = 0;
@@ -488,14 +490,30 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
488490
"failed to allocate buckets");
489491
goto end;
490492
}
491-
labels_without_le = calloc(context->metric.label_count - 1, sizeof(*labels_without_le));
493+
for (i = 0; i < context->metric.label_count; i++) {
494+
if (!strcmp(context->metric.labels[i], "le")) {
495+
has_le = CMT_TRUE;
496+
}
497+
else {
498+
label_count++;
499+
}
500+
}
501+
502+
if (!has_le) {
503+
ret = report_error(context,
504+
CMT_DECODE_PROMETHEUS_SYNTAX_ERROR,
505+
"missing histogram bucket \"le\" label");
506+
goto end;
507+
}
508+
509+
labels_without_le = calloc(label_count, sizeof(*labels_without_le));
492510
if (!labels_without_le) {
493511
ret = report_error(context,
494512
CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR,
495513
"failed to allocate labels_without_le");
496514
goto end;
497515
}
498-
values_without_le = calloc(context->metric.label_count - 1, sizeof(*labels_without_le));
516+
values_without_le = calloc(label_count, sizeof(*values_without_le));
499517
if (!values_without_le) {
500518
ret = report_error(context,
501519
CMT_DECODE_PROMETHEUS_CMT_CREATE_ERROR,
@@ -525,6 +543,13 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
525543
/* probably last bucket, which has "Inf" */
526544
break;
527545
}
546+
if (!sample->label_values[le_label_index] ||
547+
sample->label_values[le_label_index][0] == '\0') {
548+
ret = report_error(context,
549+
CMT_DECODE_PROMETHEUS_SYNTAX_ERROR,
550+
"missing histogram bucket \"le\" value");
551+
goto end;
552+
}
528553
if (parse_double(sample->label_values[le_label_index],
529554
buckets + bucket_index)) {
530555
ret = report_error(context,

lib/cmetrics/tests/prometheus_parser.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,26 @@ void test_histogram_labels()
692692
cmt_decode_prometheus_destroy(cmt);
693693
}
694694

695+
void test_histogram_missing_le_label()
696+
{
697+
int status;
698+
struct cmt *cmt;
699+
struct cmt_decode_prometheus_parse_opts opts;
700+
701+
cmt = NULL;
702+
memset(&opts, 0, sizeof(opts));
703+
704+
status = cmt_decode_prometheus_create(&cmt,
705+
"# HELP test_histogram A histogram missing the le label.\n"
706+
"# TYPE test_histogram histogram\n"
707+
"test_histogram_bucket{foo=\"bar\"} 1\n"
708+
"test_histogram_bucket{foo=\"baz\"} 2\n"
709+
"test_histogram_sum 3.5\n"
710+
"test_histogram_count 2\n", 0, &opts);
711+
712+
TEST_CHECK(status == CMT_DECODE_PROMETHEUS_SYNTAX_ERROR);
713+
}
714+
695715
void test_summary()
696716
{
697717
int status;
@@ -1712,6 +1732,7 @@ TEST_LIST = {
17121732
{"issue_71", test_issue_71},
17131733
{"histogram", test_histogram},
17141734
{"histogram_labels", test_histogram_labels},
1735+
{"histogram_missing_le_label", test_histogram_missing_le_label},
17151736
{"summary", test_summary},
17161737
{"null_labels", test_null_labels},
17171738
{"issue_fluent_bit_5541", test_issue_fluent_bit_5541},
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)