Skip to content

Commit 936f40e

Browse files
committed
lib: cmetrics: upgrade to v1.0.3
Signed-off-by: Eduardo Silva <[email protected]>
1 parent b194683 commit 936f40e

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

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 1)
88
set(CMT_VERSION_MINOR 0)
9-
set(CMT_VERSION_PATCH 2)
9+
set(CMT_VERSION_PATCH 3)
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ static int add_metric_histogram(struct cmt_decode_prometheus_context *context)
444444
size_t bucket_index;
445445
double *buckets = NULL;
446446
uint64_t *bucket_defaults = NULL;
447-
double sum;
447+
double sum = 0;
448448
uint64_t count = 0;
449449
double count_dbl;
450450
struct cfl_list *head;
@@ -1177,7 +1177,7 @@ static int parse_sample(struct cmt_decode_prometheus_context *context,
11771177
"sample value is too long (max %zu characters)", sizeof(sample->value1) - 1);
11781178
}
11791179

1180-
strncpy(sample->value1, value1, len);
1180+
memcpy(sample->value1, value1, len);
11811181
sample->value1[len] = 0;
11821182

11831183
/* value2 */
@@ -1187,7 +1187,7 @@ static int parse_sample(struct cmt_decode_prometheus_context *context,
11871187
CMT_DECODE_PROMETHEUS_SAMPLE_VALUE_TOO_LONG,
11881188
"sample value is too long (max %zu characters)", sizeof(sample->value2) - 1);
11891189
}
1190-
strncpy(sample->value2, value2, len);
1190+
memcpy(sample->value2, value2, len);
11911191
sample->value2[len] = 0;
11921192

11931193
return 0;

lib/cmetrics/src/cmt_decode_prometheus.l

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
^[ ]*#[ ]* {
4646
// Lines with "#" as the first non-whitespace character begin a comment
4747
// unless the first token is either HELP or TYPE. To handle this ambiguity,
48-
// we enter the COMMENT_START state, which contains rules for selecting
48+
// we enter the COMMENT_START state, which contains rules for selecting
4949
// if this is a HELP/TYPE tag or just a normal comment
5050
BEGIN(COMMENT_START);
5151
}
@@ -86,7 +86,7 @@
8686
// separate start condition for this to handle "\\" and "\n" escapes
8787
// more easily.
8888
BEGIN(INHELPTAG);
89-
context->strbuf = sds_alloc(256);
89+
context->strbuf = cfl_sds_create_size(256);
9090
}
9191
else {
9292
// For TYPETAG we enter INTYPETAG start condition to check only valid
@@ -149,7 +149,7 @@
149149
if (context->strbuf != NULL) {
150150
cfl_sds_destroy(context->strbuf);
151151
}
152-
context->strbuf = sds_alloc(256);
152+
context->strbuf = cfl_sds_create_size(256);
153153
}
154154

155155
<INQUOTE>[\\]["] {

lib/cmetrics/src/cmt_encode_prometheus_remote_write.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,14 +1037,28 @@ int pack_complex_type(struct cmt_prometheus_remote_write_context *context,
10371037
add_metadata = CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_ADD_METADATA;
10381038
result = CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS;
10391039

1040-
if (map->type == CMT_SUMMARY) {
1041-
additional_label.name = (cfl_sds_t) "quantile";
1042-
}
1043-
else if (map->type == CMT_HISTOGRAM) {
1044-
additional_label.name = (cfl_sds_t) "le";
1045-
}
1040+
if (map->type == CMT_SUMMARY || map->type == CMT_HISTOGRAM) {
1041+
if (map->type == CMT_SUMMARY) {
1042+
additional_label.name = (cfl_sds_t) "quantile";
1043+
}
1044+
else if (map->type == CMT_HISTOGRAM) {
1045+
additional_label.name = (cfl_sds_t) "le";
1046+
}
1047+
1048+
/*
1049+
* Suppress GCC/Clang warning for storing the address of a stack-allocated label in a list. We are
1050+
* safe here because the label is removed before function exit.
1051+
*
1052+
* This avoids a -Wdangling-pointer false positive.
1053+
*/
1054+
#pragma GCC diagnostic push
1055+
#pragma GCC diagnostic ignored "-Wdangling-pointer"
1056+
10461057

1047-
cfl_list_add(&additional_label._head, &map->label_keys);
1058+
cfl_list_add(&additional_label._head, &map->label_keys);
1059+
1060+
#pragma GCC diagnostic pop
1061+
}
10481062

10491063
if (map->metric_static_set == CMT_TRUE) {
10501064
result = pack_complex_metric_sample(context, map, &map->metric, add_metadata);
@@ -1064,8 +1078,7 @@ int pack_complex_type(struct cmt_prometheus_remote_write_context *context,
10641078
}
10651079
}
10661080

1067-
if (map->type == CMT_SUMMARY ||
1068-
map->type == CMT_HISTOGRAM) {
1081+
if (map->type == CMT_SUMMARY || map->type == CMT_HISTOGRAM) {
10691082
cfl_list_del(&additional_label._head);
10701083
}
10711084

lib/cmetrics/src/cmt_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static int filter_context_label_key_value(struct cmt *dst, struct cmt *src,
348348
return -1;
349349
}
350350

351-
map = cmt_map_create(CMT_UNTYPED, &gauge->opts,
351+
map = cmt_map_create(CMT_UNTYPED, &untyped->opts,
352352
untyped->map->label_count,
353353
labels, (void *) untyped);
354354
free(labels);

0 commit comments

Comments
 (0)