Skip to content

Revert "Reduce requests necessary for lambda log publishing to cloudwatch logs" #10294

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

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions localstack/services/lambda_/invocation/logs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import dataclasses
import logging
import threading
import time
from queue import Queue
from typing import Optional, Union

from localstack.aws.connect import connect_to
from localstack.utils.aws.client_types import ServicePrincipal
from localstack.utils.bootstrap import is_api_enabled
from localstack.utils.cloudwatch.cloudwatch_util import store_cloudwatch_logs
from localstack.utils.threads import FuncThread

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -50,32 +50,10 @@ def run_log_loop(self, *args, **kwargs) -> None:
log_item = self.log_queue.get()
if log_item is QUEUE_SHUTDOWN:
return
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
]
try:
try:
logs_client.put_log_events(
logGroupName=log_item.log_group,
logStreamName=log_item.log_stream,
logEvents=log_events,
)
except logs_client.exceptions.ResourceNotFoundException:
# create new log group
try:
logs_client.create_log_group(logGroupName=log_item.log_group)
except logs_client.exceptions.ResourceAlreadyExistsException:
pass
logs_client.create_log_stream(
logGroupName=log_item.log_group, logStreamName=log_item.log_stream
)
logs_client.put_log_events(
logGroupName=log_item.log_group,
logStreamName=log_item.log_stream,
logEvents=log_events,
)
store_cloudwatch_logs(
logs_client, log_item.log_group, log_item.log_stream, log_item.logs
)
except Exception as e:
LOG.warning(
"Error saving logs to group %s in region %s: %s",
Expand Down