Skip to content

lib: cmetrics: upgrade to v2.2.0 - #12083

Merged
edsiper merged 1 commit into
masterfrom
lib-cmetrics-2.2.0
Jul 10, 2026
Merged

lib: cmetrics: upgrade to v2.2.0#12083
edsiper merged 1 commit into
masterfrom
lib-cmetrics-2.2.0

Conversation

@edsiper

@edsiper edsiper commented Jul 10, 2026

Copy link
Copy Markdown
Member

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • New Features

    • Added metric expiration APIs to remove samples older than a specified timestamp across supported metric types.
    • Added support for preserving aggregation temporality when encoding and decoding histograms and exponential histograms.
    • Updated cmetrics to version 2.2.0.
  • Bug Fixes

    • Improved Prometheus parsing error handling and allocation-failure reporting.
    • Corrected formatting for non-finite histogram bucket values.
    • Allowed untyped metrics to decrease in value.
  • Tests

    • Added coverage for expiration, temporality preservation, parser regressions, and non-finite bucket labels.

Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

CMetrics adds timestamp-based expiration APIs, preserves aggregation temporality through MsgPack round trips, improves Prometheus allocation-error handling and non-finite bucket formatting, removes an untyped-value restriction, and introduces Docker-based CentOS 7 builds.

Changes

CMetrics changes

Layer / File(s) Summary
Build and release configuration
lib/cmetrics/.dockerignore, lib/cmetrics/.github/workflows/build.yaml, lib/cmetrics/dockerfiles/Dockerfile.centos7, lib/cmetrics/CMakeLists.txt
CentOS 7 builds run through Docker Buildx, version 2.2.0 is configured, MSVC-only lexer compatibility is applied, and Docker build exclusions are added.
Metric expiration API
lib/cmetrics/include/cmetrics/*, lib/cmetrics/src/cmetrics.c, lib/cmetrics/src/cmt_map.c, lib/cmetrics/tests/expire.c, lib/cmetrics/tests/CMakeLists.txt
New expiration APIs remove metric samples older than a threshold across supported metric types, including exponential histograms, with boundary and type-specific tests.
MsgPack temporality preservation
lib/cmetrics/src/cmt_encode_msgpack.c, lib/cmetrics/src/cmt_decode_msgpack.c, lib/cmetrics/tests/msgpack_temporality.c
Histogram and exponential-histogram aggregation types are encoded and decoded, with round-trip coverage for those types and counters.
Prometheus parsing and formatting
lib/cmetrics/src/cmt_decode_prometheus.*, lib/cmetrics/src/cmt_encode_prometheus.c, lib/cmetrics/tests/{histogram.c,prometheus_parser.c}, lib/cmetrics/tests/data/issue_274.txt
Lexer allocation failures and parser error codes are handled consistently, non-finite bucket labels avoid decimal suffixes, and parser regression coverage is added.
Untyped metric assignment
lib/cmetrics/src/cmt_untyped.c
Untyped metrics can now be assigned values lower than their current value.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant cmt_expire
  participant cmt_map_metrics_expire
  participant cmt_map_metric_destroy
  cmt_expire->>cmt_map_metrics_expire: expire metric maps at threshold
  cmt_map_metrics_expire->>cmt_map_metric_destroy: destroy older metrics
Loading

Possibly related PRs

Suggested reviewers: cosmo0920, niedbalski

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: upgrading cmetrics to version 2.2.0.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch lib-cmetrics-2.2.0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce207a66e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

struct cfl_list *head;
struct cmt_metric *metric;

cfl_list_foreach_safe(head, tmp, &map->metrics) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Expire no-label metrics as well

When cmt_expire() is used on a metric with zero labels, the sample is stored in map->metric (cmt_map_metric_get() returns &map->metric and sets metric_static_set for labels_count == 0), not in map->metrics. This loop only scans map->metrics, so a stale no-label counter/gauge/histogram is still emitted after the expiration cutoff; for example, a scrape target that stops exporting a no-label series will keep that old value forever. Please handle metric_static_set/map->metric too, taking care to release any type-specific buffers before clearing it.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with 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.

Inline comments:
In `@lib/cmetrics/CMakeLists.txt`:
- Around line 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.

In `@lib/cmetrics/tests/prometheus_parser.c`:
- Around line 1713-1725: Update test_issue_274 to initialize cmt to NULL, guard
cmt_decode_prometheus_destroy(cmt) so it runs only when cmt is non-NULL, and
replace the // issue reference with an Apache-style /* ... */ comment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d85a40bb-2585-4a71-891b-165f8d21c8a4

📥 Commits

Reviewing files that changed from the base of the PR and between cbf10cd and ce207a6.

📒 Files selected for processing (20)
  • lib/cmetrics/.dockerignore
  • lib/cmetrics/.github/workflows/build.yaml
  • lib/cmetrics/CMakeLists.txt
  • lib/cmetrics/dockerfiles/Dockerfile.centos7
  • lib/cmetrics/include/cmetrics/cmetrics.h
  • lib/cmetrics/include/cmetrics/cmt_map.h
  • lib/cmetrics/src/cmetrics.c
  • lib/cmetrics/src/cmt_decode_msgpack.c
  • lib/cmetrics/src/cmt_decode_prometheus.c
  • lib/cmetrics/src/cmt_decode_prometheus.l
  • lib/cmetrics/src/cmt_encode_msgpack.c
  • lib/cmetrics/src/cmt_encode_prometheus.c
  • lib/cmetrics/src/cmt_map.c
  • lib/cmetrics/src/cmt_untyped.c
  • lib/cmetrics/tests/CMakeLists.txt
  • lib/cmetrics/tests/data/issue_274.txt
  • lib/cmetrics/tests/expire.c
  • lib/cmetrics/tests/histogram.c
  • lib/cmetrics/tests/msgpack_temporality.c
  • lib/cmetrics/tests/prometheus_parser.c

Comment on lines +8 to +9
set(CMT_VERSION_MINOR 2)
set(CMT_VERSION_PATCH 0)

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.

Comment on lines +1713 to +1725
// reproduces https://github.com/fluent/cmetrics/issues/274
void test_issue_274()
{
int status;
struct cmt *cmt;
cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_274.txt");
size_t in_size = cfl_sds_len(in_buf);

status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, NULL);
TEST_CHECK(status == 0);
cfl_sds_destroy(in_buf);
cmt_decode_prometheus_destroy(cmt);
}

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

Initialize cmt to NULL and guard the destroy call.

If cmt_decode_prometheus_create fails, it does not set *out_cmt, leaving cmt uninitialized. The unconditional cmt_decode_prometheus_destroy(cmt) then invokes undefined behavior. The existing test_issue_fluent_bit_9267 handles this correctly with cmt = NULL and a NULL guard. Additionally, the // comment on line 1713 should use /* ... */ style per the project's Apache-style C conventions.

🔧 Proposed fix
-// reproduces https://github.com/fluent/cmetrics/issues/274
+/* reproduces https://github.com/fluent/cmetrics/issues/274 */
 void test_issue_274()
 {
     int status;
-    struct cmt *cmt;
+    struct cmt *cmt = NULL;
     cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_274.txt");
     size_t in_size = cfl_sds_len(in_buf);
 
     status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, NULL);
     TEST_CHECK(status == 0);
     cfl_sds_destroy(in_buf);
-    cmt_decode_prometheus_destroy(cmt);
+    if (cmt != NULL) {
+        cmt_decode_prometheus_destroy(cmt);
+    }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// reproduces https://github.com/fluent/cmetrics/issues/274
void test_issue_274()
{
int status;
struct cmt *cmt;
cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_274.txt");
size_t in_size = cfl_sds_len(in_buf);
status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, NULL);
TEST_CHECK(status == 0);
cfl_sds_destroy(in_buf);
cmt_decode_prometheus_destroy(cmt);
}
/* reproduces https://github.com/fluent/cmetrics/issues/274 */
void test_issue_274()
{
int status;
struct cmt *cmt = NULL;
cfl_sds_t in_buf = read_file(CMT_TESTS_DATA_PATH "/issue_274.txt");
size_t in_size = cfl_sds_len(in_buf);
status = cmt_decode_prometheus_create(&cmt, in_buf, in_size, NULL);
TEST_CHECK(status == 0);
cfl_sds_destroy(in_buf);
if (cmt != NULL) {
cmt_decode_prometheus_destroy(cmt);
}
}
🤖 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/tests/prometheus_parser.c` around lines 1713 - 1725, Update
test_issue_274 to initialize cmt to NULL, guard
cmt_decode_prometheus_destroy(cmt) so it runs only when cmt is non-NULL, and
replace the // issue reference with an Apache-style /* ... */ comment.

Source: Coding guidelines

@edsiper
edsiper merged commit 3ceed7d into master Jul 10, 2026
82 of 87 checks passed
@edsiper
edsiper deleted the lib-cmetrics-2.2.0 branch July 10, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant