Skip to content

Commit f4108db

Browse files
usharmaedsiper
authored andcommitted
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 <[email protected]> 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 <[email protected]> out_s3: fix infinite retry_limit in cb_s3_init Fixes the infinite retry limit to MAX_UPLOAD_ERRORS(old behaviour) in cb_s3_init. If negative retry limit is set, the retry limit is set to MAX_UPLOAD_ERRORS Signed-off-by: usharma <[email protected]> out_s3: fix infinite retry_limit in cb_s3_init Fixes the infinite retry limit to MAX_UPLOAD_ERRORS(old behaviour) in cb_s3_init. If negative retry limit is set, the retry limit is set to MAX_UPLOAD_ERRORS Signed-off-by: usharma <[email protected]>
1 parent 0e56bc2 commit f4108db

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

plugins/out_s3/s3.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,10 @@ static int cb_s3_init(struct flb_output_instance *ins,
617617
ctx->retry_time = 0;
618618
ctx->upload_queue_success = FLB_FALSE;
619619

620+
if(ctx->ins->retry_limit < 0) {
621+
ctx->ins->retry_limit = MAX_UPLOAD_ERRORS;
622+
}
623+
620624
/* Export context */
621625
flb_output_set_context(ins, ctx);
622626

@@ -1367,11 +1371,10 @@ static int put_all_chunks(struct flb_s3 *ctx)
13671371
continue;
13681372
}
13691373

1370-
if (chunk->failures >= MAX_UPLOAD_ERRORS) {
1374+
if (chunk->failures >= ctx->ins->retry_limit) {
13711375
flb_plg_warn(ctx->ins,
1372-
"Chunk for tag %s failed to send %i times, "
1373-
"will not retry",
1374-
(char *) fsf->meta_buf, MAX_UPLOAD_ERRORS);
1376+
"Chunk for tag %s failed to send %d/%d times, will not retry",
1377+
(char *) fsf->meta_buf, chunk->failures, ctx->ins->retry_limit);
13751378
flb_fstore_file_inactive(ctx->fs, fsf);
13761379
continue;
13771380
}
@@ -1656,7 +1659,7 @@ static struct multipart_upload *get_upload(struct flb_s3 *ctx,
16561659
if (tmp_upload->upload_state == MULTIPART_UPLOAD_STATE_COMPLETE_IN_PROGRESS) {
16571660
continue;
16581661
}
1659-
if (tmp_upload->upload_errors >= MAX_UPLOAD_ERRORS) {
1662+
if (tmp_upload->upload_errors >= ctx->ins->retry_limit) {
16601663
tmp_upload->upload_state = MULTIPART_UPLOAD_STATE_COMPLETE_IN_PROGRESS;
16611664
flb_plg_error(ctx->ins, "Upload for %s has reached max upload errors",
16621665
tmp_upload->s3_key);
@@ -1902,7 +1905,7 @@ static void s3_upload_queue(struct flb_config *config, void *out_context)
19021905

19031906
/* If retry limit was reached, discard file and remove file from queue */
19041907
upload_contents->retry_counter++;
1905-
if (upload_contents->retry_counter >= MAX_UPLOAD_ERRORS) {
1908+
if (upload_contents->retry_counter >= ctx->ins->retry_limit) {
19061909
flb_plg_warn(ctx->ins, "Chunk file failed to send %d times, will not "
19071910
"retry", upload_contents->retry_counter);
19081911
s3_store_file_inactive(ctx, upload_contents->upload_file);
@@ -3303,6 +3306,13 @@ static void cb_s3_upload(struct flb_config *config, void *data)
33033306
if (ret != FLB_OK) {
33043307
flb_plg_error(ctx->ins, "Could not send chunk with tag %s",
33053308
(char *) fsf->meta_buf);
3309+
if(chunk->failures >= ctx->ins->retry_limit){
3310+
flb_plg_warn(ctx->ins,
3311+
"Chunk for tag %s failed to send %d/%d times, will not retry",
3312+
(char *) fsf->meta_buf, chunk->failures, ctx->ins->retry_limit);
3313+
flb_fstore_file_inactive(ctx->fs, fsf);
3314+
continue;
3315+
}
33063316
}
33073317
}
33083318

@@ -3311,7 +3321,7 @@ static void cb_s3_upload(struct flb_config *config, void *data)
33113321
m_upload = mk_list_entry(head, struct multipart_upload, _head);
33123322
complete = FLB_FALSE;
33133323

3314-
if (m_upload->complete_errors >= MAX_UPLOAD_ERRORS) {
3324+
if (m_upload->complete_errors >= ctx->ins->retry_limit) {
33153325
flb_plg_error(ctx->ins,
33163326
"Upload for %s has reached max completion errors, "
33173327
"plugin will give up", m_upload->s3_key);
@@ -3823,10 +3833,10 @@ static void cb_s3_flush(struct flb_event_chunk *event_chunk,
38233833
m_upload_file, file_first_log_time);
38243834
}
38253835

3826-
/* Discard upload_file if it has failed to upload MAX_UPLOAD_ERRORS times */
3827-
if (upload_file != NULL && upload_file->failures >= MAX_UPLOAD_ERRORS) {
3828-
flb_plg_warn(ctx->ins, "File with tag %s failed to send %d times, will not "
3829-
"retry", event_chunk->tag, MAX_UPLOAD_ERRORS);
3836+
/* Discard upload_file if it has failed to upload retry_limit times */
3837+
if (upload_file != NULL && upload_file->failures >= ctx->ins->retry_limit) {
3838+
flb_plg_warn(ctx->ins, "File with tag %s failed to send %d/%d times, will not retry",
3839+
event_chunk->tag, upload_file->failures, ctx->ins->retry_limit);
38303840
s3_store_file_inactive(ctx, upload_file);
38313841
upload_file = NULL;
38323842
}

plugins/out_s3/s3.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848

4949
#define DEFAULT_UPLOAD_TIMEOUT 3600
5050

51+
#define MAX_UPLOAD_ERRORS 5
52+
5153
/*
5254
* If we see repeated errors on an upload/chunk, we will discard it
5355
* This saves us from scenarios where something goes wrong and an upload can
@@ -56,8 +58,9 @@
5658
*
5759
* The same is done for chunks, just to be safe, even though realistically
5860
* I can't think of a reason why a chunk could become unsendable.
61+
*
62+
* The retry limit is now configurable via the retry_limit parameter.
5963
*/
60-
#define MAX_UPLOAD_ERRORS 5
6164

6265
struct upload_queue {
6366
struct s3_file *upload_file;
@@ -96,7 +99,7 @@ struct multipart_upload {
9699

97100
struct mk_list _head;
98101

99-
/* see note for MAX_UPLOAD_ERRORS */
102+
/* see note for retry_limit configuration */
100103
int upload_errors;
101104
int complete_errors;
102105
};

0 commit comments

Comments
 (0)