Skip to content

Commit 943639d

Browse files
committed
input_metric: drop metrics with empty data series
When ingesting a CMetrics context into the pipeline, it may contain metadata but no actual data points (e.g., counters, gauges, histograms). Such metrics should be dropped and not ingested. Signed-off-by: Eduardo Silva <[email protected]>
1 parent e65b7b9 commit 943639d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/flb_input_metric.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <fluent-bit/flb_input_chunk.h>
2323
#include <fluent-bit/flb_input_metric.h>
2424
#include <fluent-bit/flb_input_plugin.h>
25+
#include <cfl/cfl.h>
2526

2627
static int input_metrics_append(struct flb_input_instance *ins,
2728
size_t processor_starting_stage,
@@ -33,6 +34,7 @@ static int input_metrics_append(struct flb_input_instance *ins,
3334
size_t mt_size;
3435
int processor_is_active;
3536
struct cmt *out_context = NULL;
37+
struct cmt *encode_context;
3638

3739
processor_is_active = flb_processor_is_active(ins->processor);
3840
if (processor_is_active) {
@@ -60,29 +62,31 @@ static int input_metrics_append(struct flb_input_instance *ins,
6062
}
6163
}
6264

65+
if (out_context) {
66+
encode_context = out_context;
67+
}
68+
else {
69+
encode_context = cmt;
70+
}
6371

64-
if (out_context != NULL) {
65-
/* Convert metrics to msgpack */
66-
ret = cmt_encode_msgpack_create(out_context, &mt_buf, &mt_size);
67-
68-
if (out_context != cmt) {
72+
/* Drop the context if it contains no metrics */
73+
if (encode_context == NULL || flb_metrics_is_empty(encode_context)) {
74+
if (out_context && out_context != cmt) {
6975
cmt_destroy(out_context);
7076
}
77+
return 0;
78+
}
7179

72-
if (ret != 0) {
73-
flb_plg_error(ins, "could not encode metrics");
80+
/* Convert metrics to msgpack */
81+
ret = cmt_encode_msgpack_create(encode_context, &mt_buf, &mt_size);
7482

75-
return -1;
76-
}
83+
if (out_context && out_context != cmt) {
84+
cmt_destroy(out_context);
7785
}
78-
else {
79-
/* Convert metrics to msgpack */
80-
ret = cmt_encode_msgpack_create(cmt, &mt_buf, &mt_size);
81-
if (ret != 0) {
82-
flb_plg_error(ins, "could not encode metrics");
83-
return -1;
8486

85-
}
87+
if (ret != 0) {
88+
flb_plg_error(ins, "could not encode metrics");
89+
return -1;
8690
}
8791

8892
/* Append packed metrics */

0 commit comments

Comments
 (0)