aws / amazon-cloudwatch-logs-for-fluent-bit

A Fluent Bit output plugin for CloudWatch Logs
Apache License 2.0
174 stars 49 forks source link

Add auto_create_stream #257

Closed usamj closed 2 years ago

usamj commented 2 years ago

Issue #, if available:

Description of changes:

This change:

Testing: auto_create_stream false

auto_create_stream true

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Bug explained

The bug that was discovered causes the plugin to not make progress when a user deletes and creates a stream. This bug was existent before the changes but was just noticed more easily due to streams not being auto created.

When this delete + create happens the plugin will use an incorrect (old) sequenceToken and will get a InvalidSequenceTokenException. It attempts to recover from this by fetching the token from the error message by parsing the next token from the error message. With a new stream no sequence token is expected and the parsing from the error message fails. To fix we detect if it is a new stream and use nil nextSequenceToken insted.

Error for normal sequence token error: An error occurred (InvalidSequenceTokenException) when calling the PutLogEvents operation: The given sequenceToken is invalid. The next expected sequenceToken is: 49621219915356076984497278709410931028996559626100016802

Error for new stream sequence token error: An error occurred (InvalidSequenceTokenException) when calling the PutLogEvents operation: The given sequenceToken is invalid. The next expected sequenceToken is: null