Skip to content

Commit c2b1cfd

Browse files
committed
lib: cmetrics: upgrade to v2.1.5
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent 7806758 commit c2b1cfd

7 files changed

Lines changed: 32 additions & 97 deletions

File tree

lib/cmetrics/.github/workflows/build.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
permissions:
2020
contents: read
2121
steps:
22-
- uses: actions/checkout@v6
22+
- uses: actions/checkout@v7
2323
with:
2424
submodules: true
2525

@@ -139,7 +139,7 @@ jobs:
139139
permissions:
140140
contents: read
141141
steps:
142-
- uses: actions/checkout@v6
142+
- uses: actions/checkout@v7
143143
with:
144144
submodules: true
145145

@@ -173,7 +173,7 @@ jobs:
173173
permissions:
174174
contents: read
175175
steps:
176-
- uses: actions/checkout@v6
176+
- uses: actions/checkout@v7
177177
with:
178178
submodules: true
179179

@@ -203,7 +203,7 @@ jobs:
203203
runs-on: ubuntu-latest
204204
steps:
205205
- name: Check out the repository
206-
uses: actions/checkout@v6
206+
uses: actions/checkout@v7
207207
with:
208208
submodules: true
209209

lib/cmetrics/.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
permissions:
1111
contents: read
1212
steps:
13-
- uses: actions/checkout@v6
13+
- uses: actions/checkout@v7
1414
- uses: ludeeus/action-shellcheck@master
1515

1616
actionlint:
@@ -19,7 +19,7 @@ jobs:
1919
permissions:
2020
contents: read
2121
steps:
22-
- uses: actions/checkout@v6
22+
- uses: actions/checkout@v7
2323
- run: |
2424
echo "::add-matcher::.github/actionlint-matcher.json"
2525
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)

lib/cmetrics/.github/workflows/packages.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
matrix:
1919
format: [ rpm, deb ]
2020
steps:
21-
- uses: actions/checkout@v6
21+
- uses: actions/checkout@v7
2222
with:
2323
submodules: true
2424

@@ -54,7 +54,7 @@ jobs:
5454

5555
runs-on: [ ubuntu-latest ]
5656
steps:
57-
- uses: actions/checkout@v6
57+
- uses: actions/checkout@v7
5858
with:
5959
submodules: true
6060

@@ -81,7 +81,7 @@ jobs:
8181
ext: pkg
8282
runs-on: macos-14
8383
steps:
84-
- uses: actions/checkout@v6
84+
- uses: actions/checkout@v7
8585
with:
8686
submodules: true
8787

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 4)
9+
set(CMT_VERSION_PATCH 5)
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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,14 @@ int cmt_decode_prometheus_create(
124124

125125
result = cmt_decode_prometheus_parse(scanner, &context);
126126

127-
if (context.errcode) {
128-
result = context.errcode;
129-
cmt_destroy(cmt);
130-
reset_context(&context, true);
131-
}
132-
else if (result == 0) {
127+
if (result == 0) {
133128
*out_cmt = cmt;
134129
}
135130
else {
136131
cmt_destroy(cmt);
132+
if (context.errcode) {
133+
result = context.errcode;
134+
}
137135
reset_context(&context, true);
138136
}
139137

lib/cmetrics/src/cmt_decode_prometheus.l

Lines changed: 14 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,79 +7,11 @@
77
%{
88

99
#include <cmetrics/cmt_decode_prometheus.h>
10-
#include <stdio.h>
1110

1211
#define STRBUF_RET \
1312
yylval->str = context->strbuf; \
1413
context->strbuf = NULL
1514

16-
static void set_allocation_error(struct cmt_decode_prometheus_context *context)
17-
{
18-
context->errcode = CMT_DECODE_PROMETHEUS_ALLOCATION_ERROR;
19-
20-
if (context->opts.errbuf != NULL && context->opts.errbuf_size > 0) {
21-
snprintf(context->opts.errbuf,
22-
context->opts.errbuf_size - 1,
23-
"memory allocation failed");
24-
}
25-
}
26-
27-
static int reset_strbuf(struct cmt_decode_prometheus_context *context)
28-
{
29-
if (context->strbuf != NULL) {
30-
cfl_sds_destroy(context->strbuf);
31-
}
32-
33-
context->strbuf = cfl_sds_create_size(256);
34-
if (context->strbuf == NULL) {
35-
set_allocation_error(context);
36-
37-
return -1;
38-
}
39-
40-
return 0;
41-
}
42-
43-
static int append_strbuf(struct cmt_decode_prometheus_context *context,
44-
const char *text, int length)
45-
{
46-
cfl_sds_t result;
47-
48-
result = cfl_sds_cat(context->strbuf, text, length);
49-
if (result == NULL) {
50-
set_allocation_error(context);
51-
52-
return -1;
53-
}
54-
55-
context->strbuf = result;
56-
57-
return 0;
58-
}
59-
60-
#define STRBUF_CREATE() \
61-
do { \
62-
if (reset_strbuf(context) != 0) { \
63-
return 0; \
64-
} \
65-
} while (0)
66-
67-
#define STRBUF_APPEND(text, length) \
68-
do { \
69-
if (append_strbuf(context, (text), (length)) != 0) { \
70-
return 0; \
71-
} \
72-
} while (0)
73-
74-
#define SET_STR_TOKEN() \
75-
do { \
76-
yylval->str = cfl_sds_create(yytext); \
77-
if (yylval->str == NULL) { \
78-
set_allocation_error(context); \
79-
return 0; \
80-
} \
81-
} while (0)
82-
8315
%}
8416

8517
/* here we define some states that allow us to create rules only
@@ -142,7 +74,7 @@ static int append_strbuf(struct cmt_decode_prometheus_context *context,
14274

14375
<HELPTAG,TYPETAG>[^ \t]+ {
14476
// The next token will be the metric name
145-
SET_STR_TOKEN();
77+
yylval->str = cfl_sds_create(yytext);
14678
return YYSTATE == HELPTAG ? HELP : TYPE;
14779
}
14880

@@ -154,7 +86,7 @@ static int append_strbuf(struct cmt_decode_prometheus_context *context,
15486
// separate start condition for this to handle "\\" and "\n" escapes
15587
// more easily.
15688
BEGIN(INHELPTAG);
157-
STRBUF_CREATE();
89+
context->strbuf = cfl_sds_create_size(256);
15890
}
15991
else {
16092
// For TYPETAG we enter INTYPETAG start condition to check only valid
@@ -175,17 +107,17 @@ static int append_strbuf(struct cmt_decode_prometheus_context *context,
175107

176108
<INHELPTAG>\\n {
177109
// Process linefeed escape sequence
178-
STRBUF_APPEND("\n", 1);
110+
context->strbuf = cfl_sds_cat(context->strbuf, "\n", 1);
179111
}
180112

181113
<INHELPTAG>\\\\ {
182114
// Process backslack escape sequence
183-
STRBUF_APPEND("\\", 1);
115+
context->strbuf = cfl_sds_cat(context->strbuf, "\\", 1);
184116
}
185117

186118
<INHELPTAG>[^\r\n\\]+ {
187119
// Put everything that is not a backslash or a line feed into strbuf
188-
STRBUF_APPEND(yytext, yyleng);
120+
context->strbuf = cfl_sds_cat(context->strbuf, yytext, yyleng);
189121
}
190122

191123
<INTYPETAG>counter {
@@ -214,23 +146,26 @@ static int append_strbuf(struct cmt_decode_prometheus_context *context,
214146

215147
["] {
216148
BEGIN(INQUOTE);
217-
STRBUF_CREATE();
149+
if (context->strbuf != NULL) {
150+
cfl_sds_destroy(context->strbuf);
151+
}
152+
context->strbuf = cfl_sds_create_size(256);
218153
}
219154

220155
<INQUOTE>[\\]["] {
221-
STRBUF_APPEND("\"", 1);
156+
context->strbuf = cfl_sds_cat(context->strbuf, "\"", 1);
222157
}
223158

224159
<INQUOTE>\\n {
225-
STRBUF_APPEND("\n", 1);
160+
context->strbuf = cfl_sds_cat(context->strbuf, "\n", 1);
226161
}
227162

228163
<INQUOTE>\\\\ {
229-
STRBUF_APPEND("\\", 1);
164+
context->strbuf = cfl_sds_cat(context->strbuf, "\\", 1);
230165
}
231166

232167
<INQUOTE>[^\r\n\\"]+ {
233-
STRBUF_APPEND(yytext, yyleng);
168+
context->strbuf = cfl_sds_cat(context->strbuf, yytext, yyleng);
234169
}
235170

236171
<INQUOTE>["] {
@@ -245,7 +180,7 @@ static int append_strbuf(struct cmt_decode_prometheus_context *context,
245180
}
246181

247182
[a-zA-Z_][a-zA-Z_0-9]* {
248-
SET_STR_TOKEN();
183+
yylval->str = cfl_sds_create(yytext);
249184
return IDENTIFIER;
250185
}
251186

lib/cmetrics/src/cmt_decode_prometheus_remote_write.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,15 @@ static int decode_histogram_points(struct cmt *cmt,
575575

576576
if (result == CMT_DECODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
577577
if (hist->n_negative_spans > 0) {
578-
for (i = 0; i < hist->n_negative_counts; i++) {
578+
for (i = 0; i < hist->n_negative_counts &&
579+
(size_t) i < histogram->buckets->count; i++) {
579580
cmt_metric_hist_set(metric, hist->timestamp * 1000000,
580581
i, hist->negative_counts[i]);
581582
}
582583
}
583584
else if (hist->n_positive_spans > 0) {
584-
for (i = 0; i < hist->n_positive_counts; i++) {
585+
for (i = 0; i < hist->n_positive_counts &&
586+
(size_t) i < histogram->buckets->count; i++) {
585587
cmt_metric_hist_set(metric, hist->timestamp * 1000000,
586588
i, hist->positive_counts[i]);
587589
}

0 commit comments

Comments
 (0)