Skip to content

Commit

Permalink
engine: Extract a function for calculating capacity of chunks
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 authored and edsiper committed Dec 20, 2023
1 parent b3f092b commit a8bffb2
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 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) {
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 @@ -313,8 +323,7 @@ static inline int handle_output_event(uint64_t ts,
}

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size))),
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

flb_task_retry_clean(task, ins);
Expand All @@ -327,8 +336,7 @@ static inline int handle_output_event(uint64_t ts,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size))),
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API */
Expand Down Expand Up @@ -364,8 +372,7 @@ static inline int handle_output_event(uint64_t ts,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size))),
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API */
Expand Down Expand Up @@ -425,8 +432,7 @@ static inline int handle_output_event(uint64_t ts,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size))),
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD metrics API: update the metrics since a new retry is coming */
Expand All @@ -443,8 +449,7 @@ static inline int handle_output_event(uint64_t ts,
1, (char *[]) {name});

cmt_gauge_set(ins->cmt_chunk_available_capacity_percent, ts,
(100 * (1.0 - (ins->fs_backlog_chunks_size + ins->fs_chunks_size)/
((double)ins->total_limit_size))),
calculate_chunk_capacity_percent(ins),
1, (char *[]) {name});

/* OLD API */
Expand Down

0 comments on commit a8bffb2

Please sign in to comment.