Skip to content
Merged
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
3 changes: 3 additions & 0 deletions lib/cmetrics/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
build
lib/cfl/build-review
57 changes: 16 additions & 41 deletions lib/cmetrics/.github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,50 +38,25 @@ jobs:
build-centos:
name: CentOS 7 build to confirm no issues once used downstream
runs-on: ubuntu-latest
container: centos:7
env:
# workaround required for checkout@v3, https://github.com/actions/checkout/issues/1590
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
permissions:
contents: read
steps:
- name: Set up base image dependencies
run: |
sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo
sed -i -e "s/^#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/vault.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo
yum -y update
yum install -y ca-certificates gcc gcc-c++ git make wget
yum install -y epel-release
yum install -y libcurl-devel

shell: bash

- name: Install CMake 3.20.0
run: |
CMAKE_VERSION=3.20.0
wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh
chmod +x cmake-${CMAKE_VERSION}-linux-x86_64.sh
./cmake-${CMAKE_VERSION}-linux-x86_64.sh --skip-license --prefix=/usr/local
ln -sf /usr/local/bin/cmake /usr/bin/cmake
cmake --version

- name: Clone repo without submodules (1.8.3 version of Git)
run: |
git clone https://github.com/fluent/cmetrics.git
shell: bash
- name: Check out the repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
submodules: recursive

- name: Check out the branch (1.8.3 version of Git)
env:
BRANCH_NAME: ${{ github.head_ref }}
run: |
git checkout "$BRANCH_NAME"
git submodule update --init --recursive
shell: bash
working-directory: cmetrics
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0

- name: Run compilation
run: |
cmake -DCMT_TESTS=on -DCMT_DEV=on .
make
working-directory: cmetrics
- name: Build sources on CentOS 7
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: ./dockerfiles/Dockerfile.centos7
push: false
load: false
provenance: false

build-debian:
name: Debian Buster build to confirm no issues once used downstream
Expand Down
13 changes: 8 additions & 5 deletions lib/cmetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# CMetrics Version
set(CMT_VERSION_MAJOR 2)
set(CMT_VERSION_MINOR 1)
set(CMT_VERSION_PATCH 5)
set(CMT_VERSION_MINOR 2)
set(CMT_VERSION_PATCH 0)
Comment on lines +8 to +9

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the CMT_VERSION macro in the version header template has correct operators.

# Check the actual content of the version header template
sed -n '26,36p' lib/cmetrics/include/cmetrics/cmt_version.h.in

# Also check if CMT_VERSION is used anywhere in the codebase
rg -n '\bCMT_VERSION\b' lib/cmetrics/ --type c --type h -g '!build/**' -C2

Repository: fluent/fluent-bit

Length of output: 1050


Fix the CMT_VERSION expression in lib/cmetrics/include/cmetrics/cmt_version.h.in. It currently expands without + operators between the terms, so the generated macro is invalid C when used; it should be CMT_VERSION_MAJOR * 10000 + CMT_VERSION_MINOR * 100 + CMT_VERSION_PATCH.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/cmetrics/CMakeLists.txt` around lines 8 - 9, Fix the CMT_VERSION
expression in cmt_version.h.in by adding + operators between the major, minor,
and patch terms, using CMT_VERSION_MAJOR * 10000 + CMT_VERSION_MINOR * 100 +
CMT_VERSION_PATCH.

set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down Expand Up @@ -45,9 +45,12 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMT_SYSTEM_WINDOWS On)
add_definitions(-DCMT_SYSTEM_WINDOWS)

# Disable unistd.h for flex/bison
CMT_DEFINITION(YY_NO_UNISTD_H)
message(STATUS "Specifying YY_NO_UNISTD_H")
# Disable unistd.h for flex/bison on MSVC only: MinGW provides a real
# unistd.h, and without it the generated lexer has no isatty declaration.
if(MSVC)
CMT_DEFINITION(YY_NO_UNISTD_H)
message(STATUS "Specifying YY_NO_UNISTD_H")
endif()
endif()

# Define macro to identify macOS system
Expand Down
22 changes: 22 additions & 0 deletions lib/cmetrics/dockerfiles/Dockerfile.centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This image is used only to verify that cmetrics builds on CentOS 7.
FROM centos:7

RUN sed -i -e "s/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo && \
sed -i -e "s/^#baseurl=http:\/\/mirror.centos.org/baseurl=http:\/\/vault.centos.org/g" /etc/yum.repos.d/CentOS-Base.repo && \
yum -y update && \
yum install -y ca-certificates gcc gcc-c++ make wget libcurl-devel && \
yum clean all

ARG CMAKE_VERSION="3.20.0"

RUN wget -q "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh" \
-O /tmp/cmake-installer.sh && \
chmod +x /tmp/cmake-installer.sh && \
/tmp/cmake-installer.sh --skip-license --prefix=/usr/local && \
rm -f /tmp/cmake-installer.sh

COPY . /src/
WORKDIR /src/build

RUN cmake -DCMT_TESTS=On -DCMT_DEV=On .. && \
cmake --build . -j "$(getconf _NPROCESSORS_ONLN)"
1 change: 1 addition & 0 deletions lib/cmetrics/include/cmetrics/cmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ struct cmt *cmt_create();
void cmt_destroy(struct cmt *cmt);
int cmt_label_add(struct cmt *cmt, char *key, char *val);
char *cmt_version();
void cmt_expire(struct cmt *cmt, uint64_t expiration);

#endif
3 changes: 3 additions & 0 deletions lib/cmetrics/include/cmetrics/cmt_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ int cmt_map_metric_get_val(struct cmt_opts *opts, struct cmt_map *map,
double *out_val);
void cmt_map_metric_destroy(struct cmt_metric *metric);

void cmt_map_metrics_expire(struct cmt_map *, uint64_t);

void destroy_label_list(struct cfl_list *label_list);


#endif
56 changes: 56 additions & 0 deletions lib/cmetrics/src/cmetrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cmetrics/cmt_atomic.h>
#include <cmetrics/cmt_compat.h>
#include <cmetrics/cmt_label.h>
#include <cmetrics/cmt_map.h>
#include <cmetrics/cmt_version.h>

#include <cfl/cfl_kvlist.h>
Expand Down Expand Up @@ -144,6 +145,61 @@ void cmt_destroy(struct cmt *cmt)
free(cmt);
}

void cmt_expire(struct cmt *cmt, uint64_t expiration)
{
struct cfl_list *tmp;
struct cfl_list *head;
struct cmt_counter *counter;
struct cmt_gauge *gauge;
struct cmt_summary *summary;
struct cmt_histogram *histogram;
struct cmt_untyped *untyped;
struct cmt_exp_histogram *exp_histogram;

if (cmt == NULL) {
return;
}

/* Do a first pass for all regular metrics:
* * counters
* * gauges
* * summaries
* * histograms
* * untypeds
*/
cfl_list_foreach_safe(head, tmp, &cmt->counters) {
counter = cfl_list_entry(head, struct cmt_counter, _head);
cmt_map_metrics_expire(counter->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->gauges) {
gauge = cfl_list_entry(head, struct cmt_gauge, _head);
cmt_map_metrics_expire(gauge->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->summaries) {
summary = cfl_list_entry(head, struct cmt_summary, _head);
cmt_map_metrics_expire(summary->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->histograms) {
histogram = cfl_list_entry(head, struct cmt_histogram, _head);
cmt_map_metrics_expire(histogram->map, expiration);
}

cfl_list_foreach_safe(head, tmp, &cmt->untypeds) {
untyped = cfl_list_entry(head, struct cmt_untyped, _head);
cmt_map_metrics_expire(untyped->map, expiration);
}

/* Here we cover exp_histograms separetely.
*/
cfl_list_foreach_safe(head, tmp, &cmt->exp_histograms) {
exp_histogram = cfl_list_entry(head, struct cmt_exp_histogram, _head);
cmt_map_metrics_expire(exp_histogram->map, expiration);
}
}

int cmt_label_add(struct cmt *cmt, char *key, char *val)
{
return cmt_labels_add_kv(cmt->static_labels, key, val);
Expand Down
7 changes: 7 additions & 0 deletions lib/cmetrics/src/cmt_decode_msgpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,7 @@ static int unpack_basic_type_meta(mpack_reader_t *reader, size_t index, void *co
int result;
struct cmt_summary *summary;
struct cmt_histogram *histogram;
struct cmt_exp_histogram *exp_histogram;
struct cmt_counter *counter;
struct cmt_msgpack_decode_context *decode_context;
struct cmt_mpack_map_entry_callback_t callbacks[] = \
Expand Down Expand Up @@ -1684,6 +1685,12 @@ static int unpack_basic_type_meta(mpack_reader_t *reader, size_t index, void *co
else {
histogram->buckets = NULL;
}

histogram->aggregation_type = decode_context->aggregation_type;
}
else if (decode_context->map->type == CMT_EXP_HISTOGRAM) {
exp_histogram = (struct cmt_exp_histogram *) decode_context->map->parent;
exp_histogram->aggregation_type = decode_context->aggregation_type;
}
else if (decode_context->map->type == CMT_SUMMARY) {
summary = (struct cmt_summary *) decode_context->map->parent;
Expand Down
15 changes: 10 additions & 5 deletions lib/cmetrics/src/cmt_decode_prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,19 @@ int cmt_decode_prometheus_create(

result = cmt_decode_prometheus_parse(scanner, &context);

if (context.errcode) {
result = context.errcode;
}

if (result == 0) {
*out_cmt = cmt;
}
else {
cmt_destroy(cmt);
if (context.errcode) {
result = context.errcode;
}
reset_context(&context, true);
}

reset_context(&context, true);

cmt_decode_prometheus__delete_buffer(buf, scanner);
cmt_decode_prometheus_lex_destroy(scanner);

Expand Down Expand Up @@ -1224,6 +1226,9 @@ static int cmt_decode_prometheus_error(void *yyscanner,
struct cmt_decode_prometheus_context *context,
const char *msg)
{
report_error(context, CMT_DECODE_PROMETHEUS_SYNTAX_ERROR, msg);
if (!context->errcode) {
report_error(context, CMT_DECODE_PROMETHEUS_SYNTAX_ERROR, msg);
}

return 0;
}
Loading
Loading