Skip to content

Commit 71a0233

Browse files
committed
filter: initialize cmetrics to zero
Upon initialization, metrics are created to handle generic counters, but since these are not initialized with a proper value with the required label (instance name), the metric is not exposed until the value is updated. Most of the cases the end-user would prefer to see a metric with value zero than skip it. This patch adds the initialization to change the default behavior, now all filter metrics registered shows zero when they are exposed. Signed-off-by: Eduardo Silva <[email protected]>
1 parent 264e436 commit 71a0233

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/flb_filter.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ const char *flb_filter_name(struct flb_filter_instance *ins)
372372
int flb_filter_init_all(struct flb_config *config)
373373
{
374374
int ret;
375+
uint64_t ts;
375376
char *name;
376377
struct mk_list *tmp;
377378
struct mk_list *head;
@@ -401,6 +402,7 @@ int flb_filter_init_all(struct flb_config *config)
401402

402403
/* Get name or alias for the instance */
403404
name = (char *) flb_filter_name(ins);
405+
ts = cmt_time_now();
404406

405407
/* CMetrics */
406408
ins->cmt = cmt_create();
@@ -416,13 +418,16 @@ int flb_filter_init_all(struct flb_config *config)
416418
"add_records_total",
417419
"Total number of new added records.",
418420
1, (char *[]) {"name"});
421+
cmt_counter_set(ins->cmt_add_records, ts, 0, 1, (char *[]) {name});
419422

420423
/* Register generic filter plugin metrics */
421424
ins->cmt_drop_records = cmt_counter_create(ins->cmt,
422425
"fluentbit", "filter",
423426
"drop_records_total",
424427
"Total number of dropped records.",
425428
1, (char *[]) {"name"});
429+
cmt_counter_set(ins->cmt_drop_records, ts, 0, 1, (char *[]) {name});
430+
426431
/* OLD Metrics API */
427432
#ifdef FLB_HAVE_METRICS
428433

0 commit comments

Comments
 (0)