Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: output: Add metrics for displaying the available capacity of chunks as percent #8063

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/fluent-bit/flb_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ struct flb_output_instance {
struct cmt_gauge *cmt_upstream_total_connections;
/* m: output_upstream_busy_connections */
struct cmt_gauge *cmt_upstream_busy_connections;
/* m: output_chunk_available_capacity_percent */
struct cmt_gauge *cmt_chunk_available_capacity_percent;

/* OLD Metrics API */
#ifdef FLB_HAVE_METRICS
Expand Down
30 changes: 30 additions & 0 deletions src/flb_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ static inline int handle_input_event(flb_pipefd_t fd, uint64_t ts,
return 0;
}

static inline double calculate_chunk_capacity_percent(struct flb_output_instance *ins)
{
if (ins->total_limit_size == -1) {
Copy link
Member

Choose a reason for hiding this comment

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

is there a chance that total_limit_size == 0 ? (if so, it will breaks in the next part of the code)

Copy link
Contributor Author

@cosmo0920 cosmo0920 Dec 20, 2023

Choose a reason for hiding this comment

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

There is no chance to become total_limit_size == 0 due to these lines fill out -1 value into limit in this case:
https://github.com/fluent/fluent-bit/blob/master/src/flb_output.c#L907-L915
But your suggestion is really reasonable. So, I changed the clause to check zero or lower.

return 100.0;
}

return 100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size));
}

static inline int handle_output_event(uint64_t ts,
struct flb_config *config,
uint64_t val)
Expand Down Expand Up @@ -312,6 +322,10 @@ static inline int handle_output_event(uint64_t ts,
flb_output_name(ins), out_id);
}

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

flb_task_retry_clean(task, ins);
flb_task_users_dec(task, FLB_TRUE);
}
Expand All @@ -321,6 +335,10 @@ static inline int handle_output_event(uint64_t ts,
cmt_counter_add(ins->cmt_dropped_records, ts, task->records,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_DROPPED_RECORDS, task->records, ins->metrics);
Expand Down Expand Up @@ -353,6 +371,10 @@ static inline int handle_output_event(uint64_t ts,
cmt_counter_add(ins->cmt_dropped_records, ts, task->records,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_RETRY_FAILED, 1, ins->metrics);
Expand Down Expand Up @@ -409,6 +431,10 @@ static inline int handle_output_event(uint64_t ts,
cmt_counter_add(ins->cmt_retried_records, ts, task->records,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API: update the metrics since a new retry is coming */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_RETRY, 1, ins->metrics);
Expand All @@ -422,6 +448,10 @@ static inline int handle_output_event(uint64_t ts,
cmt_counter_add(ins->cmt_dropped_records, ts, task->records,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD API */
#ifdef FLB_HAVE_METRICS
flb_metrics_sum(FLB_METRIC_OUT_ERROR, 1, ins->metrics);
Expand Down
12 changes: 12 additions & 0 deletions src/flb_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,18 @@ int flb_output_init_all(struct flb_config *config)
0,
1, (char *[]) {name});

/* output_chunk_available_capacity_percent */
ins->cmt_chunk_available_capacity_percent = cmt_gauge_create(ins->cmt,
"fluentbit",
"output",
"chunk_available_capacity_percent",
"Available chunk capacity (percent)",
1, (char *[]) {"name"});
cmt_gauge_set(ins->cmt_chunk_available_capacity_percent,
ts,
100.0,
1, (char *[]) {name});

/* old API */
ins->metrics = flb_metrics_create(name);
if (ins->metrics) {
Expand Down
Loading