Skip to content

Commit

Permalink
out_cloudwatch_logs: alloc event buffer to max size in init
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
  • Loading branch information
PettitWesley authored and edsiper committed Jul 6, 2020
1 parent df19684 commit 7654ee6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
15 changes: 0 additions & 15 deletions plugins/out_cloudwatch_logs/cloudwatch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,6 @@ int add_event(struct flb_cloudwatch *ctx, struct cw_flush *buf,
{
int ret;
struct cw_event *event;
int new_len;
size_t size;
int retry_add = FLB_FALSE;
int event_bytes = 0;

Expand All @@ -531,19 +529,6 @@ int add_event(struct flb_cloudwatch *ctx, struct cw_flush *buf,
reset_flush_buf(ctx, buf, stream);
}

/* re-alloc event buffer if needed */
if ((buf->event_index + 1) >= buf->events_capacity) {
new_len = MAX_EVENTS_PER_PUT;
size = sizeof(struct cw_event) * new_len;
flb_plg_debug(ctx->ins, "Increasing event buffer to %d", new_len);
buf->events = flb_realloc(buf->events, size);
if (!buf->events) {
flb_errno();
return -1;
}
buf->events_capacity = new_len;
}

retry_add_event:
ret = process_event(ctx, buf, obj, tms);
if (ret < 0) {
Expand Down
4 changes: 2 additions & 2 deletions plugins/out_cloudwatch_logs/cloudwatch_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ static int cb_cloudwatch_init(struct flb_output_instance *ins,
}
buf->tmp_buf_size = PUT_LOG_EVENTS_PAYLOAD_SIZE;

buf->events = flb_malloc(sizeof(struct cw_event) * 1000);
buf->events = flb_malloc(sizeof(struct cw_event) * MAX_EVENTS_PER_PUT);
if (!buf->events) {
flb_errno();
cw_flush_destroy(buf);
goto error;
}
buf->events_capacity = 1000;
buf->events_capacity = MAX_EVENTS_PER_PUT;

ctx->buf = buf;

Expand Down

0 comments on commit 7654ee6

Please sign in to comment.