From 0ca2ff6159ebc677b9200f02a863bc0c58709012 Mon Sep 17 00:00:00 2001 From: usharma Date: Wed, 3 Sep 2025 21:22:49 +0530 Subject: [PATCH 1/2] out_s3: implement retry_limit parameter retry_limit parameter is not honored and is set to 5. This feature provides dynamic retry_limit based on configuration for out_s3 plugin. Signed-off-by: usharma --- plugins/out_s3/s3.c | 32 ++++++++++++++++++++++++-------- plugins/out_s3/s3.h | 6 ++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index d9d25f187b1..bbc23383f59 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -1336,11 +1336,11 @@ static int put_all_chunks(struct flb_s3 *ctx) continue; } - if (chunk->failures >= MAX_UPLOAD_ERRORS) { + if (chunk->failures >= ctx->ins->retry_limit) { flb_plg_warn(ctx->ins, "Chunk for tag %s failed to send %i times, " "will not retry", - (char *) fsf->meta_buf, MAX_UPLOAD_ERRORS); + (char *) fsf->meta_buf, ctx->ins->retry_limit); flb_fstore_file_inactive(ctx->fs, fsf); continue; } @@ -1625,7 +1625,7 @@ static struct multipart_upload *get_upload(struct flb_s3 *ctx, if (tmp_upload->upload_state == MULTIPART_UPLOAD_STATE_COMPLETE_IN_PROGRESS) { continue; } - if (tmp_upload->upload_errors >= MAX_UPLOAD_ERRORS) { + if (tmp_upload->upload_errors >= ctx->ins->retry_limit) { tmp_upload->upload_state = MULTIPART_UPLOAD_STATE_COMPLETE_IN_PROGRESS; flb_plg_error(ctx->ins, "Upload for %s has reached max upload errors", tmp_upload->s3_key); @@ -1871,7 +1871,7 @@ static void s3_upload_queue(struct flb_config *config, void *out_context) /* If retry limit was reached, discard file and remove file from queue */ upload_contents->retry_counter++; - if (upload_contents->retry_counter >= MAX_UPLOAD_ERRORS) { + if (upload_contents->retry_counter >= ctx->ins->retry_limit) { flb_plg_warn(ctx->ins, "Chunk file failed to send %d times, will not " "retry", upload_contents->retry_counter); s3_store_file_inactive(ctx, upload_contents->upload_file); @@ -3272,6 +3272,14 @@ static void cb_s3_upload(struct flb_config *config, void *data) if (ret != FLB_OK) { flb_plg_error(ctx->ins, "Could not send chunk with tag %s", (char *) fsf->meta_buf); + if(chunk->failures >= ctx->ins->retry_limit){ + flb_plg_warn(ctx->ins, + "Chunk for tag %s failed to send %i times, " + "will not retry", + (char *) fsf->meta_buf, ctx->ins->retry_limit); + flb_fstore_file_inactive(ctx->fs, fsf); + continue; + } } } @@ -3280,7 +3288,7 @@ static void cb_s3_upload(struct flb_config *config, void *data) m_upload = mk_list_entry(head, struct multipart_upload, _head); complete = FLB_FALSE; - if (m_upload->complete_errors >= MAX_UPLOAD_ERRORS) { + if (m_upload->complete_errors >= ctx->ins->retry_limit) { flb_plg_error(ctx->ins, "Upload for %s has reached max completion errors, " "plugin will give up", m_upload->s3_key); @@ -3789,10 +3797,10 @@ static void cb_s3_flush(struct flb_event_chunk *event_chunk, m_upload_file, file_first_log_time); } - /* Discard upload_file if it has failed to upload MAX_UPLOAD_ERRORS times */ - if (upload_file != NULL && upload_file->failures >= MAX_UPLOAD_ERRORS) { + /* Discard upload_file if it has failed to upload retry_limit times */ + if (upload_file != NULL && upload_file->failures >= ctx->ins->retry_limit) { flb_plg_warn(ctx->ins, "File with tag %s failed to send %d times, will not " - "retry", event_chunk->tag, MAX_UPLOAD_ERRORS); + "retry", event_chunk->tag, ctx->ins->retry_limit); s3_store_file_inactive(ctx, upload_file); upload_file = NULL; } @@ -4140,6 +4148,14 @@ static struct flb_config_map config_map[] = { "File part delivery attempt limit" }, + { + FLB_CONFIG_MAP_INT, "retry_limit", "5", + 0, FLB_TRUE, offsetof(struct flb_s3, retry_limit), + "Maximum number of retry attempts for failed uploads/chunks. " + "If we see repeated errors on an upload/chunk, we will discard it " + "after this many attempts to prevent infinite retry loops." + }, + { FLB_CONFIG_MAP_TIME, "upload_parts_timeout", "10M", 0, FLB_TRUE, offsetof(struct flb_s3, upload_parts_timeout), diff --git a/plugins/out_s3/s3.h b/plugins/out_s3/s3.h index d1004fcfec2..74fae5c5ebd 100644 --- a/plugins/out_s3/s3.h +++ b/plugins/out_s3/s3.h @@ -56,8 +56,9 @@ * * The same is done for chunks, just to be safe, even though realistically * I can't think of a reason why a chunk could become unsendable. + * + * The retry limit is now configurable via the retry_limit parameter. */ -#define MAX_UPLOAD_ERRORS 5 struct upload_queue { struct s3_file *upload_file; @@ -96,7 +97,7 @@ struct multipart_upload { struct mk_list _head; - /* see note for MAX_UPLOAD_ERRORS */ + /* see note for retry_limit configuration */ int upload_errors; int complete_errors; }; @@ -131,6 +132,7 @@ struct flb_s3 { time_t upload_parts_freshness_threshold; int file_delivery_attempt_limit; int part_delivery_attempt_limit; + int retry_limit; flb_sds_t authorization_endpoint_url; flb_sds_t authorization_endpoint_username; flb_sds_t authorization_endpoint_password; From b6b73dad1382d0fb869a861b6708e8f094c414cf Mon Sep 17 00:00:00 2001 From: usharma Date: Thu, 4 Sep 2025 18:00:18 +0530 Subject: [PATCH 2/2] out_s3: fix retry_limit as it is part of default instance Fixed the retry_limit as it was not needed and it part of default instance Signed-off-by: usharma --- plugins/out_s3/s3.c | 8 -------- plugins/out_s3/s3.h | 1 - 2 files changed, 9 deletions(-) diff --git a/plugins/out_s3/s3.c b/plugins/out_s3/s3.c index bbc23383f59..59047ac3043 100644 --- a/plugins/out_s3/s3.c +++ b/plugins/out_s3/s3.c @@ -4148,14 +4148,6 @@ static struct flb_config_map config_map[] = { "File part delivery attempt limit" }, - { - FLB_CONFIG_MAP_INT, "retry_limit", "5", - 0, FLB_TRUE, offsetof(struct flb_s3, retry_limit), - "Maximum number of retry attempts for failed uploads/chunks. " - "If we see repeated errors on an upload/chunk, we will discard it " - "after this many attempts to prevent infinite retry loops." - }, - { FLB_CONFIG_MAP_TIME, "upload_parts_timeout", "10M", 0, FLB_TRUE, offsetof(struct flb_s3, upload_parts_timeout), diff --git a/plugins/out_s3/s3.h b/plugins/out_s3/s3.h index 74fae5c5ebd..601583102c8 100644 --- a/plugins/out_s3/s3.h +++ b/plugins/out_s3/s3.h @@ -132,7 +132,6 @@ struct flb_s3 { time_t upload_parts_freshness_threshold; int file_delivery_attempt_limit; int part_delivery_attempt_limit; - int retry_limit; flb_sds_t authorization_endpoint_url; flb_sds_t authorization_endpoint_username; flb_sds_t authorization_endpoint_password;