Skip to content

Commit 5b735b8

Browse files
committed
lib: cmetrics: upgrade to v1.0.5
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent e38a0cb commit 5b735b8

File tree

12 files changed

+105
-31
lines changed

12 files changed

+105
-31
lines changed

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@v4
22+
- uses: actions/checkout@v5
2323
with:
2424
submodules: true
2525

@@ -136,7 +136,7 @@ jobs:
136136
permissions:
137137
contents: read
138138
steps:
139-
- uses: actions/checkout@v4
139+
- uses: actions/checkout@v5
140140
with:
141141
submodules: true
142142

@@ -170,7 +170,7 @@ jobs:
170170
permissions:
171171
contents: read
172172
steps:
173-
- uses: actions/checkout@v4
173+
- uses: actions/checkout@v5
174174
with:
175175
submodules: true
176176

@@ -200,7 +200,7 @@ jobs:
200200
runs-on: ubuntu-latest
201201
steps:
202202
- name: Check out the repository
203-
uses: actions/checkout@v4
203+
uses: actions/checkout@v5
204204
with:
205205
submodules: true
206206

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@v4
13+
- uses: actions/checkout@v5
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@v4
22+
- uses: actions/checkout@v5
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: 4 additions & 4 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@v4
21+
- uses: actions/checkout@v5
2222
with:
2323
submodules: true
2424

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

5555
runs-on: [ ubuntu-latest ]
5656
steps:
57-
- uses: actions/checkout@v4
57+
- uses: actions/checkout@v5
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@v4
84+
- uses: actions/checkout@v5
8585
with:
8686
submodules: true
8787

@@ -109,7 +109,7 @@ jobs:
109109
contents: write
110110
steps:
111111
- name: Download all artefacts
112-
uses: actions/download-artifact@v4
112+
uses: actions/download-artifact@v5
113113
with:
114114
path: artifacts/
115115

lib/cmetrics/CMakeLists.txt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
2424
OUTPUT_STRIP_TRAILING_WHITESPACE
2525
)
2626
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
27-
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
27+
message(STATUS "include <ctype.h>
28+
#include <errno.h>
29+
#include <math.h>
30+
#include <stdarg.h>
31+
#include <stdint.h>
32+
33+
#include <cmetrics/cmetrics.h>
34+
#include <cmetrics/cmt_gauge.h>
35+
#include <cmetrics/cmt_untyped.h>
36+
#include <cmetrics/cmt_histogram.h>
37+
#include <cmetrics/cmt_summary.h>
38+
#include <cmetrics/cmt_counter.h>Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
2839
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
2940
endif()
3041

@@ -68,11 +79,11 @@ else()
6879
endif()
6980

7081
# Configuration options
71-
option(CMT_DEV "Enable development mode" No)
72-
option(CMT_DEBUG "Enable debug mode" No)
73-
option(CMT_TESTS "Enable unit testing" No)
82+
option(CMT_DEV "Enable development mode" No)
83+
option(CMT_DEBUG "Enable debug mode" No)
84+
option(CMT_TESTS "Enable unit testing" No)
7485
option(CMT_INSTALL_TARGETS "Enable subdirectory library installations" Yes)
75-
option(CMT_ENABLE_PROMETHEUS_DECODER "Enable prometheus decoder" Yes)
86+
option(CMT_PROMETHEUS_TEXT_DECODER "Enable prometheus text format decoder (requires Flex/Bison)" Yes)
7687

7788
if(CMT_DEV)
7889
set(CMT_TESTS Yes)
@@ -155,7 +166,7 @@ check_c_source_compiles("
155166
return 0;
156167
}" CMT_HAVE_MSGPACK)
157168

158-
if(CMT_ENABLE_PROMETHEUS_DECODER)
169+
if(CMT_PROMETHEUS_TEXT_DECODER)
159170
# Flex and Bison: check if the variables has not been defined before by
160171
# a parent project to avoid conflicts.
161172
if(NOT FLEX_FOUND)
@@ -167,7 +178,8 @@ if(CMT_ENABLE_PROMETHEUS_DECODER)
167178
endif()
168179

169180
if(FLEX_FOUND AND BISON_FOUND)
170-
set(CMT_BUILD_PROMETHEUS_DECODER 1)
181+
set(CMT_BUILD_PROMETHEUS_TEXT_DECODER 1)
182+
CMT_DEFINITION(CMT_HAVE_PROMETHEUS_TEXT_DECODER)
171183
endif()
172184
endif()
173185

lib/cmetrics/include/CMakeLists.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
# Install headers conditionally based on Prometheus text decoder availability
12
file(GLOB cmetricsHeaders "cmetrics/*.h")
2-
install(FILES ${cmetricsHeaders}
3-
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
4-
COMPONENT headers
5-
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
3+
4+
if(CMT_BUILD_PROMETHEUS_TEXT_DECODER)
5+
# Install all headers when Prometheus text decoder is enabled
6+
install(FILES ${cmetricsHeaders}
7+
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
8+
COMPONENT headers
9+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
10+
else()
11+
# Install headers except Prometheus text decoder header when disabled
12+
# (remote write decoder header is always installed)
13+
foreach(header ${cmetricsHeaders})
14+
get_filename_component(header_name ${header} NAME)
15+
if(NOT header_name STREQUAL "cmt_decode_prometheus.h")
16+
install(FILES ${header}
17+
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
18+
COMPONENT headers
19+
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
20+
endif()
21+
endforeach()
22+
endif()
623

724
file(GLOB promHeaders "prometheus_remote_write/*.h")
825
install(FILES ${promHeaders}

lib/cmetrics/include/cmetrics/cmt_decode_prometheus.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#ifndef CMT_DECODE_PROMETHEUS_H
2121
#define CMT_DECODE_PROMETHEUS_H
2222

23+
#include <cmetrics/cmt_info.h>
24+
25+
#ifdef CMT_HAVE_PROMETHEUS_TEXT_DECODER
26+
2327
#include <stdbool.h>
2428

2529
#include <cmetrics/cmetrics.h>
@@ -110,4 +114,6 @@ int cmt_decode_prometheus_create(
110114
struct cmt_decode_prometheus_parse_opts *opts);
111115
void cmt_decode_prometheus_destroy(struct cmt *cmt);
112116

117+
#endif /* CMT_HAVE_PROMETHEUS_TEXT_DECODER */
118+
113119
#endif

lib/cmetrics/src/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if (CMT_BUILD_PROMETHEUS_DECODER)
1+
if (CMT_BUILD_PROMETHEUS_TEXT_DECODER)
22
flex_target(cmt_decode_prometheus_lexer cmt_decode_prometheus.l
33
"${FLEX_BISON_GENERATED_DIR}/cmt_decode_prometheus_lexer.c"
44
DEFINES_FILE "${FLEX_BISON_GENERATED_DIR}/cmt_decode_prometheus_lexer.h"
@@ -28,7 +28,6 @@ set(src
2828
cmt_decode_opentelemetry.c
2929
cmt_encode_prometheus.c
3030
cmt_encode_prometheus_remote_write.c
31-
cmt_decode_prometheus_remote_write.c
3231
cmt_encode_splunk_hec.c
3332
cmt_encode_cloudwatch_emf.c
3433
cmt_encode_text.c
@@ -37,12 +36,16 @@ set(src
3736
cmt_decode_msgpack.c
3837
cmt_decode_statsd.c
3938
cmt_mpack_utils.c
40-
41-
# Prometheus related protobuf files
42-
external/remote.pb-c.c
43-
external/types.pb-c.c
4439
)
4540

41+
# Add Prometheus remote write decoder (always available, only needs protobuf)
42+
set(src ${src}
43+
cmt_decode_prometheus_remote_write.c
44+
# Prometheus related protobuf files
45+
external/remote.pb-c.c
46+
external/types.pb-c.c
47+
)
48+
4649

4750
if (MSVC)
4851
set(PLATFORM_SPECIFIC_ATOMIC_MODULE cmt_atomic_msvc.c)
@@ -63,7 +66,7 @@ set(src
6366
${PLATFORM_SPECIFIC_ATOMIC_MODULE}
6467
)
6568

66-
if (CMT_BUILD_PROMETHEUS_DECODER)
69+
if (CMT_BUILD_PROMETHEUS_TEXT_DECODER)
6770
set(src ${src}
6871
${FLEX_cmt_decode_prometheus_lexer_OUTPUTS}
6972
${BISON_cmt_decode_prometheus_parser_OUTPUTS}

lib/cmetrics/src/cmt_cat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static inline int cat_histogram_values(struct cmt_metric *metric_dst, struct cmt
108108
}
109109
}
110110

111-
for (i = 0; i <= histogram->buckets->count; i++) {
111+
for (i = 0; i < histogram->buckets->count; i++) {
112112
/* histogram buckets are always integers, no need to convert them */
113113
metric_dst->hist_buckets[i] += metric_src->hist_buckets[i];
114114
}

lib/cmetrics/src/cmt_decode_prometheus.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static int split_metric_name(struct cmt_decode_prometheus_context *context,
174174
*subsystem = strchr(*ns, '_');
175175
if (!(*subsystem)) {
176176
*name = *ns;
177+
*subsystem = "";
177178
*ns = "";
178179
}
179180
else {

lib/cmetrics/src/cmt_histogram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct cmt_histogram_buckets *cmt_histogram_buckets_create_size(double *bkts, si
3636
}
3737

3838
/* besides buckets set by the user, we add an implicit bucket for +inf */
39-
upper_bounds = calloc(1, sizeof(double) * (count + 1));
39+
upper_bounds = calloc(1, sizeof(double) * count + 1);
4040
if (!upper_bounds) {
4141
cmt_errno();
4242
return NULL;

0 commit comments

Comments
 (0)