Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ jobs:
working-directory: cmetrics

build-debian:
name: Debian Buster build to confirm no issues once used downstream
name: Debian Bullseye build to confirm no issues once used downstream
runs-on: ubuntu-latest
container: debian:buster
container: debian:bullseye
steps:
- name: Set up base image dependencies
run: |
Expand Down
26 changes: 19 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
message(STATUS "include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdarg.h>
#include <stdint.h>

#include <cmetrics/cmetrics.h>
#include <cmetrics/cmt_gauge.h>
#include <cmetrics/cmt_untyped.h>
#include <cmetrics/cmt_histogram.h>
#include <cmetrics/cmt_summary.h>
#include <cmetrics/cmt_counter.h>Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
endif()

Expand Down Expand Up @@ -68,11 +79,11 @@ else()
endif()

# Configuration options
option(CMT_DEV "Enable development mode" No)
option(CMT_DEBUG "Enable debug mode" No)
option(CMT_TESTS "Enable unit testing" No)
option(CMT_DEV "Enable development mode" No)
option(CMT_DEBUG "Enable debug mode" No)
option(CMT_TESTS "Enable unit testing" No)
option(CMT_INSTALL_TARGETS "Enable subdirectory library installations" Yes)
option(CMT_ENABLE_PROMETHEUS_DECODER "Enable prometheus decoder" Yes)
option(CMT_PROMETHEUS_TEXT_DECODER "Enable prometheus text format decoder (requires Flex/Bison)" Yes)

if(CMT_DEV)
set(CMT_TESTS Yes)
Expand Down Expand Up @@ -155,7 +166,7 @@ check_c_source_compiles("
return 0;
}" CMT_HAVE_MSGPACK)

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

if(FLEX_FOUND AND BISON_FOUND)
set(CMT_BUILD_PROMETHEUS_DECODER 1)
set(CMT_BUILD_PROMETHEUS_TEXT_DECODER 1)
CMT_DEFINITION(CMT_HAVE_PROMETHEUS_TEXT_DECODER)
endif()
endif()

Expand Down
25 changes: 21 additions & 4 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
# Install headers conditionally based on Prometheus text decoder availability
file(GLOB cmetricsHeaders "cmetrics/*.h")
install(FILES ${cmetricsHeaders}
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
COMPONENT headers
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)

if(CMT_BUILD_PROMETHEUS_TEXT_DECODER)
# Install all headers when Prometheus text decoder is enabled
install(FILES ${cmetricsHeaders}
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
COMPONENT headers
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
else()
# Install headers except Prometheus text decoder header when disabled
# (remote write decoder header is always installed)
foreach(header ${cmetricsHeaders})
get_filename_component(header_name ${header} NAME)
if(NOT header_name STREQUAL "cmt_decode_prometheus.h")
install(FILES ${header}
DESTINATION ${CMT_INSTALL_INCLUDEDIR}/cmetrics
COMPONENT headers
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endif()
endforeach()
endif()

file(GLOB promHeaders "prometheus_remote_write/*.h")
install(FILES ${promHeaders}
Expand Down
6 changes: 6 additions & 0 deletions include/cmetrics/cmt_decode_prometheus.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#ifndef CMT_DECODE_PROMETHEUS_H
#define CMT_DECODE_PROMETHEUS_H

#include <cmetrics/cmt_info.h>

#ifdef CMT_HAVE_PROMETHEUS_TEXT_DECODER

#include <stdbool.h>

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

#endif /* CMT_HAVE_PROMETHEUS_TEXT_DECODER */

#endif
17 changes: 10 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if (CMT_BUILD_PROMETHEUS_DECODER)
if (CMT_BUILD_PROMETHEUS_TEXT_DECODER)
flex_target(cmt_decode_prometheus_lexer cmt_decode_prometheus.l
"${FLEX_BISON_GENERATED_DIR}/cmt_decode_prometheus_lexer.c"
DEFINES_FILE "${FLEX_BISON_GENERATED_DIR}/cmt_decode_prometheus_lexer.h"
Expand Down Expand Up @@ -28,7 +28,6 @@ set(src
cmt_decode_opentelemetry.c
cmt_encode_prometheus.c
cmt_encode_prometheus_remote_write.c
cmt_decode_prometheus_remote_write.c
cmt_encode_splunk_hec.c
cmt_encode_cloudwatch_emf.c
cmt_encode_text.c
Expand All @@ -37,12 +36,16 @@ set(src
cmt_decode_msgpack.c
cmt_decode_statsd.c
cmt_mpack_utils.c

# Prometheus related protobuf files
external/remote.pb-c.c
external/types.pb-c.c
)

# Add Prometheus remote write decoder (always available, only needs protobuf)
set(src ${src}
cmt_decode_prometheus_remote_write.c
# Prometheus related protobuf files
external/remote.pb-c.c
external/types.pb-c.c
)


if (MSVC)
set(PLATFORM_SPECIFIC_ATOMIC_MODULE cmt_atomic_msvc.c)
Expand All @@ -63,7 +66,7 @@ set(src
${PLATFORM_SPECIFIC_ATOMIC_MODULE}
)

if (CMT_BUILD_PROMETHEUS_DECODER)
if (CMT_BUILD_PROMETHEUS_TEXT_DECODER)
set(src ${src}
${FLEX_cmt_decode_prometheus_lexer_OUTPUTS}
${BISON_cmt_decode_prometheus_parser_OUTPUTS}
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(UNIT_TESTS_FILES
filter.c
)

if (CMT_BUILD_PROMETHEUS_DECODER)
if (CMT_BUILD_PROMETHEUS_TEXT_DECODER)
set(UNIT_TESTS_FILES
${UNIT_TESTS_FILES}
prometheus_lexer.c
Expand Down
6 changes: 6 additions & 0 deletions tests/issues.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void test_issue_54()
cmt_destroy(cmt1);
}

#ifdef CMT_HAVE_PROMETHEUS_TEXT_DECODER

/* issue: https://github.com/fluent/fluent-bit/issues/10761 */
void test_prometheus_metric_no_subsystem()
{
Expand All @@ -117,8 +119,12 @@ void test_prometheus_metric_no_subsystem()
}
}

#endif

TEST_LIST = {
{"issue_54", test_issue_54},
#ifdef CMT_HAVE_PROMETHEUS_TEXT_DECODER
{"prometheus_metric_no_subsystem", test_prometheus_metric_no_subsystem},
#endif
{ 0 }
};
Loading