-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Reduce requests necessary for lambda log publishing to cloudwatch logs #10234
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
Conversation
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.
My only question mark is related to the behavior change that could potentially affect the logging order. If these logs get retrieved from CloudWatch with order_by timestamp
😬
Otherwise, LGTM 👍
logs = log_item.logs.splitlines() | ||
# until we have a better way to have timestamps, log events have the same time for a single invocation | ||
log_events = [ | ||
{"timestamp": int(time.time() * 1000), "message": log_line} for log_line in logs |
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.
Could that behavioral change mess up the log order in CloudWatch?
Compared to the previous heuristic:
simple heuristic: assume log lines were emitted in regular intervals
another reason to tackle structured logging and improved logging soon ...
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.
We will probably be fine, as it should not get reordered based on the timestamp in our codebase. Definitely something to look out for, and fix as soon as possible.
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.
😬 🤞
Not in our Python code, but it could happen when querying from sqlite with CloudWatch v2 🤷
For example in localstack/services/cloudwatch/cloudwatch_database_helper.py
, if we ScanBy.TimestampDescending
🙈
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.
I could increase it in 1ms intervals to be sure :)
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.
But reordering Events with the same timestamp would be a parity violation anyway, so not sure how much sense it makes.
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.
yeah, but we never had this parity
the closest we have to parity is event ordering (through some random heuristic)
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.
guess it doesn't matter too much if we fix it soonish 🔮
Motivation
We currently make 3 requests to CloudWatch logs for every lambda invocation:
CreateLogGroup
(will fail for all but the first invoke for that function)CreateLogStream
(will fail for all but the first invoke for that execution environment)PutLogEvents
We can drastically reduce the calls, and also load on the gateway, if we only execute the first two calls if
PutLogEvents
fails.If it fails, it equals to 4 calls (failed
PutLogEvents
, thenCreateLogGroup
, thenCreateLogStream
), but then only one call for every invocation (for the same environment) afterwards.Compared to 3 calls for every single invocation right now. There is also a lot of logic in
store_cloudwatch_logs
which is not necessary anymore with the new lambda provider.Changes