From 1faa77ae95dfa23e05af0b4c6f2b97cb9524c8fc Mon Sep 17 00:00:00 2001 From: Gabi Davar Date: Sat, 12 Oct 2024 18:56:18 +0300 Subject: [PATCH] Fix 8729 Unexpected behavior for metrics after the migration to 3.0.1 * move metrics collections before applying filters. Signed-off-by: Gabi Davar --- src/flb_input_chunk.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/flb_input_chunk.c b/src/flb_input_chunk.c index 1e8a4a09d75..4797f07804a 100644 --- a/src/flb_input_chunk.c +++ b/src/flb_input_chunk.c @@ -1579,6 +1579,26 @@ static int input_chunk_append_raw(struct flb_input_instance *in, flb_chunk_trace_do_input(ic); #endif /* FLB_HAVE_CHUNK_TRACE */ + /* Update 'input' metrics */ +#ifdef FLB_HAVE_METRICS + if (ic->total_records > 0) { + /* timestamp */ + ts = cfl_time_now(); + + /* fluentbit_input_records_total */ + cmt_counter_add(in->cmt_records, ts, ic->added_records, + 1, (char *[]) {(char *) flb_input_name(in)}); + + /* fluentbit_input_bytes_total */ + cmt_counter_add(in->cmt_bytes, ts, buf_size, + 1, (char *[]) {(char *) flb_input_name(in)}); + + /* OLD api */ + flb_metrics_sum(FLB_METRIC_N_RECORDS, ic->added_records, in->metrics); + flb_metrics_sum(FLB_METRIC_N_BYTES, buf_size, in->metrics); + } +#endif + filtered_data_buffer = NULL; final_data_buffer = (char *) buf; final_data_size = buf_size; @@ -1619,26 +1639,6 @@ static int input_chunk_append_raw(struct flb_input_instance *in, ic->total_records = total_records_start; } - /* Update 'input' metrics */ -#ifdef FLB_HAVE_METRICS - if (ic->total_records > 0) { - /* timestamp */ - ts = cfl_time_now(); - - /* fluentbit_input_records_total */ - cmt_counter_add(in->cmt_records, ts, ic->added_records, - 1, (char *[]) {(char *) flb_input_name(in)}); - - /* fluentbit_input_bytes_total */ - cmt_counter_add(in->cmt_bytes, ts, buf_size, - 1, (char *[]) {(char *) flb_input_name(in)}); - - /* OLD api */ - flb_metrics_sum(FLB_METRIC_N_RECORDS, ic->added_records, in->metrics); - flb_metrics_sum(FLB_METRIC_N_BYTES, buf_size, in->metrics); - } -#endif - if (ret == -1) { flb_error("[input chunk] error writing data from %s instance", in->name);