-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
out_cloudwatch_logs: Only create log group if it does not already exist #4826
Conversation
Now, if the group already exists, it won't even try to create it, it just creates the stream
However, if stream creation fails on the group not existing, then we try to create it:
This reduces unnecessary calls to CreateLogGroup API. If auto_create_group is disabled, the user gets a useful warning:
|
return -1; | ||
} else { | ||
/* retry stream creation */ | ||
goto retry_create_stream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a retry limit? This could be an infinite loop if the resource continues to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the advantage of using goto statement here vs return create_log_stream(ctx, stream);
? Is it for efficiency so the function stack doesn't need to be reinitialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the second comment... the goto is just because I didn't think of making it recursive... can change it
For the infinite loop... can it? Because the call to create_stream only happens again if the CreateLogGroup succeeds but then create stream again fails with the resource not found exception. Which shouldn't be able to happen repeatedly.
The algo is:
- Try to create stream.
- If stream fails because group doesn't exist, then create the group. Otherwise, goto 4.
- If group creation succeeds, goto 1. Otherwise, goto 4.
- Exit
I think it can't be infinite unless I guess the CW API has a bug where it continually returns the same failure incorrectly... I could add a bool to make sure we only try once. But I'm not sure its necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the call to create_stream only happens again if the CreateLogGroup succeeds but then create stream again fails with the resource not found exception. Which shouldn't be able to happen repeatedly.
Just a suggestion - I think it might be better to add a bool here so that we are sure that the creation won't happen again and again. It might be very low possibility but just in case.
return -1; | ||
} else { | ||
/* retry stream creation */ | ||
goto retry_create_stream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Makes sense.
return -1; | ||
} else { | ||
/* retry stream creation */ | ||
goto retry_create_stream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the call to create_stream only happens again if the CreateLogGroup succeeds but then create stream again fails with the resource not found exception. Which shouldn't be able to happen repeatedly.
Just a suggestion - I think it might be better to add a bool here so that we are sure that the creation won't happen again and again. It might be very low possibility but just in case.
632914b
to
2860afe
Compare
@zhonghui12 @matthewfala Addressed comments. |
@@ -391,14 +391,8 @@ static void cb_cloudwatch_flush(const void *data, size_t bytes, | |||
|
|||
ctx->buf->put_events_calls = 0; | |||
|
|||
if (ctx->create_group == FLB_TRUE && ctx->group_created == FLB_FALSE) { | |||
ret = create_log_group(ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ret
unused now. Causing tests to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Great! That looks good. |
2860afe
to
14e7110
Compare
…st to prevent throttling Signed-off-by: Wesley Pettit <wppttt@amazon.com>
14e7110
to
152fe58
Compare
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
Signed-off-by: Wesley Pettit wppttt@amazon.com
Enter
[N/A]
in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.