Skip to content

Conversation

@Lusitaniae
Copy link

@Lusitaniae Lusitaniae commented Jan 6, 2026

It allows users to specify a key (value_field) as the value to increment the counters by, instead of only incrementing by 1.

Closes #11343

Testing:

First test uncommented #value_field duration

[SERVICE]
    Flush        1
    Daemon       Off
    Log_Level    info
    Parsers_File parsers.conf

    HTTP_Server  On
    HTTP_Listen  0.0.0.0
    HTTP_Port    2020

[INPUT]
    Name        dummy
    Dummy       {"message":"dummy", "kubernetes":{"namespace_name": "default", "docker_id": "abc123", "pod_name": "pod1", "container_name": "mycontainer", "pod_id": "def456", "labels":{"app": "app1"}}, "duration": 20, "color": "red", "shape": "circle"}
    Tag         dummy.log

[INPUT]
    Name        dummy
    Dummy       {"message":"hello", "kubernetes":{"namespace_name": "default", "docker_id": "abc123", "pod_name": "pod1", "container_name": "mycontainer", "pod_id": "def456", "labels":{"app": "app1"}}, "duration": 60, "color": "blue", "shape": "square"}
    Tag         dummy.log2

[FILTER]
    name               log_to_metrics
    match              dummy.log*
    tag                test_metric
    metric_mode        counter
    metric_name        count_all_dummy_messages
    metric_description This metric counts dummy messages (increments by 1)

[FILTER]
    name               log_to_metrics
    match              dummy.log*
    tag                test_metric
    metric_mode        counter
    metric_name        duration_total
    metric_description Total duration accumulated (tests value_field support)
    #value_field        duration
    label_field        color
    label_field        shape

[OUTPUT]
    name    prometheus_exporter
    match   *
    host    0.0.0.0
    port    9999

Using value_field

curl localhost:9999/metrics
# HELP log_metric_counter_count_all_dummy_messages This metric counts dummy messages (increments by 1)
# TYPE log_metric_counter_count_all_dummy_messages counter
log_metric_counter_count_all_dummy_messages 5
# HELP log_metric_counter_count_all_dummy_messages This metric counts dummy messages (increments by 1)
# TYPE log_metric_counter_count_all_dummy_messages counter
log_metric_counter_count_all_dummy_messages 6
# HELP log_metric_counter_duration_total Total duration accumulated (tests value_field support)
# TYPE log_metric_counter_duration_total counter
log_metric_counter_duration_total{color="red",shape="circle"} 60
log_metric_counter_duration_total{color="blue",shape="square"} 120
# HELP log_metric_counter_duration_total Total duration accumulated (tests value_field support)
# TYPE log_metric_counter_duration_total counter
log_metric_counter_duration_total{color="red",shape="circle"} 60
log_metric_counter_duration_total{color="blue",shape="square"} 180

Default (commented out value_field): increment by 1

curl localhost:9999/metrics
# HELP log_metric_counter_count_all_dummy_messages This metric counts dummy messages (increments by 1)
# TYPE log_metric_counter_count_all_dummy_messages counter
log_metric_counter_count_all_dummy_messages 3
# HELP log_metric_counter_count_all_dummy_messages This metric counts dummy messages (increments by 1)
# TYPE log_metric_counter_count_all_dummy_messages counter
log_metric_counter_count_all_dummy_messages 4
# HELP log_metric_counter_duration_total Total duration accumulated (tests value_field support)
# TYPE log_metric_counter_duration_total counter
log_metric_counter_duration_total{color="red",shape="circle"} 2
log_metric_counter_duration_total{color="blue",shape="square"} 1
# HELP log_metric_counter_duration_total Total duration accumulated (tests value_field support)
# TYPE log_metric_counter_duration_total counter
log_metric_counter_duration_total{color="red",shape="circle"} 2
log_metric_counter_duration_total{color="blue",shape="square"} 2

valgrind --leak-check=full bin/fluent-bit -c fluent-bit.conf 
==2611580== Memcheck, a memory error detector
==2611580== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==2611580== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==2611580== Command: bin/fluent-bit -c fluent-bit.conf
==2611580== 
Fluent Bit v4.2.3
* Copyright (C) 2015-2025 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _             ___   _____ 
|  ___| |                | |   | ___ (_) |           /   | / __  \
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   __/ /| | `' / /'
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / / /_| |   / /  
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V /\___  |_./ /___
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/     |_(_)_____/
                                                                  
             Fluent Bit v4.2 – Direct Routes Ahead
         Celebrating 10 Years of Open, Fluent Innovation!

[2026/01/06 12:01:21.536942211] [error] [/home/i/workspace/triton/fluent-bit/src/config_format/flb_cf_fluentbit.c:289 errno=2] No such file or directory
[2026/01/06 12:01:21.551482920] [error] file=/home/i/workspace/triton/fluent-bit/build/parsers.conf
[2026/01/06 12:01:21.626731651] [ info] [fluent bit] version=4.2.3, commit=7b0c1aebb6, pid=2611580
[2026/01/06 12:01:21.639521437] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/01/06 12:01:21.639948404] [ info] [simd    ] disabled
[2026/01/06 12:01:21.640220556] [ info] [cmetrics] version=1.0.6
[2026/01/06 12:01:21.640453141] [ info] [ctraces ] version=0.6.6
[2026/01/06 12:01:21.652611648] [ info] [input:dummy:dummy.0] initializing
[2026/01/06 12:01:21.653217679] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2026/01/06 12:01:21.668451275] [ info] [input:dummy:dummy.1] initializing
[2026/01/06 12:01:21.668512362] [ info] [input:dummy:dummy.1] storage_strategy='memory' (memory only)
[2026/01/06 12:01:21.678781931] [ info] [input:emitter:emitter_for_log_to_metrics.0] initializing
[2026/01/06 12:01:21.680224323] [ info] [input:emitter:emitter_for_log_to_metrics.0] storage_strategy='memory' (memory only)
[2026/01/06 12:01:21.687729868] [ info] [input:emitter:emitter_for_log_to_metrics.1] initializing
[2026/01/06 12:01:21.687810473] [ info] [input:emitter:emitter_for_log_to_metrics.1] storage_strategy='memory' (memory only)
[2026/01/06 12:01:21.782692676] [ info] [output:prometheus_exporter:prometheus_exporter.0] listening iface=0.0.0.0 tcp_port=9999
[2026/01/06 12:01:21.847173454] [ info] [http_server] listen iface=0.0.0.0 tcp_port=2020
[2026/01/06 12:01:21.848473193] [ info] [sp] stream processor started
[2026/01/06 12:01:21.853101638] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
==2611580== Warning: client switching stacks?  SP change: 0x63ac198 --> 0x5a68290
==2611580==          to suppress, use: --max-stackframe=9715464 or greater
==2611580== Warning: client switching stacks?  SP change: 0x5a68178 --> 0x63ac198
==2611580==          to suppress, use: --max-stackframe=9715744 or greater
==2611580== Warning: client switching stacks?  SP change: 0x63ac198 --> 0x5a6e850
==2611580==          to suppress, use: --max-stackframe=9689416 or greater
==2611580==          further instances of this message will not be shown.
^C[2026/01/06 12:01:28] [engine] caught signal (SIGINT)
[2026/01/06 12:01:28.742793356] [ warn] [engine] service will shutdown in max 5 seconds
[2026/01/06 12:01:28.745915055] [ info] [engine] pausing all inputs..
[2026/01/06 12:01:28.748610819] [ info] [input] pausing dummy.0
[2026/01/06 12:01:28.750595550] [ info] [input] pausing dummy.1
[2026/01/06 12:01:28.750717534] [ info] [input] pausing emitter_for_log_to_metrics.0
[2026/01/06 12:01:28.751139462] [ info] [input] pausing emitter_for_log_to_metrics.1
[2026/01/06 12:01:28.865394107] [ info] [engine] service has stopped (0 pending tasks)
[2026/01/06 12:01:28.865606734] [ info] [input] pausing dummy.0
[2026/01/06 12:01:28.865698209] [ info] [input] pausing dummy.1
[2026/01/06 12:01:28.865740580] [ info] [input] pausing emitter_for_log_to_metrics.0
[2026/01/06 12:01:28.865777040] [ info] [input] pausing emitter_for_log_to_metrics.1
==2611580== 
==2611580== HEAP SUMMARY:
==2611580==     in use at exit: 0 bytes in 0 blocks
==2611580==   total heap usage: 24,407 allocs, 24,407 frees, 11,017,711 bytes allocated
==2611580== 
==2611580== All heap blocks were freed -- no leaks are possible
==2611580== 
==2611580== For lists of detected and suppressed errors, rerun with: -s
==2611580== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

valgrind --leak-check=full bin/fluent-bit -c fluent-bit.conf 
==2612802== Memcheck, a memory error detector
==2612802== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==2612802== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==2612802== Command: bin/fluent-bit -c fluent-bit.conf
==2612802== 
Fluent Bit v4.2.3
* Copyright (C) 2015-2025 The Fluent Bit Authors
* Fluent Bit is a CNCF graduated project under the Fluent organization
* https://fluentbit.io

______ _                  _    ______ _ _             ___   _____ 
|  ___| |                | |   | ___ (_) |           /   | / __  \
| |_  | |_   _  ___ _ __ | |_  | |_/ /_| |_  __   __/ /| | `' / /'
|  _| | | | | |/ _ \ '_ \| __| | ___ \ | __| \ \ / / /_| |   / /  
| |   | | |_| |  __/ | | | |_  | |_/ / | |_   \ V /\___  |_./ /___
\_|   |_|\__,_|\___|_| |_|\__| \____/|_|\__|   \_/     |_(_)_____/
                                                                  
             Fluent Bit v4.2 – Direct Routes Ahead
         Celebrating 10 Years of Open, Fluent Innovation!

[2026/01/06 12:02:13.923881011] [error] [/home/i/workspace/triton/fluent-bit/src/config_format/flb_cf_fluentbit.c:289 errno=2] No such file or directory
[2026/01/06 12:02:13.937950753] [error] file=/home/i/workspace/triton/fluent-bit/build/parsers.conf
[2026/01/06 12:02:14.5145604] [ info] [fluent bit] version=4.2.3, commit=7b0c1aebb6, pid=2612802
[2026/01/06 12:02:14.17649336] [ info] [storage] ver=1.5.4, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2026/01/06 12:02:14.18073809] [ info] [simd    ] disabled
[2026/01/06 12:02:14.18358455] [ info] [cmetrics] version=1.0.6
[2026/01/06 12:02:14.18597373] [ info] [ctraces ] version=0.6.6
[2026/01/06 12:02:14.30416683] [ info] [input:dummy:dummy.0] initializing
[2026/01/06 12:02:14.30999420] [ info] [input:dummy:dummy.0] storage_strategy='memory' (memory only)
[2026/01/06 12:02:14.46074389] [ info] [input:dummy:dummy.1] initializing
[2026/01/06 12:02:14.46126088] [ info] [input:dummy:dummy.1] storage_strategy='memory' (memory only)
[2026/01/06 12:02:14.56271561] [ info] [input:emitter:emitter_for_log_to_metrics.0] initializing
[2026/01/06 12:02:14.56322368] [ info] [input:emitter:emitter_for_log_to_metrics.0] storage_strategy='memory' (memory only)
[2026/01/06 12:02:14.59272522] [ info] [input:emitter:emitter_for_log_to_metrics.1] initializing
[2026/01/06 12:02:14.59320143] [ info] [input:emitter:emitter_for_log_to_metrics.1] storage_strategy='memory' (memory only)
[2026/01/06 12:02:14.151418218] [ info] [output:prometheus_exporter:prometheus_exporter.0] listening iface=0.0.0.0 tcp_port=9999
[2026/01/06 12:02:14.213239983] [ info] [http_server] listen iface=0.0.0.0 tcp_port=2020
[2026/01/06 12:02:14.214016802] [ info] [sp] stream processor started
[2026/01/06 12:02:14.216024850] [ info] [engine] Shutdown Grace Period=5, Shutdown Input Grace Period=2
==2612802== Warning: client switching stacks?  SP change: 0x63ac198 --> 0x5a67360
==2612802==          to suppress, use: --max-stackframe=9719352 or greater
==2612802== Warning: client switching stacks?  SP change: 0x5a67248 --> 0x63ac198
==2612802==          to suppress, use: --max-stackframe=9719632 or greater
==2612802== Warning: client switching stacks?  SP change: 0x63ac198 --> 0x5a6d920
==2612802==          to suppress, use: --max-stackframe=9693304 or greater
==2612802==          further instances of this message will not be shown.
^C[2026/01/06 12:02:22] [engine] caught signal (SIGINT)
[2026/01/06 12:02:22.79837968] [ warn] [engine] service will shutdown in max 5 seconds
[2026/01/06 12:02:22.80637892] [ info] [engine] pausing all inputs..
[2026/01/06 12:02:22.81454376] [ info] [input] pausing dummy.0
[2026/01/06 12:02:22.84141937] [ info] [input] pausing dummy.1
[2026/01/06 12:02:22.84578945] [ info] [input] pausing emitter_for_log_to_metrics.0
[2026/01/06 12:02:22.86426907] [ info] [input] pausing emitter_for_log_to_metrics.1
[2026/01/06 12:02:22.874632189] [ info] [engine] service has stopped (0 pending tasks)
[2026/01/06 12:02:22.875139922] [ info] [input] pausing dummy.0
[2026/01/06 12:02:22.875347931] [ info] [input] pausing dummy.1
[2026/01/06 12:02:22.875490625] [ info] [input] pausing emitter_for_log_to_metrics.0
[2026/01/06 12:02:22.875590196] [ info] [input] pausing emitter_for_log_to_metrics.1
==2612802== 
==2612802== HEAP SUMMARY:
==2612802==     in use at exit: 0 bytes in 0 blocks
==2612802==   total heap usage: 29,929 allocs, 29,929 frees, 12,646,511 bytes allocated
==2612802== 
==2612802== All heap blocks were freed -- no leaks are possible
==2612802== 
==2612802== For lists of detected and suppressed errors, rerun with: -s
==2612802== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

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

  • Bug Fixes

    • Gauge and histogram now require a configured value field and will fail setup if missing.
    • Counter metrics accept an optional value field; when provided counters add the specified numeric amount, otherwise they increment by 1.
    • Improved runtime validation and clearer error messages for missing, invalid, or non-numeric value fields.
  • Documentation

    • Configuration description clarified for required vs. optional value field usage.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 6, 2026

Warning

Rate limit exceeded

@Lusitaniae has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1c89b61 and 07039bc.

📒 Files selected for processing (1)
  • plugins/filter_log_to_metrics/log_to_metrics.c
📝 Walkthrough

Walkthrough

log_to_metrics now requires value_field for gauge/histogram and makes it optional for counters; counters may use value_field to add a numeric amount or default to +1. Initialization validates and stores a persistent record accessor for any configured value_field.

Changes

Cohort / File(s) Summary
Value_field handling & counter support
plugins/filter_log_to_metrics/log_to_metrics.c
Init validates/creates a persistent record accessor (value_ra) for configured value_field (required for gauge/histogram, optional for counter). Filter path: counter uses value_field (if present) to parse and add a numeric amount via cmt_counter_add, otherwise increments by 1. Added error paths for missing/invalid value_field and numeric conversion; updated config_map description and introduced a local counter_value during counter updates.

Sequence Diagram(s)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #10920: Adjusts creation/validation and reuse of value_ra in log_to_metrics.c, similar record-accessor handling and runtime usage.

Suggested reviewers

  • koleini

Poem

I hop through logs and fields with glee,
Counters can now eat a number from thee.
Gauges and histograms ask for a key,
Counters accept one, or add one for me. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 accurately describes the main change: enabling counter metrics to use value_field for custom increment amounts instead of always incrementing by 1.
Linked Issues check ✅ Passed The code changes fully implement the feature requested in #11343: value_field is now optional for counters and used as the increment amount when provided.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing value_field support for counter metrics in log_to_metrics, with no unrelated modifications detected.

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI Agents
In @plugins/filter_log_to_metrics/log_to_metrics.c:
- Around line 929-965: The parsing branch must validate the parsed value from
flb_ra_get_value_object/rval and reject non-numeric or negative values before
calling cmt_counter_add: check sscanf return value when rval->type ==
FLB_RA_STRING and handle a non-1 return by logging via flb_plg_error and falling
back to cmt_counter_inc (or skipping adding); for FLB_RA_FLOAT and FLB_RA_INT
verify counter_value >= 0 and if negative log an error and fall back to
cmt_counter_inc (do not call cmt_counter_add with negative), ensuring
flb_ra_key_value_destroy(rval) is called in all error paths and rval is nulled
afterwards.
🧹 Nitpick comments (2)
plugins/filter_log_to_metrics/log_to_metrics.c (2)

646-675: Logic for optional value_field in counter mode looks correct.

The initialization properly makes value_field required for gauge/histogram modes while keeping it optional for counter mode. The value_ra record accessor is created consistently in both paths.

Minor note: The local value_field variable populated at lines 653-654 and 666-667 via snprintf is never used after assignment. Consider removing these dead assignments or the local variable declaration at line 496 if it's no longer needed.


931-936: Consider logging when value_field is configured but not found.

When value_ra is set but the field is missing from the record, the code silently falls back to incrementing by 1. This could hide misconfiguration. A debug or warning log would help users troubleshoot unexpected behavior.

🔎 Suggested improvement
                     if (!rval) {
-                        /* No value field, increment by 1 */
+                        /* value_field configured but not found, increment by 1 */
+                        flb_plg_debug(f_ins,
+                                    "value_field not found in record, incrementing counter by 1");
                         ret = cmt_counter_inc(ctx->c, ts, label_count,
                                         label_values);
                     }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9191f70 and a8c83d8.

📒 Files selected for processing (1)
  • plugins/filter_log_to_metrics/log_to_metrics.c
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/filter_log_to_metrics/log_to_metrics.c (3)
src/flb_record_accessor.c (2)
  • flb_ra_create (271-358)
  • flb_ra_get_value_object (803-814)
lib/cmetrics/src/cmt_counter.c (2)
  • cmt_counter_inc (100-117)
  • cmt_counter_add (119-135)
src/flb_ra_key.c (1)
  • flb_ra_key_value_destroy (842-851)
🔇 Additional comments (1)
plugins/filter_log_to_metrics/log_to_metrics.c (1)

1107-1110: Documentation update looks good.

The updated description accurately reflects the new behavior where value_field is required for gauge/histogram modes but optional for counter mode.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
plugins/filter_log_to_metrics/log_to_metrics.c (2)

653-654: Dead code: value_field local buffer is populated but never used.

The local value_field buffer (declared at line 496) is populated with snprintf but never referenced afterward. The code uses ctx->value_field directly with flb_ra_create. Consider removing these dead assignments.

🔎 Suggested fix
     if (ctx->mode == FLB_LOG_TO_METRICS_GAUGE || ctx->mode == FLB_LOG_TO_METRICS_HISTOGRAM) {
         if (ctx->value_field == NULL || strlen(ctx->value_field) == 0) {
             flb_plg_error(f_ins, "value_field is required for gauge and histogram modes");
             log_to_metrics_destroy(ctx);
             return -1;
         }
-        snprintf(value_field, sizeof(value_field) - 1, "%s",
-                    ctx->value_field);

         ctx->value_ra = flb_ra_create(ctx->value_field, FLB_TRUE);
         if (ctx->value_ra == NULL) {
             flb_plg_error(f_ins, "invalid record accessor key for value_field");
             log_to_metrics_destroy(ctx);
             return -1;
         }
     }
     else if (ctx->mode == FLB_LOG_TO_METRICS_COUNTER && 
              ctx->value_field != NULL && strlen(ctx->value_field) > 0) {
         /* value_field is optional for counter mode */
-        snprintf(value_field, sizeof(value_field) - 1, "%s",
-                    ctx->value_field);

         ctx->value_ra = flb_ra_create(ctx->value_field, FLB_TRUE);

Also remove the unused declaration at line 496:

-    char value_field[MAX_METRIC_LENGTH];

Also applies to: 666-667


958-964: Inconsistent fallback behavior for unsupported type.

When value_field contains an unsupported type, the code logs an error and breaks without incrementing the counter. However, for other error cases (missing field, parse failure, negative value), the code falls back to incrementing by 1. This inconsistency may cause silent metric drops for unexpected field types.

Consider falling back to increment-by-1 for consistency, or document that unsupported types skip the record entirely.

🔎 Suggested fix for consistent fallback
                             else {
                                 flb_plg_error(f_ins,
-                                            "cannot convert given value to metric");
+                                            "cannot convert given value to metric, falling back to increment by 1");
                                 flb_ra_key_value_destroy(rval);
                                 rval = NULL;
-                                break;
+                                ret = cmt_counter_inc(ctx->c, ts, label_count,
+                                                label_values);
+                                break;
                             }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8c83d8 and 84cad53.

📒 Files selected for processing (1)
  • plugins/filter_log_to_metrics/log_to_metrics.c
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/filter_log_to_metrics/log_to_metrics.c (3)
src/flb_record_accessor.c (2)
  • flb_ra_create (271-358)
  • flb_ra_get_value_object (803-814)
lib/cmetrics/src/cmt_counter.c (2)
  • cmt_counter_inc (100-117)
  • cmt_counter_add (119-135)
src/flb_ra_key.c (1)
  • flb_ra_key_value_destroy (842-851)
🔇 Additional comments (2)
plugins/filter_log_to_metrics/log_to_metrics.c (2)

854-854: LGTM!

Variable declaration follows the existing pattern for gauge_value and histogram_value, and is properly initialized.


1130-1133: LGTM!

Config map description correctly documents that value_field is now supported for counters and is optional in that mode.

@Lusitaniae

This comment was marked as outdated.

@cosmo0920
Copy link
Contributor

Our commit linter complains like:

❌ Commit 84cad53d73 failed:
Missing prefix in commit subject: 'add handling for negative/missing values'

❌ Commit a8c83d8843 failed:
Missing prefix in commit subject: 'allow counter metrics to use value_field instead of increment by 1 only'

So, we need to use filter_log_to_metrics: prefix in each of your commits.

@Lusitaniae Lusitaniae force-pushed the feature/counter_value_field branch from 28a907c to 1c89b61 Compare January 6, 2026 06:13
@Lusitaniae
Copy link
Author

Is it worthwhile implementing the nitpick comments?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
plugins/filter_log_to_metrics/log_to_metrics.c (1)

959-965: Inconsistent error handling for unsupported value_field types.

When value_field is configured and present in the record, the error handling is inconsistent:

  • Non-numeric string (sscanf fails, line 948): falls back to increment by 1 ✓
  • Negative value (line 974): falls back to increment by 1 ✓
  • Unsupported type (line 964): breaks without incrementing ✗

For consistency, unsupported types (BOOL, ARRAY, MAP, etc.) should also fall back to increment by 1 rather than silently skipping the record. This would make error handling uniform and ensure counters are always updated even when value_field contains unexpected data.

🔎 Proposed fix to add fallback for unsupported types
                        else {
                            flb_plg_error(f_ins,
-                                        "cannot convert given value to metric");
+                                        "cannot convert given value to metric, falling back to increment by 1");
                            flb_ra_key_value_destroy(rval);
                            rval = NULL;
+                           ret = cmt_counter_inc(ctx->c, ts, label_count,
+                                           label_values);
                            break;
                        }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28a907c and 1c89b61.

📒 Files selected for processing (1)
  • plugins/filter_log_to_metrics/log_to_metrics.c
🧰 Additional context used
🧬 Code graph analysis (1)
plugins/filter_log_to_metrics/log_to_metrics.c (3)
src/flb_record_accessor.c (2)
  • flb_ra_create (271-358)
  • flb_ra_get_value_object (803-814)
lib/cmetrics/src/cmt_counter.c (2)
  • cmt_counter_inc (100-117)
  • cmt_counter_add (119-135)
src/flb_ra_key.c (1)
  • flb_ra_key_value_destroy (842-851)
🔇 Additional comments (2)
plugins/filter_log_to_metrics/log_to_metrics.c (2)

646-675: Initialization logic correctly implements optional value_field for counters.

The distinction between required (gauge/histogram) and optional (counter) value_field is clearly implemented. Error handling for accessor creation failures is appropriate in both branches.


1133-1133: Config description accurately reflects the new behavior.

The updated description clearly communicates that value_field is required for gauge/histogram but optional for counter mode.

@Lusitaniae Lusitaniae force-pushed the feature/counter_value_field branch from 1c89b61 to 7579b62 Compare January 6, 2026 06:16
@Lusitaniae Lusitaniae force-pushed the feature/counter_value_field branch from 7579b62 to 07039bc Compare January 6, 2026 06:19
@Lusitaniae
Copy link
Author

Our commit linter complains like:

❌ Commit 84cad53d73 failed:
Missing prefix in commit subject: 'add handling for negative/missing values'

❌ Commit a8c83d8843 failed:
Missing prefix in commit subject: 'allow counter metrics to use value_field instead of increment by 1 only'

So, we need to use filter_log_to_metrics: prefix in each of your commits.

Force pushed to address that

@Lusitaniae Lusitaniae requested a review from cosmo0920 January 6, 2026 06:21
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.

log_to_metrics counters should support value_field

2 participants