-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
When executing the following command from CLI:
chalice logs --since 1h
all logs stored in AWS for the log group name are displayed instead of only the log messages stored in the last hour. So when passing --since on its own, its not respected.
But --since is respected when passing --follow as well:
chalice logs --since 1h --follow
The above works. The last hours worth of logs are returned and displayed.
At a glance, it looks like the issue is located within chalice.awsclient.py.TypedAWSClient.iter_log_events
start_time is being passed as an arg to the method:
def iter_log_events(
self,
log_group_name: str,
start_time: Optional[datetime] = None,
interleaved: bool = True,
) -> Iterator[CWLogEvent]:
. . .
but its presence is not being detected, converted via botocore.utils.datetime2timestamp and passed as an argument to the paginator.
As a quick test, something like this seems to work for me:
def iter_log_events(
self,
log_group_name: str,
start_time: Optional[datetime] = None,
interleaved: bool = True,
) -> Iterator[CWLogEvent]:
logs = self._client('logs')
paginator = logs.get_paginator('filter_log_events')
# WORKS FOR ME:
if start_time is not None:
start_time = int(datetime2timestamp(start_time) * 1000)
pages = paginator.paginate(
logGroupName=log_group_name,
interleaved=True,
startTime=start_time
)
else:
pages = paginator.paginate(
logGroupName=log_group_name, interleaved=True
)
# END OF QUICK FIX
try:
yield from self._iter_log_messages(pages)
except logs.exceptions.ResourceNotFoundException:
# If the lambda function exists but has not been invoked yet,
# it's possible that the log group does not exist and we'll get
# a ResourceNotFoundException. If this happens we return instead
# of propagating an exception back to the user.
pass
Or maybe LogEventGenerator.iter_log_events should use TypedAWSClient.filter_log_events instead of TypedAWSClient.iter_log_events, like FollowLogEventGenerator.iter_log_events seems to?
I'm not sure. I only briefly looked at the codebase, so I may be wrong in the fix. In any case, it would be nice if this could be fixed. :-)