Skip to content

Commit 34b1f76

Browse files
committed
task: account metrics for dropped events
Signed-off-by: Eduardo Silva <[email protected]>
1 parent b6fcaab commit 34b1f76

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/flb_task.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <fluent-bit/flb_mem.h>
3232
#include <fluent-bit/flb_str.h>
3333
#include <fluent-bit/flb_scheduler.h>
34+
#include <fluent-bit/flb_time.h>
35+
#ifdef FLB_HAVE_METRICS
36+
#include <fluent-bit/flb_metrics.h>
37+
#endif
3438
#include <string.h>
3539

3640
/*
@@ -73,6 +77,60 @@ static inline void map_free_task_id(int id, struct flb_config *config)
7377
config->task_map[id].task = NULL;
7478
}
7579

80+
#ifdef FLB_HAVE_METRICS
81+
static void record_unmatched_route_drop_metrics(struct flb_input_instance *ins,
82+
struct flb_input_chunk *ic,
83+
size_t chunk_size)
84+
{
85+
struct flb_router *router;
86+
uint64_t now;
87+
double dropped_bytes;
88+
char *labels[2];
89+
90+
if (!ins || !ic || !ins->config) {
91+
return;
92+
}
93+
94+
if (ic->event_type != FLB_INPUT_LOGS || ic->total_records <= 0) {
95+
return;
96+
}
97+
98+
router = ins->config->router;
99+
if (!router) {
100+
return;
101+
}
102+
103+
now = cfl_time_now();
104+
labels[0] = (char *) flb_input_name(ins);
105+
labels[1] = "unmatched";
106+
107+
dropped_bytes = (double) chunk_size;
108+
if (dropped_bytes <= 0) {
109+
ssize_t real_size;
110+
111+
real_size = flb_input_chunk_get_real_size(ic);
112+
if (real_size > 0) {
113+
dropped_bytes = (double) real_size;
114+
}
115+
else {
116+
dropped_bytes = 0;
117+
}
118+
}
119+
120+
cmt_counter_add(router->logs_drop_records_total,
121+
now,
122+
(double) ic->total_records,
123+
2,
124+
labels);
125+
126+
cmt_counter_add(router->logs_drop_bytes_total,
127+
now,
128+
dropped_bytes,
129+
2,
130+
labels);
131+
}
132+
#endif
133+
76134
static int task_collect_output_references(struct flb_config *config,
77135
const struct flb_chunk_direct_route *route,
78136
struct flb_output_instance ***out_matches,
@@ -806,6 +864,9 @@ struct flb_task *flb_task_create(uint64_t ref_id,
806864

807865
/* no destinations ?, useless task. */
808866
if (count == 0) {
867+
#ifdef FLB_HAVE_METRICS
868+
record_unmatched_route_drop_metrics(i_ins, task_ic, size);
869+
#endif
809870
flb_debug("[task] created task=%p id=%i without routes, dropping.",
810871
task, task->id);
811872
if (router_context_initialized) {

0 commit comments

Comments
 (0)