Skip to content
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

Update empty message filtering to catch formatted string case #162

Merged
merged 1 commit into from
Nov 29, 2021

Conversation

o-nikolas
Copy link
Contributor

Overview

  • Empty message filtering added in 2.0 does not catch the edge case
    where the empty message is delivered as a formatted string (see repro example below).

  • Update tests to catch future regressions of this case

  • Update .gitignore to ignore the coverage file created by make tests


repro

from watchtower import CloudWatchLogHandler
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.addHandler(CloudWatchLogHandler(log_group='test_empty_msg_json',
                                                  use_queues=True))

logger.info("foo")
logger.info("%s", '')
logger.info("bar")

Running the above script yields this failure, where the empty message fails cloudwatch local validation and the whole batch of logs are not emitted to cloudwatch:

INFO:botocore.credentials:Found credentials in shared credentials file: ~/.aws/credentials
INFO:__main__:foo
INFO:__main__:
INFO:__main__:bar
/home/ANT.AMAZON.COM/onikolas/code/oss/watchtower/o-nikolas_watchtower/watchtower/watchtower.py:330: WatchtowerWarning: Failed to deliver logs: Parameter validation failed:
Invalid length for parameter logEvents[1].message, value: 0, valid min length: 1
  warnings.warn("Failed to deliver logs: {}".format(e), WatchtowerWarning)
/home/ANT.AMAZON.COM/onikolas/code/oss/watchtower/o-nikolas_watchtower/watchtower/watchtower.py:334: WatchtowerWarning: Failed to deliver logs: None
  warnings.warn("Failed to deliver logs: {}".format(response), WatchtowerWarning)

Running with the changes in this PR yields the expected behaviour of just emitting the warning for empty messages, but the other two valid messages are still sent to cloudwatch:

INFO:botocore.credentials:Found credentials in shared credentials file: ~/.aws/credentials
INFO:__main__:foo
/home/ANT.AMAZON.COM/onikolas/code/oss/watchtower/o-nikolas_watchtower/watchtower/watchtower.py:349: WatchtowerWarning: Received empty message. Empty messages cannot be sent to CloudWatch Logs
  warnings.warn("Received empty message. Empty messages cannot be sent to CloudWatch Logs", WatchtowerWarning)
INFO:__main__:
INFO:__main__:bar

- Empty message filtering added in 2.0 does not catch the edge case
where the empty message is delivered as a formatted string.

- Update tests to catch future regressions of this case

- Update .gitignore to ignore the coverage file created by make tests
@kislyuk
Copy link
Owner

kislyuk commented Nov 29, 2021

Thanks for your contribution @o-nikolas. Will cut a release shortly.

@kislyuk
Copy link
Owner

kislyuk commented Nov 29, 2021

Released in v2.0.1.

@o-nikolas
Copy link
Contributor Author

Thanks Andrey, I appreciate your ongoing support for this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants