Skip to content

Commit f06029c

Browse files
committed
build: refactor ability to include prometheus text decoder
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 991c12c commit f06029c

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ else()
6868
endif()
6969

7070
# 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)
71+
option(CMT_DEV "Enable development mode" No)
72+
option(CMT_DEBUG "Enable debug mode" No)
73+
option(CMT_TESTS "Enable unit testing" No)
7474
option(CMT_INSTALL_TARGETS "Enable subdirectory library installations" Yes)
75-
option(CMT_ENABLE_PROMETHEUS_DECODER "Enable prometheus decoder" Yes)
75+
option(CMT_PROMETHEUS_TEXT_DECODER "Enable prometheus text format decoder (requires Flex/Bison)" Yes)
7676

7777
if(CMT_DEV)
7878
set(CMT_TESTS Yes)
@@ -155,7 +155,7 @@ check_c_source_compiles("
155155
return 0;
156156
}" CMT_HAVE_MSGPACK)
157157

158-
if(CMT_ENABLE_PROMETHEUS_DECODER)
158+
if(CMT_PROMETHEUS_TEXT_DECODER)
159159
# Flex and Bison: check if the variables has not been defined before by
160160
# a parent project to avoid conflicts.
161161
if(NOT FLEX_FOUND)
@@ -167,7 +167,8 @@ if(CMT_ENABLE_PROMETHEUS_DECODER)
167167
endif()
168168

169169
if(FLEX_FOUND AND BISON_FOUND)
170-
set(CMT_BUILD_PROMETHEUS_DECODER 1)
170+
set(CMT_BUILD_PROMETHEUS_TEXT_DECODER 1)
171+
CMT_DEFINITION(CMT_HAVE_PROMETHEUS_TEXT_DECODER)
171172
endif()
172173
endif()
173174

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}

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

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}

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(UNIT_TESTS_FILES
1414
filter.c
1515
)
1616

17-
if (CMT_BUILD_PROMETHEUS_DECODER)
17+
if (CMT_BUILD_PROMETHEUS_TEXT_DECODER)
1818
set(UNIT_TESTS_FILES
1919
${UNIT_TESTS_FILES}
2020
prometheus_lexer.c

tests/issues.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ void test_issue_54()
9191
cmt_destroy(cmt1);
9292
}
9393

94+
#ifdef CMT_HAVE_PROMETHEUS_TEXT_DECODER
95+
9496
/* issue: https://github.com/fluent/fluent-bit/issues/10761 */
9597
void test_prometheus_metric_no_subsystem()
9698
{
@@ -117,8 +119,12 @@ void test_prometheus_metric_no_subsystem()
117119
}
118120
}
119121

122+
#endif
123+
120124
TEST_LIST = {
121125
{"issue_54", test_issue_54},
126+
#ifdef CMT_HAVE_PROMETHEUS_TEXT_DECODER
122127
{"prometheus_metric_no_subsystem", test_prometheus_metric_no_subsystem},
128+
#endif
123129
{ 0 }
124130
};

0 commit comments

Comments
 (0)